| | |
| | | |
| | | import com.alibaba.excel.util.DateUtils; |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | |
| | | import com.zy.asrs.entity.param.EmptyPlateOutParam; |
| | | 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.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.concurrent.ExecutionException; |
| | |
| | | public long defaultUserId; |
| | | @Value("${wms.zpalletId}") |
| | | public String WMS_ZPALLET_ID; |
| | | |
| | | // 海康RCS地址 |
| | | @Value("${hik.url}") |
| | | private String HIK_URL; |
| | | |
| | | // 华晓RCS地址 |
| | | @Value("${hx.url}") |
| | | private String HX_URL; |
| | | |
| | | @Resource |
| | | private RcsService rcsService; |
| | |
| | | private DocTypeService docTypeService; |
| | | @Autowired |
| | | private OrderService orderService; |
| | | @Autowired |
| | | private CanFinMapper canFinMapper; |
| | | |
| | | |
| | | // region MES接口 |
| | |
| | | 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; |
| | | } |
| | | |
| | | /* |
| | | // 查询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")) { |
| | | // 只修改需要更新的字段 |
| | | firstCanFin.setOutType("waiting"); |
| | | firstCanFin.setOutNo(mesCallOutApply.getOrderNo()); |
| | | // 确保其他字段保持不变 |
| | | canFinMapper.updateById(firstCanFin); |
| | | |
| | | log.info("已更新can_fin表最早记录的out_no,ID:{},出库单号:{}", |
| | | firstCanFin.getId(), mesCallOutApply.getOrderNo()); |
| | | } |
| | | } |
| | | */ |
| | | |
| | | //生成出库单 |
| | | if (docType.getPakout() == 1) { |
| | | long settle = 1; |
| | |
| | | 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()) { |
| | |
| | | |
| | | set.add(mesOutApplyItem.getTrayid()); |
| | | Mat mat = matService.selectByMatnr(mesOutApplyItem.getItemno()); |
| | | if (Cools.isEmpty(mat)) { |
| | | log.error("物料编号不存在: {}", mesOutApplyItem.getItemno()); |
| | | throw new CoolException("物料编号不存在: " + mesOutApplyItem.getItemno()); |
| | | } |
| | | OrderDetlPakout orderDetlPakout = new OrderDetlPakout(); |
| | | orderDetlPakout.setOrderId(orderPakout.getId()); |
| | | orderDetlPakout.setOrderNo(orderPakout.getOrderNo()); |
| | |
| | | Task task = new Task(); |
| | | task.setWrkNo(workNo); |
| | | task.setTaskType("ZX-AGV"); |
| | | if (transTask.getTransType()!= null){ |
| | | if (transTask.getTransType().equals("08-1")){ |
| | | task.setTaskType("ZX-AGV-08-1"); |
| | | }else if (transTask.getTransType().equals("08-2")){ |
| | | task.setTaskType("ZX-AGV-08-2"); |
| | | }else if (transTask.getTransType().equals("11")){ |
| | | task.setTaskType("ZP-AGV"); |
| | | } |
| | | } |
| | | task.setWrkSts(301L);//301.AGV任务创建 |
| | | task.setIoType(3);//3.站到站 |
| | | task.setIoPri(10.00); |
| | |
| | | task.setPltType(transTask.getAgvFactory());//华晓AGV |
| | | task.setPacked(transTask.getRackNumber());//料架号 |
| | | task.setCtnType(1); |
| | | task.setIsPda(transTask.getIsPDA()); |
| | | |
| | | if (taskService.insert(task)) { |
| | | if (transTask.getNextStationId().equals("402") || transTask.getNextStationId().equals("401")){ |
| | | CanFin canFin = new CanFin(); |
| | | // canFin.setAgvType("agv-in-out"); |
| | | canFin.setAgvType("agv-in"); |
| | | canFin.setTaskStatus("waiting"); |
| | | canFin.setInNo(transTask.getTaskno()); |
| | | canFin.setApplyTime(now); |
| | | canFinMapper.insert(canFin); |
| | | result.put("Success", "1"); |
| | | result.put("Message", "任务接收成功"); |
| | | |
| | | result.put("Message", "任务下发给RCS成功"); |
| | | } |
| | | result.put("Success", "1"); |
| | | result.put("Message", "任务下发给RCS成功"); |
| | | }else { |
| | | result.put("Success", "2"); |
| | | result.put("Message", "任务下发给RCS失败"); |
| | |
| | | mesReturn.setSuccess("2"); |
| | | |
| | | if ("Y".equals(allow.getStatus())) { |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("task_no", allow.getTaskno())); |
| | | 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)); |
| | | if (Cools.isEmpty(task)) { |
| | | mesReturn.setMessage("没有找个该任务编号=" + allow.getTaskno() + "的AGV移动任务"); |
| | | |
| | | mesReturn.setMessage("没有找到该任务编号=" + allow.getTaskno() + "的AGV移动任务"); |
| | | } else { |
| | | //查看申请站点的是海康还是华晓 |
| | | //海康 |
| | |
| | | mesReturn.setSuccess(success == 1 ? "1" : "2"); |
| | | mesReturn.setMessage(success == 1 ? "" : "转发给RCS失败"); |
| | | } else { |
| | | JSONObject params = new JSONObject(); |
| | | params.put("EqptCode", allow.getStationId()); |
| | | params.put("TaskCode", allow.getTaskno()); |
| | | params.put("ActionStatus", "1"); |
| | | allow.setMethod("APPLY_IN_STATION"); |
| | | int success = rcsService.continueTask(allow, 2); |
| | | mesReturn.setSuccess(success == 1 ? "1" : "2"); |
| | | mesReturn.setMessage(success == 1 ? "" : "转发给RCS失败"); |
| | | int success1 = rcsService.applyIn(params, 2); |
| | | if (success1 == 1 || success == 1){ |
| | | mesReturn.setSuccess("1"); |
| | | mesReturn.setMessage(""); |
| | | }else { |
| | | mesReturn.setSuccess(success1 == 1 ? "1" : "2"); |
| | | mesReturn.setMessage(success1 == 1 ? "" : "转发给RCS失败"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | return mesReturn; |
| | |
| | | mesReturn.setSuccess("2"); |
| | | |
| | | if ("Y".equals(allow.getStatus())) { |
| | | Task task = taskService.selectOne(new EntityWrapper<Task>().eq("task_no", allow.getTaskno())); |
| | | 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)); |
| | | if (Cools.isEmpty(task)) { |
| | | mesReturn.setMessage("没有找个该任务编号=" + allow.getTaskno() + "的AGV移动任务"); |
| | | } else { |
| | | //查看申请站点的是海康还是华晓 |
| | | //海康 |
| | | if (Cools.isEmpty(task.getPltType()) || task.getPltType() == 1) { |
| | | if (Cools.isEmpty(task.getPltType()) || task.getPltType() == 1 || task.getPltType() == 0) { |
| | | RcsTaskContinue rcsTaskContinue = new RcsTaskContinue(); |
| | | rcsTaskContinue.setRobotTaskCode(allow.getTaskno()); |
| | | rcsTaskContinue.setTriggerType("TASK"); |
| | | rcsTaskContinue.setTriggerCode(allow.getTaskno()); |
| | | // rcsTaskContinue.setTriggerType("ROBOT"); |
| | | // rcsTaskContinue.setTriggerCode(allow.getAgvCode()); |
| | | |
| | | int success = rcsService.continueTask(rcsTaskContinue, 1); |
| | | mesReturn.setSuccess(success == 1 ? "1" : "2"); |
| | | mesReturn.setMessage(success == 1 ? "" : "转发给RCS失败"); |
| | | |
| | | } else { |
| | | allow.setMethod("APPLY_OFF_STATION"); |
| | | int success = rcsService.continueTask(allow, 2); |
| | |
| | | return mesReturn; |
| | | } |
| | | |
| | | |
| | | // endregion |
| | | |
| | | /** |
| | |
| | | AgvInfo agvInfo = agvInfoMapper.selectById(agvNo); |
| | | return agvInfo.getAgvFactory(); |
| | | } |
| | | @Override |
| | | public int AGVPause(JSONObject params, int AGVType){ |
| | | MesReturn mesReturn = new MesReturn(); |
| | | |
| | | String hik_blockUrl = "api/robot/controller/zone/blockade"; |
| | | String hik_pauseUrl = "api/robot/controller/zone/pause"; |
| | | String hx_url = "robot/controller/notify/isstop"; |
| | | |
| | | if (AGVType == 1){ |
| | | String BLOCK_URL = HIK_URL + hik_blockUrl; |
| | | String PAUSE_URL = HIK_URL + hik_pauseUrl; |
| | | |
| | | String blockResponse = RcsServiceImpl.sendPost(BLOCK_URL, JSONObject.toJSONString(params)); |
| | | JSONObject jsonObject = JSON.parseObject(blockResponse); |
| | | if (!StringUtils.isEmpty(blockResponse) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) { |
| | | String PauseResponse = RcsServiceImpl.sendPost(PAUSE_URL, JSONObject.toJSONString(params)); |
| | | JSONObject pauseJsonObject = JSON.parseObject(PauseResponse); |
| | | if (!StringUtils.isEmpty(PauseResponse) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) { |
| | | return 1; |
| | | }else |
| | | return 2; |
| | | }else |
| | | return 2; |
| | | }else { |
| | | String URL = ""; |
| | | URL = HX_URL + hx_url; |
| | | String PauseResponse = RcsServiceImpl.sendPost(URL, JSONObject.toJSONString(params)); |
| | | JSONObject jsonObject = JSON.parseObject(PauseResponse); |
| | | if (!StringUtils.isEmpty(PauseResponse) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) { |
| | | return 1; |
| | | }else |
| | | return 2; |
| | | } |
| | | |
| | | } |
| | | } |