feat(job): 添加ERP基础数据信息定时同步任务
- 创建ErpBasicDataInformationJob实现增量同步计量单位、往来单位、批次号、批次和仓库数据 - 新增ErpBfMeasureUnit实体类用于存储计量单位信息并配置数据库映射关系 - 新增ErpBfPartner实体类用于存储往来单位信息并配置数据库映射关系 - 新增ErpScmBaseSn实体类用于存储批次号信息并配置数据库映射关系 - 新增ErpScmBatch实体类用于存储批次信息并配置数据库映射关系 - 实现各实体对应的Mapper接口及从ERP数据库查询和按时间戳同步的方法 - 添加异常处理机制确保各数据类型同步失败时不影响其他数据类型的同步 - 集成Quartz定时任务框架支持基础数据的周期性增量同步
This commit is contained in:
@@ -97,6 +97,7 @@
|
||||
<artifactId>orai18n</artifactId>
|
||||
<version>21.1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
|
||||
@@ -2,11 +2,15 @@ package com.lideeyunji.core.framework.config.job;
|
||||
|
||||
import com.lideeyunji.core.framework.entity.*;
|
||||
import com.lideeyunji.core.framework.mapper.erp.*;
|
||||
import com.lideeyunji.core.framework.service.erp.ErpDataSyncLogService;
|
||||
import com.lideeyunji.tool.framework.common.constant.lideeYunJiBaseConstant;
|
||||
import com.lideeyunji.tool.framework.quartz.core.handler.JobHandler;
|
||||
import com.lideeyunji.tool.framework.yunji.component.redis.lideeYunjiRedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component("ErpBasicDataInformationJob")
|
||||
@@ -28,43 +32,65 @@ public class ErpBasicDataInformationJob implements JobHandler {
|
||||
@Resource
|
||||
private ErpScmWarehouseMapper erpScmWarehouseMapper;
|
||||
|
||||
@Resource
|
||||
private ErpDataSyncLogService erpDataSyncLogService;
|
||||
|
||||
@Resource
|
||||
private lideeYunjiRedisUtils redisUtil;
|
||||
|
||||
private static final String erpLastUpdateTIme = "erp_update_time";
|
||||
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
log.info("*********** 开始同步基础数据信息 ************");
|
||||
ErpDtaSyncLogEntity latestLog = erpDataSyncLogService.selectone(lideeYunJiBaseConstant.ERP_DATASOURCE);
|
||||
Date time = latestLog != null ? latestLog.getLastUpdateTime() : null;
|
||||
try {
|
||||
syncMeasureUnitIncrement();
|
||||
syncMeasureUnitIncrement(time);
|
||||
} catch (Exception e) {
|
||||
log.error("增量同步计量单位数据失败", e);
|
||||
}
|
||||
try {
|
||||
syncPartnerIncrement();
|
||||
syncPartnerIncrement(time);
|
||||
} catch (Exception e) {
|
||||
log.error("增量同步往来单位数据失败", e);
|
||||
}
|
||||
try {
|
||||
syncBaseSnIncrement();
|
||||
syncBaseSnIncrement(time);
|
||||
} catch (Exception e) {
|
||||
log.error("增量同步批次号数据失败", e);
|
||||
}
|
||||
try {
|
||||
syncBatchIncrement();
|
||||
syncBatchIncrement(time);
|
||||
} catch (Exception e) {
|
||||
log.error("增量同步批次数据失败", e);
|
||||
}
|
||||
try {
|
||||
syncWarehouseIncrement();
|
||||
syncWarehouseIncrement(time);
|
||||
} catch (Exception e) {
|
||||
log.error("增量同步仓库数据失败", e);
|
||||
}
|
||||
Date now = new Date();
|
||||
// if (latestLog != null) {
|
||||
// erpDataSyncLogMapper.update(null,
|
||||
// new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<ErpDtaSyncLogEntity>()
|
||||
// .eq(ErpDtaSyncLogEntity::getId, latestLog.getId())
|
||||
// .set(ErpDtaSyncLogEntity::getLastUpdateTime, now)
|
||||
// );
|
||||
// } else {
|
||||
// ErpDtaSyncLogEntity newLog = new ErpDtaSyncLogEntity();
|
||||
// newLog.setLastUpdateTime(now);
|
||||
// erpDataSyncLogMapper.insert(newLog);
|
||||
// }
|
||||
log.info("========== 所有ERP数据增量同步完成 ==========");
|
||||
return "========== 所有ERP数据增量同步完成 ==========";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int[] syncMeasureUnitIncrement() {
|
||||
public int[] syncMeasureUnitIncrement(Date time) {
|
||||
log.info("开始增量同步计量单位数据...");
|
||||
List<ErpBfMeasureUnit> dataList = erpBfMeasureUnitMapper.selectMeasureUnitFromErp();
|
||||
|
||||
List<ErpBfMeasureUnit> dataList = erpBfMeasureUnitMapper.selectMeasureUnitFromErp(time);
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
log.info("计量单位数据为空,跳过同步");
|
||||
return new int[]{0, 0, 0};
|
||||
@@ -84,9 +110,9 @@ public class ErpBasicDataInformationJob implements JobHandler {
|
||||
return new int[]{insertCount, updateCount, skipCount};
|
||||
}
|
||||
|
||||
public int[] syncPartnerIncrement() {
|
||||
public int[] syncPartnerIncrement(Date time) {
|
||||
log.info("开始增量同步往来单位数据...");
|
||||
List<ErpBfPartner> dataList = erpBfPartnerMapper.selectPartnerFromErp();
|
||||
List<ErpBfPartner> dataList = erpBfPartnerMapper.selectPartnerFromErp(time);
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
log.info("往来单位数据为空,跳过同步");
|
||||
return new int[]{0, 0, 0};
|
||||
@@ -106,9 +132,9 @@ public class ErpBasicDataInformationJob implements JobHandler {
|
||||
return new int[]{insertCount, updateCount, skipCount};
|
||||
}
|
||||
|
||||
public int[] syncBaseSnIncrement() {
|
||||
public int[] syncBaseSnIncrement(Date time) {
|
||||
log.info("开始增量同步批次号数据...");
|
||||
List<ErpScmBaseSn> dataList = erpScmBaseSnMapper.selectBaseSnFromErp();
|
||||
List<ErpScmBaseSn> dataList = erpScmBaseSnMapper.selectBaseSnFromErp(time);
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
log.info("批次号数据为空,跳过同步");
|
||||
return new int[]{0, 0, 0};
|
||||
@@ -128,9 +154,9 @@ public class ErpBasicDataInformationJob implements JobHandler {
|
||||
return new int[]{insertCount, updateCount, skipCount};
|
||||
}
|
||||
|
||||
public int[] syncBatchIncrement() {
|
||||
public int[] syncBatchIncrement(Date time) {
|
||||
log.info("开始增量同步批次数据...");
|
||||
List<ErpScmBatch> dataList = erpScmBatchMapper.selectBatchFromErp();
|
||||
List<ErpScmBatch> dataList = erpScmBatchMapper.selectBatchFromErp(time);
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
log.info("批次数据为空,跳过同步");
|
||||
return new int[]{0, 0, 0};
|
||||
@@ -150,9 +176,9 @@ public class ErpBasicDataInformationJob implements JobHandler {
|
||||
return new int[]{insertCount, updateCount, skipCount};
|
||||
}
|
||||
|
||||
public int[] syncWarehouseIncrement() {
|
||||
public int[] syncWarehouseIncrement(Date time) {
|
||||
log.info("开始增量同步仓库数据...");
|
||||
List<ErpScmWarehouse> dataList = erpScmWarehouseMapper.selectWarehouseFromErp();
|
||||
List<ErpScmWarehouse> dataList = erpScmWarehouseMapper.selectWarehouseFromErp(time);
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
log.info("仓库数据为空,跳过同步");
|
||||
return new int[]{0, 0, 0};
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.lideeyunji.core.framework.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* erp数据同步中间表 ERP_DATASYNCLOG
|
||||
*
|
||||
* @author 雷神
|
||||
* @date 2026-04-10
|
||||
*/
|
||||
@TableName("ERP_DATASYNCLOG")
|
||||
@Data
|
||||
public class ErpDtaSyncLogEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
@TableId(value = "ID", type = IdType.INPUT)
|
||||
private String id;
|
||||
|
||||
/** 创建时间 */
|
||||
@TableField(value = "CREATE_TIME")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
/** 最后修改时间 */
|
||||
@TableField(value = "LAST_UPDATE_TIME")
|
||||
private Date lastUpdateTime;
|
||||
|
||||
|
||||
|
||||
/** 更改类型(1 新增,2更改) */
|
||||
@TableField(value = "CHANGE_TYPE")
|
||||
private Integer changeType;
|
||||
|
||||
/** 报文 */
|
||||
@TableField(value = "MESSAGE")
|
||||
private String message;
|
||||
}
|
||||
@@ -16,37 +16,124 @@ import java.util.List;
|
||||
* @since 2026-04-11
|
||||
*/
|
||||
@Mapper
|
||||
@DS("sjzt")
|
||||
public interface ErpBfMeasureUnitMapper extends BaseMapper<ErpBfMeasureUnit> {
|
||||
|
||||
|
||||
@DS("erp")
|
||||
default List<ErpBfMeasureUnit> selectMeasureUnitFromErp() {
|
||||
return this.selectList(new LambdaQueryWrapper<>());
|
||||
default List<ErpBfMeasureUnit> selectMeasureUnitFromErp(Date time) {
|
||||
return this.selectList(new LambdaQueryWrapper<ErpBfMeasureUnit>().ge(ErpBfMeasureUnit::getTimeStampLastChangedOn, time));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步单条计量单位数据(根据时间戳判断新增/更新/跳过)
|
||||
*
|
||||
* @return 1:新增, 2:更新, 0:跳过
|
||||
*/
|
||||
@DS("sjzt")
|
||||
default int syncMeasureUnitByTimestamp(ErpBfMeasureUnit sourceData) {
|
||||
ErpBfMeasureUnit targetData = this.selectById(sourceData.getId());
|
||||
|
||||
// 目标不存在 → 新增
|
||||
if (targetData == null) {
|
||||
// 目标库不存在,新增
|
||||
this.insert(sourceData);
|
||||
return 1;
|
||||
}
|
||||
// 比较时间戳
|
||||
Date sourceTime = sourceData.getTimeStampLastChangedOn();
|
||||
Date targetTime = targetData.getTimeStampLastChangedOn();
|
||||
if (sourceTime != null && targetTime != null && !sourceTime.equals(targetTime)) {
|
||||
// 时间戳不同,更新
|
||||
this.updateById(sourceData);
|
||||
|
||||
// 标记是否需要更新
|
||||
boolean needUpdate = false;
|
||||
|
||||
// 构建要更新的对象(只更新需要更新的字段,不覆盖有值字段)
|
||||
ErpBfMeasureUnit updateData = new ErpBfMeasureUnit();
|
||||
updateData.setId(targetData.getId());
|
||||
|
||||
// ====================== 逐字段判断 ======================
|
||||
// 编码:目标为null 或 不同 → 更新
|
||||
if (shouldUpdateField(sourceData.getCode(), targetData.getCode())) {
|
||||
updateData.setCode(sourceData.getCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 名称
|
||||
if (shouldUpdateField(sourceData.getName(), targetData.getName())) {
|
||||
updateData.setName(sourceData.getName());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 精度
|
||||
if (shouldUpdateField(sourceData.getAccuracy(), targetData.getAccuracy())) {
|
||||
updateData.setAccuracy(sourceData.getAccuracy());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 创建人
|
||||
if (shouldUpdateField(sourceData.getTimeStampCreatedBy(), targetData.getTimeStampCreatedBy())) {
|
||||
updateData.setTimeStampCreatedBy(sourceData.getTimeStampCreatedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 创建时间
|
||||
if (shouldUpdateField(sourceData.getTimeStampCreatedOn(), targetData.getTimeStampCreatedOn())) {
|
||||
updateData.setTimeStampCreatedOn(sourceData.getTimeStampCreatedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 最后修改人
|
||||
if (shouldUpdateField(sourceData.getTimeStampLastChangedBy(), targetData.getTimeStampLastChangedBy())) {
|
||||
updateData.setTimeStampLastChangedBy(sourceData.getTimeStampLastChangedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 最后修改时间
|
||||
if (shouldUpdateField(sourceData.getTimeStampLastChangedOn(), targetData.getTimeStampLastChangedOn())) {
|
||||
updateData.setTimeStampLastChangedOn(sourceData.getTimeStampLastChangedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 是否可用
|
||||
if (shouldUpdateField(sourceData.getStateIsEnabled(), targetData.getStateIsEnabled())) {
|
||||
updateData.setStateIsEnabled(sourceData.getStateIsEnabled());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 停用时间
|
||||
if (shouldUpdateField(sourceData.getStateDisableTime(), targetData.getStateDisableTime())) {
|
||||
updateData.setStateDisableTime(sourceData.getStateDisableTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 异步删除状态
|
||||
if (shouldUpdateField(sourceData.getStateAsyncDeleteStatus(), targetData.getStateAsyncDeleteStatus())) {
|
||||
updateData.setStateAsyncDeleteStatus(sourceData.getStateAsyncDeleteStatus());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 单位类别
|
||||
if (shouldUpdateField(sourceData.getUnitType(), targetData.getUnitType())) {
|
||||
updateData.setUnitType(sourceData.getUnitType());
|
||||
needUpdate = true;
|
||||
}
|
||||
// 排序号
|
||||
if (shouldUpdateField(sourceData.getSortOrder(), targetData.getSortOrder())) {
|
||||
updateData.setSortOrder(sourceData.getSortOrder());
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
// 2. 需要更新 → 只更新变化的字段
|
||||
if (needUpdate) {
|
||||
this.updateById(updateData);
|
||||
return 2;
|
||||
}
|
||||
// 时间戳相同,跳过
|
||||
|
||||
// 3. 无需更新 → 跳过
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 核心判断规则:
|
||||
* 1. 目标字段 == null → 需要更新
|
||||
* 2. 目标字段 != null,但 和源数据值不同 → 需要更新
|
||||
* 3. 目标字段有值 + 和源相同 → 不更新
|
||||
*/
|
||||
public static boolean shouldUpdateField(Object source, Object target) {
|
||||
//目标
|
||||
if (target == null)
|
||||
return true;
|
||||
//源
|
||||
if (source == null)
|
||||
return false;
|
||||
return !target.equals(source);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.lideeyunji.core.framework.mapper.erp;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lideeyunji.core.framework.entity.ErpBfMeasureUnit;
|
||||
import com.lideeyunji.core.framework.entity.ErpBfPartner;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -16,37 +17,435 @@ import java.util.List;
|
||||
* @since 2026-04-11
|
||||
*/
|
||||
@Mapper
|
||||
@DS("sjzt")
|
||||
public interface ErpBfPartnerMapper extends BaseMapper<ErpBfPartner> {
|
||||
|
||||
// ==================== 往来单位 ====================
|
||||
|
||||
@DS("erp")
|
||||
default List<ErpBfPartner> selectPartnerFromErp() {
|
||||
return this.selectList(new LambdaQueryWrapper<>());
|
||||
default List<ErpBfPartner> selectPartnerFromErp(Date time) {
|
||||
return this.selectList(new LambdaQueryWrapper<ErpBfPartner>().ge(ErpBfPartner::getTimeStampLastChangedOn, time));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步单条往来单位数据(根据时间戳判断新增/更新/跳过)
|
||||
*
|
||||
* @return 1:新增, 2:更新, 0:跳过
|
||||
*/
|
||||
@DS("sjzt")
|
||||
default int syncPartnerByTimestamp(ErpBfPartner sourceData) {
|
||||
ErpBfPartner targetData = this.selectById(sourceData.getId());
|
||||
// 1. 目标不存在 → 新增
|
||||
if (targetData == null) {
|
||||
// 目标库不存在,新增
|
||||
this.insert(sourceData);
|
||||
return 1;
|
||||
}
|
||||
// 比较时间戳
|
||||
Date sourceTime = sourceData.getTimeStampLastChangedOn();
|
||||
Date targetTime = targetData.getTimeStampLastChangedOn();
|
||||
if (sourceTime != null && targetTime != null && !sourceTime.equals(targetTime)) {
|
||||
// 时间戳不同,更新
|
||||
this.updateById(sourceData);
|
||||
|
||||
boolean needUpdate = false;
|
||||
ErpBfPartner updateData = new ErpBfPartner();
|
||||
updateData.setId(targetData.getId());
|
||||
|
||||
// ====================== 逐字段判断 ======================
|
||||
if (shouldUpdateField(sourceData.getCode(), targetData.getCode())) {
|
||||
updateData.setCode(sourceData.getCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getName(), targetData.getName())) {
|
||||
updateData.setName(sourceData.getName());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRemark(), targetData.getRemark())) {
|
||||
updateData.setRemark(sourceData.getRemark());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStateIsEnabled(), targetData.getStateIsEnabled())) {
|
||||
updateData.setStateIsEnabled(sourceData.getStateIsEnabled());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStateDisableTime(), targetData.getStateDisableTime())) {
|
||||
updateData.setStateDisableTime(sourceData.getStateDisableTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStateAsyncDeleteStatus(), targetData.getStateAsyncDeleteStatus())) {
|
||||
updateData.setStateAsyncDeleteStatus(sourceData.getStateAsyncDeleteStatus());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAttachment(), targetData.getAttachment())) {
|
||||
updateData.setAttachment(sourceData.getAttachment());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRepresentative(), targetData.getRepresentative())) {
|
||||
updateData.setRepresentative(sourceData.getRepresentative());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIndustry(), targetData.getIndustry())) {
|
||||
updateData.setIndustry(sourceData.getIndustry());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getArea(), targetData.getArea())) {
|
||||
updateData.setArea(sourceData.getArea());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOrganizationCode(), targetData.getOrganizationCode())) {
|
||||
updateData.setOrganizationCode(sourceData.getOrganizationCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getCountryOrRegion(), targetData.getCountryOrRegion())) {
|
||||
updateData.setCountryOrRegion(sourceData.getCountryOrRegion());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOfRegion(), targetData.getOfRegion())) {
|
||||
updateData.setOfRegion(sourceData.getOfRegion());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getType(), targetData.getType())) {
|
||||
updateData.setType(sourceData.getType());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampCreatedBy(), targetData.getTimeStampCreatedBy())) {
|
||||
updateData.setTimeStampCreatedBy(sourceData.getTimeStampCreatedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampCreatedOn(), targetData.getTimeStampCreatedOn())) {
|
||||
updateData.setTimeStampCreatedOn(sourceData.getTimeStampCreatedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampLastChangedBy(), targetData.getTimeStampLastChangedBy())) {
|
||||
updateData.setTimeStampLastChangedBy(sourceData.getTimeStampLastChangedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampLastChangedOn(), targetData.getTimeStampLastChangedOn())) {
|
||||
updateData.setTimeStampLastChangedOn(sourceData.getTimeStampLastChangedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDefaultCurrencyId(), targetData.getDefaultCurrencyId())) {
|
||||
updateData.setDefaultCurrencyId(sourceData.getDefaultCurrencyId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBillStatus(), targetData.getBillStatus())) {
|
||||
updateData.setBillStatus(sourceData.getBillStatus());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getInstanceId(), targetData.getInstanceId())) {
|
||||
updateData.setInstanceId(sourceData.getInstanceId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSuperiorPartner(), targetData.getSuperiorPartner())) {
|
||||
updateData.setSuperiorPartner(sourceData.getSuperiorPartner());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRegisteredCapital(), targetData.getRegisteredCapital())) {
|
||||
updateData.setRegisteredCapital(sourceData.getRegisteredCapital());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getCompanyWebsite(), targetData.getCompanyWebsite())) {
|
||||
updateData.setCompanyWebsite(sourceData.getCompanyWebsite());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getEmail(), targetData.getEmail())) {
|
||||
updateData.setEmail(sourceData.getEmail());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDefaultAddress(), targetData.getDefaultAddress())) {
|
||||
updateData.setDefaultAddress(sourceData.getDefaultAddress());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDefaultContact(), targetData.getDefaultContact())) {
|
||||
updateData.setDefaultContact(sourceData.getDefaultContact());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getCompanyOrPerson(), targetData.getCompanyOrPerson())) {
|
||||
updateData.setCompanyOrPerson(sourceData.getCompanyOrPerson());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsCustomer(), targetData.getIsCustomer())) {
|
||||
updateData.setIsCustomer(sourceData.getIsCustomer());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsVender(), targetData.getIsVender())) {
|
||||
updateData.setIsVender(sourceData.getIsVender());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsOther(), targetData.getIsOther())) {
|
||||
updateData.setIsOther(sourceData.getIsOther());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getInteriorCompany(), targetData.getInteriorCompany())) {
|
||||
updateData.setInteriorCompany(sourceData.getInteriorCompany());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDistribution(), targetData.getDistribution())) {
|
||||
updateData.setDistribution(sourceData.getDistribution());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getInteriorAccountingOrg(), targetData.getInteriorAccountingOrg())) {
|
||||
updateData.setInteriorAccountingOrg(sourceData.getInteriorAccountingOrg());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getInteriorAdminOrg(), targetData.getInteriorAdminOrg())) {
|
||||
updateData.setInteriorAdminOrg(sourceData.getInteriorAdminOrg());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTaxpayer(), targetData.getTaxpayer())) {
|
||||
updateData.setTaxpayer(sourceData.getTaxpayer());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDefaultCompany(), targetData.getDefaultCompany())) {
|
||||
updateData.setDefaultCompany(sourceData.getDefaultCompany());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTaxIdNumber(), targetData.getTaxIdNumber())) {
|
||||
updateData.setTaxIdNumber(sourceData.getTaxIdNumber());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRegisteredAddress(), targetData.getRegisteredAddress())) {
|
||||
updateData.setRegisteredAddress(sourceData.getRegisteredAddress());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getContactInfo(), targetData.getContactInfo())) {
|
||||
updateData.setContactInfo(sourceData.getContactInfo());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBank(), targetData.getBank())) {
|
||||
updateData.setBank(sourceData.getBank());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAccount(), targetData.getAccount())) {
|
||||
updateData.setAccount(sourceData.getAccount());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTypeOfTaxpayer(), targetData.getTypeOfTaxpayer())) {
|
||||
updateData.setTypeOfTaxpayer(sourceData.getTypeOfTaxpayer());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTaxpayerEmail(), targetData.getTaxpayerEmail())) {
|
||||
updateData.setTaxpayerEmail(sourceData.getTaxpayerEmail());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTelForInvoice(), targetData.getTelForInvoice())) {
|
||||
updateData.setTelForInvoice(sourceData.getTelForInvoice());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTypeOfSuppier(), targetData.getTypeOfSuppier())) {
|
||||
updateData.setTypeOfSuppier(sourceData.getTypeOfSuppier());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRegionOfSuppier(), targetData.getRegionOfSuppier())) {
|
||||
updateData.setRegionOfSuppier(sourceData.getRegionOfSuppier());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTypeOfClient(), targetData.getTypeOfClient())) {
|
||||
updateData.setTypeOfClient(sourceData.getTypeOfClient());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRegionOfClient(), targetData.getRegionOfClient())) {
|
||||
updateData.setRegionOfClient(sourceData.getRegionOfClient());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getLineOfCredit(), targetData.getLineOfCredit())) {
|
||||
updateData.setLineOfCredit(sourceData.getLineOfCredit());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAccountPeriod(), targetData.getAccountPeriod())) {
|
||||
updateData.setAccountPeriod(sourceData.getAccountPeriod());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBankForInvoice(), targetData.getBankForInvoice())) {
|
||||
updateData.setBankForInvoice(sourceData.getBankForInvoice());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getShortName(), targetData.getShortName())) {
|
||||
updateData.setShortName(sourceData.getShortName());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSummary(), targetData.getSummary())) {
|
||||
updateData.setSummary(sourceData.getSummary());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOwnerOrg(), targetData.getOwnerOrg())) {
|
||||
updateData.setOwnerOrg(sourceData.getOwnerOrg());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOwnerDomain(), targetData.getOwnerDomain())) {
|
||||
updateData.setOwnerDomain(sourceData.getOwnerDomain());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSecLevel(), targetData.getSecLevel())) {
|
||||
updateData.setSecLevel(sourceData.getSecLevel());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSecLevelId(), targetData.getSecLevelId())) {
|
||||
updateData.setSecLevelId(sourceData.getSecLevelId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDomainType(), targetData.getDomainType())) {
|
||||
updateData.setDomainType(sourceData.getDomainType());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReferId1(), targetData.getReferId1())) {
|
||||
updateData.setReferId1(sourceData.getReferId1());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReferId2(), targetData.getReferId2())) {
|
||||
updateData.setReferId2(sourceData.getReferId2());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReferId3(), targetData.getReferId3())) {
|
||||
updateData.setReferId3(sourceData.getReferId3());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReferId4(), targetData.getReferId4())) {
|
||||
updateData.setReferId4(sourceData.getReferId4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReferId5(), targetData.getReferId5())) {
|
||||
updateData.setReferId5(sourceData.getReferId5());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPlainText1(), targetData.getPlainText1())) {
|
||||
updateData.setPlainText1(sourceData.getPlainText1());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPlainText2(), targetData.getPlainText2())) {
|
||||
updateData.setPlainText2(sourceData.getPlainText2());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPlainText3(), targetData.getPlainText3())) {
|
||||
updateData.setPlainText3(sourceData.getPlainText3());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPlainText4(), targetData.getPlainText4())) {
|
||||
updateData.setPlainText4(sourceData.getPlainText4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPlainText5(), targetData.getPlainText5())) {
|
||||
updateData.setPlainText5(sourceData.getPlainText5());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDec1(), targetData.getDec1())) {
|
||||
updateData.setDec1(sourceData.getDec1());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDec2(), targetData.getDec2())) {
|
||||
updateData.setDec2(sourceData.getDec2());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDec3(), targetData.getDec3())) {
|
||||
updateData.setDec3(sourceData.getDec3());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDec4(), targetData.getDec4())) {
|
||||
updateData.setDec4(sourceData.getDec4());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDec5(), targetData.getDec5())) {
|
||||
updateData.setDec5(sourceData.getDec5());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getUnitNature(), targetData.getUnitNature())) {
|
||||
updateData.setUnitNature(sourceData.getUnitNature());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getNRemark(), targetData.getNRemark())) {
|
||||
updateData.setNRemark(sourceData.getNRemark());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getNSummary(), targetData.getNSummary())) {
|
||||
updateData.setNSummary(sourceData.getNSummary());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getNRegisteredAddress(), targetData.getNRegisteredAddress())) {
|
||||
updateData.setNRegisteredAddress(sourceData.getNRegisteredAddress());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getEnableESign(), targetData.getEnableESign())) {
|
||||
updateData.setEnableESign(sourceData.getEnableESign());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRegisteredTime(), targetData.getRegisteredTime())) {
|
||||
updateData.setRegisteredTime(sourceData.getRegisteredTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPaidInCapital(), targetData.getPaidInCapital())) {
|
||||
updateData.setPaidInCapital(sourceData.getPaidInCapital());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getCreditRating(), targetData.getCreditRating())) {
|
||||
updateData.setCreditRating(sourceData.getCreditRating());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getManagementState(), targetData.getManagementState())) {
|
||||
updateData.setManagementState(sourceData.getManagementState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getActualController(), targetData.getActualController())) {
|
||||
updateData.setActualController(sourceData.getActualController());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMnemocode(), targetData.getMnemocode())) {
|
||||
updateData.setMnemocode(sourceData.getMnemocode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBillType(), targetData.getBillType())) {
|
||||
updateData.setBillType(sourceData.getBillType());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getActualControllerPartner(), targetData.getActualControllerPartner())) {
|
||||
updateData.setActualControllerPartner(sourceData.getActualControllerPartner());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIeOwnerDomains(), targetData.getIeOwnerDomains())) {
|
||||
updateData.setIeOwnerDomains(sourceData.getIeOwnerDomains());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBusinessScope(), targetData.getBusinessScope())) {
|
||||
updateData.setBusinessScope(sourceData.getBusinessScope());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPublicRatingLevel(), targetData.getPublicRatingLevel())) {
|
||||
updateData.setPublicRatingLevel(sourceData.getPublicRatingLevel());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPublicRatingScore(), targetData.getPublicRatingScore())) {
|
||||
updateData.setPublicRatingScore(sourceData.getPublicRatingScore());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getInPublicBlacklist(), targetData.getInPublicBlacklist())) {
|
||||
updateData.setInPublicBlacklist(sourceData.getInPublicBlacklist());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOfficePhone(), targetData.getOfficePhone())) {
|
||||
updateData.setOfficePhone(sourceData.getOfficePhone());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getEnterpriseScale(), targetData.getEnterpriseScale())) {
|
||||
updateData.setEnterpriseScale(sourceData.getEnterpriseScale());
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
// 2. 需要更新 → 只更新变化字段
|
||||
if (needUpdate) {
|
||||
this.updateById(updateData);
|
||||
return 2;
|
||||
}
|
||||
// 时间戳相同,跳过
|
||||
|
||||
// 3. 无需更新
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心判断规则:
|
||||
* 1. 目标字段 == null → 需要更新
|
||||
* 2. 目标字段 != null,但 和源数据值不同 → 需要更新
|
||||
* 3. 目标字段有值 + 和源相同 → 不更新
|
||||
*/
|
||||
public static boolean shouldUpdateField(Object source, Object target) {
|
||||
//目标
|
||||
if (target == null)
|
||||
return true;
|
||||
//源
|
||||
if (source == null)
|
||||
return false;
|
||||
return !target.equals(source);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.lideeyunji.core.framework.mapper.erp;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lideeyunji.core.framework.entity.ErpDtaSyncLogEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface ErpDataSyncLogMapper extends BaseMapper<ErpDtaSyncLogEntity> {
|
||||
@DS(value = "#dataSourceType")
|
||||
default List<ErpDtaSyncLogEntity> getList(@Param("dataSourceType") String dataSourceType){
|
||||
return this.selectList(new QueryWrapper<>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.lideeyunji.core.framework.mapper.erp;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lideeyunji.core.framework.entity.ErpBfPartner;
|
||||
import com.lideeyunji.core.framework.entity.ErpScmBaseSn;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -16,20 +17,20 @@ import java.util.List;
|
||||
* @since 2026-04-11
|
||||
*/
|
||||
@Mapper
|
||||
@DS("sjzt")
|
||||
public interface ErpScmBaseSnMapper extends BaseMapper<ErpScmBaseSn> {
|
||||
|
||||
|
||||
|
||||
@DS("erp")
|
||||
default List<ErpScmBaseSn> selectBaseSnFromErp() {
|
||||
return this.selectList(new LambdaQueryWrapper<>());
|
||||
default List<ErpScmBaseSn> selectBaseSnFromErp(Date time) {
|
||||
return this.selectList(new LambdaQueryWrapper<ErpScmBaseSn>().ge(ErpScmBaseSn::getTimeStampLastChangedOn, time));
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步单条批次号数据(根据时间戳判断新增/更新/跳过)
|
||||
*
|
||||
* @return 1:新增, 2:更新, 0:跳过
|
||||
*/
|
||||
@DS("sjzt")
|
||||
default int syncBaseSnByTimestamp(ErpScmBaseSn sourceData) {
|
||||
ErpScmBaseSn targetData = this.selectById(sourceData.getId());
|
||||
if (targetData == null) {
|
||||
@@ -37,15 +38,478 @@ public interface ErpScmBaseSnMapper extends BaseMapper<ErpScmBaseSn> {
|
||||
this.insert(sourceData);
|
||||
return 1;
|
||||
}
|
||||
// 比较时间戳
|
||||
Date sourceTime = sourceData.getTimeStampLastChangedOn();
|
||||
Date targetTime = targetData.getTimeStampLastChangedOn();
|
||||
if (sourceTime != null && targetTime != null && !sourceTime.equals(targetTime)) {
|
||||
// 时间戳不同,更新
|
||||
this.updateById(sourceData);
|
||||
boolean needUpdate = false;
|
||||
ErpScmBaseSn updateData = new ErpScmBaseSn();
|
||||
updateData.setId(targetData.getId());
|
||||
// ====================== 逐字段判断 ======================
|
||||
if (shouldUpdateField(sourceData.getSn(), targetData.getSn())) {
|
||||
updateData.setSn(sourceData.getSn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDataYear(), targetData.getDataYear())) {
|
||||
updateData.setDataYear(sourceData.getDataYear());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDataMonth(), targetData.getDataMonth())) {
|
||||
updateData.setDataMonth(sourceData.getDataMonth());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getImOrgId(), targetData.getImOrgId())) {
|
||||
updateData.setImOrgId(sourceData.getImOrgId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMaterialId(), targetData.getMaterialId())) {
|
||||
updateData.setMaterialId(sourceData.getMaterialId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMCode(), targetData.getMCode())) {
|
||||
updateData.setMCode(sourceData.getMCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMName(), targetData.getMName())) {
|
||||
updateData.setMName(sourceData.getMName());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMSpecs(), targetData.getMSpecs())) {
|
||||
updateData.setMSpecs(sourceData.getMSpecs());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMModel(), targetData.getMModel())) {
|
||||
updateData.setMModel(sourceData.getMModel());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMNote(), targetData.getMNote())) {
|
||||
updateData.setMNote(sourceData.getMNote());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSecQty(), targetData.getSecQty())) {
|
||||
updateData.setSecQty(sourceData.getSecQty());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSecUnitId(), targetData.getSecUnitId())) {
|
||||
updateData.setSecUnitId(sourceData.getSecUnitId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSecUnit(), targetData.getSecUnit())) {
|
||||
updateData.setSecUnit(sourceData.getSecUnit());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getConvRule(), targetData.getConvRule())) {
|
||||
updateData.setConvRule(sourceData.getConvRule());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getConvRatio(), targetData.getConvRatio())) {
|
||||
updateData.setConvRatio(sourceData.getConvRatio());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSecPrecision(), targetData.getSecPrecision())) {
|
||||
updateData.setSecPrecision(sourceData.getSecPrecision());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRemarks(), targetData.getRemarks())) {
|
||||
updateData.setRemarks(sourceData.getRemarks());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getExContentId(), targetData.getExContentId())) {
|
||||
updateData.setExContentId(sourceData.getExContentId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getExContent(), targetData.getExContent())) {
|
||||
updateData.setExContent(sourceData.getExContent());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMExContentId(), targetData.getMExContentId())) {
|
||||
updateData.setMExContentId(sourceData.getMExContentId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMExContent(), targetData.getMExContent())) {
|
||||
updateData.setMExContent(sourceData.getMExContent());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMFeatureId(), targetData.getMFeatureId())) {
|
||||
updateData.setMFeatureId(sourceData.getMFeatureId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchId(), targetData.getBatchId())) {
|
||||
updateData.setBatchId(sourceData.getBatchId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchCode(), targetData.getBatchCode())) {
|
||||
updateData.setBatchCode(sourceData.getBatchCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getQualityState(), targetData.getQualityState())) {
|
||||
updateData.setQualityState(sourceData.getQualityState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getQualityLevel(), targetData.getQualityLevel())) {
|
||||
updateData.setQualityLevel(sourceData.getQualityLevel());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getQualityTime(), targetData.getQualityTime())) {
|
||||
updateData.setQualityTime(sourceData.getQualityTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchStockState(), targetData.getBatchStockState())) {
|
||||
updateData.setBatchStockState(sourceData.getBatchStockState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReleaseState(), targetData.getReleaseState())) {
|
||||
updateData.setReleaseState(sourceData.getReleaseState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getVenderId(), targetData.getVenderId())) {
|
||||
updateData.setVenderId(sourceData.getVenderId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getFactoryId(), targetData.getFactoryId())) {
|
||||
updateData.setFactoryId(sourceData.getFactoryId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOriBatchCode(), targetData.getOriBatchCode())) {
|
||||
updateData.setOriBatchCode(sourceData.getOriBatchCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRecDate(), targetData.getRecDate())) {
|
||||
updateData.setRecDate(sourceData.getRecDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getProductDate(), targetData.getProductDate())) {
|
||||
updateData.setProductDate(sourceData.getProductDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getEfficientDate(), targetData.getEfficientDate())) {
|
||||
updateData.setEfficientDate(sourceData.getEfficientDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDisableDate(), targetData.getDisableDate())) {
|
||||
updateData.setDisableDate(sourceData.getDisableDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getWh(), targetData.getWh())) {
|
||||
updateData.setWh(sourceData.getWh());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMFeature(), targetData.getMFeature())) {
|
||||
updateData.setMFeature(sourceData.getMFeature());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBin(), targetData.getBin())) {
|
||||
updateData.setBin(sourceData.getBin());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getWhId(), targetData.getWhId())) {
|
||||
updateData.setWhId(sourceData.getWhId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBinId(), targetData.getBinId())) {
|
||||
updateData.setBinId(sourceData.getBinId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPileCode(), targetData.getPileCode())) {
|
||||
updateData.setPileCode(sourceData.getPileCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMVersion(), targetData.getMVersion())) {
|
||||
updateData.setMVersion(sourceData.getMVersion());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStoreState(), targetData.getStoreState())) {
|
||||
updateData.setStoreState(sourceData.getStoreState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsStop(), targetData.getIsStop())) {
|
||||
updateData.setIsStop(sourceData.getIsStop());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopTime(), targetData.getStopTime())) {
|
||||
updateData.setStopTime(sourceData.getStopTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopUserId(), targetData.getStopUserId())) {
|
||||
updateData.setStopUserId(sourceData.getStopUserId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopUser(), targetData.getStopUser())) {
|
||||
updateData.setStopUser(sourceData.getStopUser());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsArchive(), targetData.getIsArchive())) {
|
||||
updateData.setIsArchive(sourceData.getIsArchive());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsPrinted(), targetData.getIsPrinted())) {
|
||||
updateData.setIsPrinted(sourceData.getIsPrinted());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPrintingTimes(), targetData.getPrintingTimes())) {
|
||||
updateData.setPrintingTimes(sourceData.getPrintingTimes());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAttachmentCnts(), targetData.getAttachmentCnts())) {
|
||||
updateData.setAttachmentCnts(sourceData.getAttachmentCnts());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getSnRuleId(), targetData.getSnRuleId())) {
|
||||
updateData.setSnRuleId(sourceData.getSnRuleId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC01(), targetData.getC01())) {
|
||||
updateData.setC01(sourceData.getC01());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC02(), targetData.getC02())) {
|
||||
updateData.setC02(sourceData.getC02());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC03(), targetData.getC03())) {
|
||||
updateData.setC03(sourceData.getC03());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC04(), targetData.getC04())) {
|
||||
updateData.setC04(sourceData.getC04());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC05(), targetData.getC05())) {
|
||||
updateData.setC05(sourceData.getC05());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC06(), targetData.getC06())) {
|
||||
updateData.setC06(sourceData.getC06());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC07(), targetData.getC07())) {
|
||||
updateData.setC07(sourceData.getC07());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC08(), targetData.getC08())) {
|
||||
updateData.setC08(sourceData.getC08());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC09(), targetData.getC09())) {
|
||||
updateData.setC09(sourceData.getC09());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC10(), targetData.getC10())) {
|
||||
updateData.setC10(sourceData.getC10());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC11(), targetData.getC11())) {
|
||||
updateData.setC11(sourceData.getC11());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC12(), targetData.getC12())) {
|
||||
updateData.setC12(sourceData.getC12());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC13(), targetData.getC13())) {
|
||||
updateData.setC13(sourceData.getC13());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC14(), targetData.getC14())) {
|
||||
updateData.setC14(sourceData.getC14());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC15(), targetData.getC15())) {
|
||||
updateData.setC15(sourceData.getC15());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC16(), targetData.getC16())) {
|
||||
updateData.setC16(sourceData.getC16());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC17(), targetData.getC17())) {
|
||||
updateData.setC17(sourceData.getC17());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC18(), targetData.getC18())) {
|
||||
updateData.setC18(sourceData.getC18());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC19(), targetData.getC19())) {
|
||||
updateData.setC19(sourceData.getC19());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC20(), targetData.getC20())) {
|
||||
updateData.setC20(sourceData.getC20());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN01(), targetData.getN01())) {
|
||||
updateData.setN01(sourceData.getN01());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN02(), targetData.getN02())) {
|
||||
updateData.setN02(sourceData.getN02());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN03(), targetData.getN03())) {
|
||||
updateData.setN03(sourceData.getN03());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN04(), targetData.getN04())) {
|
||||
updateData.setN04(sourceData.getN04());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN05(), targetData.getN05())) {
|
||||
updateData.setN05(sourceData.getN05());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN06(), targetData.getN06())) {
|
||||
updateData.setN06(sourceData.getN06());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN07(), targetData.getN07())) {
|
||||
updateData.setN07(sourceData.getN07());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN08(), targetData.getN08())) {
|
||||
updateData.setN08(sourceData.getN08());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN09(), targetData.getN09())) {
|
||||
updateData.setN09(sourceData.getN09());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN10(), targetData.getN10())) {
|
||||
updateData.setN10(sourceData.getN10());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampCreatedBy(), targetData.getTimeStampCreatedBy())) {
|
||||
updateData.setTimeStampCreatedBy(sourceData.getTimeStampCreatedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampCreatedOn(), targetData.getTimeStampCreatedOn())) {
|
||||
updateData.setTimeStampCreatedOn(sourceData.getTimeStampCreatedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampLastChangedBy(), targetData.getTimeStampLastChangedBy())) {
|
||||
updateData.setTimeStampLastChangedBy(sourceData.getTimeStampLastChangedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimeStampLastChangedOn(), targetData.getTimeStampLastChangedOn())) {
|
||||
updateData.setTimeStampLastChangedOn(sourceData.getTimeStampLastChangedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getVersion(), targetData.getVersion())) {
|
||||
updateData.setVersion(sourceData.getVersion());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStoragePeriod(), targetData.getStoragePeriod())) {
|
||||
updateData.setStoragePeriod(sourceData.getStoragePeriod());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAssayDate(), targetData.getAssayDate())) {
|
||||
updateData.setAssayDate(sourceData.getAssayDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getCheckDate(), targetData.getCheckDate())) {
|
||||
updateData.setCheckDate(sourceData.getCheckDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRecheckDate(), targetData.getRecheckDate())) {
|
||||
updateData.setRecheckDate(sourceData.getRecheckDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPreOilSealDate(), targetData.getPreOilSealDate())) {
|
||||
updateData.setPreOilSealDate(sourceData.getPreOilSealDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOilSealDate(), targetData.getOilSealDate())) {
|
||||
updateData.setOilSealDate(sourceData.getOilSealDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAssayNum(), targetData.getAssayNum())) {
|
||||
updateData.setAssayNum(sourceData.getAssayNum());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRecheckNum(), targetData.getRecheckNum())) {
|
||||
updateData.setRecheckNum(sourceData.getRecheckNum());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOccId(), targetData.getOccId())) {
|
||||
updateData.setOccId(sourceData.getOccId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOccType(), targetData.getOccType())) {
|
||||
updateData.setOccType(sourceData.getOccType());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOccState(), targetData.getOccState())) {
|
||||
updateData.setOccState(sourceData.getOccState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMDrawingNo(), targetData.getMDrawingNo())) {
|
||||
updateData.setMDrawingNo(sourceData.getMDrawingNo());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getProjectId(), targetData.getProjectId())) {
|
||||
updateData.setProjectId(sourceData.getProjectId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getProjectName(), targetData.getProjectName())) {
|
||||
updateData.setProjectName(sourceData.getProjectName());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getProjectCode(), targetData.getProjectCode())) {
|
||||
updateData.setProjectCode(sourceData.getProjectCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGiBillId(), targetData.getGiBillId())) {
|
||||
updateData.setGiBillId(sourceData.getGiBillId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGiBillCode(), targetData.getGiBillCode())) {
|
||||
updateData.setGiBillCode(sourceData.getGiBillCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGiBillItemId(), targetData.getGiBillItemId())) {
|
||||
updateData.setGiBillItemId(sourceData.getGiBillItemId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGiBillItemNo(), targetData.getGiBillItemNo())) {
|
||||
updateData.setGiBillItemNo(sourceData.getGiBillItemNo());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGrBillId(), targetData.getGrBillId())) {
|
||||
updateData.setGrBillId(sourceData.getGrBillId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGrBillCode(), targetData.getGrBillCode())) {
|
||||
updateData.setGrBillCode(sourceData.getGrBillCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGrBillItemId(), targetData.getGrBillItemId())) {
|
||||
updateData.setGrBillItemId(sourceData.getGrBillItemId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getGrBillItemNo(), targetData.getGrBillItemNo())) {
|
||||
updateData.setGrBillItemNo(sourceData.getGrBillItemNo());
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
// 2. 需要更新 → 只更新变化字段
|
||||
if (needUpdate) {
|
||||
this.updateById(updateData);
|
||||
return 2;
|
||||
}
|
||||
// 时间戳相同,跳过
|
||||
|
||||
// 3. 无需更新
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心判断规则:
|
||||
* 1. 目标字段 == null → 需要更新
|
||||
* 2. 目标字段 != null,但 和源数据值不同 → 需要更新
|
||||
* 3. 目标字段有值 + 和源相同 → 不更新
|
||||
*/
|
||||
public static boolean shouldUpdateField(Object source, Object target) {
|
||||
//目标
|
||||
if (target == null)
|
||||
return true;
|
||||
//源
|
||||
if (source == null)
|
||||
return false;
|
||||
return !target.equals(source);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.lideeyunji.core.framework.mapper.erp;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lideeyunji.core.framework.entity.ErpScmBaseSn;
|
||||
import com.lideeyunji.core.framework.entity.ErpScmBatch;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -16,19 +17,20 @@ import java.util.List;
|
||||
* @since 2026-04-11
|
||||
*/
|
||||
@Mapper
|
||||
@DS("sjzt")
|
||||
public interface ErpScmBatchMapper extends BaseMapper<ErpScmBatch> {
|
||||
|
||||
@DS("erp")
|
||||
default List<ErpScmBatch> selectBatchFromErp() {
|
||||
return this.selectList(new LambdaQueryWrapper<>());
|
||||
default List<ErpScmBatch> selectBatchFromErp(Date time) {
|
||||
return this.selectList(new LambdaQueryWrapper<ErpScmBatch>().ge(ErpScmBatch::getTimestampsLastChangedOn, time));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步单条批次数据(根据时间戳判断新增/更新/跳过)
|
||||
*
|
||||
* @return 1:新增, 2:更新, 0:跳过
|
||||
*/
|
||||
@DS("sjzt")
|
||||
default int syncBatchByTimestamp(ErpScmBatch sourceData) {
|
||||
ErpScmBatch targetData = this.selectById(sourceData.getId());
|
||||
if (targetData == null) {
|
||||
@@ -37,14 +39,399 @@ public interface ErpScmBatchMapper extends BaseMapper<ErpScmBatch> {
|
||||
return 1;
|
||||
}
|
||||
// 比较时间戳
|
||||
Date sourceTime = sourceData.getTimestampsLastChangedOn();
|
||||
Date targetTime = targetData.getTimestampsLastChangedOn();
|
||||
if (sourceTime != null && targetTime != null && !sourceTime.equals(targetTime)) {
|
||||
// 时间戳不同,更新
|
||||
this.updateById(sourceData);
|
||||
boolean needUpdate = false;
|
||||
ErpScmBatch updateData = new ErpScmBatch();
|
||||
updateData.setId(targetData.getId());
|
||||
|
||||
// ====================== 逐字段判断 ======================
|
||||
if (shouldUpdateField(sourceData.getVersion(), targetData.getVersion())) {
|
||||
updateData.setVersion(sourceData.getVersion());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBizOrgId(), targetData.getBizOrgId())) {
|
||||
updateData.setBizOrgId(sourceData.getBizOrgId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getMaterialId(), targetData.getMaterialId())) {
|
||||
updateData.setMaterialId(sourceData.getMaterialId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchCode(), targetData.getBatchCode())) {
|
||||
updateData.setBatchCode(sourceData.getBatchCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getQualityState(), targetData.getQualityState())) {
|
||||
updateData.setQualityState(sourceData.getQualityState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getQualityLevel(), targetData.getQualityLevel())) {
|
||||
updateData.setQualityLevel(sourceData.getQualityLevel());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getQualityTime(), targetData.getQualityTime())) {
|
||||
updateData.setQualityTime(sourceData.getQualityTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchStockState(), targetData.getBatchStockState())) {
|
||||
updateData.setBatchStockState(sourceData.getBatchStockState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReleaseState(), targetData.getReleaseState())) {
|
||||
updateData.setReleaseState(sourceData.getReleaseState());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getVenderId(), targetData.getVenderId())) {
|
||||
updateData.setVenderId(sourceData.getVenderId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getFactoryId(), targetData.getFactoryId())) {
|
||||
updateData.setFactoryId(sourceData.getFactoryId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOriBatchCode(), targetData.getOriBatchCode())) {
|
||||
updateData.setOriBatchCode(sourceData.getOriBatchCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRecDate(), targetData.getRecDate())) {
|
||||
updateData.setRecDate(sourceData.getRecDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getProductDate(), targetData.getProductDate())) {
|
||||
updateData.setProductDate(sourceData.getProductDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getEfficientDate(), targetData.getEfficientDate())) {
|
||||
updateData.setEfficientDate(sourceData.getEfficientDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDisableDate(), targetData.getDisableDate())) {
|
||||
updateData.setDisableDate(sourceData.getDisableDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getInvUnitId(), targetData.getInvUnitId())) {
|
||||
updateData.setInvUnitId(sourceData.getInvUnitId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchUnitId(), targetData.getBatchUnitId())) {
|
||||
updateData.setBatchUnitId(sourceData.getBatchUnitId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getInvUnitRate(), targetData.getInvUnitRate())) {
|
||||
updateData.setInvUnitRate(sourceData.getInvUnitRate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchUnitRate(), targetData.getBatchUnitRate())) {
|
||||
updateData.setBatchUnitRate(sourceData.getBatchUnitRate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getExContentId(), targetData.getExContentId())) {
|
||||
updateData.setExContentId(sourceData.getExContentId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getExContent(), targetData.getExContent())) {
|
||||
updateData.setExContent(sourceData.getExContent());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getNote(), targetData.getNote())) {
|
||||
updateData.setNote(sourceData.getNote());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getContractId(), targetData.getContractId())) {
|
||||
updateData.setContractId(sourceData.getContractId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getContractCode(), targetData.getContractCode())) {
|
||||
updateData.setContractCode(sourceData.getContractCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPoId(), targetData.getPoId())) {
|
||||
updateData.setPoId(sourceData.getPoId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPoCode(), targetData.getPoCode())) {
|
||||
updateData.setPoCode(sourceData.getPoCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsStop(), targetData.getIsStop())) {
|
||||
updateData.setIsStop(sourceData.getIsStop());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopTime(), targetData.getStopTime())) {
|
||||
updateData.setStopTime(sourceData.getStopTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopUserId(), targetData.getStopUserId())) {
|
||||
updateData.setStopUserId(sourceData.getStopUserId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopUser(), targetData.getStopUser())) {
|
||||
updateData.setStopUser(sourceData.getStopUser());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsArchive(), targetData.getIsArchive())) {
|
||||
updateData.setIsArchive(sourceData.getIsArchive());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchRuleId(), targetData.getBatchRuleId())) {
|
||||
updateData.setBatchRuleId(sourceData.getBatchRuleId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsPrinted(), targetData.getIsPrinted())) {
|
||||
updateData.setIsPrinted(sourceData.getIsPrinted());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPrintingTimes(), targetData.getPrintingTimes())) {
|
||||
updateData.setPrintingTimes(sourceData.getPrintingTimes());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBatchPrice(), targetData.getBatchPrice())) {
|
||||
updateData.setBatchPrice(sourceData.getBatchPrice());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAssAttribute(), targetData.getAssAttribute())) {
|
||||
updateData.setAssAttribute(sourceData.getAssAttribute());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getEffectiveTimes(), targetData.getEffectiveTimes())) {
|
||||
updateData.setEffectiveTimes(sourceData.getEffectiveTimes());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getValidDate(), targetData.getValidDate())) {
|
||||
updateData.setValidDate(sourceData.getValidDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAttachmentCnts(), targetData.getAttachmentCnts())) {
|
||||
updateData.setAttachmentCnts(sourceData.getAttachmentCnts());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getProject(), targetData.getProject())) {
|
||||
updateData.setProject(sourceData.getProject());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getWarehouse(), targetData.getWarehouse())) {
|
||||
updateData.setWarehouse(sourceData.getWarehouse());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getWbs(), targetData.getWbs())) {
|
||||
updateData.setWbs(sourceData.getWbs());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getWbsCode(), targetData.getWbsCode())) {
|
||||
updateData.setWbsCode(sourceData.getWbsCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getWarehouseCode(), targetData.getWarehouseCode())) {
|
||||
updateData.setWarehouseCode(sourceData.getWarehouseCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getProjectCode(), targetData.getProjectCode())) {
|
||||
updateData.setProjectCode(sourceData.getProjectCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC01(), targetData.getC01())) {
|
||||
updateData.setC01(sourceData.getC01());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC02(), targetData.getC02())) {
|
||||
updateData.setC02(sourceData.getC02());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC03(), targetData.getC03())) {
|
||||
updateData.setC03(sourceData.getC03());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC04(), targetData.getC04())) {
|
||||
updateData.setC04(sourceData.getC04());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC05(), targetData.getC05())) {
|
||||
updateData.setC05(sourceData.getC05());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC06(), targetData.getC06())) {
|
||||
updateData.setC06(sourceData.getC06());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC07(), targetData.getC07())) {
|
||||
updateData.setC07(sourceData.getC07());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC08(), targetData.getC08())) {
|
||||
updateData.setC08(sourceData.getC08());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC09(), targetData.getC09())) {
|
||||
updateData.setC09(sourceData.getC09());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC10(), targetData.getC10())) {
|
||||
updateData.setC10(sourceData.getC10());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC11(), targetData.getC11())) {
|
||||
updateData.setC11(sourceData.getC11());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC12(), targetData.getC12())) {
|
||||
updateData.setC12(sourceData.getC12());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC13(), targetData.getC13())) {
|
||||
updateData.setC13(sourceData.getC13());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC14(), targetData.getC14())) {
|
||||
updateData.setC14(sourceData.getC14());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC15(), targetData.getC15())) {
|
||||
updateData.setC15(sourceData.getC15());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC16(), targetData.getC16())) {
|
||||
updateData.setC16(sourceData.getC16());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC17(), targetData.getC17())) {
|
||||
updateData.setC17(sourceData.getC17());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC18(), targetData.getC18())) {
|
||||
updateData.setC18(sourceData.getC18());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC19(), targetData.getC19())) {
|
||||
updateData.setC19(sourceData.getC19());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getC20(), targetData.getC20())) {
|
||||
updateData.setC20(sourceData.getC20());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN01(), targetData.getN01())) {
|
||||
updateData.setN01(sourceData.getN01());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN02(), targetData.getN02())) {
|
||||
updateData.setN02(sourceData.getN02());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN03(), targetData.getN03())) {
|
||||
updateData.setN03(sourceData.getN03());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN04(), targetData.getN04())) {
|
||||
updateData.setN04(sourceData.getN04());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN05(), targetData.getN05())) {
|
||||
updateData.setN05(sourceData.getN05());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN06(), targetData.getN06())) {
|
||||
updateData.setN06(sourceData.getN06());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN07(), targetData.getN07())) {
|
||||
updateData.setN07(sourceData.getN07());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN08(), targetData.getN08())) {
|
||||
updateData.setN08(sourceData.getN08());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN09(), targetData.getN09())) {
|
||||
updateData.setN09(sourceData.getN09());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getN10(), targetData.getN10())) {
|
||||
updateData.setN10(sourceData.getN10());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampsCreatedBy(), targetData.getTimestampsCreatedBy())) {
|
||||
updateData.setTimestampsCreatedBy(sourceData.getTimestampsCreatedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampsCreatedOn(), targetData.getTimestampsCreatedOn())) {
|
||||
updateData.setTimestampsCreatedOn(sourceData.getTimestampsCreatedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampsLastChangedBy(), targetData.getTimestampsLastChangedBy())) {
|
||||
updateData.setTimestampsLastChangedBy(sourceData.getTimestampsLastChangedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampsLastChangedOn(), targetData.getTimestampsLastChangedOn())) {
|
||||
updateData.setTimestampsLastChangedOn(sourceData.getTimestampsLastChangedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getReQcDate(), targetData.getReQcDate())) {
|
||||
updateData.setReQcDate(sourceData.getReQcDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStoragePeriod(), targetData.getStoragePeriod())) {
|
||||
updateData.setStoragePeriod(sourceData.getStoragePeriod());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAssayDate(), targetData.getAssayDate())) {
|
||||
updateData.setAssayDate(sourceData.getAssayDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getCheckDate(), targetData.getCheckDate())) {
|
||||
updateData.setCheckDate(sourceData.getCheckDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRecheckDate(), targetData.getRecheckDate())) {
|
||||
updateData.setRecheckDate(sourceData.getRecheckDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getPreOilSealDate(), targetData.getPreOilSealDate())) {
|
||||
updateData.setPreOilSealDate(sourceData.getPreOilSealDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getOilSealDate(), targetData.getOilSealDate())) {
|
||||
updateData.setOilSealDate(sourceData.getOilSealDate());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAssayNum(), targetData.getAssayNum())) {
|
||||
updateData.setAssayNum(sourceData.getAssayNum());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRecheckNum(), targetData.getRecheckNum())) {
|
||||
updateData.setRecheckNum(sourceData.getRecheckNum());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getManufacturerId(), targetData.getManufacturerId())) {
|
||||
updateData.setManufacturerId(sourceData.getManufacturerId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getValidTo(), targetData.getValidTo())) {
|
||||
updateData.setValidTo(sourceData.getValidTo());
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
// 2. 需要更新 → 只更新变化字段
|
||||
if (needUpdate) {
|
||||
this.updateById(updateData);
|
||||
return 2;
|
||||
}
|
||||
// 时间戳相同,跳过
|
||||
|
||||
// 3. 无需更新
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心判断规则:
|
||||
* 1. 目标字段 == null → 需要更新
|
||||
* 2. 目标字段 != null,但 和源数据值不同 → 需要更新
|
||||
* 3. 目标字段有值 + 和源相同 → 不更新
|
||||
*/
|
||||
public static boolean shouldUpdateField(Object source, Object target) {
|
||||
//目标
|
||||
if (target == null)
|
||||
return true;
|
||||
//源
|
||||
if (source == null)
|
||||
return false;
|
||||
return !target.equals(source);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.lideeyunji.core.framework.mapper.erp;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.lideeyunji.core.framework.entity.ErpScmBatch;
|
||||
import com.lideeyunji.core.framework.entity.ErpScmWarehouse;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -16,20 +17,20 @@ import java.util.List;
|
||||
* @since 2026-04-11
|
||||
*/
|
||||
@Mapper
|
||||
@DS("sjzt")
|
||||
public interface ErpScmWarehouseMapper extends BaseMapper<ErpScmWarehouse> {
|
||||
|
||||
|
||||
|
||||
@DS("erp")
|
||||
default List<ErpScmWarehouse> selectWarehouseFromErp() {
|
||||
return this.selectList(new LambdaQueryWrapper<>());
|
||||
default List<ErpScmWarehouse> selectWarehouseFromErp(Date time) {
|
||||
return this.selectList(new LambdaQueryWrapper<ErpScmWarehouse>().ge(ErpScmWarehouse::getTimestampLastChangedOn, time));
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步单条仓库数据(根据时间戳判断新增/更新/跳过)
|
||||
*
|
||||
* @return 1:新增, 2:更新, 0:跳过
|
||||
*/
|
||||
@DS("sjzt")
|
||||
default int syncWarehouseByTimestamp(ErpScmWarehouse sourceData) {
|
||||
ErpScmWarehouse targetData = this.selectById(sourceData.getId());
|
||||
if (targetData == null) {
|
||||
@@ -37,16 +38,152 @@ public interface ErpScmWarehouseMapper extends BaseMapper<ErpScmWarehouse> {
|
||||
this.insert(sourceData);
|
||||
return 1;
|
||||
}
|
||||
// 比较时间戳
|
||||
Date sourceTime = sourceData.getTimestampLastChangedOn();
|
||||
Date targetTime = targetData.getTimestampLastChangedOn();
|
||||
if (sourceTime != null && targetTime != null && !sourceTime.equals(targetTime)) {
|
||||
// 时间戳不同,更新
|
||||
this.updateById(sourceData);
|
||||
boolean needUpdate = false;
|
||||
ErpScmWarehouse updateData = new ErpScmWarehouse();
|
||||
updateData.setId(targetData.getId());
|
||||
|
||||
// ====================== 逐字段判断 ======================
|
||||
if (shouldUpdateField(sourceData.getWarehouseCode(), targetData.getWarehouseCode())) {
|
||||
updateData.setWarehouseCode(sourceData.getWarehouseCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getWarehouseName(), targetData.getWarehouseName())) {
|
||||
updateData.setWarehouseName(sourceData.getWarehouseName());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getAddress(), targetData.getAddress())) {
|
||||
updateData.setAddress(sourceData.getAddress());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsMgrBin(), targetData.getIsMgrBin())) {
|
||||
updateData.setIsMgrBin(sourceData.getIsMgrBin());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getVersion(), targetData.getVersion())) {
|
||||
updateData.setVersion(sourceData.getVersion());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getLongitude(), targetData.getLongitude())) {
|
||||
updateData.setLongitude(sourceData.getLongitude());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getLatitude(), targetData.getLatitude())) {
|
||||
updateData.setLatitude(sourceData.getLatitude());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampCreatedBy(), targetData.getTimestampCreatedBy())) {
|
||||
updateData.setTimestampCreatedBy(sourceData.getTimestampCreatedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampCreatedOn(), targetData.getTimestampCreatedOn())) {
|
||||
updateData.setTimestampCreatedOn(sourceData.getTimestampCreatedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampLastChangedBy(), targetData.getTimestampLastChangedBy())) {
|
||||
updateData.setTimestampLastChangedBy(sourceData.getTimestampLastChangedBy());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getTimestampLastChangedOn(), targetData.getTimestampLastChangedOn())) {
|
||||
updateData.setTimestampLastChangedOn(sourceData.getTimestampLastChangedOn());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getHotZoneInfo(), targetData.getHotZoneInfo())) {
|
||||
updateData.setHotZoneInfo(sourceData.getHotZoneInfo());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getCreateOrg(), targetData.getCreateOrg())) {
|
||||
updateData.setCreateOrg(sourceData.getCreateOrg());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopStatus(), targetData.getStopStatus())) {
|
||||
updateData.setStopStatus(sourceData.getStopStatus());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRemarks(), targetData.getRemarks())) {
|
||||
updateData.setRemarks(sourceData.getRemarks());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDeptId(), targetData.getDeptId())) {
|
||||
updateData.setDeptId(sourceData.getDeptId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getContactUser(), targetData.getContactUser())) {
|
||||
updateData.setContactUser(sourceData.getContactUser());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getContactPhone(), targetData.getContactPhone())) {
|
||||
updateData.setContactPhone(sourceData.getContactPhone());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getBinCnt(), targetData.getBinCnt())) {
|
||||
updateData.setBinCnt(sourceData.getBinCnt());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsMgrStack(), targetData.getIsMgrStack())) {
|
||||
updateData.setIsMgrStack(sourceData.getIsMgrStack());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopTime(), targetData.getStopTime())) {
|
||||
updateData.setStopTime(sourceData.getStopTime());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopUserId(), targetData.getStopUserId())) {
|
||||
updateData.setStopUserId(sourceData.getStopUserId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getStopUser(), targetData.getStopUser())) {
|
||||
updateData.setStopUser(sourceData.getStopUser());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsMgrWhStack(), targetData.getIsMgrWhStack())) {
|
||||
updateData.setIsMgrWhStack(sourceData.getIsMgrWhStack());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getRegion(), targetData.getRegion())) {
|
||||
updateData.setRegion(sourceData.getRegion());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getIsInterSUage(), targetData.getIsInterSUage())) {
|
||||
updateData.setIsInterSUage(sourceData.getIsInterSUage());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDefBinId(), targetData.getDefBinId())) {
|
||||
updateData.setDefBinId(sourceData.getDefBinId());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDefBinCode(), targetData.getDefBinCode())) {
|
||||
updateData.setDefBinCode(sourceData.getDefBinCode());
|
||||
needUpdate = true;
|
||||
}
|
||||
if (shouldUpdateField(sourceData.getDefBin(), targetData.getDefBin())) {
|
||||
updateData.setDefBin(sourceData.getDefBin());
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
// 2. 需要更新 → 只更新变化字段
|
||||
if (needUpdate) {
|
||||
this.updateById(updateData);
|
||||
return 2;
|
||||
}
|
||||
// 时间戳相同,跳过
|
||||
|
||||
// 3. 无需更新
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心判断规则:
|
||||
* 1. 目标字段 == null → 需要更新
|
||||
* 2. 目标字段 != null,但 和源数据值不同 → 需要更新
|
||||
* 3. 目标字段有值 + 和源相同 → 不更新
|
||||
*/
|
||||
public static boolean shouldUpdateField(Object source, Object target) {
|
||||
//目标
|
||||
if (target == null)
|
||||
return true;
|
||||
//源
|
||||
if (source == null)
|
||||
return false;
|
||||
return !target.equals(source);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lideeyunji.core.framework.service.erp;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.lideeyunji.core.framework.entity.ErpDtaSyncLogEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface ErpDataSyncLogService {
|
||||
ErpDtaSyncLogEntity selectone(@Param("dataSourceType") String dataSourceType);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.lideeyunji.core.framework.service.erp.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lideeyunji.core.framework.entity.ErpDtaSyncLogEntity;
|
||||
import com.lideeyunji.core.framework.mapper.erp.ErpDataSyncLogMapper;
|
||||
import com.lideeyunji.core.framework.service.erp.ErpDataSyncLogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ErpDataSyncLogServiceImpl extends ServiceImpl<ErpDataSyncLogMapper, ErpDtaSyncLogEntity> implements ErpDataSyncLogService{
|
||||
|
||||
@DSTransactional
|
||||
@DS(value = "#dataSourceType")
|
||||
public ErpDtaSyncLogEntity selectone( String dataSourceType) {
|
||||
// 1. 打印注解上配置的数据源名称
|
||||
System.out.println("1. @DS 注解指定的数据源是: erp");
|
||||
|
||||
// 2. 获取当前线程正在使用的数据源 Key
|
||||
String currentDsKey = DynamicDataSourceContextHolder.peek();
|
||||
System.out.println("2. 当前线程使用的数据源 Key 是: " + currentDsKey);
|
||||
List<ErpDtaSyncLogEntity> list = this.baseMapper.getList(
|
||||
dataSourceType
|
||||
);
|
||||
return list.isEmpty() ? null : list.get(0);
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,12 @@ public interface lideeYunJiBaseConstant {
|
||||
String DS_MASTER="master";//主服务
|
||||
String DS_ORACLE_GRYYBI="oracle_gryybi";//报表平台 oracle
|
||||
String DS_ERP_BI_DATA="erp_bi_data";//报表平台 mysql
|
||||
String ERP_DATASOURCE = "erp";
|
||||
String SJZT_DATASOURCE = "sjzt";
|
||||
|
||||
String REQUEST_URL_START="/lideeyunji";//公共请求
|
||||
String BASE_PACKAGES="com.lideeyunji";//公共包名称
|
||||
String BASE_PACKAGES_CODE=BASE_PACKAGES+".core";//核心包名
|
||||
String BASE_PACKAGES_MODULE = BASE_PACKAGES+".module";//个人业务模块
|
||||
|
||||
}
|
||||
|
||||
1400
sql/gzgl.sql
1400
sql/gzgl.sql
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user