| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.domain.NotifyDto; |
| | | import com.zy.asrs.domain.ShuttleGatherResult; |
| | | import com.zy.asrs.domain.enums.NotifyMsgType; |
| | | import com.zy.asrs.domain.param.*; |
| | | import com.zy.asrs.entity.ApiLog; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.utils.NotifyUtils; |
| | | import com.zy.common.annotations.OpenApiLog; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.dispatcher.ShuttleDispatchUtils; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.ForkLiftSlave; |
| | | import com.zy.core.model.ShuttleSlave; |
| | | import com.zy.core.model.protocol.ForkLiftProtocol; |
| | | import com.zy.core.model.protocol.ShuttleProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.ForkLiftThread; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | |
| | | private ShuttleDispatchUtils shuttleDispatchUtils; |
| | | @Autowired |
| | | private NotifyUtils notifyUtils; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | |
| | | @PostMapping("/createMoveTask") |
| | | @OpenApiLog(memo = "小车移动任务") |
| | | public R createMoveTask(@RequestBody CreateMoveTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean dispatchShuttle = shuttleDispatchUtils.dispatchShuttle(null, param.getLocNo(), param.getShuttleNo()); |
| | | boolean dispatchShuttle = shuttleDispatchUtils.dispatchShuttle(null, param.getSourceLocNo(), param.getLocNo(), param.getShuttleNo(), param.getFlag()); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "小车移动任务" |
| | | , "/createMoveTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , dispatchShuttle ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (dispatchShuttle) { |
| | | return R.ok(); |
| | | } |
| | |
| | | |
| | | //移库任务 |
| | | @PostMapping("/createLocMoveTask") |
| | | @OpenApiLog(memo = "移库任务") |
| | | public R createLocMoveTask(@RequestBody CreateLocMoveTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean result = commonService.createLocMoveTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "移库任务" |
| | | , "/createLocMoveTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , result ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (result) { |
| | | return R.ok(); |
| | | } |
| | |
| | | |
| | | //入库任务 |
| | | @PostMapping("/createInTask") |
| | | @OpenApiLog(memo = "入库任务") |
| | | public R createInTask(@RequestBody CreateInTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean result = commonService.createInTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "入库任务" |
| | | , "/createInTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , result ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (result) { |
| | | return R.ok(); |
| | | } |
| | |
| | | |
| | | //出库任务 |
| | | @PostMapping("/createOutTask") |
| | | @OpenApiLog(memo = "出库任务") |
| | | public R createOutTask(@RequestBody CreateOutTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean result = commonService.createOutTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "出库任务" |
| | | , "/createOutTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , result ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (result) { |
| | | return R.ok(); |
| | | } |
| | |
| | | } |
| | | |
| | | @PostMapping("/completeTask") |
| | | @OpenApiLog(memo = "任务完成") |
| | | public R completeTask(@RequestBody CompleteTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean completeTask = commonService.completeTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "任务完成" |
| | | , "/completeTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , completeTask ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (completeTask) { |
| | | return R.ok(); |
| | | } |
| | |
| | | } |
| | | |
| | | @PostMapping("/cancelTask") |
| | | @OpenApiLog(memo = "任务取消") |
| | | public R cancelTask(@RequestBody CancelTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean completeTask = commonService.cancelTask(param); |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "任务取消" |
| | | , "/cancelTask" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , null |
| | | , null |
| | | , completeTask ? 1 : 0 |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | if (completeTask) { |
| | | return R.ok(); |
| | | } |
| | | return R.error("任务取消失败"); |
| | | } |
| | | |
| | | @PostMapping("/deviceStatus") |
| | | @OpenApiLog(memo = "获取设备状态") |
| | | public R getDeviceStatus() { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | //获取小车数据 |
| | | ArrayList<ShuttleProtocol> shuttleProtocols = new ArrayList<>(); |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | } |
| | | shuttleProtocols.add(shuttleProtocol); |
| | | } |
| | | |
| | | //获取货叉提升机数据 |
| | | ArrayList<ForkLiftProtocol> forkLiftProtocols = new ArrayList<>(); |
| | | for (ForkLiftSlave slave : slaveProperties.getForkLift()) { |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId()); |
| | | if (forkLiftThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | if (forkLiftProtocol == null) { |
| | | continue; |
| | | } |
| | | forkLiftProtocols.add(forkLiftProtocol); |
| | | } |
| | | |
| | | map.put("shuttle", shuttleProtocols); |
| | | map.put("forkLift", forkLiftProtocols); |
| | | |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "获取设备状态" |
| | | , "/deviceStatus" |
| | | , null |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(map) |
| | | , null |
| | | , null |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @PostMapping("/getLocInformation") |
| | | @OpenApiLog(memo = "获取指定库位信息") |
| | | public R getLocInformation(@RequestBody GetLocInformationParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | LocMast locMast = locMastService.queryByLoc(param.getLocNo()); |
| | | if (locMast == null) { |
| | | return R.error("库位信息不存在"); |
| | | } |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("locNo", locMast.getLocNo()); |
| | | map.put("locSts", locMast.getLocSts()); |
| | | |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "获取指定库位信息" |
| | | , "/getLocInformation" |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(param) |
| | | , JSON.toJSONString(map) |
| | | , null |
| | | , null |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @PostMapping("/getAllLocInformation") |
| | | @OpenApiLog(memo = "获取全部库位信息") |
| | | public R getAllLocInformation() { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()); |
| | | if (locMasts.isEmpty()) { |
| | | return R.error("库位信息不存在"); |
| | | } |
| | | |
| | | ArrayList<HashMap<String, Object>> list = new ArrayList<>(); |
| | | for (LocMast locMast : locMasts) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("locNo", locMast.getLocNo()); |
| | | map.put("locSts", locMast.getLocSts()); |
| | | list.add(map); |
| | | } |
| | | |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "获取指定库位信息" |
| | | , "/getLocInformation" |
| | | , null |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(list) |
| | | , null |
| | | , null |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | |
| | | return R.ok().add(list); |
| | | } |
| | | |
| | | @PostMapping("/shuttleGather") |
| | | @OpenApiLog(memo = "小车集合") |
| | | public R shuttleGather(@RequestBody ShuttleGatherParam param) { |
| | | List<ShuttleGatherResult> shuttleGather = shuttleDispatchUtils.shuttleGather(param); |
| | | |
| | | apiLogService.insert(new ApiLog( |
| | | null |
| | | , "获取指定库位信息" |
| | | , "/getLocInformation" |
| | | , null |
| | | , null |
| | | , null |
| | | , null |
| | | , JSON.toJSONString(shuttleGather) |
| | | , null |
| | | , null |
| | | , 1 |
| | | , new Date() |
| | | , null |
| | | , null |
| | | )); |
| | | |
| | | return R.ok().add(shuttleGather); |
| | | } |
| | | |
| | | @GetMapping("/test") |
| | | public R test() { |
| | | notifyUtils.notify(String.valueOf(SlaveType.Shuttle), 1, "9999", NotifyMsgType.SHUTTLE_MOVING); |
| | | notifyUtils.notify(String.valueOf(SlaveType.Shuttle), 2, "9999", NotifyMsgType.SHUTTLE_MOVE_COMPLETE); |
| | | notifyUtils.notify("task", 1, "9999", "W9999", NotifyMsgType.SHUTTLE_MOVING, "data"); |
| | | notifyUtils.notify(String.valueOf(SlaveType.Shuttle), 2, "9999", "W9999", NotifyMsgType.SHUTTLE_MOVE_COMPLETE); |
| | | return R.ok(); |
| | | } |
| | | |