【工作中心】同步SAP逻辑优化
This commit is contained in:
parent
9d99f8bf60
commit
f6c5072ee4
|
|
@ -1,7 +1,8 @@
|
||||||
package com.nflg.product.technology.service;
|
package com.nflg.product.technology.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
|
@ -73,17 +74,15 @@ public class ProcessWorkCenterService extends ServiceImpl<ProcessWorkCenterMappe
|
||||||
if (!CollectionUtils.isEmpty(tOut)) {
|
if (!CollectionUtils.isEmpty(tOut)) {
|
||||||
log.info("工作中心SAP数据:{}", JSON.toJSONString(tOut));
|
log.info("工作中心SAP数据:{}", JSON.toJSONString(tOut));
|
||||||
// 只过滤出作业类型是:1000 人工的工作中心数据(一般情况下同一工厂同一工作中心存5条,作业类型 1000 2000 3000 4000 空,取一条即可)
|
// 只过滤出作业类型是:1000 人工的工作中心数据(一般情况下同一工厂同一工作中心存5条,作业类型 1000 2000 3000 4000 空,取一条即可)
|
||||||
tOut = tOut.stream().filter(add -> "1000".equals(add.get("LSTAR"))).collect(Collectors.toList());
|
tOut = tOut.stream().filter(out -> "1000".equals(out.get("LSTAR"))).collect(Collectors.toList());
|
||||||
List<ProcessWorkCenterEntity> addList = new ArrayList<>(tOut.size());
|
// SAP所有数据
|
||||||
|
List<ProcessWorkCenterEntity> sapList = new ArrayList<>(tOut.size());
|
||||||
tOut.forEach(out -> {
|
tOut.forEach(out -> {
|
||||||
ProcessWorkCenterEntity add = new ProcessWorkCenterEntity();
|
ProcessWorkCenterEntity add = new ProcessWorkCenterEntity();
|
||||||
add.setRowId(IdWorker.getId());
|
|
||||||
// add.setMaterialNo(out.get("MATNR").toString().replaceAll("^[0]+",""));
|
|
||||||
add.setWorkCenter(out.get("ARBPL").toString());
|
add.setWorkCenter(out.get("ARBPL").toString());
|
||||||
add.setFactory(out.get("WERKS").toString());
|
add.setFactory(out.get("WERKS").toString());
|
||||||
add.setName(out.get("KTEXT1").toString());
|
add.setName(out.get("KTEXT1").toString());
|
||||||
add.setType(out.get("VERWE").toString());
|
add.setType(out.get("VERWE").toString());
|
||||||
// workCenter.setDescription();// 描述
|
|
||||||
add.setHeader(out.get("VERAN").toString());
|
add.setHeader(out.get("VERAN").toString());
|
||||||
add.setHeaderDescription(out.get("KTEXT").toString());
|
add.setHeaderDescription(out.get("KTEXT").toString());
|
||||||
add.setUsefulness(out.get("PLANV").toString());
|
add.setUsefulness(out.get("PLANV").toString());
|
||||||
|
|
@ -102,25 +101,44 @@ public class ProcessWorkCenterService extends ServiceImpl<ProcessWorkCenterMappe
|
||||||
add.setProcessingFormulaDescription(out.get("TXT2").toString());
|
add.setProcessingFormulaDescription(out.get("TXT2").toString());
|
||||||
add.setCostControllingArea(out.get("KOKRS").toString());
|
add.setCostControllingArea(out.get("KOKRS").toString());
|
||||||
add.setCostCenter(out.get("KOSTL").toString());
|
add.setCostCenter(out.get("KOSTL").toString());
|
||||||
add.setCreatedBy(SessionUtil.getUserName());
|
|
||||||
add.setCreatedTime(new Date());
|
|
||||||
add.setUpdatedBy(SessionUtil.getUserName());
|
add.setUpdatedBy(SessionUtil.getUserName());
|
||||||
add.setUpdatedTime(new Date());
|
add.setUpdatedTime(new Date());
|
||||||
// workCenter.setCostCenterDescription();// 成本中心描述
|
sapList.add(add);
|
||||||
// workCenter.setStartTime();//开始日期
|
|
||||||
// workCenter.setEndTime();结束日期
|
|
||||||
// processWorkCenterMapper.insert(add);
|
|
||||||
addList.add(add);
|
|
||||||
});
|
});
|
||||||
// 删除旧数据
|
// 数据库已有数据
|
||||||
LambdaQueryWrapper<ProcessWorkCenterEntity> wrapper = new LambdaQueryWrapper<>();
|
List<ProcessWorkCenterEntity> dbList = this.list();
|
||||||
processWorkCenterMapper.delete(wrapper);
|
Set<String> workCenterSet = new HashSet<>();
|
||||||
|
if (CollUtil.isNotEmpty(dbList)) {
|
||||||
//全量新增
|
// 工厂_工作中心代码 唯一
|
||||||
processWorkCenterMapper.insertBatch(addList);
|
workCenterSet = dbList.stream().map(item -> item.getFactory() + "_" + item.getWorkCenter()).collect(Collectors.toSet());
|
||||||
/* list = Convert.convert(new TypeReference<List<ProcessWorkCenterVO>>() {
|
}
|
||||||
}, tOut);*/
|
|
||||||
|
|
||||||
|
// 本次SAP新增数据
|
||||||
|
List<ProcessWorkCenterEntity> newList = new ArrayList<>();
|
||||||
|
// 数据库已有的SAP数据
|
||||||
|
List<ProcessWorkCenterEntity> existsList = new ArrayList<>();
|
||||||
|
for (ProcessWorkCenterEntity sap : sapList) {
|
||||||
|
if (!workCenterSet.contains(sap.getFactory() + "_" + sap.getWorkCenter())) {
|
||||||
|
sap.setRowId(IdWorker.getId());
|
||||||
|
sap.setCreatedBy(SessionUtil.getUserName());
|
||||||
|
sap.setCreatedTime(new Date());
|
||||||
|
// TODO 自动关联虚拟工作中心
|
||||||
|
newList.add(sap);
|
||||||
|
} else {
|
||||||
|
existsList.add(sap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(newList)) {
|
||||||
|
this.saveBatch(newList);
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(existsList)) {
|
||||||
|
existsList.forEach(exists -> {
|
||||||
|
UpdateWrapper<ProcessWorkCenterEntity> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("factory", exists.getFactory())
|
||||||
|
.eq("work_center", exists.getWorkCenter());
|
||||||
|
this.update(exists, updateWrapper);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue