|
|
|
@ -1,200 +0,0 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPojoVersionService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
|
|
|
|
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.ISyncFuncService;
|
|
|
|
|
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesPart;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesPojoVersion;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCell;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesPartRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesProduceSnRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import com.google.common.base.Objects;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : 生成零件条码
|
|
|
|
|
* @Author : wangjie
|
|
|
|
|
**/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
public class MesProductSnGenerateStepServiceBak extends BaseStepService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private SnowflakeIdMaker snowflakeIdMaker;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesPartRepository mesPartRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesProduceSnRepository mesProduceSnRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISyncFuncService syncFuncService;
|
|
|
|
|
|
|
|
|
|
public static final String ORDER_NO_JIS_SORT = "ORDER_NO_JIS_SORT";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesProductionDispatchContextStepService mesProductionDispatchContextStepService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesPojoVersionService mesPojoVersionService;
|
|
|
|
|
|
|
|
|
|
/**todo 有产成无进料场景
|
|
|
|
|
* todo 根据装配件条码没有找到加工规则,如果需要跳过装配件绑定,直接生成条码,就需要不看加工规则,直接根据产成零件生成条码,当前设计方式就需要变更。
|
|
|
|
|
* @param reqBean
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
|
|
|
|
|
|
StationResultBean resultBean = new StationResultBean();
|
|
|
|
|
|
|
|
|
|
StepResult stepResult = StepResult.getSuccessComplete();
|
|
|
|
|
String result = mesProductionDispatchContextStepService.getProductResultContext(reqBean);
|
|
|
|
|
// 获取上下文信息
|
|
|
|
|
MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getEquipmentVariableList(reqBean, MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PRODUCTION.getValue());
|
|
|
|
|
MesWorkCell mesWorkCell = productionProcessContext.getWorkCell();
|
|
|
|
|
// 获取产出零件信息
|
|
|
|
|
List<MesProductionPartContext> productionPartContextList = mesProductionDispatchContextStepService.getProductionPartContext(reqBean);
|
|
|
|
|
if (CollectionUtils.isEmpty(productionPartContextList)) {
|
|
|
|
|
foundExThrow(reqBean, "必过工步不允许跳过");
|
|
|
|
|
}
|
|
|
|
|
// 获取零件号,可能存在多个
|
|
|
|
|
List<String> partNoList = productionPartContextList.stream().map(MesProductionPartContext::getPartNo).collect(Collectors.toList());
|
|
|
|
|
// 根据零件号组装产品条码信息
|
|
|
|
|
List<MesProduceSn> mesProduceSns = generateSn(reqBean, productionProcessContext, mesWorkCell, partNoList, result);
|
|
|
|
|
// 保存条码信息
|
|
|
|
|
mesProduceSnRepository.saveAll(mesProduceSns);
|
|
|
|
|
|
|
|
|
|
savePojoVersion(mesProduceSns);
|
|
|
|
|
|
|
|
|
|
List<MesProductionPsOutContext> mesProductionPsOutContexts = new ArrayList<>();
|
|
|
|
|
for (MesProduceSn mesProduceSn : mesProduceSns) {
|
|
|
|
|
MesProductionPsOutContext mesProductionPsOutContext = new MesProductionPsOutContext();
|
|
|
|
|
BeanUtils.copyProperties(mesProduceSn, mesProductionPsOutContext);
|
|
|
|
|
mesProductionPsOutContexts.add(mesProductionPsOutContext);
|
|
|
|
|
}
|
|
|
|
|
// 放到上下文
|
|
|
|
|
mesProductionDispatchContextStepService.saveProductionPsOutContext(reqBean, mesProductionPsOutContexts);
|
|
|
|
|
|
|
|
|
|
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "生成零件条码成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void savePojoVersion(List<MesProduceSn> mesProduceSns) {
|
|
|
|
|
mesProduceSns.forEach(mesProduceSn -> {
|
|
|
|
|
MesPojoVersion version = new MesPojoVersion();
|
|
|
|
|
version.setRefId(mesProduceSn.getId());
|
|
|
|
|
version.setRefClass(mesProduceSn.getClass().getName());
|
|
|
|
|
version.setBean(JsonUtilTool.encode(mesProduceSn));
|
|
|
|
|
version.setCreateUser(version.getCreateUser());
|
|
|
|
|
version.setModifyUser(version.getModifyUser());
|
|
|
|
|
version.setVersionMethodName("insert");
|
|
|
|
|
version.setOrganizeCode(mesProduceSn.getOrganizeCode());
|
|
|
|
|
mesPojoVersionService.recordPojoVersion(version);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据零件号组装产品条码信息
|
|
|
|
|
* @param reqBean
|
|
|
|
|
* @param productionProcessContext
|
|
|
|
|
* @param mesWorkCell
|
|
|
|
|
* @param partNoList
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private List<MesProduceSn> generateSn(StationRequestBean reqBean, MesProductionProcessContext productionProcessContext, MesWorkCell mesWorkCell, List<String> partNoList, String result) {
|
|
|
|
|
List<MesProduceSn> mesProduceSns = new ArrayList<>();
|
|
|
|
|
for (String partNo : partNoList) {
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(reqBean.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(partNo, "partNo", packBean);
|
|
|
|
|
MesPart mesPart = mesPartRepository.getByProperty(packBean);
|
|
|
|
|
if (mesPart == null) {
|
|
|
|
|
MesPcnException.throwFlowException("零件号不存在");
|
|
|
|
|
}
|
|
|
|
|
// 根据条码规则生成条码
|
|
|
|
|
String sn = generateByRule(mesPart);
|
|
|
|
|
// 组装条码信息
|
|
|
|
|
MesProduceSn mesProduceSn = generateMesProduceSn(mesPart, sn, mesWorkCell, productionProcessContext, reqBean, result);
|
|
|
|
|
ConvertBean.serviceModelInitialize(mesProduceSn, reqBean.getUserInfo());
|
|
|
|
|
mesProduceSns.add(mesProduceSn);
|
|
|
|
|
}
|
|
|
|
|
return mesProduceSns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成条码
|
|
|
|
|
* @param mesPart
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String generateByRule(MesPart mesPart) {
|
|
|
|
|
//生成工单号
|
|
|
|
|
GenSerialNoModel genSerialNoModel = new GenSerialNoModel(ORDER_NO_JIS_SORT);
|
|
|
|
|
genSerialNoModel.setPartNo(mesPart.getPartNo());
|
|
|
|
|
List<String> resultList = syncFuncService.syncSerialNo(genSerialNoModel, mesPart.getCreateUser(), mesPart.getOrganizeCode(), 1).getResultList();
|
|
|
|
|
return resultList.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, MesWorkCell mesWorkCell,MesProductionProcessContext productionProcessContext, StationRequestBean reqBean, String result) {
|
|
|
|
|
long serialNum = snowflakeIdMaker.nextId();
|
|
|
|
|
|
|
|
|
|
MesProduceSn mesProduceSn = new MesProduceSn();
|
|
|
|
|
mesProduceSn.setSerialNumber(serialNum + "");
|
|
|
|
|
mesProduceSn.setProductSn(sn);
|
|
|
|
|
mesProduceSn.setCustSn(sn);
|
|
|
|
|
mesProduceSn.setPartNo(mesPart.getPartNo());
|
|
|
|
|
mesProduceSn.setPartName(mesPart.getPartName());
|
|
|
|
|
mesProduceSn.setAreaCode(mesWorkCell.getAreaCode());
|
|
|
|
|
mesProduceSn.setWorkCenterCode(mesWorkCell.getWorkCenterCode());
|
|
|
|
|
mesProduceSn.setWorkCellCode(mesWorkCell.getWorkCellCode());
|
|
|
|
|
mesProduceSn.setProcessLabelTemplate(mesPart.getProcessLabelTemplate());
|
|
|
|
|
mesProduceSn.setCustLabelTemplate(mesPart.getCustLabelTemplate());
|
|
|
|
|
mesProduceSn.setProcessLabelTemplate(mesPart.getProcessLabelTemplate());
|
|
|
|
|
mesProduceSn.setQty(1d);
|
|
|
|
|
mesProduceSn.setSnStatus(10);
|
|
|
|
|
Integer qcStatus = MesExtEnumUtil.PRODUCE_QC_STATUS.QUALIFIED.getValue();
|
|
|
|
|
if (Objects.equal(MesExtEnumUtil.EQUIP_VARIABLE_CFG_CATEGORY.PRODUCT_SCRAP.getValue(), result)) {
|
|
|
|
|
qcStatus = MesExtEnumUtil.PRODUCE_QC_STATUS.SCRAP.getValue();
|
|
|
|
|
} else if (Objects.equal(MesExtEnumUtil.EQUIP_VARIABLE_CFG_CATEGORY.PRODUCT_SUSPICIOUS.getValue(), result)) {
|
|
|
|
|
qcStatus = MesExtEnumUtil.PRODUCE_QC_STATUS.SUSPICIOUS.getValue();
|
|
|
|
|
}
|
|
|
|
|
mesProduceSn.setQcStatus(qcStatus);
|
|
|
|
|
mesProduceSn.setLotNo(DateUtil.format(new Date(), "YYYYMMDD"));
|
|
|
|
|
mesProduceSn.setRouteCode(reqBean.getRouteCode());
|
|
|
|
|
mesProduceSn.setProcessCode(productionProcessContext.getProcessCode());
|
|
|
|
|
mesProduceSn.setCraftCode(productionProcessContext.getCraftCode());
|
|
|
|
|
mesProduceSn.setPrintCount(0);
|
|
|
|
|
mesProduceSn.setPrintStatus(10);
|
|
|
|
|
mesProduceSn.setOrganizeCode(reqBean.getOrganizeCode());
|
|
|
|
|
|
|
|
|
|
return mesProduceSn;
|
|
|
|
|
}
|
|
|
|
|
}
|