|
|
|
@ -0,0 +1,179 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.roundness;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.base.strategy.IRoundnessStrategy;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.MesCustSoftInfoServiceImpl;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesCustSortInfo;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.IMesProdGroupPartBtoCountRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesPartSapRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesProductVersionRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesWorkOrderRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : 按时圆整,交给spring做策略
|
|
|
|
|
* @Reference :
|
|
|
|
|
* @Author : Castle
|
|
|
|
|
* @CreateDate : 2024/6/2 21:22
|
|
|
|
|
* @Modify:
|
|
|
|
|
**/
|
|
|
|
|
@Service
|
|
|
|
|
public class MesTimeRoundnessService implements IRoundnessStrategy {
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(MesTimeRoundnessService.class);
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesProdGroupPartBtoCountRepository btoCountRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesPartSapRepository mesPartSapRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesProductVersionRepository mesProductVersionRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesWorkOrderRepository mesWorkOrderRao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesCustSoftInfoServiceImpl custSoftInfoService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute(MesPartProdGroup partProdGroup, List<MesCustSortInfo> sortInfoList, List<MesPartProdGroupDetail> details) {
|
|
|
|
|
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
|
Long createSeq = Long.parseLong(dateFormat.format(new Date()));
|
|
|
|
|
//遍历零件生产组零件,过滤出
|
|
|
|
|
for (MesPartProdGroupDetail detail : details) {
|
|
|
|
|
//根据detail.id 获取
|
|
|
|
|
MesProdGroupPartBtoCount btoCountInfo = getByGroupPartId(detail.getId(), detail.getOrganizeCode());
|
|
|
|
|
//历史累计差异
|
|
|
|
|
double btoCount = btoCountInfo.getCurrentQty();
|
|
|
|
|
//获取圆整数量
|
|
|
|
|
double roundQty = detail.getRoundQty();
|
|
|
|
|
List<MesCustSortInfo> sortInfos = sortInfoList.stream().filter(info -> info.getCustPartNo().equals(detail.getCustPartNo())).collect(Collectors.toList());
|
|
|
|
|
if (sortInfos.isEmpty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//本次排序需要的数量
|
|
|
|
|
Double qty = sortInfoList.stream().map(MesCustSortInfo::getQty).reduce(Double::sum).get() * detail.getProductPartQty();
|
|
|
|
|
qty -= btoCount;
|
|
|
|
|
//倍数
|
|
|
|
|
int multiple;
|
|
|
|
|
//如果上次累计的差异值大于当前排序信息累计值,则不需要生成加工单
|
|
|
|
|
if (qty <= 0) {
|
|
|
|
|
multiple = 0;
|
|
|
|
|
} else {
|
|
|
|
|
//看看多少倍,乘以圆整数量就是需求数,QTY就是多累积数
|
|
|
|
|
multiple = (int) Math.round(Math.ceil(Math.ceil(qty / roundQty)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取生产零件信息
|
|
|
|
|
MesPartSap mesPartSap = getMesPart(detail.getProductPartNo(), detail.getOrganizeCode());
|
|
|
|
|
if (mesPartSap.getId() == null) {
|
|
|
|
|
log.info("零件生成组零件:{}找不到对应的零件信息", detail.getProductPartNo());
|
|
|
|
|
throw ImppExceptionBuilder.newInstance().setErrorDetail("零件生成组零件:{}找不到对应的零件信息", detail.getProductPartNo()).build();
|
|
|
|
|
}
|
|
|
|
|
MesWorkOrder mesWorkOrder = new MesWorkOrder();
|
|
|
|
|
mesWorkOrder.setWorkOrderType(MesExtEnumUtil.ORDER_TYPE.BTO.getValue());
|
|
|
|
|
mesWorkOrder.setWorkOrderSeq(createSeq.toString());
|
|
|
|
|
mesWorkOrder.setProduceSeq(createSeq);
|
|
|
|
|
mesWorkOrder.setOrganizeCode(detail.getOrganizeCode());
|
|
|
|
|
//产线
|
|
|
|
|
mesWorkOrder.setWorkCenterCode(detail.getWorkCenterCode());
|
|
|
|
|
//工位
|
|
|
|
|
mesWorkOrder.setWorkCellCode(detail.getWorkCellCode());
|
|
|
|
|
//生产日期,计划时间
|
|
|
|
|
List<MesCustSortInfo> sortInfosSorted = sortInfos.stream().sorted(Comparator.comparing(MesCustSortInfo::getMatchTime)).collect(Collectors.toList());
|
|
|
|
|
// workorderinfo.ProductDate = custsortinfopartlist.Min(d => d.MatchTime.GetValueOrDefault()).ToString("yyyy-MM-dd");
|
|
|
|
|
// workorderinfo.PlanStartTime = custsortinfopartlist.Min(d => d.MatchTime.GetValueOrDefault());
|
|
|
|
|
// workorderinfo.PlanEndTime = custsortinfopartlist.Max(d => d.MatchTime.GetValueOrDefault());
|
|
|
|
|
// 10. 根据工厂,产线,planStartTime 获取班次名称
|
|
|
|
|
String matchTime = sortInfosSorted.get(0).getMatchTime();
|
|
|
|
|
// 11. 是否将生成日期减一天
|
|
|
|
|
// 12.零件相关
|
|
|
|
|
mesWorkOrder.setPartNo(mesPartSap.getPartNo());
|
|
|
|
|
mesWorkOrder.setPartName(mesPartSap.getPartName());
|
|
|
|
|
// 13.生产版本 organizeCode + partNo
|
|
|
|
|
MesProductVersion prodVersion = getProdVersion(detail.getOrganizeCode(), mesPartSap.getPartNo());
|
|
|
|
|
if (prodVersion == null) {
|
|
|
|
|
log.info("请配置工厂:{},partNo:{}的生产版本", detail.organizeCode, mesPartSap.getPartNo());
|
|
|
|
|
}
|
|
|
|
|
String productVersion = prodVersion.getProductVersion();
|
|
|
|
|
mesWorkOrder.setProductVersion(productVersion);
|
|
|
|
|
// 14.bomCode partNo + 生产版本+ organizeCode
|
|
|
|
|
// 数量
|
|
|
|
|
double realQty = roundQty * multiple;
|
|
|
|
|
mesWorkOrder.setQty(realQty);
|
|
|
|
|
mesWorkOrder.setUnCompleteQty(realQty);
|
|
|
|
|
mesWorkOrder.setUnit(mesPartSap.getUnit());
|
|
|
|
|
if (partProdGroup.getIsAutoRelease() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
|
|
|
|
|
mesWorkOrder.setStatus(MesExtEnumUtil.ORDER_STATUS.RELEASE.getValue());
|
|
|
|
|
} else {
|
|
|
|
|
mesWorkOrder.setStatus(MesExtEnumUtil.ORDER_STATUS.CREATE.getValue());
|
|
|
|
|
}
|
|
|
|
|
mesWorkOrder.setPartProdGroupCode(partProdGroup.getPartProdGroupCode());
|
|
|
|
|
|
|
|
|
|
//bto
|
|
|
|
|
btoCountInfo.setGroupPartId(detail.getId());
|
|
|
|
|
btoCountInfo.setOrganizeCode(detail.getOrganizeCode());
|
|
|
|
|
btoCountInfo.setRoundnessQty(roundQty);
|
|
|
|
|
btoCountInfo.setCurrentQty(realQty-qty);
|
|
|
|
|
ConvertBean.saveOrUpdate(btoCountInfo,"edi");
|
|
|
|
|
btoCountRao.save(btoCountInfo);
|
|
|
|
|
|
|
|
|
|
// 保存工单
|
|
|
|
|
ConvertBean.saveOrUpdate(mesWorkOrder, "edi");
|
|
|
|
|
mesWorkOrderRao.insert(mesWorkOrder);
|
|
|
|
|
//更新 custSortInfo 状态已解析
|
|
|
|
|
for (MesCustSortInfo sortInfo : sortInfos) {
|
|
|
|
|
sortInfo.setServiceFlag(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
custSoftInfoService.updateCustSortInfo(sortInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MesProdGroupPartBtoCount getByGroupPartId(Long groupPartId, String organizeCode) {
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(groupPartId, "groupPartId", ddlPackBean);
|
|
|
|
|
List<MesProdGroupPartBtoCount> btoCountList = btoCountRao.findByHqlWhere(ddlPackBean);
|
|
|
|
|
return btoCountList.isEmpty() ? new MesProdGroupPartBtoCount() : btoCountList.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesPartSap getMesPart(String productPartNo, String organizeCode) {
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(productPartNo, "partNo", ddlPackBean);
|
|
|
|
|
List<MesPartSap> parts = mesPartSapRao.findByHqlWhere(ddlPackBean);
|
|
|
|
|
return parts.isEmpty() ? new MesPartSap() : parts.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesProductVersion getProdVersion(String organizeCode, String partNo) {
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(partNo, "partNo", ddlPackBean);
|
|
|
|
|
List<MesProductVersion> mesProductVersionList = mesProductVersionRao.findByHqlWhere(ddlPackBean);
|
|
|
|
|
return mesProductVersionList.isEmpty() ? null : mesProductVersionList.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
double qty = 7.00;
|
|
|
|
|
double roundQty = 3.00;
|
|
|
|
|
int multiple = (int) Math.round(Math.ceil(Math.ceil(qty / roundQty)));
|
|
|
|
|
System.out.println(multiple);
|
|
|
|
|
}
|
|
|
|
|
}
|