Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
潘荣晟
2026-02-26 16:41:47 +08:00
8 changed files with 119 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
package com.zt.plat.module.base.controller.admin.base;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.base.controller.admin.base.vo.MasterDataSyncReqVO;
@@ -9,16 +10,23 @@ import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataSyncCommand;
import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataSyncReport;
import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataCategorySyncReport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import static com.zt.plat.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 主数据同步")
@@ -41,11 +49,15 @@ public class MasterDataSyncController {
return success(report);
}
@PostMapping("/categories")
@GetMapping("/categories")
@Operation(summary = "同步物料分类")
@PreAuthorize("@ss.hasPermission('base:master-data-sync:categories')")
public CommonResult<MasterDataCategorySyncReport> syncCategories() {
MasterDataCategorySyncReport report = masterDataCategorySyncService.syncAll();
@Parameters({
@Parameter(name = "since", description = "增量同步的起始记录时间", required = true)
})
public CommonResult<MasterDataCategorySyncReport> syncCategories(@RequestParam("since") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime since) {
MasterDataCategorySyncReport report = masterDataCategorySyncService.syncByAuditTime( since);
return success(report);
}
}

View File

@@ -4,7 +4,9 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.zt.plat.module.base.dal.dataobject.masterdata.MdmMaterialCategoryDO;
import com.zt.plat.module.base.framework.sync.constant.MasterDataSyncConstants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -18,4 +20,9 @@ public interface MdmMaterialCategoryMapper {
* 拉取全部分类档案。
*/
List<MdmMaterialCategoryDO> selectAll();
/**
* 查询分类档案,仅拉取审核时间时间大于指定时间段的数据审核通过数据
*/
List<MdmMaterialCategoryDO> selectByAuditTime(@Param("since") LocalDateTime since);
}

View File

@@ -0,0 +1,60 @@
package com.zt.plat.module.base.job;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.base.service.masterdatasync.MasterDataCategorySyncService;
import com.zt.plat.module.base.service.masterdatasync.MasterDataSyncService;
import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataCategorySyncReport;
import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataSyncCommand;
import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataSyncReport;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* 物料同步定时任务
* 2026/2/26 14:30
*/
@Component
@Slf4j
public class MasterDataSyncJob {
@Resource
private MasterDataSyncService masterDataSyncService;
@Resource
private MasterDataCategorySyncService masterDataCategorySyncService;
/**
* 同步物料数据(同步今天00:00:00 ~ 当前时间)
*/
@XxlJob("syncMasterData")
public void syncMasterData() {
log.info("[同步物料数据][开始执行]");
MasterDataSyncCommand command = new MasterDataSyncCommand();
command.setSince(LocalDateTimeUtil.beginOfDay(LocalDateTime.now()));
MasterDataSyncReport report = masterDataSyncService.sync(command);
if (report.isSuccess()) {
log.info("[同步物料数据][结束执行][成功]");
} else {
log.error("[同步物料数据][结束执行][失败]" + report.getMessage());
}
}
/**
* 同步物料分类(同步今天 00:00:00 ~ 当前时间 通过审核的数据)
*/
@XxlJob("syncCategories")
public void syncCategories() {
log.info("[同步物料分类][开始执行]");
MasterDataCategorySyncReport report = masterDataCategorySyncService.syncByAuditTime(LocalDateTimeUtil.beginOfDay(LocalDateTime.now()));
if (report.isSuccess()) {
log.info("[同步物料分类][结束执行][成功]");
} else {
log.error("[同步物料分类][结束执行][失败]" + report.getMessage());
}
}
}

View File

@@ -2,10 +2,14 @@ package com.zt.plat.module.base.service.masterdatasync;
import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataCategorySyncReport;
import java.time.LocalDateTime;
/**
* 物料分类同步服务接口。
*/
public interface MasterDataCategorySyncService {
MasterDataCategorySyncReport syncAll();
MasterDataCategorySyncReport syncByAuditTime(LocalDateTime since);
}

View File

@@ -14,6 +14,7 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashMap;
@@ -40,14 +41,28 @@ public class MasterDataCategorySyncServiceImpl implements MasterDataCategorySync
@Resource
private MasterDataSyncProperties properties;
@Override
public MasterDataCategorySyncReport syncAll() {
List<MdmMaterialCategoryDO> categories = mdmMaterialCategoryMapper.selectAll();
return doSync(categories);
}
@Override
public MasterDataCategorySyncReport syncByAuditTime(LocalDateTime since) {
if (since == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.MASTER_DATA_SYNC_SINCE_NULL);
}
List<MdmMaterialCategoryDO> categories = mdmMaterialCategoryMapper.selectByAuditTime(since);
return doSync(categories);
}
public MasterDataCategorySyncReport doSync(List<MdmMaterialCategoryDO> categories) {
if (!properties.isEnabled()) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.MASTER_DATA_SYNC_DISABLED);
}
MasterDataCategorySyncReport report = MasterDataCategorySyncReport.start();
try {
List<MdmMaterialCategoryDO> categories = mdmMaterialCategoryMapper.selectAll();
if (CollUtil.isEmpty(categories)) {
report.markSuccess();
return report;

View File

@@ -73,7 +73,7 @@ public class MasterDataSyncServiceImpl implements MasterDataSyncService {
if (!properties.isEnabled()) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.MASTER_DATA_SYNC_DISABLED);
}
if (command.getBatchSize() > 1000) {
if (command.getBatchSize() != null && command.getBatchSize() > 1000) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.MASTER_DATA_SYNC_BATCH_SIZE_TOO_LARGE, command.getBatchSize());
}
MasterDataSyncReport report = MasterDataSyncReport.start(command);

View File

@@ -14,4 +14,19 @@
ORDER BY CODE ASC
</select>
<select id="selectByAuditTime" resultType="com.zt.plat.module.base.dal.dataobject.masterdata.MdmMaterialCategoryDO">
SELECT
CODEID AS codeId,
CODE AS code,
DESC1 AS name,
DESC2 AS remark,
PARENTID AS parentCodeId
FROM mdm_wlfl_code
where AUDITFLAG = '2'
<if test="since != null">
AND recordtime &gt;= #{since}
</if>
ORDER BY CODE ASC
</select>
</mapper>