sap接口调整

highway
zhaoxiaolin 1 year ago
parent 170a3926a8
commit 1cedbf3c9e

@ -1,15 +1,14 @@
package com.op.system.api.domain.dto;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.op.common.core.annotation.Excel;
import com.op.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
import com.op.common.core.annotation.Excel;
import com.op.common.core.web.domain.BaseEntity;
/**
* mes_prepare
* mes_prepareDTO
*
* @author Open Platform
* @date 2023-08-03
@ -23,6 +22,7 @@ public class MesPrepareDTO extends BaseEntity {
/** 工单编码 */
@Excel(name = "工单编码")
private String workorderCode;
private String workorderCodeSap;
/** 工单名称 */
@Excel(name = "工单名称")
@ -120,6 +120,25 @@ public class MesPrepareDTO extends BaseEntity {
/** 工厂编码 */
@Excel(name = "工厂编码")
private String factoryCode;
private String dayStr;
public String getWorkorderCodeSap() {
return workorderCodeSap;
}
public void setWorkorderCodeSap(String workorderCodeSap) {
this.workorderCodeSap = workorderCodeSap;
}
public String getDayStr() {
return dayStr;
}
public void setDayStr(String dayStr) {
this.dayStr = dayStr;
}
public String getMaterialCode() {
return materialCode;
}
@ -305,37 +324,37 @@ public class MesPrepareDTO extends BaseEntity {
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("prepareId", getPrepareId())
.append("workorderCode", getWorkorderCode())
.append("workorderName", getWorkorderName())
.append("parentOrder", getParentOrder())
.append("orderId", getOrderId())
.append("orderCode", getOrderCode())
.append("productId", getProductId())
.append("productCode", getProductCode())
.append("prodType", getProdType())
.append("productName", getProductName())
.append("productSpc", getProductSpc())
.append("wetDetailPlanId", getWetDetailPlanId())
.append("productDate", getProductDate())
.append("shiftId", getShiftId())
.append("ancestors", getAncestors())
.append("status", getStatus())
.append("remark", getRemark())
.append("attr1", getAttr1())
.append("attr2", getAttr2())
.append("attr3", getAttr3())
.append("attr4", getAttr4())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("factoryCode", getFactoryCode())
.append("materialCode", getMaterialCode())
.append("materialName", getMaterialName())
.append("materialSpc", getMaterialSpc())
.append("quantity", getQuantity())
.append("unit", getUnit())
.toString();
.append("prepareId", getPrepareId())
.append("workorderCode", getWorkorderCode())
.append("workorderName", getWorkorderName())
.append("parentOrder", getParentOrder())
.append("orderId", getOrderId())
.append("orderCode", getOrderCode())
.append("productId", getProductId())
.append("productCode", getProductCode())
.append("prodType", getProdType())
.append("productName", getProductName())
.append("productSpc", getProductSpc())
.append("wetDetailPlanId", getWetDetailPlanId())
.append("productDate", getProductDate())
.append("shiftId", getShiftId())
.append("ancestors", getAncestors())
.append("status", getStatus())
.append("remark", getRemark())
.append("attr1", getAttr1())
.append("attr2", getAttr2())
.append("attr3", getAttr3())
.append("attr4", getAttr4())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("factoryCode", getFactoryCode())
.append("materialCode", getMaterialCode())
.append("materialName", getMaterialName())
.append("materialSpc", getMaterialSpc())
.append("quantity", getQuantity())
.append("unit", getUnit())
.toString();
}
}

