|
|
|
@ -4,13 +4,16 @@ import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
|
import com.op.common.core.utils.DateUtils;
|
|
|
|
|
import com.op.common.core.utils.bean.BeanUtils;
|
|
|
|
|
import com.op.common.core.utils.uuid.IdUtils;
|
|
|
|
|
import com.op.common.security.utils.SecurityUtils;
|
|
|
|
|
import com.op.mes.domain.*;
|
|
|
|
|
import com.op.mes.mapper.MesReportWorkMapper;
|
|
|
|
|
import com.op.system.api.RemoteSapService;
|
|
|
|
|
import com.op.system.api.domain.dto.BaseBomDTO;
|
|
|
|
|
import com.op.system.api.domain.mes.BaseProductDTO;
|
|
|
|
|
import com.op.system.api.domain.mes.BaseTeamTDTO;
|
|
|
|
@ -38,6 +41,9 @@ public class MesReportWorkConsumeServiceImpl implements IMesReportWorkConsumeSer
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesReportWorkMapper mesReportWorkMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RemoteSapService remoteSapService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询生产报工物料消耗
|
|
|
|
|
*
|
|
|
|
@ -164,42 +170,82 @@ public class MesReportWorkConsumeServiceImpl implements IMesReportWorkConsumeSer
|
|
|
|
|
@Override
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
public int submitConsumePS(List<MesReportWorkConsume> mesReportWorkConsumes) {
|
|
|
|
|
Date nowTime = DateUtils.getNowDate();
|
|
|
|
|
String updateBy = SecurityUtils.getUsername();
|
|
|
|
|
for (MesReportWorkConsume mesReportWorkConsume : mesReportWorkConsumes) {
|
|
|
|
|
mesReportWorkConsume.setUpdateTime(nowTime);
|
|
|
|
|
mesReportWorkConsume.setUpdateBy(updateBy);
|
|
|
|
|
|
|
|
|
|
//根据belong_work_order找到sap工单(子子母)
|
|
|
|
|
List<MesReportWork> workOrders = mesReportWorkMapper.getSapWorkOrder(mesReportWorkConsumes.get(0).getParentOrder());
|
|
|
|
|
if (CollectionUtils.isEmpty(workOrders)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
List<MesReportWorkConsume> updates = mesReportWorkConsumes
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(u -> u.getCreateTime()!=null).collect(Collectors.toList());
|
|
|
|
|
List<MesReportWorkConsume> adds = mesReportWorkConsumes
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(u -> u.getCreateTime()==null).collect(Collectors.toList());
|
|
|
|
|
if(!CollectionUtils.isEmpty(adds)){
|
|
|
|
|
Map<String,MesReportWorkConsume> consumeInfoMap = new HashMap<>();
|
|
|
|
|
for(MesReportWorkConsume add:adds){
|
|
|
|
|
MesReportWorkConsume newConsumeInfo = consumeInfoMap.get(add.getWorkorderCode());
|
|
|
|
|
if(newConsumeInfo==null){
|
|
|
|
|
MesReportWorkConsume mapItem = mesReportWorkConsumeMapper.getNewConsumeInfo(add.getWorkorderCode());
|
|
|
|
|
consumeInfoMap.put(add.getWorkorderCode(),mapItem);
|
|
|
|
|
|
|
|
|
|
/**修改sap物料损耗组成**/
|
|
|
|
|
R updateBomsSap = this.updateAttr1BomsSap(workOrders);
|
|
|
|
|
if(updateBomsSap.getCode()== 500){
|
|
|
|
|
return 0;
|
|
|
|
|
}else {
|
|
|
|
|
Date nowTime = DateUtils.getNowDate();
|
|
|
|
|
String updateBy = SecurityUtils.getUsername();
|
|
|
|
|
for (MesReportWorkConsume mesReportWorkConsume : mesReportWorkConsumes) {
|
|
|
|
|
mesReportWorkConsume.setUpdateTime(nowTime);
|
|
|
|
|
mesReportWorkConsume.setUpdateBy(updateBy);
|
|
|
|
|
}
|
|
|
|
|
List<MesReportWorkConsume> updates = mesReportWorkConsumes
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(u -> u.getCreateTime() != null).collect(Collectors.toList());
|
|
|
|
|
List<MesReportWorkConsume> adds = mesReportWorkConsumes
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(u -> u.getCreateTime() == null).collect(Collectors.toList());
|
|
|
|
|
if (!CollectionUtils.isEmpty(adds)) {
|
|
|
|
|
Map<String, MesReportWorkConsume> consumeInfoMap = new HashMap<>();
|
|
|
|
|
for (MesReportWorkConsume add : adds) {
|
|
|
|
|
MesReportWorkConsume newConsumeInfo = consumeInfoMap.get(add.getWorkorderCode());
|
|
|
|
|
if (newConsumeInfo == null) {
|
|
|
|
|
MesReportWorkConsume mapItem = mesReportWorkConsumeMapper.getNewConsumeInfo(add.getWorkorderCode());
|
|
|
|
|
consumeInfoMap.put(add.getWorkorderCode(), mapItem);
|
|
|
|
|
}
|
|
|
|
|
newConsumeInfo = consumeInfoMap.get(add.getWorkorderCode());
|
|
|
|
|
|
|
|
|
|
add.setRecordId(IdUtils.fastSimpleUUID());
|
|
|
|
|
add.setReportCode(newConsumeInfo.getReportCode());
|
|
|
|
|
add.setWorkorderCode(newConsumeInfo.getWorkorderCode());
|
|
|
|
|
add.setCreateTime(nowTime);
|
|
|
|
|
add.setCreateTime(nowTime);
|
|
|
|
|
add.setAttr1("1");//新增标识
|
|
|
|
|
add.setParentOrder(newConsumeInfo.getParentOrder());
|
|
|
|
|
}
|
|
|
|
|
newConsumeInfo = consumeInfoMap.get(add.getWorkorderCode());
|
|
|
|
|
|
|
|
|
|
add.setRecordId(IdUtils.fastSimpleUUID());
|
|
|
|
|
add.setReportCode(newConsumeInfo.getReportCode());
|
|
|
|
|
add.setWorkorderCode(newConsumeInfo.getWorkorderCode());
|
|
|
|
|
add.setCreateTime(nowTime);
|
|
|
|
|
add.setCreateTime(nowTime);
|
|
|
|
|
add.setAttr1("1");//新增标识
|
|
|
|
|
add.setParentOrder(newConsumeInfo.getParentOrder());
|
|
|
|
|
int addNum = mesReportWorkConsumeMapper.addConsumePS(adds);
|
|
|
|
|
System.out.println("addNum:" + addNum);
|
|
|
|
|
}
|
|
|
|
|
int updateNum = mesReportWorkConsumeMapper.submitConsumePS(updates);
|
|
|
|
|
System.out.println("addNum:" + updateNum);
|
|
|
|
|
return updateNum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//修改报工物料组成
|
|
|
|
|
private R updateAttr1BomsSap(List<MesReportWork> workOrderCodes) {
|
|
|
|
|
//是否有变动的物料损耗组成
|
|
|
|
|
List<MesReportWorkConsume> updateBoms = mesReportWorkMapper.getUpdateAttr1Boms(workOrderCodes.get(workOrderCodes.size()-1));
|
|
|
|
|
if(!CollectionUtils.isEmpty(updateBoms)){
|
|
|
|
|
List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
|
|
Map<String, Object> mapBom = null;
|
|
|
|
|
for(MesReportWorkConsume updateBom:updateBoms){
|
|
|
|
|
mapBom = new HashMap<String, Object>();
|
|
|
|
|
mapBom.put("P_AUFNR",updateBom.getWorkorderCodeSap());// 订单号 例如:000100308287
|
|
|
|
|
mapBom.put("P_MATNR",updateBom.getMaterialCode());// 物料号 例如:000000040000015089
|
|
|
|
|
//mapBom.put("P_GMEIN",updateBom.getUnit());// 基本计量单位 例如:m
|
|
|
|
|
mapBom.put("P_WERKS",workOrderCodes.get(0).getFactoryCode());//物料工厂 例如:1000
|
|
|
|
|
mapBom.put("P_LGORT",updateBom.getWarehouseCode());//仓库编号 例如:0013
|
|
|
|
|
mapList.add(mapBom);
|
|
|
|
|
}
|
|
|
|
|
int addNum =mesReportWorkConsumeMapper.addConsumePS(adds);
|
|
|
|
|
System.out.println("addNum:"+addNum);
|
|
|
|
|
|
|
|
|
|
logger.info(workOrderCodes.get(workOrderCodes.size()-1).getWorkorderCode()
|
|
|
|
|
+ "报工损耗物料组件修改请求:" + JSONObject.toJSONString(mapList));
|
|
|
|
|
R bomUpdateR = remoteSapService.shopOrderBomUpdate(mapList);
|
|
|
|
|
logger.info(workOrderCodes.get(workOrderCodes.size()-1).getWorkorderCode()
|
|
|
|
|
+ "报工损耗物料组件修改结果:" + JSONObject.toJSONString(bomUpdateR));
|
|
|
|
|
return bomUpdateR;
|
|
|
|
|
}
|
|
|
|
|
int updateNum =mesReportWorkConsumeMapper.submitConsumePS(updates);
|
|
|
|
|
System.out.println("addNum:"+updateNum);
|
|
|
|
|
return updateNum;
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|