|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.BaseRes; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.service.LocMastService; | 
|---|
|  |  |  | import com.zy.asrs.service.WrkMastService; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.model.NyShuttleOperaResult; | 
|---|
|  |  |  | import com.zy.common.model.enums.NavigationMapType; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.common.utils.NyHttpUtils; | 
|---|
|  |  |  | import com.zy.common.utils.NyShuttleOperaUtils; | 
|---|
|  |  |  | import com.zy.common.utils.RedisUtil; | 
|---|
|  |  |  | import com.zy.common.utils.ShuttleDispatchUtils; | 
|---|
|  |  |  | import com.zy.core.cache.MessageQueue; | 
|---|
|  |  |  | import com.zy.core.cache.OutputQueue; | 
|---|
|  |  |  | import com.zy.core.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.core.enums.*; | 
|---|
|  |  |  | import com.zy.core.model.ShuttleSlave; | 
|---|
|  |  |  | import com.zy.core.model.Task; | 
|---|
|  |  |  | import com.zy.core.model.command.NyShuttleHttpCommand; | 
|---|
|  |  |  | import com.zy.core.model.command.ShuttleAssignCommand; | 
|---|
|  |  |  | import com.zy.core.model.command.ShuttleCommand; | 
|---|
|  |  |  | import com.zy.core.model.command.ShuttleRedisCommand; | 
|---|
|  |  |  | import com.zy.core.model.protocol.NyShuttleProtocol; | 
|---|
|  |  |  | import com.zy.core.model.protocol.ShuttleProtocol; | 
|---|
|  |  |  | 
|---|
|  |  |  | private CommonService commonService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisUtil redisUtil; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShuttleDispatchUtils shuttleDispatchUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/table/shuttle/state") | 
|---|
|  |  |  | @ManagerAuth(memo = "四向穿梭车信息表") | 
|---|
|  |  |  | public R shuttleStateTable(){ | 
|---|
|  |  |  | ArrayList<NyShuttleProtocol> list = new ArrayList<>(); | 
|---|
|  |  |  | ArrayList<JSONObject> list = new ArrayList<>(); | 
|---|
|  |  |  | List<BasShuttle> shuttles = basShuttleService.selectList(new EntityWrapper<BasShuttle>().orderBy("shuttle_no")); | 
|---|
|  |  |  | for (BasShuttle basShuttle : shuttles) { | 
|---|
|  |  |  | // 表格行 | 
|---|
|  |  |  | JSONObject baseObj = new JSONObject(); | 
|---|
|  |  |  | baseObj.put("shuttleNo", basShuttle.getShuttleNo()); | 
|---|
|  |  |  | list.add(baseObj); | 
|---|
|  |  |  | // 获取四向穿梭车信息 | 
|---|
|  |  |  | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, basShuttle.getShuttleNo()); | 
|---|
|  |  |  | if (shuttleThread == null) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); | 
|---|
|  |  |  | JSONObject shuttleData = JSON.parseObject(JSON.toJSONString(shuttleProtocol)); | 
|---|
|  |  |  | if (shuttleProtocol == null || shuttleProtocol.getShuttleNo()==null) { | 
|---|
|  |  |  | if (shuttleData != null) { | 
|---|
|  |  |  | baseObj.putAll(shuttleData); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | list.add(shuttleProtocol); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleData.put("moveAdvancePath", null);//穿梭车预计路径 | 
|---|
|  |  |  | if (shuttleProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | //存在任务,获取指令 | 
|---|
|  |  |  | Object object = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo()); | 
|---|
|  |  |  | if (object != null) { | 
|---|
|  |  |  | ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class); | 
|---|
|  |  |  | shuttleData.put("moveAdvancePath", redisCommand.getAssignCommand().getNodes());//穿梭车预计路径 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | baseObj.putAll(shuttleData); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok().add(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); | 
|---|
|  |  |  | ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); | 
|---|
|  |  |  | List<ShuttleCommand> commands = assignCommand.getCommands(); | 
|---|
|  |  |  | ShuttleCommand command = commands.get(commandStep); | 
|---|
|  |  |  | List<NyShuttleHttpCommand> commands = assignCommand.getCommands(); | 
|---|
|  |  |  | NyShuttleHttpCommand command = commands.get(commandStep); | 
|---|
|  |  |  | command.setComplete(complete != 0); | 
|---|
|  |  |  | redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | 
|---|
|  |  |  | assignCommand.setTaskNo((short) commonService.getWorkNo(3));//获取任务号 | 
|---|
|  |  |  | assignCommand.setAuto(false);//手动模式 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (shuttleTaskModeType == ShuttleTaskModeType.TRANSPORT) { | 
|---|
|  |  |  | //搬运货物任务 | 
|---|
|  |  |  | NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), shuttleProtocol.getCurrentLocNo(), param.getSourceLocNo(), param.getDistLocNo()); | 
|---|
|  |  |  | if (result == null) { | 
|---|
|  |  |  | throw new CoolException("路径计算失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | assignCommand.setCommands(result.getCommands()); | 
|---|
|  |  |  | assignCommand.setNodes(result.getNodes()); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO) { | 
|---|
|  |  |  | //移动到目标库位 | 
|---|
|  |  |  | Integer mapType = NavigationMapType.NORMAL.id; | 
|---|
|  |  |  | if (shuttleProtocol.getLiftPosition() == 2) { | 
|---|
|  |  |  | mapType = NavigationMapType.DFX.id; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), shuttleProtocol.getCurrentLocNo(), param.getDistLocNo(), mapType); | 
|---|
|  |  |  | if (result == null) { | 
|---|
|  |  |  | throw new CoolException("路径计算失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | assignCommand.setCommands(result.getCommands()); | 
|---|
|  |  |  | assignCommand.setNodes(result.getNodes()); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.PALLET_LIFT) { | 
|---|
|  |  |  | //托盘顶升 | 
|---|
|  |  |  | NyShuttleHttpCommand command = NyHttpUtils.getPalletLiftCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), true); | 
|---|
|  |  |  | ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | assignCommand.setCommands(commands); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.PALLET_DOWN) { | 
|---|
|  |  |  | //托盘下降 | 
|---|
|  |  |  | NyShuttleHttpCommand command = NyHttpUtils.getPalletLiftCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), false); | 
|---|
|  |  |  | ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | assignCommand.setCommands(commands); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.CHARGE) { | 
|---|
|  |  |  | //充电开关 | 
|---|
|  |  |  | boolean charge = false; | 
|---|
|  |  |  | if (shuttleProtocol.getChargState() == 1) { | 
|---|
|  |  |  | //已充电,关闭充电 | 
|---|
|  |  |  | charge = false; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | //开启充电 | 
|---|
|  |  |  | charge = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | NyShuttleHttpCommand command = NyHttpUtils.getChargeCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), charge); | 
|---|
|  |  |  | ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | assignCommand.setCommands(commands); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.RESET) { | 
|---|
|  |  |  | //复位 | 
|---|
|  |  |  | shuttleProtocol.setTaskNo(0);//工作号清空 | 
|---|
|  |  |  | shuttleProtocol.setToken(0);//令牌清空 | 
|---|
|  |  |  | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);//任务状态-空闲 | 
|---|
|  |  |  | shuttleProtocol.setPakMk(false);//作业标记复位 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleProtocol.setMoveLoc(false); | 
|---|
|  |  |  | shuttleProtocol.setMoveType(0); | 
|---|
|  |  |  | shuttleProtocol.setXStart(0); | 
|---|
|  |  |  | shuttleProtocol.setXTarget(0); | 
|---|
|  |  |  | shuttleProtocol.setXCurrent(0); | 
|---|
|  |  |  | shuttleProtocol.setYStart(0); | 
|---|
|  |  |  | shuttleProtocol.setYTarget(0); | 
|---|
|  |  |  | shuttleProtocol.setYCurrent(0); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.SHUTTLE_CONTROL) { | 
|---|
|  |  |  | //小车管制 | 
|---|
|  |  |  | NyShuttleHttpCommand suspendCommand = NyHttpUtils.getSuspendCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), true); | 
|---|
|  |  |  | ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  | commands.add(suspendCommand); | 
|---|
|  |  |  | assignCommand.setCommands(commands); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.SHUTTLE_CANCEL_CONTROL) { | 
|---|
|  |  |  | //小车取消管制 | 
|---|
|  |  |  | NyShuttleHttpCommand suspendCommand = NyHttpUtils.getSuspendCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), false); | 
|---|
|  |  |  | ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  | commands.add(suspendCommand); | 
|---|
|  |  |  | assignCommand.setCommands(commands); | 
|---|
|  |  |  | } else if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO_WRK_MAST) { | 
|---|
|  |  |  | //移动到目标库位(生成移动任务) | 
|---|
|  |  |  | shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), param.getDistLocNo(), param.getShuttleNo()); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("未知命令"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (MessageQueue.offer(SlaveType.Shuttle, shuttleSlave.getId(), new Task(3, assignCommand))) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping("/detl/update") | 
|---|
|  |  |  | @ManagerAuth(memo = "修改数据") | 
|---|
|  |  |  | public R shuttleUpdate(@RequestParam Integer shuttleNo, | 
|---|
|  |  |  | @RequestParam Integer workNo, | 
|---|
|  |  |  | @RequestParam String pakMk){ | 
|---|
|  |  |  | @RequestParam Integer workNo, | 
|---|
|  |  |  | @RequestParam String pakMk, | 
|---|
|  |  |  | @RequestParam Integer token) { | 
|---|
|  |  |  | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); | 
|---|
|  |  |  | if (shuttleThread == null) { | 
|---|
|  |  |  | return R.error("plc已掉线"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (pakMk != null) { | 
|---|
|  |  |  | shuttleProtocol.setPakMk(pakMk.equals("Y")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (token != null) { | 
|---|
|  |  |  | shuttleProtocol.setToken(token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库程序 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/moveLoc") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R moveLoc(@RequestParam Integer shuttleNo, | 
|---|
|  |  |  | @RequestParam Integer moveType, | 
|---|
|  |  |  | @RequestParam Integer xStart, | 
|---|
|  |  |  | @RequestParam Integer xTarget, | 
|---|
|  |  |  | @RequestParam Integer yStart, | 
|---|
|  |  |  | @RequestParam Integer yTarget) { | 
|---|
|  |  |  | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); | 
|---|
|  |  |  | if (shuttleThread == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); | 
|---|
|  |  |  | if (shuttleProtocol == null) { | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!shuttleProtocol.isIdle()) { | 
|---|
|  |  |  | return R.error("小车忙碌中"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shuttleProtocol.setMoveLoc(true);//开启跑库 | 
|---|
|  |  |  | shuttleProtocol.setMoveType(moveType); | 
|---|
|  |  |  | shuttleProtocol.setXStart(xStart); | 
|---|
|  |  |  | shuttleProtocol.setXTarget(xTarget); | 
|---|
|  |  |  | shuttleProtocol.setXCurrent(xStart); | 
|---|
|  |  |  | shuttleProtocol.setYStart(yStart); | 
|---|
|  |  |  | shuttleProtocol.setYTarget(yTarget); | 
|---|
|  |  |  | shuttleProtocol.setYCurrent(yStart); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|