@ -1,12 +1,11 @@
package com.op.system.api.domain.dto;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.op.common.core.annotation.Excel;
import com.op.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
import com.op.common.core.annotation.Excel;
import com.op.common.core.web.domain.BaseEntity;
/**
* mes mes_prepare_detail
@ -42,7 +41,9 @@ public class MesPrepareDetailDTO extends BaseEntity {
/** 生产数量 */
@Excel(name = "生产数量")
private Long quantity;
private String quantity;
private String fundQuanlity;
/** 工单生产日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@ -76,11 +77,57 @@ public class MesPrepareDetailDTO extends BaseEntity {
/** 产品类型 */
@Excel(name = "产品类型")
private String prodType;
/** 库位 */
private String locator;
private String needDate;
private String recoil;
private String buyFlag;
public String getBuyFlag() {
return buyFlag;
}
public void setBuyFlag(String buyFlag) {
this.buyFlag = buyFlag;
}
/** $column.columnComment */
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
private String factoryCode;
public String getRecoil() {
return recoil;
}
public void setRecoil(String recoil) {
this.recoil = recoil;
}
public String getFundQuanlity() {
return fundQuanlity;
}
public void setFundQuanlity(String fundQuanlity) {
this.fundQuanlity = fundQuanlity;
}
public String getNeedDate() {
return needDate;
}
public void setNeedDate(String needDate) {
this.needDate = needDate;
}
public String getLocator() {
return locator;
}
public void setLocator(String locator) {
this.locator = locator;
}
public void setRecordId(String recordId) {
this.recordId = recordId;
}
@ -123,11 +170,11 @@ public class MesPrepareDetailDTO extends BaseEntity {
public String getUnit() {
return unit;
}
public void setQuantity(Long quantity) {
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public Long getQuantity() {
public String getQuantity() {
return quantity;
}
public void setProductDate(Date productDate) {
@ -197,27 +244,27 @@ public class MesPrepareDetailDTO extends BaseEntity {
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("recordId", getRecordId())
.append("prepareId", getPrepareId())
.append("materialCode", getMaterialCode())
.append("materailName", getMaterailName())
.append("materailSpc", getMaterailSpc())
.append("unit", getUnit())
.append("quantity", getQuantity())
.append("productDate", getProductDate())
.append("shiftId", getShiftId())
.append("status", getStatus())
.append("remark", getRemark())
.append("attr1", getAttr1())
.append("attr2", getAttr2())
.append("attr3", getAttr3())
.append("attr4", getAttr4())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("prodType", getProdType())
.append("factoryCode", getFactoryCode())
.toString();
.append("recordId", getRecordId())
.append("prepareId", getPrepareId())
.append("materialCode", getMaterialCode())
.append("materailName", getMaterailName())
.append("materailSpc", getMaterailSpc())
.append("unit", getUnit())
.append("quantity", getQuantity())
.append("productDate", getProductDate())
.append("shiftId", getShiftId())
.append("status", getStatus())
.append("remark", getRemark())
.append("attr1", getAttr1())
.append("attr2", getAttr2())
.append("attr3", getAttr3())
.append("attr4", getAttr4())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("prodType", getProdType())
.append("factoryCode", getFactoryCode())
.toString();
}
}

@ -53,7 +53,7 @@ public class RyTask {
remoteSapService.shopOrderSync(sapProOrder);
}
/**22
/**22
* 16
* 0 00 22 * * ?
*/

@ -60,6 +60,7 @@ public interface IMesPrepareService {
*/
public int deleteMesPrepareByPrepareId(String prepareId);
/**废弃**/
public R getMesPrepare();
public R reportWorkTask();

@ -140,9 +140,11 @@ public class MesPrepareServiceImpl implements IMesPrepareService {
new LinkedBlockingQueue<Runnable>());
try {
dateSources.forEach(dateSource -> {
logger.info("++++++++++++" + dateSource.get("poolName") + "++++开始++++++++++");
Runnable run = () -> getMesPrepareByFactory(dateSource.get("poolName"));
executorService.execute(run);
if(!"ds_999".equals(dateSource.get("poolName"))){
logger.info("++++++++++++" + dateSource.get("poolName") + "++++开始++++++++++");
Runnable run = () -> getMesPrepareByFactory(dateSource.get("poolName"));
executorService.execute(run);
}
});
} catch (Exception e) {
logger.error("service == deviceOfflineTimingTask == exception", e);
@ -156,67 +158,63 @@ public class MesPrepareServiceImpl implements IMesPrepareService {
}
public void getMesPrepareByFactory(String poolName) {
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
// List<SapMaterialPreparation> list = sapMaterialPreparationList.stream()
// .filter(a->a.getWERKS().equals(poolName))
// .collect(Collectors.toList());
//获取T+1天的所有母工单
MesPrepare qo = new MesPrepare();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);//这里改为1
Date time = cal.getTime();
qo.setDayStr(new SimpleDateFormat("yyyy-MM-dd").format(time));
List<MesPrepare> parents = mesPrepareMapper.getParentWorkOrderT1(qo);
if (CollectionUtils.isEmpty(parents)) {
System.out.println("T+1无母工单数据");
}
for (MesPrepare mesPrepare : parents) {
List<SapMaterialPreparation> sapMaterialPreparationList = remoteSapService.materialPreparation(mesPrepare.getWorkorderCodeSap()).getData();
if (CollectionUtils.isEmpty(sapMaterialPreparationList)) {
System.out.println("sap无领料单数据");
}
//取出各领料单
Set<String> orderCodes = sapMaterialPreparationList.stream().map(SapMaterialPreparation::getAUFNR).collect(Collectors.toSet());
for (String orderCode : orderCodes) {
/**mes_prepare**/
String mesPrepareId = IdUtils.fastSimpleUUID();
MesPrepare mesPrepare0 = new MesPrepare();
mesPrepare0.setPrepareId(mesPrepareId);
mesPrepare0.setWorkorderCode(orderCode);//工单(子)
mesPrepare0.setCreateTime(DateUtils.getNowDate());
mesPrepare0.setCreateBy(SecurityUtils.getUsername());
mesPrepare0.setStatus("L0");//默认待确认
mesPrepareMapper.insertMesPrepare(mesPrepare0);
/**mes_prepare_detail**/
List<MesPrepareDetail> details = new ArrayList<>();
// List<SapMaterialPreparation> listdetails = list.stream()
// .filter(a->a.getAUFNR().equals(orderCode))
// .collect(Collectors.toList());
MesPrepareDetail detail = null;
Date createDate = DateUtils.getNowDate();
for (SapMaterialPreparation sap : sapMaterialPreparationList) {
detail = new MesPrepareDetail();
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);
}
mesPrepareDetailMapper.insertMesPrepareDetails(details);
}
}
// DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
// //获取T+1天的所有母工单
// MesPrepare qo = new MesPrepare();
// Calendar cal = Calendar.getInstance();
// cal.add(Calendar.DATE, 1);//这里改为1
// Date time = cal.getTime();
// qo.setDayStr(new SimpleDateFormat("yyyy-MM-dd").format(time));
// List<MesPrepare> parents = mesPrepareMapper.getParentWorkOrderT1(qo);
// if (CollectionUtils.isEmpty(parents)) {
// System.out.println("T+1无母工单数据");
// }
// for (MesPrepare mesPrepare : parents) {
// List<SapMaterialPreparation> sapMaterialPreparationList = remoteSapService.materialPreparation(mesPrepare.getWorkorderCodeSap()).getData();
// if (CollectionUtils.isEmpty(sapMaterialPreparationList)) {
// System.out.println("sap无领料单数据");
// }
// //取出各领料单
// Set<String> orderCodes = sapMaterialPreparationList.stream().map(SapMaterialPreparation::getAUFNR).collect(Collectors.toSet());
// for (String orderCode : orderCodes) {
// /**mes_prepare**/
// String mesPrepareId = IdUtils.fastSimpleUUID();
// MesPrepare mesPrepare0 = new MesPrepare();
// mesPrepare0.setPrepareId(mesPrepareId);
// mesPrepare0.setWorkorderCode(orderCode);//工单(子)
// mesPrepare0.setCreateTime(DateUtils.getNowDate());
// mesPrepare0.setCreateBy(SecurityUtils.getUsername());
// mesPrepare0.setStatus("L0");//默认待确认
// mesPrepareMapper.insertMesPrepare(mesPrepare0);
// /**mes_prepare_detail**/
// List<MesPrepareDetail> details = new ArrayList<>();
//// List<SapMaterialPreparation> listdetails = list.stream()
//// .filter(a->a.getAUFNR().equals(orderCode))
//// .collect(Collectors.toList());
// MesPrepareDetail detail = null;
// Date createDate = DateUtils.getNowDate();
// for (SapMaterialPreparation sap : sapMaterialPreparationList) {
// detail = new MesPrepareDetail();
// 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);
// }
// mesPrepareDetailMapper.insertMesPrepareDetails(details);
// }
// }
}

@ -100,7 +100,7 @@ public interface ProOrderWorkorderMapper {
ProOrderWorkorder selectWorkOrderByCode(String workorderCode);
/**下发生产订单**/
public int downProOrderWorkorderByWorkorderIds(String[] workorderIds);
public int downWorkorders(String[] workorderIds);
public List<ProOrderWorkorder> getWorkOrderByIds(String[] workorderIds);
@ -158,5 +158,13 @@ public interface ProOrderWorkorderMapper {
ProOrderWorkorder getWorkOrderByCode(String workorderCode);
void updateProOrderWorkorderM(ProOrderWorkorder proWorkOrder);
void insertMesPrepare(MesPrepareDTO mesPrepare0);
int insertMesPrepareDetails(@Param("list") List<MesPrepareDetailDTO> details);
int updateWhiteWorkOrder(ProOrderWorkorder whiteOrder);
ProOrderWorkorder getPWorkOrder(ProOrderWorkorder whiteOrder);
}

@ -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

@ -360,6 +360,14 @@
from pro_order_workorder
where workorder_code = #{workorderCode} and del_flag = '0'
</select>
<select id="getPWorkOrder" resultMap="ProOrderWorkorderResult">
select workorder_id, workorder_code, order_id, order_code,
product_code, product_name, product_date, parent_order,
quantity_split,unit,prod_type, factory_code
from pro_order_workorder
where workorder_code = #{workorderCode}
and del_flag = '0'
</select>
<insert id="createPrepareDetails">
insert into mes_prepare_detail
@ -376,6 +384,90 @@
)
</foreach>
</insert>
<insert id="insertMesPrepare">
insert into mes_prepare
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="prepareId != null">prepare_id,</if>
<if test="workorderCode != null and workorderCode != ''">workorder_code,</if>
<if test="workorderName != null">workorder_name,</if>
<if test="parentOrder != null and parentOrder != ''">parent_order,</if>
<if test="orderId != null and orderId != ''">order_id,</if>
<if test="orderCode != null">order_code,</if>
<if test="productId != null">product_id,</if>
<if test="productCode != null and productCode != ''">product_code,</if>
<if test="prodType != null">prod_type,</if>
<if test="productName != null and productName != ''">product_name,</if>
<if test="productSpc != null">product_spc,</if>
<if test="wetDetailPlanId != null">wet_detail_plan_id,</if>
<if test="productDate != null">product_date,</if>
<if test="shiftId != null">shift_id,</if>
<if test="ancestors != null">ancestors,</if>
<if test="status != null">status,</if>
<if test="remark != null">remark,</if>
<if test="attr1 != null">attr1,</if>
<if test="attr2 != null">attr2,</if>
<if test="attr3 != null">attr3,</if>
<if test="attr4 != null">attr4,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="factoryCode != null">factory_code,</if>
<if test="materialCode != null and materialCode != ''">material_code,</if>
<if test="materialName != null and materialName != ''">material_name,</if>
<if test="materialSpc != null">material_spc,</if>
<if test="unit != null and unit != ''">unit,</if>
<if test="quantity != null">quantity,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="prepareId != null">#{prepareId},</if>
<if test="workorderCode != null and workorderCode != ''">#{workorderCode},</if>
<if test="workorderName != null">#{workorderName},</if>
<if test="parentOrder != null and parentOrder != ''">#{parentOrder},</if>
<if test="orderId != null and orderId != ''">#{orderId},</if>
<if test="orderCode != null">#{orderCode},</if>
<if test="productId != null">#{productId},</if>
<if test="productCode != null and productCode != ''">#{productCode},</if>
<if test="prodType != null">#{prodType},</if>
<if test="productName != null and productName != ''">#{productName},</if>
<if test="productSpc != null">#{productSpc},</if>
<if test="wetDetailPlanId != null">#{wetDetailPlanId},</if>
<if test="productDate != null">#{productDate},</if>
<if test="shiftId != null">#{shiftId},</if>
<if test="ancestors != null">#{ancestors},</if>
<if test="status != null">#{status},</if>
<if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if>
<if test="attr2 != null">#{attr2},</if>
<if test="attr3 != null">#{attr3},</if>
<if test="attr4 != null">#{attr4},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="factoryCode != null">#{factoryCode},</if>
<if test="materialCode != null and materialCode != ''">#{materialCode},</if>
<if test="materialName != null and materialName != ''">#{materialName},</if>
<if test="materialSpc != null">#{materialSpc},</if>
<if test="unit != null and unit != ''">#{unit},</if>
<if test="quantity != null">#{quantity},</if>
</trim>
</insert>
<insert id="insertMesPrepareDetails">
INSERT INTO mes_prepare_detail (
record_id,prepare_id,material_code,material_name,unit,
quantity,create_by,create_time,factory_code,status,
locator,need_date,recoil,fund_quanlity,buy_flag
)VALUES
<foreach collection="list" item="d" index="index" separator=",">
(
#{d.recordId},#{d.prepareId},#{d.materialCode},#{d.materailName},#{d.unit},
#{d.quantity},#{d.createBy},#{d.createTime},#{d.factoryCode},#{d.status},
#{d.locator},#{d.needDate},#{d.recoil},#{d.fundQuanlity},#{d.buyFlag}
)
</foreach>
</insert>
<update id="updateProOrderWorkorder" parameterType="ProOrderWorkorder">
update pro_order_workorder
@ -415,12 +507,12 @@
where workorder_id = #{workorderId}
</update>
<!--工单下发-->
<update id="downProOrderWorkorderByWorkorderIds">
<update id="downWorkorders">
update pro_order_workorder
set status = 'w1'
where workorder_code in
<foreach item="workorderCode" collection="array" open="(" separator="," close=")">
#{workorderCode}
where workorder_id in
<foreach item="workorderId" collection="array" open="(" separator="," close=")">
#{workorderId}
</foreach>
and del_flag = '0'
</update>
@ -440,6 +532,11 @@
</trim>
where workorder_id = #{workorderId}
</update>
<update id="updateWhiteWorkOrder">
update pro_order_workorder
set status = 'w1'
where workorder_id = #{workorderId}
</update>
<delete id="deleteProOrderWorkorderByWorkorderId" parameterType="String">
update pro_order_workorder

Loading…
Cancel
Save