添加零件信息定时任务同步

This commit is contained in:
梁琦涛
2024-10-12 16:41:07 +08:00
parent bd30ab964d
commit a641540e4d
10 changed files with 168 additions and 20 deletions
@@ -0,0 +1,45 @@
package com.jero.modules.laws.part.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 零件信息
*
* @TableName laws_ods_qr_cgbom_pmm_info_part_diff_df
*/
@TableName(value ="laws_ods_qr_cgbom_pmm_info_part_diff_df")
@Data
public class LawsOdsQrCgbomPmmInfoPartDiffDf implements Serializable {
/**
* 零件号
*/
private String partnumber;
/**
* 零件名称(中文)
*/
private String partnamecn;
/**
* 零件名称(英文)
*/
private String partnameen;
/**
* 首次适用FND代码
*/
private String firstusedfna;
/**
* 首次适用GPC
*/
private String firstusedupc;
/**
* 上一次修改时间
*/
private String lastmodifiedtime;
/**
* 传输批次
*/
private String transuid;
}
@@ -25,7 +25,7 @@ public class LawsPartInfo implements Serializable {
/**
* 主键ID
*/
@TableId(type = IdType.ASSIGN_ID)
@TableId(type = IdType.AUTO)
@ApiModelProperty(value = "主键ID")
private String id;
/**
@@ -79,4 +79,16 @@ public class LawsPartInfo implements Serializable {
*/
@ApiModelProperty(value = "FND+GPC关联")
private String fndGpc;
/**
* 上一次修改时间
*/
@ApiModelProperty(value = "上一次修改时间")
private String lastModifiedTime;
/**
* 传输批次
*/
@ApiModelProperty(value = "传输批次")
private String transuId;
}
@@ -1,12 +1,21 @@
package com.jero.modules.laws.part.job;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.jero.modules.laws.part.entity.LawsOdsQrCgbomPmmInfoPartDiffDf;
import com.jero.modules.laws.part.entity.LawsPartInfo;
import com.jero.modules.laws.part.service.ILawsOdsQrCgbomPmmInfoPartDiffDfService;
import com.jero.modules.laws.part.service.ILawsPartInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
/**
* 同步零件数据
@@ -16,10 +25,59 @@ public class SyncPartPmmInfoPartDiffJob implements Job {
@Resource
private ILawsPartInfoService lawsPartInfoService;
@Resource
private ILawsOdsQrCgbomPmmInfoPartDiffDfService lawsOdsQrCgbomPmmInfoPartDiffDfService;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
lawsPartInfoService.truncatePartPmmInfoPartDiff();
lawsPartInfoService.syncPartPmmInfoPartDiff();
long l = lawsPartInfoService.count();
// 首次同步全量数据
if(l == 0){
lawsPartInfoService.syncPartPmmInfoPartDiff();
return;
}
// 同步增量
QueryWrapper<LawsPartInfo> query = new QueryWrapper<>();
query.select("max(transu_id) as transu_id");
query.isNotNull("transu_id");
LawsPartInfo transuIdObj = lawsPartInfoService.getOne(query,false);
if(Objects.isNull(transuIdObj)){
lawsPartInfoService.syncPartPmmInfoPartDiff();
return;
}
LambdaQueryWrapper<LawsOdsQrCgbomPmmInfoPartDiffDf> queryLawsOdsQrCgbomPmmInfoPartDiffDf = new LambdaQueryWrapper<>();
queryLawsOdsQrCgbomPmmInfoPartDiffDf.gt(LawsOdsQrCgbomPmmInfoPartDiffDf::getTransuid,transuIdObj.getTransuId());
List<LawsOdsQrCgbomPmmInfoPartDiffDf> listLawsOdsQrCgbomPmmInfoPartDiffDf = lawsOdsQrCgbomPmmInfoPartDiffDfService.list(queryLawsOdsQrCgbomPmmInfoPartDiffDf);
if(CollectionUtils.isEmpty(listLawsOdsQrCgbomPmmInfoPartDiffDf)){
return;
}
for (LawsOdsQrCgbomPmmInfoPartDiffDf obj : listLawsOdsQrCgbomPmmInfoPartDiffDf) {
LambdaQueryWrapper<LawsPartInfo> queryLawsPartInfo = new LambdaQueryWrapper<>();
queryLawsPartInfo.eq(LawsPartInfo::getPartNum,obj.getPartnumber());
LawsPartInfo lawsPartInfo = lawsPartInfoService.getOne(queryLawsPartInfo,false);
// 新增
if(Objects.isNull(lawsPartInfo)){
LawsPartInfo data = new LawsPartInfo();
data.setPartNum(obj.getPartnumber());
data.setPartName(obj.getPartnamecn());
data.setPartNameEn(obj.getPartnameen());
data.setFndGpc(obj.getFirstusedfna() + obj.getFirstusedupc());
data.setLastModifiedTime(obj.getLastmodifiedtime());
data.setTransuId(obj.getTransuid());
lawsPartInfoService.save(data);
}else{
// 修改
LambdaUpdateWrapper<LawsPartInfo> update = new LambdaUpdateWrapper<>();
update.eq(LawsPartInfo::getId,lawsPartInfo.getId());
update.set(LawsPartInfo::getPartNum,obj.getPartnumber());
update.set(LawsPartInfo::getPartName,obj.getPartnamecn());
update.set(LawsPartInfo::getPartNameEn,obj.getPartnameen());
update.set(LawsPartInfo::getFndGpc,obj.getFirstusedfna() + obj.getFirstusedupc());
update.set(LawsPartInfo::getLastModifiedTime,obj.getLastmodifiedtime());
update.set(LawsPartInfo::getTransuId,obj.getTransuid());
lawsPartInfoService.update(update);
}
}
}
}
@@ -0,0 +1,13 @@
package com.jero.modules.laws.part.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jero.modules.laws.part.entity.LawsOdsQrCgbomPmmInfoPartDiffDf;
public interface LawsOdsQrCgbomPmmInfoPartDiffDfMapper extends BaseMapper<LawsOdsQrCgbomPmmInfoPartDiffDf> {
}
@@ -3,14 +3,13 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jero.modules.laws.part.mapper.LawsPartInfoMapper">
<delete id="truncatePartPmmInfoPartDiff">
TRUNCATE TABLE ods_qr_cgbom_pmm_info_part_diff_df;
</delete>
<insert id="syncPartPmmInfoPartDiff">
insert into laws_part_pmm_partition_info(reg_part_name_cn,fnd_gpc)
(SELECT regpartnamecn as reg_part_name_cn,CONCAT(fna,upc) as fnd_gpc FROM `ods_qr_cgbom_pmm_partition_info_df` where fna is not null and upc is not null
and regpartnamecn is not null and regpartnamecn != '-' and regpartnamecn != '/' group by CONCAT(fna,upc))
insert into laws_part_info(part_num,part_name, part_name_en,fnd_gpc,last_modified_time,transu_id,create_by,create_time,del_flag)
(select o2.partnumber,o2.partnamecn,o2.partnameen,CONCAT(o2.firstusedfna,o2.firstusedupc),o2.lastmodifiedtime,o2.transuid,'admin',NOW(),'0' from
(
select partnumber,CONCAT(firstusedfna,firstusedupc),count(*),max(lastmodifiedtime) as lastmodifiedtime,max(transuid) as transuid from laws_ods_qr_cgbom_pmm_info_part_diff_df
group by partnumber
) o1
left join laws_ods_qr_cgbom_pmm_info_part_diff_df o2 on o1.partnumber = o2.partnumber and o1.lastmodifiedtime = o2.lastmodifiedtime and o1.transuid = o2.transuid)
</insert>
</mapper>
@@ -5,8 +5,8 @@
<mapper namespace="com.jero.modules.laws.part.mapper.LawsPartPmmPartitionInfoMapper">
<insert id="syncLawsPartPmmPartitionInfo">
insert into laws_part_pmm_partition_info(reg_part_name_cn,fnd_gpc)
(SELECT regpartnamecn as reg_part_name_cn,CONCAT(fna,upc) as fnd_gpc FROM `ods_qr_cgbom_pmm_partition_info_df` where fna is not null and upc is not null
insert into laws_part_pmm_partition_info(reg_part_name_cn,fnd_gpc,create_by,create_time,del_flag)
(SELECT regpartnamecn as reg_part_name_cn,CONCAT(fna,upc) as fnd_gpc,'admin',NOW(),'0' FROM `laws_ods_qr_cgbom_pmm_partition_info_df` where fna is not null and upc is not null
and regpartnamecn is not null and regpartnamecn != '-' and regpartnamecn != '/' group by CONCAT(fna,upc))
</insert>
<delete id="truncateLawsPartPmmPartitionInfo">
@@ -0,0 +1,8 @@
package com.jero.modules.laws.part.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.laws.part.entity.LawsOdsQrCgbomPmmInfoPartDiffDf;
public interface ILawsOdsQrCgbomPmmInfoPartDiffDfService extends IService<LawsOdsQrCgbomPmmInfoPartDiffDf> {
}
@@ -14,7 +14,5 @@ public interface ILawsPartInfoService extends IService<LawsPartInfo> {
IPage<LawsPartInfo> queryPage(LawsPartInfo lawsPartInfo,Integer pageNo, Integer pageSize,HttpServletRequest req);
void truncatePartPmmInfoPartDiff();
void syncPartPmmInfoPartDiff();
}
@@ -0,0 +1,20 @@
package com.jero.modules.laws.part.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.modules.laws.part.entity.LawsOdsQrCgbomPmmInfoPartDiffDf;
import com.jero.modules.laws.part.mapper.LawsOdsQrCgbomPmmInfoPartDiffDfMapper;
import com.jero.modules.laws.part.service.ILawsOdsQrCgbomPmmInfoPartDiffDfService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class LawsOdsQrCgbomPmmInfoPartDiffDfServiceImpl extends ServiceImpl<LawsOdsQrCgbomPmmInfoPartDiffDfMapper, LawsOdsQrCgbomPmmInfoPartDiffDf>
implements ILawsOdsQrCgbomPmmInfoPartDiffDfService {
}
@@ -39,11 +39,6 @@ public class LawsPartInfoServiceImpl extends ServiceImpl<LawsPartInfoMapper, Law
return page(page, queryWrapper);
}
@Override
public void truncatePartPmmInfoPartDiff() {
lawsPartInfoMapper.truncatePartPmmInfoPartDiff();
}
@Override
public void syncPartPmmInfoPartDiff() {
lawsPartInfoMapper.syncPartPmmInfoPartDiff();