| | |
| | | import com.zy.asrs.entity.mes.*; |
| | | import com.zy.asrs.entity.rcs.*; |
| | | import com.zy.asrs.mapper.AgvInfoMapper; |
| | | import com.zy.asrs.mapper.CanFinMapper; |
| | | import com.zy.asrs.mapper.MatItemBarcodeMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.OrderInAndOutUtil; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.sql.Time; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | private DocTypeService docTypeService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private CanFinMapper canFinMapper; |
| | | |
| | | |
| | | // region MES接口 |
| | |
| | | newTag.setUpdateBy(defaultUserId); |
| | | newTag.setUpdateTime(now); |
| | | |
| | | if (!tagService.insert(newTag)) |
| | | if (!tagService.insert(newTag)){ |
| | | log.error("插入tag失败"); |
| | | return -1; |
| | | } |
| | | tagId = newTag.getId(); |
| | | } else { |
| | | tagId = tag.getId(); |
| | |
| | | newMat.setUpdateTime(now); |
| | | newMat.setStatus(1); |
| | | if (mat == null) { |
| | | if (!matService.insert(newMat)) |
| | | if (!matService.insert(newMat)){ |
| | | log.error("插入失败"); |
| | | return -2; |
| | | } |
| | | } |
| | | } else { |
| | | log.error("tagId小于0"); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | |
| | | // 校验订单是否重复 |
| | | OrderPakin order = orderPakinService.selectByNo(entry.getKey()); |
| | | // 如果单据不存在则添加;如果单据存在,作业中无法修改,反之则修改单据 |
| | | OrderPakin orderPakin; |
| | | |
| | | // 如果单据不存在则添加;如果单据存在且settle为1则追加明细;如果settle为6则删除后重新生成;作业中无法修改 |
| | | if (!Cools.isEmpty(order)) { |
| | | if (order.getSettle() > 1L) { |
| | | if (order.getSettle() > 1L && order.getSettle() < 6L) { |
| | | throw new CoolException(entry.getKey() + "正在出库,无法修改单据"); |
| | | } else if (order.getSettle() == 6L) { |
| | | orderPakinService.remove(order.getId()); |
| | | orderPakin = null; |
| | | } else if (order.getSettle() == 1L) { |
| | | orderPakin = order; |
| | | } else { |
| | | orderPakin = null; |
| | | } |
| | | orderPakinService.remove(order.getId()); |
| | | } else { |
| | | orderPakin = null; |
| | | } |
| | | |
| | | // 生成订单 |
| | | // 生成订单或更新订单 |
| | | JSONObject newMemo = new JSONObject(); |
| | | newMemo.put("sourceNo", matRecvForm.getSourceNo()); |
| | | newMemo.put("sourceName", matRecvForm.getSourceName()); |
| | |
| | | newMemo.put("itemdata", list); |
| | | |
| | | |
| | | // 生成订单 |
| | | OrderPakin orderPakin = new OrderPakin(); |
| | | orderPakin.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | orderPakin.setOrderNo(entry.getKey()); |
| | | orderPakin.setOrderTime(DateUtils.convert(now)); |
| | | orderPakin.setDocType(docType); |
| | | orderPakin.setSettle(1L); |
| | | orderPakin.setStatus(1); |
| | | orderPakin.setCreateBy(defaultUserId); |
| | | orderPakin.setCreateTime(now); |
| | | orderPakin.setUpdateBy(defaultUserId); |
| | | orderPakin.setUpdateTime(now); |
| | | orderPakin.setMemo(JSONObject.toJSONString(newMemo)); //为出库完成反馈保存 |
| | | orderPakin.setPakinPakoutStatus(1); |
| | | orderPakinService.insert(orderPakin); |
| | | // 如果订单不存在或已删除,则生成新订单 |
| | | if (orderPakin == null) { |
| | | orderPakin = new OrderPakin(); |
| | | orderPakin.setUuid(String.valueOf(snowflakeIdWorker.nextId())); |
| | | orderPakin.setOrderNo(entry.getKey()); |
| | | orderPakin.setOrderTime(DateUtils.convert(now)); |
| | | orderPakin.setDocType(docType); |
| | | orderPakin.setSettle(1L); |
| | | orderPakin.setStatus(1); |
| | | orderPakin.setCreateBy(defaultUserId); |
| | | orderPakin.setCreateTime(now); |
| | | orderPakin.setMemo(JSONObject.toJSONString(newMemo)); |
| | | orderPakin.setPakinPakoutStatus(1); |
| | | orderPakinService.insert(orderPakin); |
| | | } else { |
| | | // 更新订单的memo和更新时间 |
| | | orderPakin.setMemo(JSONObject.toJSONString(newMemo)); |
| | | orderPakin.setUpdateBy(defaultUserId); |
| | | orderPakin.setUpdateTime(now); |
| | | orderPakinService.updateById(orderPakin); |
| | | } |
| | | if (list != null && !list.isEmpty()) { |
| | | for (MesMatInfo mesMatInfo : list) { |
| | | |
| | |
| | | OrderDetlPakin orderDetlPakin = new OrderDetlPakin(); |
| | | orderDetlPakin.setOrderId(orderPakin.getId()); |
| | | orderDetlPakin.setOrderNo(orderPakin.getOrderNo()); |
| | | orderDetlPakin.setAnfme(Double.valueOf(mesMatInfo.getQty())); |
| | | orderDetlPakin.setAnfme(mesMatInfo.getQty()); |
| | | orderDetlPakin.setQty(0.0); |
| | | orderDetlPakin.setMatnr(mat.getMatnr()); |
| | | orderDetlPakin.setMaktx(mat.getMaktx()); |
| | |
| | | if (docType == null) { |
| | | return 0; |
| | | } |
| | | |
| | | //生成出库单 |
| | | if (docType.getPakout() == 1) { |
| | | long settle = 1; |
| | |
| | | orderPakout.setMemo(JSONObject.toJSONString(mesCallOutApply)); |
| | | orderPakout.setPakinPakoutStatus(2); |
| | | orderPakout.setCstmrName(mesCallOutApply.getStationId());//agv目标站点 |
| | | /* |
| | | // 查询can_fin表中apply_time最新的记录 |
| | | List<CanFin> canFinList = canFinMapper.selectList(new EntityWrapper<CanFin>() |
| | | .orderBy("apply_time", false) |
| | | ); |
| | | if (!canFinList.isEmpty()) { |
| | | CanFin firstCanFin = canFinList.get(0); |
| | | if (firstCanFin.getAgvType().equals("agv-in-out")) { |
| | | // 只修改需要更新的字段 |
| | | if (firstCanFin.getOutNo() == null){ |
| | | firstCanFin.setOutType("waiting"); |
| | | firstCanFin.setOutNo(mesCallOutApply.getOrderNo()); |
| | | // 确保其他字段保持不变 |
| | | canFinMapper.updateById(firstCanFin); |
| | | log.info("已更新can_fin表最早记录的out_no,ID:{},出库单号:{}", |
| | | firstCanFin.getId(), mesCallOutApply.getOrderNo()); |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | |
| | | if (!orderPakoutService.insert(orderPakout)) { |
| | | log.error("MES保存出库订单(叫料)主档失败"); |
| | | throw new CoolException("保存出库订单(叫料)主档失败"); |
| | | } |
| | | |
| | | if (mesCallOutApply.getTransType().equals("装配出库单")){ |
| | | CanFin canFin = new CanFin(); |
| | | Date time = now; |
| | | canFin.setAgvType("agv-out"); |
| | | canFin.setOutNo(mesCallOutApply.getOrderNo()); |
| | | List<CanFin> canFinList = canFinMapper.selectList(new EntityWrapper<>()); |
| | | if (canFinList.isEmpty()){ |
| | | canFin.setTaskStatus("canout"); |
| | | }else { |
| | | canFin.setTaskStatus("waiting"); |
| | | } |
| | | canFin.setApplyTime(time); |
| | | canFinMapper.insert(canFin); |
| | | } |
| | | |
| | | Set<String> set = new HashSet<>(); |
| | | // 生成明细 |
| | | if (mesCallOutApply.getItemdata() != null && !mesCallOutApply.getItemdata().isEmpty()) { |
| | |
| | | //有多少种不同的配盘号 只有配盘出库单需要知道 |
| | | if (mesCallOutApply.getTransType().equals("配盘出库单")) { |
| | | orderPakout.setPayType(set.size()); |
| | | String shipCode = mesCallOutApply.getItemdata().get(0).getTrayid().split("-")[2]; |
| | | String orderNo = mesCallOutApply.getOrderNo(); |
| | | String shipCode = orderNo.substring(orderNo.lastIndexOf("-") + 1); |
| | | orderPakout.setShipCode(shipCode);//区域 是否是特殊托盘 |
| | | orderPakoutService.updateById(orderPakout); |
| | | } |
| | |
| | | task.setPltType(transTask.getAgvFactory());//华晓AGV |
| | | task.setPacked(transTask.getRackNumber());//料架号 |
| | | task.setCtnType(1); |
| | | task.setIsPda(transTask.getIsPDA()); |
| | | |
| | | if (taskService.insert(task)) { |
| | | if (transTask.getNextStationId().equals("307")){ |
| | | CanFin canFin = new CanFin(); |
| | | Date time = now; |
| | | // canFin.setAgvType("agv-in-out"); |
| | | canFin.setAgvType("agv-in"); |
| | | canFin.setInNo(transTask.getTaskno()); |
| | | canFin.setTaskStatus("waiting"); |
| | | canFin.setApplyTime(time); |
| | | canFinMapper.insert(canFin); |
| | | } |
| | | result.put("Success", "1"); |
| | | result.put("Message", "任务接收成功"); |
| | | |
| | |
| | | mesReturn.setSuccess("2"); |
| | | |
| | | if ("Y".equals(allow.getStatus())) { |
| | | String TaskNo = allow.getTaskno(); |
| | | if(allow.getTaskno().contains("-")){ |
| | | TaskNo = allow.getTaskno().substring(0, allow.getTaskno().length() - 2); |
| | | |
| | | // 修改后的逻辑:有"-"则去掉最后一个"-"及后面内容,没有则保持原样 |
| | | String taskNo = allow.getTaskno(); |
| | | if (taskNo.contains("-")) { |
| | | taskNo = allow.getTaskno().substring(0, taskNo.lastIndexOf("-")); |
| | | } |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("task_no", TaskNo)); |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("task_no", taskNo)); |
| | | if (Cools.isEmpty(task)) { |
| | | mesReturn.setMessage("没有找个该任务编号=" + allow.getTaskno() + "的AGV移动任务"); |
| | | } else { |
| | |
| | | mesReturn.setSuccess("2"); |
| | | |
| | | if ("Y".equals(allow.getStatus())) { |
| | | String TaskNo = allow.getTaskno(); |
| | | if(allow.getTaskno().contains("-")){ |
| | | TaskNo = allow.getTaskno().substring(0, allow.getTaskno().length() - 2); |
| | | // 修改后的逻辑:有"-"则去掉最后一个"-"及后面内容,没有则保持原样 |
| | | String taskNo = allow.getTaskno(); |
| | | if (taskNo.contains("-")) { |
| | | taskNo = allow.getTaskno().substring(0, taskNo.lastIndexOf("-")); |
| | | } |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("task_no", TaskNo)); |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("task_no", taskNo)); |
| | | if (Cools.isEmpty(task)) { |
| | | mesReturn.setMessage("没有找个该任务编号=" + TaskNo + "的AGV移动任务"); |
| | | mesReturn.setMessage("没有找个该任务编号=" + taskNo + "的AGV移动任务"); |
| | | } else { |
| | | //查看申请站点的是海康还是华晓 |
| | | //海康 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int AGVPause(JSONObject params, int AGVType){ |
| | | MesReturn mesReturn = new MesReturn(); |
| | | public int AGVPause(JSONObject mesInfo, String Type){ |
| | | |
| | | String hik_url = "api/robot/controller/zone/pause"; |
| | | String hx_url = ""; |
| | | String URL = ""; |
| | | if (AGVType == 1){ |
| | | URL = HIK_URL + hik_url; |
| | | int i = HikPersonIn(mesInfo, Type); |
| | | int j = HxPersonIn(mesInfo, Type); |
| | | |
| | | if (i == 1){ |
| | | if (j == 1){ |
| | | return 1; |
| | | }else |
| | | return 2; |
| | | }else { |
| | | URL = HX_URL + hx_url; |
| | | if (j == 1){ |
| | | return 3; |
| | | }else |
| | | return 4; |
| | | } |
| | | } |
| | | |
| | | //人员入侵系统海康实现方法 |
| | | public int HikPersonIn(JSONObject param, String Type) { |
| | | String hik_blockUrl = "api/robot/controller/zone/blockade"; |
| | | String hik_pauseUrl = "api/robot/controller/zone/pause"; |
| | | |
| | | String BLOCK_URL = HIK_URL + hik_blockUrl; |
| | | String PAUSE_URL = HIK_URL + hik_pauseUrl; |
| | | |
| | | JSONObject rcsBlock = new JSONObject(); |
| | | JSONObject rcsPause = new JSONObject(); |
| | | |
| | | rcsBlock.put("mapCode", "BB"); |
| | | rcsPause.put("mapCode", "BB"); |
| | | |
| | | rcsBlock.put("zoneCode", param.getString("AreaCode")); |
| | | rcsPause.put("zoneCode", param.getString("AreaCode")); |
| | | |
| | | if (Type.equals("STOP")){ |
| | | rcsBlock.put("invoke", "BLOCKADE"); |
| | | rcsPause.put("invoke","FREEZE"); |
| | | } |
| | | if (Type.equals("START")){ |
| | | rcsBlock.put("invoke", "OPENUP"); |
| | | rcsPause.put("invoke","RUN"); |
| | | } |
| | | |
| | | String response = RcsServiceImpl.sendPost(URL, JSONObject.toJSONString(params)); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (!StringUtils.isEmpty(response) && jsonObject.getString("code").equals("SUCCESS")) { |
| | | String blockResponse = RcsServiceImpl.sendPost(BLOCK_URL, JSONObject.toJSONString(rcsBlock)); |
| | | String PauseResponse = RcsServiceImpl.sendPost(PAUSE_URL, JSONObject.toJSONString(rcsPause)); |
| | | JSONObject blockJsonObject = JSON.parseObject(blockResponse); |
| | | JSONObject pauseJsonObject = JSON.parseObject(PauseResponse); |
| | | if (!StringUtils.isEmpty(blockResponse) && (blockJsonObject.getString("code").equals("SUCCESS"))) { |
| | | if (!StringUtils.isEmpty(PauseResponse) && (pauseJsonObject.getString("code").equals("SUCCESS"))) { |
| | | return 1; |
| | | }else |
| | | return 2; |
| | | } |
| | | return 0; |
| | | } |
| | | //直接返回,不需要信息 |
| | | return 0; |
| | | } |
| | | |
| | | //人员入侵系统华晓实现方法 |
| | | public int HxPersonIn(JSONObject param, String Type) { |
| | | JSONObject rcsPause = new JSONObject(); |
| | | |
| | | String hx_url = "controller/notify/isstop"; |
| | | String URL = HX_URL + hx_url; |
| | | |
| | | rcsPause.put("agvno", 0); |
| | | rcsPause.put("areaNo", param.getString("AreaCode")); |
| | | |
| | | if (Type.equals("STOP")) |
| | | rcsPause.put("action", "stop"); |
| | | |
| | | if (Type.equals("START")) |
| | | rcsPause.put("action", "start"); |
| | | |
| | | if (Type.equals("STOP")){ |
| | | for (int i = 0; i < 10; i++){ |
| | | String response = RcsServiceImpl.sendPost(URL, JSONObject.toJSONString(rcsPause)); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (!StringUtils.isEmpty(response) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) { |
| | | return 1; |
| | | }else |
| | | return 0; |
| | | } |
| | | } |
| | | if (Type.equals("START")){ |
| | | String response = RcsServiceImpl.sendPost(URL, JSONObject.toJSONString(rcsPause)); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (!StringUtils.isEmpty(response) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) { |
| | | return 1; |
| | | }else |
| | | return 0; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | // endregion |