| | |
| | | |
| | | private Long id; |
| | | |
| | | //设备类型 |
| | | private String deviceType; |
| | | //通知类型 |
| | | private String notifyType; |
| | | |
| | | //设备号 |
| | | private Integer device; |
| | |
| | | //消息类型 |
| | | private String msgType; |
| | | |
| | | //消息内容 |
| | | private String content; |
| | | //消息描述 |
| | | private String msgDesc; |
| | | |
| | | //消息数据 |
| | | private String data; |
| | | |
| | | //失败重试次数 |
| | | private Integer failTimes = 3; |
| | |
| | | SHUTTLE_POWER_COMPLETE("shuttle_power_complete", "小车充电完成"), |
| | | SHUTTLE_ERROR("shuttle_error", "小车异常"), |
| | | FORK_LIFT_ERROR("fork_lift_error", "货叉提升机异常"), |
| | | |
| | | //任务 |
| | | TASK_COMPLETE("task_complete", "任务完成"), |
| | | TASK_CHARGE_COMPLETE("task_charge_complete", "充电任务完成"), |
| | | TASK_CANCEL("task_cancel", "任务取消"), |
| | | ; |
| | | |
| | | public String flag; |
| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.zy.asrs.domain.enums.NotifyMsgType; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.WrkMastLogService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.asrs.utils.NotifyUtils; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | private WrkMastLogService wrkMastLogService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private NotifyUtils notifyUtils; |
| | | |
| | | @Scheduled(cron = "0/1 * * * * ? ") |
| | | @Transactional |
| | |
| | | if (!wrkMastService.deleteById(wrkMast)) { |
| | | log.info("删除工作主档[workNo={}]失败", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | //上报 |
| | | notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.TASK_COMPLETE, JSON.toJSONString(wrkMast)); |
| | | } |
| | | } |
| | | |
| | |
| | | if (!wrkMastService.deleteById(wrkMast)) { |
| | | log.info("删除工作主档[workNo={}]失败", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | //上报 |
| | | notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.TASK_COMPLETE, JSON.toJSONString(wrkMast)); |
| | | } |
| | | } |
| | | |
| | |
| | | if (!wrkMastService.deleteById(wrkMast)) { |
| | | log.info("删除工作主档[workNo={}]失败", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | //上报 |
| | | notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.TASK_COMPLETE, JSON.toJSONString(wrkMast)); |
| | | } |
| | | } |
| | | |
| | |
| | | if (!wrkMastService.deleteById(wrkMast)) { |
| | | log.info("删除工作主档[workNo={}]失败", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | //上报 |
| | | notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.TASK_CHARGE_COMPLETE, JSON.toJSONString(wrkMast)); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0/1 * * * * ? ") |
| | | @Transactional |
| | | public void executeCancelTask(){ |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("mk", "taskCancel")); |
| | | if (wrkMasts.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (WrkMast wrkMast : wrkMasts) { |
| | | // 保存工作主档历史档 |
| | | if (!wrkMastLogService.save(wrkMast.getWrkNo())) { |
| | | log.info("保存工作历史档[workNo={}]失败", wrkMast.getWrkNo()); |
| | | } |
| | | // 删除工作主档 |
| | | if (!wrkMastService.deleteById(wrkMast)) { |
| | | log.info("删除工作主档[workNo={}]失败", wrkMast.getWrkNo()); |
| | | } |
| | | |
| | | //上报 |
| | | notifyUtils.notify("task", 1, String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.TASK_CANCEL, JSON.toJSONString(wrkMast)); |
| | | } |
| | | } |
| | | |
| | |
| | | @Autowired |
| | | private ConfigService configService; |
| | | |
| | | public synchronized boolean notify(String deviceType, Integer device, String taskNo, NotifyMsgType msgType) { |
| | | SlaveType type = SlaveType.findInstance(deviceType); |
| | | if (type == null) { |
| | | return false; |
| | | public synchronized boolean notify(String notifyType, Integer device, String taskNo, NotifyMsgType msgType) { |
| | | return append(notifyType, device, taskNo, msgType, null); |
| | | } |
| | | return append(type, device, taskNo, msgType); |
| | | |
| | | public synchronized boolean notify(String notifyType, Integer device, String taskNo, NotifyMsgType msgType, String data) { |
| | | return append(notifyType, device, taskNo, msgType, data); |
| | | } |
| | | |
| | | public synchronized List<String> takeKeys(String deviceType, Integer device) { |
| | |
| | | return key; |
| | | } |
| | | |
| | | private boolean append(SlaveType deviceType, Integer device, String taskNo, NotifyMsgType msgType) { |
| | | private boolean append(String notifyType, Integer device, String taskNo, NotifyMsgType msgType, String data) { |
| | | String key = null; |
| | | switch (deviceType) { |
| | | case Shuttle: |
| | | if (notifyType.equals(String.valueOf(SlaveType.Shuttle))) { |
| | | key = RedisKeyType.QUEUE_SHUTTLE.key + device; |
| | | break; |
| | | case ForkLift: |
| | | } else if (notifyType.equals(String.valueOf(SlaveType.ForkLift))) { |
| | | key = RedisKeyType.QUEUE_FORK_LIFT.key + device; |
| | | break; |
| | | default: |
| | | } else if (notifyType.equals("task")) { |
| | | key = RedisKeyType.QUEUE_FORK_LIFT.key + device; |
| | | } else { |
| | | return false; |
| | | } |
| | | |
| | | NotifyDto dto = new NotifyDto(); |
| | | dto.setId(snowflakeIdWorker.nextId()); |
| | | dto.setDeviceType(String.valueOf(deviceType)); |
| | | dto.setNotifyType(notifyType); |
| | | dto.setDevice(device); |
| | | dto.setMsgType(msgType.flag); |
| | | dto.setContent(msgType.desc); |
| | | dto.setMsgDesc(msgType.desc); |
| | | dto.setData(data); |
| | | dto.setTaskNo(taskNo); |
| | | |
| | | //重试次数 |
| | |
| | | throw new CoolException("任务不存在"); |
| | | } |
| | | |
| | | wrkMastLogService.save(wrkNo); |
| | | wrkMastService.deleteById(wrkNo); |
| | | wrkMast.setMk("taskCancel"); |
| | | wrkMast.setModiTime(new Date()); |
| | | wrkMastService.updateById(wrkMast); |
| | | return true; |
| | | } |
| | | |
| | |
| | | BASIC_MAP("basicMap_"), |
| | | QUEUE_SHUTTLE("queue_shuttle_"), |
| | | QUEUE_FORK_LIFT("queue_fork_lift_"), |
| | | QUEUE_TASK("queue_task_"), |
| | | ; |
| | | |
| | | public String key; |