|
|
|
@ -8,6 +8,7 @@ import cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.BaseMesService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
|
|
|
|
|
import cn.estsh.i3plus.icloud.core.sdk.ICoreUtilCloud;
|
|
|
|
|
import cn.estsh.i3plus.mes.api.iservice.busi.ISyncFuncService;
|
|
|
|
|
import cn.estsh.i3plus.mes.apiservice.util.DateUtil;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
@ -22,6 +23,7 @@ import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentSpotCheckDetailRepository
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentSpotCheckPartRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesSpotCheckOrderPartRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesSpotCheckOrderResultRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.DateUtilExt;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
@ -33,9 +35,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
@ -386,4 +387,169 @@ public class MesSpotCheckOrderService extends BaseMesService<MesSpotCheckOrder>
|
|
|
|
|
DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"createDatetime"}, packBean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void insertMesSpotCheckOrder(List<MesEquipmentSpotCheck> mesEquipmentSpotCheckList,String userName) {
|
|
|
|
|
MesEquipmentSpotCheck next = mesEquipmentSpotCheckList.iterator().next();
|
|
|
|
|
List<Long> spotCheckIdList = mesEquipmentSpotCheckList.stream().map(MesEquipmentSpotCheck::getId).collect(Collectors.toList());
|
|
|
|
|
//查询未处理的单据
|
|
|
|
|
Map<Long, MesSpotCheckOrder> spotCheckOrderMap = getMesSpotCheckOrderMap(next.getOrganizeCode(), spotCheckIdList);
|
|
|
|
|
//查询明细数据
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(next.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getInPackList(spotCheckIdList,"pid", packBean);
|
|
|
|
|
List<MesEquipmentSpotCheckDetail> detailList = equipmentSpotCheckDetailRepository.findByHqlWhere(packBean);
|
|
|
|
|
Map<Long,List<MesEquipmentSpotCheckDetail>> detailMap = null;
|
|
|
|
|
if (!CollectionUtils.isEmpty(detailList)) {
|
|
|
|
|
detailMap = detailList.stream().collect(Collectors.groupingBy(MesEquipmentSpotCheckDetail::getPid));
|
|
|
|
|
}
|
|
|
|
|
//查询点检零件
|
|
|
|
|
List<MesEquipmentSpotCheckPart> equipmentSpotCheckPartList = equipmentSpotCheckPartRepository.findByHqlWhere(packBean);
|
|
|
|
|
Map<Long,List<MesEquipmentSpotCheckPart>> checkPartListMap = null;
|
|
|
|
|
if (!CollectionUtils.isEmpty(equipmentSpotCheckPartList)) {
|
|
|
|
|
checkPartListMap = equipmentSpotCheckPartList.stream().collect(Collectors.groupingBy(MesEquipmentSpotCheckPart::getPid));
|
|
|
|
|
}
|
|
|
|
|
//属性校验
|
|
|
|
|
List<MesEquipmentSpotCheck> mesEquipmentSpotChecks = getCheckList(mesEquipmentSpotCheckList, spotCheckOrderMap, detailMap, checkPartListMap);
|
|
|
|
|
//保存单据
|
|
|
|
|
if(mesEquipmentSpotChecks.size() > 0){
|
|
|
|
|
saveOrder(userName, next, detailMap, checkPartListMap, mesEquipmentSpotChecks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveOrder(String userName, MesEquipmentSpotCheck next, Map<Long, List<MesEquipmentSpotCheckDetail>> detailMap, Map<Long, List<MesEquipmentSpotCheckPart>> checkPartListMap, List<MesEquipmentSpotCheck> mesEquipmentSpotChecks) {
|
|
|
|
|
//生成单号
|
|
|
|
|
GenSerialNoModel genSerialNoModel = new GenSerialNoModel(MesCommonConstant.SPOT_CHECK_ORDER_NO_RULE);
|
|
|
|
|
List<String> resultList = syncFuncService.syncSerialNo(genSerialNoModel, userName, next.getOrganizeCode(), mesEquipmentSpotChecks.size()).getResultList();
|
|
|
|
|
String orderNo;
|
|
|
|
|
int count = 0 ;
|
|
|
|
|
//单据生成
|
|
|
|
|
for (MesEquipmentSpotCheck spotCheck : mesEquipmentSpotChecks) {
|
|
|
|
|
orderNo = resultList.get(count);
|
|
|
|
|
MesSpotCheckOrder mesSpotCheckOrder = new MesSpotCheckOrder();
|
|
|
|
|
BeanUtils.copyProperties(spotCheck, mesSpotCheckOrder, "id");
|
|
|
|
|
mesSpotCheckOrder.setTaskResource(MesCommonConstant.SPOT_CHECK_ORDER_TASK_RESOURCE);
|
|
|
|
|
mesSpotCheckOrder.setStatus(MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getValue());
|
|
|
|
|
mesSpotCheckOrder.setSpotCheckId(spotCheck.getId());
|
|
|
|
|
mesSpotCheckOrder.setSpotCheckOrderNo(orderNo);
|
|
|
|
|
ConvertBean.serviceModelInitialize(mesSpotCheckOrder, userName);
|
|
|
|
|
mesSpotCheckOrder = baseRDao.insert(mesSpotCheckOrder);
|
|
|
|
|
//保存单据明细
|
|
|
|
|
saveMesSpotCheckOrderDetails(userName, detailMap, spotCheck.getId(), mesSpotCheckOrder);
|
|
|
|
|
//保存单据零件
|
|
|
|
|
saveMesEquipmentSpotCheckPartList(userName, checkPartListMap, spotCheck.getId(), mesSpotCheckOrder.getId());
|
|
|
|
|
ConvertBean.serviceModelUpdate(spotCheck, userName);
|
|
|
|
|
baseRDao.update(spotCheck);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<MesEquipmentSpotCheck> getCheckList(List<MesEquipmentSpotCheck> mesEquipmentSpotCheckList, Map<Long, MesSpotCheckOrder> spotCheckOrderMap, Map<Long, List<MesEquipmentSpotCheckDetail>> detailMap, Map<Long, List<MesEquipmentSpotCheckPart>> checkPartListMap) {
|
|
|
|
|
List<MesEquipmentSpotCheck> mesEquipmentSpotChecks = new ArrayList<>();
|
|
|
|
|
for (MesEquipmentSpotCheck spotCheck : mesEquipmentSpotCheckList) {
|
|
|
|
|
log.info("开始处理点检项目代码:{}",spotCheck.getSpotCheckCode());
|
|
|
|
|
//校验是否存在未处理的单据
|
|
|
|
|
if(!Objects.isNull(spotCheckOrderMap) && spotCheckOrderMap.containsKey(spotCheck.getId())){
|
|
|
|
|
log.info("存在相同配置状态为{}的点检单 id:{},请检查数据",MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getDescription(), spotCheck.getId());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//时间触发方式
|
|
|
|
|
if (checkTime(spotCheck)) continue;
|
|
|
|
|
//明细是否存在
|
|
|
|
|
if (Objects.isNull(detailMap) || !detailMap.containsKey(spotCheck.getId())) {
|
|
|
|
|
log.info("【{}】点检方案明细不存在,请检查数据",spotCheck.getId());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//检测零件
|
|
|
|
|
if(spotCheck.getSpotCheckOrderType() == MesExtEnumUtil.SPOT_CHECK_ORDER_TYPE.FIRST_PRODUCT_INSPECTION.getValue() && (Objects.isNull(checkPartListMap) || !checkPartListMap.containsKey(spotCheck.getId()))){
|
|
|
|
|
log.info("【{}】点检方案类型为【{}】配置零件号为空,请检查数据", spotCheck.getId(), MesExtEnumUtil.SPOT_CHECK_ORDER_TYPE.FIRST_PRODUCT_INSPECTION.getDescription());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
mesEquipmentSpotChecks.add(spotCheck);
|
|
|
|
|
}
|
|
|
|
|
return mesEquipmentSpotChecks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean checkTime(MesEquipmentSpotCheck spotCheck) {
|
|
|
|
|
if(null == MesExtEnumUtil.EQUIPMENT_CHECK_INSPECTION_TRIGGER_CONFIG.valueOfDescription(spotCheck.getTimeTriggerMode())){
|
|
|
|
|
log.info("时间触发方式{}不存在,请检查数据", spotCheck.getTimeTriggerMode());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
//触发窗口时间
|
|
|
|
|
if(MesExtEnumUtil.EQUIPMENT_CHECK_INSPECTION_TRIGGER_CONFIG.OPTION1.getValue() == spotCheck.getTimeTriggerMode()){
|
|
|
|
|
try {
|
|
|
|
|
if(!DateUtilExt.between(DateUtil.SHORT_FORMAT_HOUR_MINUTE,TimeTool.getTimeShortWithColon(),TimeTool.pareDateToString(DateUtil.SHORT_FORMAT_HOUR_MINUTE,DateUtil.addMinutes(new Date(),30)),spotCheck.getTriggerWindowTime())){
|
|
|
|
|
log.info("{},触发窗口时间{}不产生单据,请检查数据", spotCheck.getSpotCheckCode(), spotCheck.getTriggerWindowTime());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("{},触发窗口时间格式异常", spotCheck.getSpotCheckCode());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
//查询执行成功的单据信息
|
|
|
|
|
MesSpotCheckOrder finishedOrder = getMesSpotCheckOrder(spotCheck);
|
|
|
|
|
if(!Objects.isNull(finishedOrder)){
|
|
|
|
|
spotCheck.setLastSpotCheckTime(finishedOrder.getModifyDatetime());
|
|
|
|
|
if(Integer.parseInt(DateUtil.minutesBetweenTwoTime(new Date(),TimeTool.stringParseToDate(finishedOrder.getModifyDatetime()))+"") < spotCheck.getTriggerWindowInterval()){
|
|
|
|
|
log.info("最后点检完成时间:{},距现在不足{}分钟,不创建单据",finishedOrder.getModifyDatetime(), spotCheck.getTriggerWindowInterval());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesSpotCheckOrder getMesSpotCheckOrder(MesEquipmentSpotCheck spotCheck) {
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(spotCheck.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(spotCheck.getId(),"spotCheckId", packBean);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.COMPLETE.getValue(), "status", packBean);
|
|
|
|
|
DdlPreparedPack.getOrderBy("modifyDatetime",CommonEnumUtil.ASC_OR_DESC.DESC.getValue(),packBean);
|
|
|
|
|
return baseRDao.getByProperty(packBean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveMesEquipmentSpotCheckPartList(String userName,Map<Long, List<MesEquipmentSpotCheckPart>> checkPartListMap, Long spotCheckId, Long spotCheckOrderId) {
|
|
|
|
|
if (!Objects.isNull(checkPartListMap) && checkPartListMap.containsKey(spotCheckId)) {
|
|
|
|
|
List<MesSpotCheckOrderPart> spotCheckOrderPartList = new ArrayList<>();
|
|
|
|
|
checkPartListMap.get(spotCheckId).forEach(k -> {
|
|
|
|
|
MesSpotCheckOrderPart spotCheckOrderPart = new MesSpotCheckOrderPart();
|
|
|
|
|
spotCheckOrderPart.setSpotCheckOrderId(spotCheckOrderId);
|
|
|
|
|
BeanUtils.copyProperties(k, spotCheckOrderPart, "id");
|
|
|
|
|
ConvertBean.serviceModelInitialize(spotCheckOrderPart, userName);
|
|
|
|
|
spotCheckOrderPartList.add(spotCheckOrderPart);
|
|
|
|
|
});
|
|
|
|
|
spotCheckOrderPartRepository.saveAll(spotCheckOrderPartList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveMesSpotCheckOrderDetails(String userName, Map<Long, List<MesEquipmentSpotCheckDetail>> detailMap, Long spotCheckId, MesSpotCheckOrder mesSpotCheckOrder) {
|
|
|
|
|
List<MesSpotCheckOrderResult> spotCheckOrderResults = new ArrayList<>();
|
|
|
|
|
detailMap.get(spotCheckId).forEach(k -> {
|
|
|
|
|
MesSpotCheckOrderResult result = new MesSpotCheckOrderResult();
|
|
|
|
|
BeanUtils.copyProperties(k, result, "id");
|
|
|
|
|
result.setSpotCheckOrderNo(mesSpotCheckOrder.getSpotCheckOrderNo());
|
|
|
|
|
result.setPid(mesSpotCheckOrder.getId());
|
|
|
|
|
result.setWorkCenterCode(mesSpotCheckOrder.getWorkCenterCode());
|
|
|
|
|
result.setWorkCellCode(mesSpotCheckOrder.getWorkCellCode());
|
|
|
|
|
result.setSpotCheckItemId(k.getId());
|
|
|
|
|
result.setTaskItemName(k.getSpotCheckItemName());
|
|
|
|
|
result.setSpotCheckStandardValue(k.getStandardValue());
|
|
|
|
|
ConvertBean.serviceModelInitialize(result, userName);
|
|
|
|
|
spotCheckOrderResults.add(result);
|
|
|
|
|
});
|
|
|
|
|
spotCheckOrderResultRepository.saveAll(spotCheckOrderResults);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, MesSpotCheckOrder> getMesSpotCheckOrderMap(String organizeCode, List<Long> spotCheckIdList) {
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getInPackList(spotCheckIdList,"spotCheckId", packBean);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getValue(), "status", packBean);
|
|
|
|
|
List<MesSpotCheckOrder> mesSpotCheckOrderList = baseRDao.findByHqlWhere(packBean);
|
|
|
|
|
Map<Long, MesSpotCheckOrder> spotCheckOrderMap = null;
|
|
|
|
|
if (!CollectionUtils.isEmpty(mesSpotCheckOrderList)) {
|
|
|
|
|
spotCheckOrderMap = new HashMap<>();
|
|
|
|
|
for (MesSpotCheckOrder mesSpotCheckOrder : mesSpotCheckOrderList) {
|
|
|
|
|
spotCheckOrderMap.put(mesSpotCheckOrder.getSpotCheckId(),mesSpotCheckOrder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return spotCheckOrderMap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|