| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | |
| | | import com.zy.asrs.domain.vo.*; |
| | | import com.zy.asrs.entity.BasLift; |
| | | import com.zy.asrs.service.BasLiftService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.LiftSlave; |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.LiftAssignCommand; |
| | | import com.zy.core.model.command.*; |
| | | import com.zy.core.model.protocol.LiftProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.LiftThread; |
| | |
| | | @Autowired |
| | | private BasLiftService basLiftService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | @PostMapping("/table/lift/state") |
| | | @ManagerAuth(memo = "提升机信息表") |
| | |
| | | |
| | | LiftAssignCommand assignCommand = new LiftAssignCommand(); |
| | | assignCommand.setLiftNo(liftSlave.getId().shortValue()); // 提升机编号 |
| | | assignCommand.setTaskNo((short) 9999); |
| | | assignCommand.setTaskNo((short) commonService.getWorkNo(3));//获取任务号 |
| | | assignCommand.setTaskMode(param.getLiftTaskMode().shortValue()); |
| | | assignCommand.setAuto(false);//手动模式 |
| | | assignCommand.setLev(param.getLev());//移动楼层 |
| | |
| | | return R.error(); |
| | | } |
| | | |
| | | @PostMapping("/detl/update") |
| | | @ManagerAuth(memo = "修改数据") |
| | | public R liftUpdate(@RequestParam Integer liftNo, |
| | | @RequestParam Short workNo, |
| | | @RequestParam String pakMk){ |
| | | for (LiftSlave liftSlave : slaveProperties.getLift()) { |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId()); |
| | | if (liftThread == null) { |
| | | return R.error("plc已掉线"); |
| | | } |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | if (liftProtocol == null) { |
| | | return R.error("plc已掉线"); |
| | | } |
| | | if (workNo != null) { |
| | | liftProtocol.setTaskNo(workNo); |
| | | } |
| | | if (pakMk != null) { |
| | | liftProtocol.setPakMk(pakMk.equals("Y")); |
| | | } |
| | | } |
| | | return R.error("plc已掉线"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/command/query") |
| | | public R liftCommandQuery(@RequestParam("wrkNo") Integer wrkNo) { |
| | | Object o = redisUtil.get("lift_wrk_no_" + wrkNo); |
| | | if (o == null) { |
| | | return R.error(); |
| | | } |
| | | LiftRedisCommand redisCommand = JSON.parseObject(o.toString(), LiftRedisCommand.class); |
| | | return R.ok().add(redisCommand); |
| | | } |
| | | |
| | | //回退命令 |
| | | @RequestMapping(value = "/command/rollback") |
| | | public R liftCommandRollback(@RequestParam("wrkNo") Integer wrkNo |
| | | , @RequestParam("commandStep") Integer commandStep) { |
| | | Object o = redisUtil.get("lift_wrk_no_" + wrkNo); |
| | | if (o == null) { |
| | | return R.error(); |
| | | } |
| | | LiftRedisCommand redisCommand = JSON.parseObject(o.toString(), LiftRedisCommand.class); |
| | | redisCommand.setCommandStep(commandStep); |
| | | redisUtil.set("lift_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | //命令完成状态切换 |
| | | @RequestMapping(value = "/command/completeSwitch") |
| | | public R liftCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo |
| | | , @RequestParam("commandStep") Integer commandStep |
| | | , @RequestParam("complete") Integer complete) { |
| | | Object o = redisUtil.get("lift_wrk_no_" + wrkNo); |
| | | if (o == null) { |
| | | return R.error(); |
| | | } |
| | | LiftRedisCommand redisCommand = JSON.parseObject(o.toString(), LiftRedisCommand.class); |
| | | LiftAssignCommand assignCommand = redisCommand.getAssignCommand(); |
| | | List<LiftCommand> commands = assignCommand.getCommands(); |
| | | LiftCommand command = commands.get(commandStep); |
| | | command.setComplete(complete != 0); |
| | | redisUtil.set("lift_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | //重启任务(命令) |
| | | @RequestMapping(value = "/command/restart") |
| | | public R liftCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo) { |
| | | Object o = redisUtil.get("lift_wrk_no_" + wrkNo); |
| | | if (o == null) { |
| | | return R.error(); |
| | | } |
| | | LiftRedisCommand redisCommand = JSON.parseObject(o.toString(), LiftRedisCommand.class); |
| | | Short liftNo = redisCommand.getLiftNo(); |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo.intValue()); |
| | | if (liftThread == null) { |
| | | return R.error(); |
| | | } |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | if (liftProtocol == null) { |
| | | return R.error(); |
| | | } |
| | | if (!liftProtocol.isIdle()) { |
| | | return R.error(); |
| | | } |
| | | //提升机处于空闲状态,进行任务的恢复 |
| | | liftProtocol.setTaskNo(redisCommand.getWrkNo());//将提升机线程分配任务号 |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//工作状态 |
| | | return R.ok(); |
| | | } |
| | | |
| | | //删除任务(命令) |
| | | @RequestMapping(value = "/command/del") |
| | | public R liftCommandDel(@RequestParam("wrkNo") Integer wrkNo) { |
| | | Object o = redisUtil.get("lift_wrk_no_" + wrkNo); |
| | | if (o == null) { |
| | | return R.error(); |
| | | } |
| | | redisUtil.del("lift_wrk_no_" + wrkNo); |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |