新增业务逻辑
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
package com.zt.plat.module.base.controller.admin.base;
|
||||||
|
|
||||||
|
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;
|
||||||
|
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.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.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
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.RestController;
|
||||||
|
|
||||||
|
import static com.zt.plat.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 主数据同步")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/base/master-data-sync")
|
||||||
|
@Validated
|
||||||
|
public class MasterDataSyncController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MasterDataSyncService masterDataSyncService;
|
||||||
|
@Resource
|
||||||
|
private MasterDataCategorySyncService masterDataCategorySyncService;
|
||||||
|
|
||||||
|
@PostMapping("/execute")
|
||||||
|
@Operation(summary = "执行主数据同步")
|
||||||
|
@PreAuthorize("@ss.hasPermission('base:master-data-sync:execute')")
|
||||||
|
public CommonResult<MasterDataSyncReport> execute(@Valid @RequestBody MasterDataSyncReqVO reqVO) {
|
||||||
|
MasterDataSyncCommand command = BeanUtils.toBean(reqVO, MasterDataSyncCommand.class);
|
||||||
|
MasterDataSyncReport report = masterDataSyncService.sync(command);
|
||||||
|
return success(report);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/categories")
|
||||||
|
@Operation(summary = "同步物料分类")
|
||||||
|
@PreAuthorize("@ss.hasPermission('base:master-data-sync:categories')")
|
||||||
|
public CommonResult<MasterDataCategorySyncReport> syncCategories() {
|
||||||
|
MasterDataCategorySyncReport report = masterDataCategorySyncService.syncAll();
|
||||||
|
return success(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.zt.plat.module.base.controller.admin.base.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.Positive;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "主数据同步请求参数")
|
||||||
|
public class MasterDataSyncReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "增量同步的起始记录时间,留空执行全量")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime since;
|
||||||
|
|
||||||
|
@Schema(description = "拉取批大小,不填写则使用配置默认值")
|
||||||
|
@Positive(message = "batchSize 必须为正数")
|
||||||
|
private Integer batchSize;
|
||||||
|
|
||||||
|
@Schema(description = "指定要刷新同步的物料编码列表")
|
||||||
|
private List<String> materialCodes;
|
||||||
|
|
||||||
|
@Schema(description = "可选的本次同步记录数上限,未填写表示不限制")
|
||||||
|
@Positive(message = "recordLimit 必须为正数")
|
||||||
|
private Long recordLimit;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.zt.plat.module.base.dal.dataobject.masterdata;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部 MDM 分类视图的数据对象。
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MdmMaterialCategoryDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类主键 ID(CODEID)。
|
||||||
|
*/
|
||||||
|
private Long codeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类编码,例如 01 / 0101 / 010101。
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类名称(DESC1)。
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注信息(DESC2)。
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父级分类主键 ID(PARENTID)。
|
||||||
|
*/
|
||||||
|
private Long parentCodeId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.zt.plat.module.base.dal.dataobject.masterdata;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部 MDM MySQL 物料视图的投影,用于承接同步字段。
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MdmMaterialViewDO {
|
||||||
|
|
||||||
|
private Long codeId;
|
||||||
|
private String materialCode;
|
||||||
|
private String categoryCode;
|
||||||
|
private String categoryName;
|
||||||
|
private String materialName;
|
||||||
|
private String baseUnitCode;
|
||||||
|
private String baseUnitName;
|
||||||
|
private String shortDescription;
|
||||||
|
private String longDescription;
|
||||||
|
private String chalcoCode;
|
||||||
|
private String majorClassCode;
|
||||||
|
private String majorClassName;
|
||||||
|
private String specification;
|
||||||
|
private String model;
|
||||||
|
private String texture;
|
||||||
|
private String drawingNumber;
|
||||||
|
private String orderNumber;
|
||||||
|
private String otherParameters;
|
||||||
|
private String equipmentCategory;
|
||||||
|
private String manufacturer;
|
||||||
|
private String source;
|
||||||
|
private LocalDateTime recordTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.zt.plat.module.base.dal.mysql.masterdata;
|
||||||
|
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取外部 MDM 分类视图的 Mapper。
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@DS(MasterDataSyncConstants.DEFAULT_SOURCE_DATASOURCE)
|
||||||
|
public interface MdmMaterialCategoryMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉取全部分类档案。
|
||||||
|
*/
|
||||||
|
List<MdmMaterialCategoryDO> selectAll();
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.zt.plat.module.base.dal.mysql.masterdata;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.zt.plat.module.base.dal.dataobject.masterdata.MdmMaterialViewDO;
|
||||||
|
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.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapper that exposes read-only access to the external MDM material view.
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@DS(MasterDataSyncConstants.DEFAULT_SOURCE_DATASOURCE)
|
||||||
|
public interface MdmMaterialViewMapper {
|
||||||
|
|
||||||
|
List<MdmMaterialViewDO> selectSlice(@Param("offset") long offset,
|
||||||
|
@Param("limit") int limit,
|
||||||
|
@Param("since") LocalDateTime since,
|
||||||
|
@Param("codes") Collection<String> codes);
|
||||||
|
|
||||||
|
Long countEligible(@Param("since") LocalDateTime since,
|
||||||
|
@Param("codes") Collection<String> codes);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.zt.plat.module.base.framework.sync.config;
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主数据同步用到的基础配置。
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties(MasterDataSyncProperties.class)
|
||||||
|
public class MasterDataSyncConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OkHttpClient masterDataSyncOkHttpClient(MasterDataSyncProperties properties) {
|
||||||
|
MasterDataSyncProperties.HttpProperties http = properties.getHttp();
|
||||||
|
return new OkHttpClient.Builder()
|
||||||
|
.connectTimeout(http.getConnectTimeout())
|
||||||
|
.readTimeout(http.getReadTimeout())
|
||||||
|
.writeTimeout(http.getWriteTimeout())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.zt.plat.module.base.framework.sync.config;
|
||||||
|
|
||||||
|
import com.zt.plat.module.base.framework.sync.constant.MasterDataSyncConstants;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主数据同步管道的配置项。
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Validated
|
||||||
|
@ConfigurationProperties(prefix = "base.master-data-sync")
|
||||||
|
public class MasterDataSyncProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否允许运行主数据同步。
|
||||||
|
*/
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从外部数据源读取时的默认批量大小。
|
||||||
|
*/
|
||||||
|
@Min(1)
|
||||||
|
private int batchSize = 500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指向外部 MDM MySQL 的动态数据源名称。
|
||||||
|
*/
|
||||||
|
private String sourceDatasourceName = MasterDataSyncConstants.DEFAULT_SOURCE_DATASOURCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功是否进行回调通知。
|
||||||
|
*/
|
||||||
|
private boolean notifyOnSuccess = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败是否进行回调通知。
|
||||||
|
*/
|
||||||
|
private boolean notifyOnFailure = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可选的回调地址,用于推送同步结果。
|
||||||
|
*/
|
||||||
|
private String callbackUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回调请求需要附加的静态请求头。
|
||||||
|
*/
|
||||||
|
private Map<String, String> callbackHeaders = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP 客户端的超时时间等参数。
|
||||||
|
*/
|
||||||
|
private final HttpProperties http = new HttpProperties();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class HttpProperties {
|
||||||
|
private Duration connectTimeout = Duration.ofSeconds(5);
|
||||||
|
private Duration readTimeout = Duration.ofSeconds(30);
|
||||||
|
private Duration writeTimeout = Duration.ofSeconds(30);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.zt.plat.module.base.framework.sync.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主数据同步相关的通用常量。
|
||||||
|
*/
|
||||||
|
public final class MasterDataSyncConstants {
|
||||||
|
|
||||||
|
private MasterDataSyncConstants() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指向外部 MDM MySQL 的默认数据源名称。
|
||||||
|
*/
|
||||||
|
public static final String DEFAULT_SOURCE_DATASOURCE = "mdm";
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.zt.plat.module.base.service.masterdatasync;
|
||||||
|
|
||||||
|
import com.zt.plat.module.base.service.masterdatasync.dto.MasterDataCategorySyncReport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料分类同步服务接口。
|
||||||
|
*/
|
||||||
|
public interface MasterDataCategorySyncService {
|
||||||
|
|
||||||
|
MasterDataCategorySyncReport syncAll();
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user