|  |  | 
 |  |  | import com.dy.pmsGlobal.pojoPr.PrProductionNode; | 
 |  |  | import com.dy.pmsGlobal.pojoSta.StaAssemblyWorkHistory; | 
 |  |  | import com.dy.pmsGlobal.pojoSta.StaAssemblyWorkLast; | 
 |  |  | import com.dy.pmsGlobal.util.QrCodeConstant; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.BeanUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | 
 |  |  |     private static final int STATUS_WORK_LAST_LOGOUT = 2; | 
 |  |  |     private static final int STATUS_REPAIR = 3; | 
 |  |  |     private static final int STATUS_WASTE = 4; | 
 |  |  |  | 
 |  |  |     private static final String WORK_TYPE_ASSEMBLY = "1"; | 
 |  |  |     private static final String WORK_TYPE_TEST = "2"; | 
 |  |  |     private static final String WORK_TYPE_INSPECTION = "3"; | 
 |  |  |     private static final String WORK_TYPE_REPAIR = "4"; | 
 |  |  |  | 
 |  |  |     private static final String USER_PREFIX = "101"; | 
 |  |  |     private static final String STATION_PREFIX = "103"; | 
 |  |  | 
 |  |  |         } | 
 |  |  |         BaUser userInfo = getUserInfo(result.getUserId().toString()); | 
 |  |  |         PltStation stationInfo = getStationInfo(result.getStationId().toString()); | 
 |  |  |         //校验planId processId nodeId | 
 |  |  |         PrAssemblyPlan assyPlan = assemblyDao.selectByPrimaryKey(result.getPlanId()); | 
 |  |  |         boolean hasNodeId = assyPlan.getProcess().getNodes().stream() | 
 |  |  |                 .anyMatch(node -> node.id.equals(result.getNodeId())); | 
 |  |  |         if (userInfo == null || stationInfo == null || assyPlan == null || (!hasNodeId)) { | 
 |  |  |             //直接删除记录 | 
 |  |  |             logout(result.getId().toString()); | 
 |  |  |             result.setId(null); | 
 |  |  |             result.setStatus(STATUS_WORK_LAST_LOGOUT); | 
 |  |  |             if (userInfo == null) { | 
 |  |  |                 result.setUserId(null); | 
 |  |  |                 result.setUserName(""); | 
 |  |  |             } | 
 |  |  |             if (stationInfo == null) { | 
 |  |  |                 result.setStationId(null); | 
 |  |  |                 result.setStationName(""); | 
 |  |  |             } | 
 |  |  |             if (assyPlan == null) { | 
 |  |  |                 result.setPlanId(null); | 
 |  |  |                 result.setPlanName(""); | 
 |  |  |             } | 
 |  |  |             if (!hasNodeId) { | 
 |  |  |                 result.setNodeId(null); | 
 |  |  |                 result.setNodeName(""); | 
 |  |  |             } | 
 |  |  |             return result; | 
 |  |  |         } else { | 
 |  |  |             result.setPlanName(assyPlan.getName()); | 
 |  |  |             result.setProcessName(assyPlan.getProcessName()); | 
 |  |  |             result.setNodeName(assyPlan.getProcess().getNodes().get(0).getContent()); | 
 |  |  |             //找到对应的产品信息 | 
 |  |  |             PltProduct product = productDao.selectByPrimaryKey(assyPlan.getProId()); | 
 |  |  |             if (product != null) { | 
 |  |  |                 result.setProId(product.getId()); | 
 |  |  |                 result.setProName(product.getName()); | 
 |  |  |                 String devicePrefix = "110" + product.getCode() + assyPlan.getBatchNo(); | 
 |  |  |                 result.setDevicePrefix(devicePrefix); | 
 |  |  |         //如果是无任务计划 如维修work_type 没有 planId processId nodeId | 
 |  |  |         if (result.getPlanId() != null) { | 
 |  |  |             //校验planId processId nodeId | 
 |  |  |             PrAssemblyPlan assyPlan = assemblyDao.selectByPrimaryKey(result.getPlanId()); | 
 |  |  |             boolean hasNodeId = assyPlan.getProcess().getNodes().stream() | 
 |  |  |                     .anyMatch(node -> node.id.equals(result.getNodeId())); | 
 |  |  |             if (userInfo == null || stationInfo == null || assyPlan == null || (!hasNodeId)) { | 
 |  |  |                 //直接删除记录 | 
 |  |  |                 logout(result.getId().toString()); | 
 |  |  |                 result.setId(null); | 
 |  |  |                 result.setStatus(STATUS_WORK_LAST_LOGOUT); | 
 |  |  |                 if (userInfo == null) { | 
 |  |  |                     result.setUserId(null); | 
 |  |  |                     result.setUserName(""); | 
 |  |  |                 } | 
 |  |  |                 if (stationInfo == null) { | 
 |  |  |                     result.setStationId(null); | 
 |  |  |                     result.setStationName(""); | 
 |  |  |                 } | 
 |  |  |                 if (assyPlan == null) { | 
 |  |  |                     result.setPlanId(null); | 
 |  |  |                     result.setPlanName(""); | 
 |  |  |                 } | 
 |  |  |                 if (!hasNodeId) { | 
 |  |  |                     result.setNodeId(null); | 
 |  |  |                     result.setNodeName(""); | 
 |  |  |                 } | 
 |  |  |                 return result; | 
 |  |  |             } else { | 
 |  |  |                 result.setPlanName(assyPlan.getName()); | 
 |  |  |                 result.setProcessName(assyPlan.getProcessName()); | 
 |  |  |                 result.setNodeName(assyPlan.getProcess().getNodes().get(0).getContent()); | 
 |  |  |                 //找到对应的产品信息 | 
 |  |  |                 PltProduct product = productDao.selectByPrimaryKey(assyPlan.getProId()); | 
 |  |  |                 if (product != null) { | 
 |  |  |                     result.setProId(product.getId()); | 
 |  |  |                     result.setProName(product.getName()); | 
 |  |  |                     String devicePrefix = QrCodeConstant.TypeProduct + product.getCode() + assyPlan.getBatchNo(); | 
 |  |  |                     result.setDevicePrefix(devicePrefix); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         result.setStationId(stationInfo.getId()); | 
 |  |  | 
 |  |  |     public StaAssemblyWorkLast save(QueryVo vo) { | 
 |  |  |         //先check | 
 |  |  |         StaAssemblyWorkLast checkResult = checkUserAndStationUsed(vo); | 
 |  |  |         //校验planId processId nodeId | 
 |  |  |         PrAssemblyPlan assyPlan = assemblyDao.selectByPrimaryKey(vo.getPlanId()); | 
 |  |  |         if (assyPlan == null) { | 
 |  |  |             throw new RuntimeException("组装任务已经在系统中删除请检查,刷新并重新选择任务"); | 
 |  |  |         } | 
 |  |  |         boolean hasNodeId = assyPlan.getProcess().getNodes().stream() | 
 |  |  |                 .anyMatch(node -> node.id.equals(vo.getNodeId())); | 
 |  |  |         if (!hasNodeId) { | 
 |  |  |             throw new RuntimeException("节点信息有误或被其他人员修改,请重新选择节点信息"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //数据逐个封装返回 | 
 |  |  |         vo.setLineId(checkResult.getLineId()); | 
 |  |  |         StaAssemblyWorkLast staLast = new StaAssemblyWorkLast(); | 
 |  |  |         BeanUtils.copyProperties(vo, staLast); | 
 |  |  |         staLast.setUserId(checkResult.getUserId()); | 
 |  |  |         staLast.setStationId(checkResult.getStationId()); | 
 |  |  |         //校验planId processId nodeId | 
 |  |  |         PrAssemblyPlan assyPlan = new PrAssemblyPlan(); | 
 |  |  |         if (vo.getPlanId() != null) { | 
 |  |  |             assyPlan = assemblyDao.selectByPrimaryKey(vo.getPlanId()); | 
 |  |  |             if (assyPlan == null) { | 
 |  |  |                 throw new RuntimeException("组装任务已经在系统中删除请检查,刷新并重新选择任务"); | 
 |  |  |             } | 
 |  |  |             boolean hasNodeId = assyPlan.getProcess().getNodes().stream() | 
 |  |  |                     .anyMatch(node -> node.id.equals(vo.getNodeId())); | 
 |  |  |             if (!hasNodeId) { | 
 |  |  |                 throw new RuntimeException("节点信息有误或被其他人员修改,请重新选择节点信息"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         int count = 0; | 
 |  |  |         if (checkResult.getId() == null) { | 
 |  |  |             BeanUtils.copyProperties(vo, staLast);//vo拷贝到staLast | 
 |  |  | 
 |  |  |         } else { | 
 |  |  |             //保存一条history? | 
 |  |  |             BeanUtils.copyProperties(checkResult, staLast); | 
 |  |  |             staLast.setPlanId(assyPlan.getId()); | 
 |  |  |             staLast.setProcessId(assyPlan.getProcess().getId()); | 
 |  |  |             staLast.setNodeId(vo.getNodeId()); | 
 |  |  |             if (vo.getPlanId() != null) { | 
 |  |  |                 staLast.setPlanId(assyPlan.getId()); | 
 |  |  |                 staLast.setProcessId(assyPlan.getProcess().getId()); | 
 |  |  |                 staLast.setNodeId(vo.getNodeId()); | 
 |  |  |             } | 
 |  |  |             staLast.setWorkType(vo.getWorkType()); | 
 |  |  |             staLast.setStatus(STATUS_NORMAL); | 
 |  |  |             staLast.setStartTime(new Date()); | 
 |  |  |             count = assemblyWorkLastDao.updateByPrimaryKeySelective(staLast); | 
 |  |  | 
 |  |  |             throw new RuntimeException("数据库存储失败"); | 
 |  |  |         } | 
 |  |  |         StaAssemblyWorkLast result = assemblyWorkLastDao.selectByPrimaryKey(staLast.getId()); | 
 |  |  |         List<PrProductionNode> nodeInfo = assyPlan.getProcess().getNodes().stream() | 
 |  |  |                 .filter(node -> node.id.equals(vo.getNodeId())).collect(Collectors.toList()); | 
 |  |  |         result.setPlanName(assyPlan.getName()); | 
 |  |  |         result.setProcessName(assyPlan.getProcessName()); | 
 |  |  |         result.setNodeName(assyPlan.getProcess().getNodes().get(0).getContent()); | 
 |  |  |         //找到对应的产品信息 | 
 |  |  |         PltProduct product = productDao.selectByPrimaryKey(assyPlan.getProId()); | 
 |  |  |         if (product == null) { | 
 |  |  |             throw new RuntimeException("产品信息有误或被其他人员修改,请登录管理系统查看任务关联产品ID为:" + assyPlan.getProId()); | 
 |  |  |         if (assyPlan != null) { | 
 |  |  |             List<PrProductionNode> nodeInfo = assyPlan.getProcess().getNodes().stream() | 
 |  |  |                     .filter(node -> node.id.equals(vo.getNodeId())).collect(Collectors.toList()); | 
 |  |  |             result.setPlanName(assyPlan.getName()); | 
 |  |  |             result.setProcessName(assyPlan.getProcessName()); | 
 |  |  |             result.setNodeName(assyPlan.getProcess().getNodes().get(0).getContent()); | 
 |  |  |             //找到对应的产品信息 | 
 |  |  |             PltProduct product = productDao.selectByPrimaryKey(assyPlan.getProId()); | 
 |  |  |             if (product == null) { | 
 |  |  |                 throw new RuntimeException("产品信息有误或被其他人员修改,请登录管理系统查看任务关联产品ID为:" + assyPlan.getProId()); | 
 |  |  |             } | 
 |  |  |             result.setProId(product.getId()); | 
 |  |  |             result.setProName(product.getName()); | 
 |  |  |             String devicePrefix = QrCodeConstant.TypeProduct + product.getCode() + assyPlan.getBatchNo(); | 
 |  |  |             result.setDevicePrefix(devicePrefix); | 
 |  |  |         } | 
 |  |  |         result.setProId(product.getId()); | 
 |  |  |         result.setProName(product.getName()); | 
 |  |  |         String devicePrefix = "110" + product.getCode() + assyPlan.getBatchNo(); | 
 |  |  |         result.setDevicePrefix(devicePrefix); | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  |