|
|
|
@ -2,6 +2,7 @@ package com.op.plan.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
|
import com.op.common.core.context.SecurityContextHolder;
|
|
|
|
|
import com.op.common.core.domain.R;
|
|
|
|
|
import com.op.common.core.exception.ServiceException;
|
|
|
|
@ -21,7 +22,9 @@ import com.op.system.api.domain.SysSapLog;
|
|
|
|
|
import com.op.system.api.domain.dto.MesPrepareDTO;
|
|
|
|
|
import com.op.system.api.domain.dto.MesPrepareDetailDTO;
|
|
|
|
|
import com.op.system.api.domain.sap.SapCreateOrder;
|
|
|
|
|
import com.op.system.api.domain.sap.SapMaterialPreparation;
|
|
|
|
|
import net.bytebuddy.matcher.FilterableList;
|
|
|
|
|
import org.apache.commons.collections4.ListUtils;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -33,6 +36,7 @@ import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -219,8 +223,6 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public int downProOrderWorkorderByWorkorderIds(String[] workorderIds) {
|
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
|
List<ProOrder> psorders = new ArrayList<>();//父级工单
|
|
|
|
|
List<SapCreateOrder> sapList = null;//回传给sap的工单
|
|
|
|
|
//如果是白坯生成备料单
|
|
|
|
|
for (String workorderId : workorderIds) {
|
|
|
|
@ -256,11 +258,30 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
|
|
|
|
|
details.add(detail);
|
|
|
|
|
proOrderWorkorderMapper.createPrepareDetails(details);
|
|
|
|
|
|
|
|
|
|
ids.add(workorderId);
|
|
|
|
|
}else{
|
|
|
|
|
//无湿料计划,下发不了
|
|
|
|
|
}
|
|
|
|
|
} else if (whiteOrder != null && !"white".equals(whiteOrder.getProdType())) {//成品的母工单回传sap
|
|
|
|
|
|
|
|
|
|
whiteOrder.setUpdateBy(SecurityUtils.getUsername());
|
|
|
|
|
whiteOrder.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
return proOrderWorkorderMapper.updateWhiteWorkOrder(whiteOrder);
|
|
|
|
|
} else if (whiteOrder != null && !"white".equals(whiteOrder.getProdType())) {
|
|
|
|
|
List<String> pcodes = new ArrayList<>();//一起下发用
|
|
|
|
|
List<String> wcodes = new ArrayList<>();//领料单用
|
|
|
|
|
//成品的母工单//查上一级工单
|
|
|
|
|
Boolean isTop = true;
|
|
|
|
|
while(isTop) {
|
|
|
|
|
pcodes.add(whiteOrder.getWorkorderId());
|
|
|
|
|
wcodes.add(whiteOrder.getWorkorderCode());
|
|
|
|
|
//查上一级工单
|
|
|
|
|
whiteOrder.setWorkorderCode(whiteOrder.getParentOrder());
|
|
|
|
|
ProOrderWorkorder pWorkOrder = proOrderWorkorderMapper.getPWorkOrder(whiteOrder);
|
|
|
|
|
if(pWorkOrder == null || "0".equals(pWorkOrder.getParentOrder())){
|
|
|
|
|
isTop = false;
|
|
|
|
|
}else{
|
|
|
|
|
BeanUtils.copyProperties(pWorkOrder,whiteOrder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sapList = new ArrayList<>();
|
|
|
|
|
SapCreateOrder sap = new SapCreateOrder();
|
|
|
|
|
sap.setWerks(whiteOrder.getFactoryCode());//工厂编码
|
|
|
|
@ -274,7 +295,7 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
|
|
|
|
|
//添加调用sap日志
|
|
|
|
|
SysSapLog sysSapLog = new SysSapLog();
|
|
|
|
|
sysSapLog.setId(IdUtils.fastSimpleUUID());
|
|
|
|
|
sysSapLog.setMesssge(sapList.toString());
|
|
|
|
|
sysSapLog.setMesssge(Arrays.asList(sapList).toString());
|
|
|
|
|
sysSapLog.setMethod("downProOrderWorkorderByWorkorderIds");
|
|
|
|
|
sysSapLog.setReqcode("请求");
|
|
|
|
|
sysSapLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
@ -287,65 +308,31 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
List<String> returnCodes = r.getData();
|
|
|
|
|
Date updateTime = DateUtils.getNowDate();
|
|
|
|
|
if (!CollectionUtils.isEmpty(returnCodes)) {
|
|
|
|
|
for (String sapCode : returnCodes) {
|
|
|
|
|
logger.info("sap工单回传sap虚拟工单号:" + StringUtils.join(returnCodes, ","));
|
|
|
|
|
for (int m=0;m<returnCodes.size();m++) {
|
|
|
|
|
ProOrderWorkorder oworkSap = new ProOrderWorkorder();
|
|
|
|
|
oworkSap.setWorkorderCodeSap(sapCode);
|
|
|
|
|
oworkSap.setWorkorderId(workorderId);//工单编码
|
|
|
|
|
oworkSap.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
oworkSap.setWorkorderCodeSap(returnCodes.get(m));
|
|
|
|
|
oworkSap.setWorkorderId(pcodes.get(returnCodes.size()-(m+1)));//工单编码
|
|
|
|
|
oworkSap.setUpdateTime(updateTime);
|
|
|
|
|
/**pro_order_workorder**/
|
|
|
|
|
proOrderWorkorderMapper.updateWorkOrderCodeSap(oworkSap);
|
|
|
|
|
|
|
|
|
|
ProOrder order = this.getTopOrder(workorderId);
|
|
|
|
|
ProOrderWorkorder oworkSapParent = new ProOrderWorkorder();
|
|
|
|
|
oworkSapParent.setWorkorderCodeSap(sapCode);
|
|
|
|
|
oworkSapParent.setWorkorderId(order.getOrderCode());//母工单编码
|
|
|
|
|
oworkSapParent.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
proOrderWorkorderMapper.updateWorkOrderCodeSap(oworkSapParent);
|
|
|
|
|
|
|
|
|
|
logger.info("sap工单回传sap虚拟工单号:" + sapCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//子查父工单,都要工单状态改下发
|
|
|
|
|
ProOrder pOrder = new ProOrder();
|
|
|
|
|
pOrder.setParentOrder(workorderId);
|
|
|
|
|
List<ProOrder> pordes = getListBySonCode(pOrder);
|
|
|
|
|
if(!CollectionUtils.isEmpty(pordes)){
|
|
|
|
|
psorders.addAll(pordes);
|
|
|
|
|
}
|
|
|
|
|
//获取领料单
|
|
|
|
|
Collections.reverse(wcodes);
|
|
|
|
|
this.getMesPrepare(returnCodes,wcodes);
|
|
|
|
|
|
|
|
|
|
ids.add(workorderId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!CollectionUtils.isEmpty(ids)){
|
|
|
|
|
String[] idsArray = (String[])ids.toArray(new String[ids.size()]);
|
|
|
|
|
List<ProOrderWorkorder> workorders = proOrderWorkorderMapper.getWorkOrderByIds(idsArray);
|
|
|
|
|
for (ProOrderWorkorder workorder : workorders) {
|
|
|
|
|
//关联工艺
|
|
|
|
|
if (StringUtils.isNotBlank(workorder.getRouteCode())) {
|
|
|
|
|
List<ProWorkorderProcessDetail> workDetails = proWorkorderProcessDetailMapper.getWorkOrderDetailsByRouteCode(workorder);
|
|
|
|
|
if (!CollectionUtils.isEmpty(workDetails)) {
|
|
|
|
|
workDetails.forEach(str -> {
|
|
|
|
|
str.setRecordId(IdUtils.fastSimpleUUID());
|
|
|
|
|
str.setWorkorderId(workorder.getWorkorderId());
|
|
|
|
|
str.setStatus("s0");//未执行
|
|
|
|
|
str.setCreateBy(SecurityContextHolder.getUserName());
|
|
|
|
|
str.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
str.setFactoryCode(workorder.getFactoryCode());
|
|
|
|
|
});
|
|
|
|
|
proWorkorderProcessDetailMapper.addWorkOrderDetails(workDetails);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//下达工单
|
|
|
|
|
if(!CollectionUtils.isEmpty(psorders)){
|
|
|
|
|
List<String> pcodes = psorders.stream().map(e -> e.getOrderCode()).collect(Collectors.toList());
|
|
|
|
|
ids.addAll(pcodes);
|
|
|
|
|
//关闭订单//母订单的订单编码
|
|
|
|
|
R closeR= remoteSapService.sapCloseOrder(whiteOrder.getOrderCode());
|
|
|
|
|
logger.info("下发工单后关闭订单"+whiteOrder.getOrderCode()+":"+closeR.getMsg());
|
|
|
|
|
|
|
|
|
|
//下达工单
|
|
|
|
|
String[] idsArrayAll = (String[])pcodes.toArray(new String[pcodes.size()]);
|
|
|
|
|
return proOrderWorkorderMapper.downWorkorders(idsArrayAll);
|
|
|
|
|
}
|
|
|
|
|
String[] idsArrayAll = (String[])ids.toArray(new String[ids.size()]);
|
|
|
|
|
//下达工单
|
|
|
|
|
return proOrderWorkorderMapper.downProOrderWorkorderByWorkorderIds(idsArrayAll);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -361,45 +348,73 @@ public class ProOrderWorkorderServiceImpl implements IProOrderWorkorderService {
|
|
|
|
|
return codeList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// //获取最低级材料
|
|
|
|
|
// private void getLastChildren(List<BaseBomComponentDTO> all, List<BaseBomComponentDTO> allChildren , BaseBomComponentDTO bc) {
|
|
|
|
|
// List<BaseBomComponentDTO> cList = all.stream().filter(item -> item.getCumc().equals(bc.getComponent()))
|
|
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
// if(CollectionUtils.isEmpty(cList)){
|
|
|
|
|
// allChildren.add(bc);
|
|
|
|
|
// }else{
|
|
|
|
|
// for(BaseBomComponentDTO bcc : cList){
|
|
|
|
|
// getLastChildren(all, allChildren ,bcc);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //获取顶级定单的bom组成
|
|
|
|
|
// private List<BaseBomComponentDTO> getBomDtos(String workorderId){
|
|
|
|
|
// List<BaseBomComponentDTO> bomdtoAdds = new ArrayList<>();//所有数据
|
|
|
|
|
//
|
|
|
|
|
// List<BaseBomComponentDTO> cumsDtos = new ArrayList<>();
|
|
|
|
|
// BaseBomComponentDTO cumsDto = new BaseBomComponentDTO();
|
|
|
|
|
// ProOrder order = this.getTopOrder(workorderId);
|
|
|
|
|
// cumsDto.setCumc(order.getProdCode());
|
|
|
|
|
// cumsDtos.add(cumsDto);
|
|
|
|
|
// List<BaseBomComponentDTO> bomdtos = proOrderWorkorderMapper.getBomComponents(order,cumsDtos);//最新版本的第一层子
|
|
|
|
|
// bomdtoAdds.addAll(bomdtos);
|
|
|
|
|
// Boolean isTrue = true;
|
|
|
|
|
// while(isTrue){
|
|
|
|
|
// List<BaseBomComponentDTO> bomdtoTop = new ArrayList<>();
|
|
|
|
|
// bomdtos.forEach(e->e.setCumc(e.getComponent()));
|
|
|
|
|
// bomdtoTop.addAll(bomdtos);
|
|
|
|
|
// List<BaseBomComponentDTO> bomdtoSon = proOrderWorkorderMapper.getBomComponents(order,bomdtoTop);
|
|
|
|
|
// if(CollectionUtils.isEmpty(bomdtoSon)){
|
|
|
|
|
// isTrue = false;
|
|
|
|
|
// }else{
|
|
|
|
|
// bomdtos = bomdtoSon;
|
|
|
|
|
// bomdtoAdds.addAll(bomdtoSon);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return bomdtos;
|
|
|
|
|
// }
|
|
|
|
|
public void getMesPrepare(List<String> sapWorkOrders,List<String> workOrders) {
|
|
|
|
|
for(String sapWorkOrder:sapWorkOrders){
|
|
|
|
|
logger.info("获取sap领料单:" + sapWorkOrder+"开始");
|
|
|
|
|
// //添加调用sap日志
|
|
|
|
|
// SysSapLog sysSapLog = new SysSapLog();
|
|
|
|
|
// sysSapLog.setId(IdUtils.fastSimpleUUID());
|
|
|
|
|
// sysSapLog.setMesssge(sapWorkOrder);
|
|
|
|
|
// sysSapLog.setMethod("getMesPrepare");
|
|
|
|
|
// sysSapLog.setReqcode("请求");
|
|
|
|
|
// sysSapLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
// proOrderMapper.addSapLog(sysSapLog);
|
|
|
|
|
|
|
|
|
|
List<SapMaterialPreparation> sapMaterialPreparationList = remoteSapService.materialPreparation(sapWorkOrder).getData();
|
|
|
|
|
if (CollectionUtils.isEmpty(sapMaterialPreparationList)) {
|
|
|
|
|
System.out.println("sap无领料单数据");
|
|
|
|
|
}
|
|
|
|
|
//取出各领料单
|
|
|
|
|
List<String> orderCodes = sapMaterialPreparationList.stream().map(SapMaterialPreparation::getAUFNR).collect(Collectors.toList());
|
|
|
|
|
Date createDate = DateUtils.getNowDate();
|
|
|
|
|
for (int m = 0;m<orderCodes.size();m++) {
|
|
|
|
|
String orderCode = orderCodes.get(m);
|
|
|
|
|
logger.info("领料单内容:"+orderCode);
|
|
|
|
|
/**mes_prepare**/
|
|
|
|
|
String mesPrepareId = IdUtils.fastSimpleUUID();
|
|
|
|
|
MesPrepareDTO mesPrepare0 = new MesPrepareDTO();
|
|
|
|
|
mesPrepare0.setPrepareId(mesPrepareId);
|
|
|
|
|
mesPrepare0.setWorkorderCode(workOrders.get(m));
|
|
|
|
|
mesPrepare0.setWorkorderName(orderCode);//工单(子)
|
|
|
|
|
mesPrepare0.setCreateTime(createDate);
|
|
|
|
|
mesPrepare0.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
|
mesPrepare0.setStatus("L0");//默认待确认
|
|
|
|
|
proOrderWorkorderMapper.insertMesPrepare(mesPrepare0);
|
|
|
|
|
/**mes_prepare_detail**/
|
|
|
|
|
List<MesPrepareDetailDTO> details = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
MesPrepareDetailDTO detail = null;
|
|
|
|
|
for (SapMaterialPreparation sap : sapMaterialPreparationList) {
|
|
|
|
|
detail = new MesPrepareDetailDTO();
|
|
|
|
|
detail.setPrepareId(mesPrepareId);
|
|
|
|
|
detail.setRecordId(IdUtils.fastSimpleUUID());
|
|
|
|
|
detail.setAttr1(sap.getRSPOS());//预留/相关需求的项目编号
|
|
|
|
|
detail.setMaterialCode(sap.getMATNR());//物料号
|
|
|
|
|
detail.setMaterailName(sap.getMAKTX());//物料描述(短文本)
|
|
|
|
|
detail.setFactoryCode(sap.getWERKS());//工厂
|
|
|
|
|
detail.setLocator(sap.getLGORT());//库存地点
|
|
|
|
|
detail.setNeedDate(sap.getBDTER());//组件的需求日期
|
|
|
|
|
detail.setQuantity(sap.getBDMNG());////需求量
|
|
|
|
|
detail.setFundQuanlity(sap.getZQLSL());//欠料数量
|
|
|
|
|
detail.setUnit(sap.getMEINS());//基本计量单位
|
|
|
|
|
detail.setRecoil(sap.getRGEKZ());//反冲标识
|
|
|
|
|
detail.setBuyFlag(sap.getDBSKZ());//直接采购标识
|
|
|
|
|
detail.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
|
detail.setCreateTime(createDate);
|
|
|
|
|
details.add(detail);
|
|
|
|
|
logger.info("领料单内容detail:"+sap.getRSPOS()+","+sap.getMATNR()+","+
|
|
|
|
|
sap.getMAKTX()+","+sap.getWERKS()+","+ sap.getLGORT()+","+
|
|
|
|
|
sap.getBDTER()+","+sap.getBDMNG()+","+sap.getZQLSL()+","+
|
|
|
|
|
sap.getMEINS()+","+sap.getRGEKZ()+","+sap.getDBSKZ()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
proOrderWorkorderMapper.insertMesPrepareDetails(details);
|
|
|
|
|
logger.info("获取sap领料单:" + sapWorkOrder+"结束");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据工单子单编码获取最顶级订单的母单
|
|
|
|
|
private ProOrder getTopOrder(String workorderId) {
|
|
|
|
|
//pro_order_workorder
|
|
|
|
|