forked from I3-YF/i3plus-mes-pcn-yfai
Merge branch 'uat-temp-nht-2506240000-step-feeding' into uat-temp-nht-2506120000-jialiao
commit
f51eb189e3
@ -0,0 +1,45 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesContainerPackageDetailContext;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerPackage;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerPackageDetail;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerSnStation;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesStation;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IMesStationContainerSnExtService {
|
||||
|
||||
@ApiOperation(value = "根据设备代码查询站点信息")
|
||||
List<MesStation> getStationList(String organizeCode, String equipmentCode);
|
||||
|
||||
@ApiOperation(value = "获取站点关联的容器条码")
|
||||
Map<String, List<MesContainerSnStation>> getContainerSnStationMap(String organizeCode, List<MesStation> stationList);
|
||||
|
||||
@ApiOperation(value = "获取站点关联的容器条码")
|
||||
List<MesContainerSnStation> getContainerSnStationList(String organizeCode, List<MesStation> stationList);
|
||||
|
||||
@ApiOperation(value = "获取站点关联的容器条码")
|
||||
List<MesContainerSnStation> getContainerSnStationListByStation(String organizeCode, List<String> stationList);
|
||||
|
||||
@ApiOperation(value = "获取容器条码上料明细表信息【可扣减】【根据 主表seq,主表createDatetime,明细表createDatetime 正序】")
|
||||
List<MesContainerPackageDetailContext> getContainerSnStationContext(String organizeCode, List<MesStation> stationList);
|
||||
|
||||
@ApiOperation(value = "获取容器条码上料主表信息")
|
||||
List<MesContainerPackage> getContainerPackageList(String organizeCode, List<MesContainerSnStation> containerSnStationList, Integer packageStatus);
|
||||
|
||||
@ApiOperation(value = "获取容器条码上料主表信息")
|
||||
List<MesContainerPackage> getContainerPackageListByContainerSn(String organizeCode, List<String> containerSnList, Integer packageStatus);
|
||||
|
||||
@ApiOperation(value = "获取容器条码上料明细表信息【可扣减】")
|
||||
List<MesContainerPackageDetail> getContainerPackageDetailList(String organizeCode, List<MesContainerPackage> containerPackageList);
|
||||
|
||||
@ApiOperation(value = "获取容器条码上料明细表信息【可扣减】")
|
||||
List<MesContainerPackageDetail> getContainerPackageDetailListById(String organizeCode, List<Long> idList);
|
||||
|
||||
@ApiOperation(value = "获取容器条码的一条上料明细表信息【可扣减】")
|
||||
Boolean checkIsExistContainerPackageDetail(String organizeCode, Long id);
|
||||
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesStationContainerSnExtService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesContainerPackageDetailContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
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.MesContainerPackage;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerPackageDetail;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerSnStation;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesStation;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesContainerPackageDetailRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesContainerPackageRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesContainerSnStationRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesStationRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 容器条码上料业务
|
||||
*/
|
||||
@Service
|
||||
public class MesStationContainerSnExtService implements IMesStationContainerSnExtService {
|
||||
|
||||
@Autowired
|
||||
private MesStationRepository stationRepository;
|
||||
|
||||
@Autowired
|
||||
private MesContainerSnStationRepository containerSnStationRepository;
|
||||
|
||||
@Autowired
|
||||
private MesContainerPackageRepository containerPackageRepository;
|
||||
|
||||
@Autowired
|
||||
private MesContainerPackageDetailRepository containerPackageDetailRepository;
|
||||
|
||||
//根据设备代码查询站点信息
|
||||
@Override
|
||||
public List<MesStation> getStationList(String organizeCode, String equipmentCode) {
|
||||
if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(equipmentCode)) return null;
|
||||
return stationRepository.findByProperty(
|
||||
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.EQUIPMENT_CODE},
|
||||
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), equipmentCode});
|
||||
}
|
||||
|
||||
//获取站点关联的容器条码
|
||||
@Override
|
||||
public Map<String, List<MesContainerSnStation>> getContainerSnStationMap(String organizeCode, List<MesStation> stationList) {
|
||||
if (StringUtils.isEmpty(organizeCode) || CollectionUtils.isEmpty(stationList)) return null;
|
||||
List<MesContainerSnStation> containerSnStationList = getContainerSnStationList(organizeCode, stationList);
|
||||
return CollectionUtils.isEmpty(containerSnStationList) ? null :
|
||||
containerSnStationList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesContainerSnStation::getContainerSn));
|
||||
}
|
||||
|
||||
//获取站点关联的容器条码
|
||||
@Override
|
||||
public List<MesContainerSnStation> getContainerSnStationList(String organizeCode, List<MesStation> stationList) {
|
||||
if (StringUtils.isEmpty(organizeCode) || CollectionUtils.isEmpty(stationList)) return null;
|
||||
List<String> stations = stationList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getStation()))).map(MesStation::getStation).collect(Collectors.toList());
|
||||
return getContainerSnStationListByStation(organizeCode, stations);
|
||||
}
|
||||
|
||||
//获取站点关联的容器条码
|
||||
@Override
|
||||
public List<MesContainerSnStation> getContainerSnStationListByStation(String organizeCode, List<String> stationList) {
|
||||
if (StringUtils.isEmpty(organizeCode) || CollectionUtils.isEmpty(stationList)) return null;
|
||||
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
|
||||
if (stationList.size() == 1) DdlPreparedPack.getStringEqualPack(stationList.get(0), MesPcnExtConstWords.STATION, packBean);
|
||||
else DdlPreparedPack.getInPackList(stationList, MesPcnExtConstWords.STATION, packBean);
|
||||
return containerSnStationRepository.findByHqlWhere(packBean);
|
||||
}
|
||||
|
||||
//获取容器条码上料明细表信息【可扣减】【根据 主表seq,主表createDatetime,明细表createDatetime 正序】
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public List<MesContainerPackageDetailContext> getContainerSnStationContext(String organizeCode, List<MesStation> stationList) {
|
||||
//获取站点关联的容器条码, key = containerSn
|
||||
Map<String, List<MesContainerSnStation>> containerSnStationMap = getContainerSnStationMap(organizeCode, stationList);
|
||||
if (CollectionUtils.isEmpty(containerSnStationMap)) return null;
|
||||
//获取容器条码上料主表信息【已关箱】
|
||||
List<MesContainerPackage> containerPackageList = getContainerPackageListByContainerSn(organizeCode,
|
||||
new ArrayList<>(containerSnStationMap.keySet()), MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_20.getValue());
|
||||
if (CollectionUtils.isEmpty(containerPackageList)) return null;
|
||||
//获取容器条码上料明细表信息
|
||||
List<MesContainerPackageDetail> containerPackageDetailList = getContainerPackageDetailList(organizeCode, containerPackageList);
|
||||
if (CollectionUtils.isEmpty(containerPackageDetailList)) return null;
|
||||
//封装容器条码对应的【可扣减】的上料明细表信息
|
||||
List<MesContainerPackageDetailContext> containerSnStationContextList = new ArrayList<>();
|
||||
for (MesContainerPackageDetail containerPackageDetail : containerPackageDetailList) {
|
||||
if (null == containerPackageDetail) continue;
|
||||
MesContainerSnStation containerSnStation = containerSnStationMap.get(containerPackageDetail.getContainerSn()).get(0);
|
||||
containerSnStationContextList.add(new MesContainerPackageDetailContext(containerPackageDetail).station(containerSnStation));
|
||||
}
|
||||
//根据 主表seq,主表createDatetime,明细表createDatetime 正序
|
||||
containerSnStationContextList = containerSnStationContextList.stream().filter(o -> null != o).sorted(Comparator.comparing(MesContainerPackageDetailContext::getSeq)
|
||||
.thenComparing(MesContainerPackageDetailContext::getCreateDatetime2Package).thenComparing(MesContainerPackageDetailContext::getCreateDatetime)).collect(Collectors.toList());
|
||||
return containerSnStationContextList;
|
||||
}
|
||||
|
||||
//获取容器条码上料主表信息
|
||||
@Override
|
||||
public List<MesContainerPackage> getContainerPackageList(String organizeCode, List<MesContainerSnStation> containerSnStationList, Integer packageStatus) {
|
||||
if (StringUtils.isEmpty(organizeCode) || CollectionUtils.isEmpty(containerSnStationList)) return null;
|
||||
List<String> containerSnList = containerSnStationList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getContainerSn()))).map(MesContainerSnStation::getContainerSn).collect(Collectors.toList());
|
||||
return getContainerPackageListByContainerSn(organizeCode, containerSnList, packageStatus);
|
||||
}
|
||||
|
||||
//获取容器条码上料主表信息
|
||||
@Override
|
||||
public List<MesContainerPackage> getContainerPackageListByContainerSn(String organizeCode, List<String> containerSnList, Integer packageStatus) {
|
||||
if (StringUtils.isEmpty(organizeCode) || CollectionUtils.isEmpty(containerSnList)) return null;
|
||||
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
|
||||
if (containerSnList.size() == 1) DdlPreparedPack.getStringEqualPack(containerSnList.get(0), MesPcnExtConstWords.CONTAINER_SN, packBean);
|
||||
else DdlPreparedPack.getInPackList(containerSnList, MesPcnExtConstWords.STATION, packBean);
|
||||
DdlPreparedPack.getNumEqualPack(packageStatus, MesPcnExtConstWords.PACKAGE_STATUS, packBean);
|
||||
return containerPackageRepository.findByHqlWhere(packBean);
|
||||
}
|
||||
|
||||
//获取容器条码上料明细表信息【可扣减】
|
||||
@Override
|
||||
public List<MesContainerPackageDetail> getContainerPackageDetailList(String organizeCode, List<MesContainerPackage> containerPackageList) {
|
||||
if (StringUtils.isEmpty(organizeCode) || CollectionUtils.isEmpty(containerPackageList)) return null;
|
||||
List<Long> idList = containerPackageList.stream().filter(o -> null != o).map(MesContainerPackage::getId).collect(Collectors.toList());
|
||||
return getContainerPackageDetailListById(organizeCode, idList);
|
||||
}
|
||||
|
||||
//获取容器条码上料明细表信息【可扣减】
|
||||
@Override
|
||||
public List<MesContainerPackageDetail> getContainerPackageDetailListById(String organizeCode, List<Long> idList) {
|
||||
if (StringUtils.isEmpty(organizeCode) || CollectionUtils.isEmpty(idList)) return null;
|
||||
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
|
||||
if (idList.size() == 1) DdlPreparedPack.getNumEqualPack(idList.get(0), MesPcnExtConstWords.PID, packBean);
|
||||
else DdlPreparedPack.getInPackList(idList, MesPcnExtConstWords.PID, packBean);
|
||||
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.CONTAINER_BARCODE_STATUS.STATUS_10.getValue(), MesPcnExtConstWords.SN_STATUS, packBean);
|
||||
return containerPackageDetailRepository.findByHqlWhere(packBean);
|
||||
}
|
||||
|
||||
//获取容器条码的一条上料明细表信息【可扣减】
|
||||
@Override
|
||||
public Boolean checkIsExistContainerPackageDetail(String organizeCode, Long id) {
|
||||
if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(id)) return null;
|
||||
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
|
||||
DdlPreparedPack.getNumEqualPack(id, MesPcnExtConstWords.PID, packBean);
|
||||
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.CONTAINER_BARCODE_STATUS.STATUS_10.getValue(), MesPcnExtConstWords.SN_STATUS, packBean);
|
||||
return containerPackageDetailRepository.isExitByHql(packBean);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesContainerSnBindService;
|
||||
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.pojo.context.MesProductionProcessContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesContainerPartsModel;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesContainerSnBindModel;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
import cn.estsh.i3plus.platform.common.util.MesConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.*;
|
||||
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.MesContainerPackageRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesContainerSnPartRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesContainerSnStationRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesContainerTypePartRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description : 零件条码绑定装配件站点容器工步
|
||||
* @Author : jason.niu
|
||||
**/
|
||||
@Slf4j
|
||||
@Service("mesStationFeedContainerPackageDetailStepService")
|
||||
public class MesStationFeedContainerPackageDetailStepService extends BaseStepService {
|
||||
@Autowired
|
||||
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
@Autowired
|
||||
private MesContainerSnStationRepository containerSnStationRDao;
|
||||
@Autowired
|
||||
private MesContainerTypePartRepository containerTypePartRDao;
|
||||
@Autowired
|
||||
private MesContainerSnPartRepository containerSnPartRDao;
|
||||
@Autowired
|
||||
private IMesContainerSnBindService containerSnBindService;
|
||||
@Autowired
|
||||
private MesContainerPackageRepository containerPackageRDao;
|
||||
|
||||
@Override
|
||||
public StepResult execute(StationRequestBean reqBean) {
|
||||
|
||||
StationResultBean resultBean = new StationResultBean();
|
||||
|
||||
StepResult stepResult = StepResult.getSuccessComplete();
|
||||
|
||||
//获取工位当前设备信息
|
||||
MesProductionProcessContext productionProcessContext = productionProcessContextStepService.dispatchCurCellEquipment(reqBean);
|
||||
|
||||
//配置错误 抛出异常
|
||||
if (!productionProcessContext.getSuccess()) {
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
}
|
||||
|
||||
//获取站点用于缺料时进行上料绑定
|
||||
List<MesStation> stationList = productionDispatchContextStepService.getMatchStationContext(reqBean);
|
||||
if (CollectionUtils.isEmpty(stationList)) {
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "容器条码扣减装配件时验证设备未关联支持上料的站点");
|
||||
}
|
||||
final String organizeCode = reqBean.getOrganizeCode();
|
||||
|
||||
String barcode = productionDispatchContextStepService.getMatchStationFeedScanSnContext(reqBean);
|
||||
final String lastFeedContainerSn = productionDispatchContextStepService.getMatchStationFeedContainerSnContext(reqBean);
|
||||
|
||||
if (!StringUtils.isEmpty(lastFeedContainerSn)) {
|
||||
if (executeFeedPartSn(reqBean, lastFeedContainerSn, barcode)) {
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "零件条码上料成功!");
|
||||
}
|
||||
}
|
||||
|
||||
for (MesStation station : stationList) {
|
||||
List<MesContainerSnStation> containerSnStations = getMesContainerSnStation(organizeCode, station.getStation());
|
||||
if (CollectionUtils.isEmpty(containerSnStations)) {
|
||||
continue;
|
||||
}
|
||||
for (MesContainerSnStation containerSnStation : containerSnStations) {
|
||||
final String feedContainerSn = containerSnStation.getTopContainerSn();
|
||||
if (Objects.equals(feedContainerSn, lastFeedContainerSn)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (executeFeedPartSn(reqBean, feedContainerSn, barcode)) {
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "零件条码上料成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "零件条码上料成功!");
|
||||
}
|
||||
|
||||
private List<MesContainerSnStation> getMesContainerSnStation(String organizeCode, String station) {
|
||||
List<MesContainerSnStation> containerSnStations = containerSnStationRDao.findByProperty(new String[]{MesConstWords.ORGANIZE_CODE, MesConstWords.IS_VALID, MesConstWords.IS_DELETED, "station"},
|
||||
new Object[]{organizeCode, CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), station});
|
||||
containerSnStations.removeIf(temp -> !Objects.equals(temp.getContainerSn(), temp.getTopContainerSn()));
|
||||
return containerSnStations;
|
||||
}
|
||||
|
||||
private boolean executeFeedPartSn(StationRequestBean reqBean, String containerSn, String barcode) {
|
||||
final String organizeCode = reqBean.getOrganizeCode();
|
||||
MesContainerSnBindModel model = MesContainerSnBindModel.builder()
|
||||
.organizeCode(organizeCode)
|
||||
.userName(reqBean.getUserInfo())
|
||||
.containerSn(containerSn)
|
||||
.barCode(barcode)
|
||||
.build();
|
||||
try {
|
||||
containerSnBindService.doScanBarcode(model);
|
||||
final String lastFeedContainerSn = hasFullPackage(organizeCode, containerSn) ? "" : containerSn;
|
||||
//加料后容器还未满,保存最近使用的站点
|
||||
productionDispatchContextStepService.dispatchMatchStationFeedContainerSnContext(reqBean, lastFeedContainerSn);
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasFullPackage(String organizeCode, String containerSn) {
|
||||
MesContainerPackage containerPackage = containerPackageRDao.getByProperty(new String[]{MesConstWords.ORGANIZE_CODE, MesConstWords.IS_VALID, MesConstWords.IS_DELETED, "containerSn"},
|
||||
new Object[]{organizeCode, CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), containerSn});
|
||||
return containerPackage != null && Objects.equals(containerPackage.getPackageStatus(), MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_20.getValue());
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesConfigService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionCustomContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
||||
import cn.estsh.i3plus.platform.common.util.MesConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesConfig;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerPackage;
|
||||
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.MesContainerPackageRepository;
|
||||
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description : 容器上料扫描容器条码/扫描原料条码/扫描关箱工步
|
||||
* @Author : jason.niu
|
||||
**/
|
||||
@Slf4j
|
||||
@Service("mesStationFeedScanSnStepService")
|
||||
public class MesStationFeedScanSnStepService extends BaseStepService {
|
||||
@Autowired
|
||||
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
@Autowired
|
||||
private IMesProductionCustomContextStepService productionCustomContextStepService;
|
||||
@Autowired
|
||||
private IMesConfigService configService;
|
||||
@Autowired
|
||||
private MesContainerPackageRepository containerPackageRDao;
|
||||
|
||||
@Override
|
||||
public StepResult guide(StationRequestBean reqBean) {
|
||||
|
||||
productionCustomContextStepService.sendStepContextMessage(reqBean);
|
||||
|
||||
return stepSuccessCompleteAndSendGuideReturn(reqBean, new StationResultBean().writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), "请扫描上料条码!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StepResult execute(StationRequestBean reqBean) {
|
||||
StationResultBean resultBean = new StationResultBean();
|
||||
|
||||
StepResult stepResult = StepResult.getSuccessComplete();
|
||||
|
||||
//扫描信息置空
|
||||
String scanInfo = reqBean.resetScanInfo(reqBean.getScanInfo());
|
||||
|
||||
if (StringUtils.isEmpty(scanInfo)) stepSendGuideAndThrowEx(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), "请扫描装配件条码!");
|
||||
|
||||
// 判断是否为关箱条码
|
||||
MesConfig mesConfig = configService.getCfgValueByCode(reqBean.getOrganizeCode(), MesPcnExtConstWords.MATCH_STATION_FEED_CLOSE_PACKAGE);
|
||||
if (mesConfig != null && Objects.equals(scanInfo, mesConfig.getCfgValue())) {
|
||||
String containerSn = productionDispatchContextStepService.getMatchStationFeedContainerSnContext(reqBean);
|
||||
if (StringUtils.isEmpty(containerSn)) {
|
||||
stepSendGuideAndThrowEx(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), "不存在需要关箱的容器条码!");
|
||||
}
|
||||
MesContainerPackage containerPackage = containerPackageRDao.getByProperty(new String[]{MesConstWords.ORGANIZE_CODE, MesConstWords.IS_VALID, MesConstWords.IS_DELETED, "containerSn"},
|
||||
new Object[]{reqBean.getOrganizeCode(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), containerSn});
|
||||
if (containerPackage == null) {
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("容器条码【%s】未绑定零件!", containerSn));
|
||||
}
|
||||
assert containerPackage != null;
|
||||
containerPackage.setPackageStatus(MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_20.getValue());
|
||||
ConvertBean.serviceModelUpdate(containerPackage, reqBean.getUserInfo());
|
||||
containerPackageRDao.update(containerPackage);
|
||||
}
|
||||
|
||||
//保存扫描条码用于缺料时进行上料绑定
|
||||
productionDispatchContextStepService.dispatchMatchStationFeedScanSnContext(reqBean, scanInfo);
|
||||
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.SCAN.getValue()).scanInfo(scanInfo), stepResult,
|
||||
String.format("当前扫描信息装配件条码[%s]", scanInfo));
|
||||
}
|
||||
}
|
@ -0,0 +1,195 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.*;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesContainerPackageDetailContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionAssemblyContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
||||
import cn.estsh.i3plus.platform.common.tool.MathOperation;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesStation;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
|
||||
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.util.MesExtEnumUtil;
|
||||
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @Description : 容器扣减匹配装配件站点工步
|
||||
* @Author : wangjie
|
||||
**/
|
||||
@Slf4j
|
||||
@Service("mesStationMatchAssemblyStepService")
|
||||
public class MesStationMatchAssemblyStepService extends BaseStepService {
|
||||
|
||||
@Autowired
|
||||
private IMesProductionProcessContextStepService productionProcessContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesProductionCustomContextStepService productionCustomContextStepService;
|
||||
|
||||
@Autowired
|
||||
private IMesStationContainerSnExtService stationContainerSnExtService;
|
||||
|
||||
@Autowired
|
||||
private IMesTimeEfficientCfgMatchService timeEfficientCfgMatchService;
|
||||
|
||||
@Autowired
|
||||
private MesAssemblyShowNosortStepService assemblyShowNosortStepService;
|
||||
|
||||
@Override
|
||||
public StepResult execute(StationRequestBean reqBean) {
|
||||
|
||||
StationResultBean resultBean = new StationResultBean();
|
||||
|
||||
StepResult stepResult = StepResult.getSuccessComplete();
|
||||
|
||||
//获取工位当前设备信息
|
||||
MesProductionProcessContext productionProcessContext = productionProcessContextStepService.dispatchCurCellEquipment(reqBean);
|
||||
|
||||
//配置错误 抛出异常
|
||||
if (!productionProcessContext.getSuccess()) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
|
||||
|
||||
//获取上下文产品加工规则数据信息集合
|
||||
List<MesProdRuleContext> prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
||||
if (CollectionUtils.isEmpty(prodRuleContextList)) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "当前不存在产品加工规则信息,请重置工序解决!");
|
||||
|
||||
//验证是否存在装配件容器匹配
|
||||
Optional<MesProdRuleContext> optional = prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getIsMatchContainer()))).findFirst();
|
||||
if (null == optional || !optional.isPresent()) {
|
||||
return stepDynamicsCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, true,
|
||||
MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT, "验证每腔不存在容器匹配的装配件,默认跳过容器条码扣减装配件!");
|
||||
}
|
||||
|
||||
//处理设备站点【装配件站点&&混料站点】
|
||||
List<MesStation> stationList = productionProcessContextStepService.dispatchEquipmentStationContext(reqBean, productionProcessContext.getCurCellEquip().getEquipmentCode(),
|
||||
Stream.of(MesExtEnumUtil.STATION_TYPE.STATION_TYPE_20.getValue(), MesExtEnumUtil.STATION_TYPE.STATION_TYPE_40.getValue()).collect(Collectors.toList()));
|
||||
|
||||
if (CollectionUtils.isEmpty(stationList)) stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "容器条码扣减装配件时验证设备未关联支持扣减的站点");
|
||||
|
||||
//保存站点用于缺料时进行上料绑定
|
||||
productionDispatchContextStepService.dispatchMatchStationContext(reqBean, stationList);
|
||||
|
||||
//获取容器条码上料明细表信息【可扣减】【根据 主表seq,主表createDatetime,明细表createDatetime 正序】
|
||||
List<MesContainerPackageDetailContext> containerSnStationList = stationContainerSnExtService.getContainerSnStationContext(reqBean.getOrganizeCode(), stationList);
|
||||
|
||||
if (CollectionUtils.isEmpty(containerSnStationList)) return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "容器条码扣减装配件时验证当前无可扣减的原材料信息!");
|
||||
|
||||
//将可扣减的条码进行原子性缓存, 并获取最新的实际库存
|
||||
productionCustomContextStepService.dispatchContainerSnAtomicity(reqBean.getOrganizeCode(), containerSnStationList);
|
||||
|
||||
//获取弹框输入的工单数量, 未弹框默认 数量=1
|
||||
Double orderQtyDialogContext = productionDispatchContextStepService.getOrderQtyDialogContext(reqBean);
|
||||
|
||||
MesWorkCenter workCenter = productionProcessContext.getWorkCenter();
|
||||
|
||||
//匹配装配件的工序用量
|
||||
dispatchStationMatchAssembly(reqBean, resultBean, stepResult, workCenter, prodRuleContextList, containerSnStationList, orderQtyDialogContext);
|
||||
|
||||
if (!stepResult.isCompleted()) return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, stepResult.getMsg());
|
||||
|
||||
productionDispatchContextStepService.dispatchProdRuleDataContext(reqBean, prodRuleContextList);
|
||||
|
||||
if (workCenter.getCenterType().compareTo(MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue()) == 0)
|
||||
((MesAssemblyShowNosortStepService) SpringContextsUtil.getBean("mesAssemblyShowNosortStepService")).showProductionAssembly(reqBean, resultBean, workCenter, prodRuleContextList);
|
||||
else
|
||||
((MesAssemblyShowSortStepService) SpringContextsUtil.getBean("mesAssemblyShowSortStepService")).showProductionAssembly(reqBean, resultBean, workCenter, prodRuleContextList, true, true);
|
||||
|
||||
|
||||
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "容器条码扣减装配件验证成功!");
|
||||
}
|
||||
|
||||
//匹配装配件的工序用量【遍历加工规则】
|
||||
private void dispatchStationMatchAssembly(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter,
|
||||
List<MesProdRuleContext> prodRuleContextList, List<MesContainerPackageDetailContext> containerSnStationList, Double orderQtyDialogContext) {
|
||||
for (MesProdRuleContext prodRuleContext : prodRuleContextList) {
|
||||
if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getIsMatchContainer())) continue;
|
||||
List<MesProductionAssemblyContext> productionAssemblyContextList = dispatchStationMatchAssembly(reqBean, resultBean, stepResult, workCenter, prodRuleContext, containerSnStationList, orderQtyDialogContext);
|
||||
if (!stepResult.isCompleted()) break;
|
||||
prodRuleContext.assemblyDataJson(productionAssemblyContextList);
|
||||
}
|
||||
}
|
||||
|
||||
//匹配装配件的工序用量【遍历装配件】
|
||||
private List<MesProductionAssemblyContext> dispatchStationMatchAssembly(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter,
|
||||
MesProdRuleContext prodRuleContext, List<MesContainerPackageDetailContext> containerSnStationList, Double orderQtyDialogContext) {
|
||||
List<MesProductionAssemblyContext> productionAssemblyContextList = prodRuleContext.getAssemblyDataContext(workCenter);
|
||||
for (MesProductionAssemblyContext productionAssemblyContext : productionAssemblyContextList) {
|
||||
if (null == productionAssemblyContext || productionAssemblyContext.getMatchType().compareTo(MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.MATCH_TYPE_80.getValue()) != 0) continue;
|
||||
|
||||
if (StringUtils.isEmpty(productionAssemblyContext.getPartNo()) || StringUtils.isEmpty(productionAssemblyContext.getQty()))
|
||||
stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("当前产成对应的[%s]类型的装配件信息维护零件号或工序用量!", MesExtEnumUtil.ASSEMBLY_MATCH_TYPE.MATCH_TYPE_80.getDescription()));
|
||||
|
||||
//未匹配的工序用量
|
||||
Double unMatchQty = MathOperation.mul(productionAssemblyContext.getQty(), orderQtyDialogContext);
|
||||
List<String> containerSnDataList = null;
|
||||
List<String> containerSnList = null;
|
||||
for (MesContainerPackageDetailContext containerPackageDetailContext : containerSnStationList) {
|
||||
if (null == containerPackageDetailContext || StringUtils.isEmpty(containerPackageDetailContext.getPartNo())) continue;
|
||||
if (!containerPackageDetailContext.getPartNo().equals(productionAssemblyContext.getPartNo()) || MathOperation.compareTo(containerPackageDetailContext.getRemainQty(), new Double(0)) <= 0) continue;
|
||||
|
||||
//验证时效性
|
||||
Map<String, Object> result = timeEfficientCfgMatchService.checkSnTimelinessContainerMatch(reqBean.getOrganizeCode(), containerPackageDetailContext,
|
||||
workCenter.getCenterType().compareTo(MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue()) == 0 ? productionAssemblyContext.getSourceId() : productionAssemblyContext.getPid());
|
||||
if (!(Boolean)result.get(MesPcnExtConstWords.RESULT)) continue;
|
||||
|
||||
//如果存在未匹配的工序用量
|
||||
if (MathOperation.compareTo(unMatchQty, new Double(0)) > 0) {
|
||||
//剩余未匹配的工序用量
|
||||
Double remainQty = MathOperation.sub(containerPackageDetailContext.getRemainQty(), unMatchQty);
|
||||
//全部匹配完成
|
||||
if (MathOperation.compareTo(remainQty, new Double(0)) >= 0) {
|
||||
containerPackageDetailContext.remainQty(remainQty);
|
||||
unMatchQty = new Double(0);
|
||||
} else {
|
||||
//未匹配完成, 0-负数=正数
|
||||
containerPackageDetailContext.remainQty(new Double(0));
|
||||
unMatchQty = MathOperation.sub(new Double(0), remainQty);
|
||||
}
|
||||
}
|
||||
//将能够扣减的所有条码跟当前装配件关联
|
||||
if (CollectionUtils.isEmpty(containerSnDataList)) {
|
||||
containerSnDataList = new ArrayList<>();
|
||||
containerSnList = new ArrayList<>();
|
||||
}
|
||||
containerSnDataList.add(productionCustomContextStepService.getContainerSnAtomicityKey(reqBean.getOrganizeCode(), containerPackageDetailContext));
|
||||
containerSnList.add(containerPackageDetailContext.getContainerSn());
|
||||
}
|
||||
|
||||
if (MathOperation.compareTo(unMatchQty, new Double(0)) > 0) {
|
||||
if (!StringUtils.isEmpty(productionAssemblyContext.getAssemblySn())) {
|
||||
productionAssemblyContext.setAssemblyStatus(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue());
|
||||
productionAssemblyContext.setAssemblySn(null);
|
||||
productionAssemblyContext.setMatchDatetime(null);
|
||||
}
|
||||
stepResult.isCompleted(false).msg(String.format("容器条码扣减装配件时验证零件号[%s]当前缺料,请扫描上料条码!", productionAssemblyContext.getPartNo()));
|
||||
break;
|
||||
}
|
||||
|
||||
productionAssemblyContext.setAssemblyStatus(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_10.getValue());
|
||||
productionAssemblyContext.setAssemblySn(containerSnList.get(0));
|
||||
productionAssemblyContext.setMatchDatetime((new SimpleDateFormat(MesPcnExtConstWords.DATE_FORMAT_SSS)).format(new Date()));
|
||||
productionAssemblyContext.setContainerSnData(JSONObject.toJSONString(containerSnDataList));
|
||||
}
|
||||
|
||||
return productionAssemblyContextList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.pojo.context;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerPackageDetail;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesContainerSnStation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 生产过程上下文对象-容器条码上料明细
|
||||
*/
|
||||
@Data
|
||||
public class MesContainerPackageDetailContext extends MesContainerPackageDetail implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3519172978836073435L;
|
||||
|
||||
@ApiParam(name = "站点")
|
||||
private String station;
|
||||
|
||||
@ApiParam("顺序号")
|
||||
private Integer seq;
|
||||
|
||||
@ApiParam(value = "主表创建日期")
|
||||
private String createDatetime2Package;
|
||||
|
||||
@ApiParam("库存")
|
||||
private Double remainQty;
|
||||
|
||||
public MesContainerPackageDetailContext() {}
|
||||
|
||||
public MesContainerPackageDetailContext(MesContainerPackageDetail containerPackageDetail) {
|
||||
BeanUtils.copyProperties(containerPackageDetail, this);
|
||||
}
|
||||
|
||||
public MesContainerPackageDetailContext station(MesContainerSnStation containerSnStation) {
|
||||
this.station = containerSnStation.getStation();
|
||||
this.seq = !StringUtils.isEmpty(containerSnStation.getSeq()) ? containerSnStation.getSeq() : MesPcnExtConstWords.ZERO;
|
||||
this.createDatetime2Package = containerSnStation.getCreateDatetime();
|
||||
return this;
|
||||
}
|
||||
|
||||
public MesContainerPackageDetailContext remainQty(String remainQty) {
|
||||
return remainQty(!StringUtils.isEmpty(remainQty) ? new Double(remainQty) : new Double(MesPcnExtConstWords.ZERO));
|
||||
}
|
||||
|
||||
public MesContainerPackageDetailContext remainQty(Double remainQty) {
|
||||
this.remainQty = remainQty;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue