| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.domain.NotifyDto; |
| | | import com.zy.asrs.domain.enums.NotifyMsgType; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.domain.param.*; |
| | | import com.zy.asrs.utils.NotifyUtils; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.DeviceConfigService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | 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 com.zy.core.enums.WrkIoType; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.DualCrnProtocol; |
| | | import com.zy.core.model.protocol.RgvProtocol; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.CrnThread; |
| | | import com.zy.core.thread.DualCrnThread; |
| | | import com.zy.core.thread.RgvThread; |
| | | import com.zy.core.thread.StationThread; |
| | | 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.beans.factory.annotation.Value; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/openapi") |
| | | public class OpenController { |
| | | |
| | | @Value("${mainProcessPlugin}") |
| | | private String mainProcessPlugin; |
| | | @Value("${app.version:1.0.0}") |
| | | private String appVersion; |
| | | @Value("${app.version-type:stable}") |
| | | private String appVersionType; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private ShuttleDispatchUtils shuttleDispatchUtils; |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private NotifyUtils notifyUtils; |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private DeviceConfigService deviceConfigService; |
| | | |
| | | @PostMapping("/createMoveTask") |
| | | public R createMoveTask(@RequestBody CreateMoveTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean dispatchShuttle = shuttleDispatchUtils.dispatchShuttle(null, param.getLocNo(), param.getShuttleNo()); |
| | | if (dispatchShuttle) { |
| | | return R.ok(); |
| | | } |
| | | return R.error("生成失败"); |
| | | } |
| | | |
| | | //移库任务 |
| | | // 移库任务 |
| | | @PostMapping("/createLocMoveTask") |
| | | @OpenApiLog(memo = "移库任务") |
| | | public R createLocMoveTask(@RequestBody CreateLocMoveTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | |
| | | return R.error("生成移库任务失败"); |
| | | } |
| | | |
| | | //入库任务 |
| | | // 入库任务 |
| | | @PostMapping("/createInTask") |
| | | @OpenApiLog(memo = "入库任务") |
| | | public R createInTask(@RequestBody CreateInTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | boolean result = commonService.createInTask(param); |
| | | if (result) { |
| | | WrkMast wrkMast = commonService.createInTask(param); |
| | | if (wrkMast != null) { |
| | | return R.ok(); |
| | | } |
| | | return R.error("生成入库任务失败"); |
| | | } |
| | | |
| | | //出库任务 |
| | | // 出库任务 |
| | | @PostMapping("/createOutTask") |
| | | @OpenApiLog(memo = "出库任务") |
| | | public R createOutTask(@RequestBody CreateOutTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | |
| | | return R.error("生成出库任务失败"); |
| | | } |
| | | |
| | | // 批量出库任务 |
| | | @PostMapping("/createOutTaskBatch") |
| | | @OpenApiLog(memo = "批量出库任务") |
| | | @Transactional |
| | | public R createOutTaskBatch(@RequestBody CreateOutTaskBatchParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | | } |
| | | |
| | | List<CreateOutTaskParam> taskList = param.getTaskList(); |
| | | if (taskList == null || taskList.size() == 0) { |
| | | return R.error("任务列表不能为空"); |
| | | } |
| | | |
| | | for (CreateOutTaskParam createOutTaskParam : taskList) { |
| | | if (createOutTaskParam == null) { |
| | | throw new CoolException("任务参数不能为空"); |
| | | } |
| | | commonService.createOutTask(createOutTaskParam); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/completeTask") |
| | | @OpenApiLog(memo = "任务完成") |
| | | public R completeTask(@RequestBody CompleteTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | |
| | | } |
| | | |
| | | @PostMapping("/cancelTask") |
| | | @OpenApiLog(memo = "任务取消") |
| | | public R cancelTask(@RequestBody CancelTaskParam param) { |
| | | if (param == null) { |
| | | return R.error("参数不能为空"); |
| | |
| | | return R.error("任务取消失败"); |
| | | } |
| | | |
| | | @PostMapping("/deviceStatus") |
| | | @RequestMapping("/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) { |
| | | // 获取堆垛机数据 |
| | | ArrayList<CrnProtocol> crnProtocols = new ArrayList<>(); |
| | | List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Crn))); |
| | | for (DeviceConfig device : crnList) { |
| | | CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, device.getDeviceNo()); |
| | | if (crnThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | CrnProtocol crnProtocol = crnThread.getStatus(); |
| | | if (crnProtocol == null) { |
| | | continue; |
| | | } |
| | | shuttleProtocols.add(shuttleProtocol); |
| | | crnProtocols.add(crnProtocol); |
| | | } |
| | | |
| | | //获取货叉提升机数据 |
| | | ArrayList<ForkLiftProtocol> forkLiftProtocols = new ArrayList<>(); |
| | | for (ForkLiftSlave slave : slaveProperties.getForkLift()) { |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, slave.getId()); |
| | | if (forkLiftThread == null) { |
| | | // 获取RGV数据 |
| | | ArrayList<RgvProtocol> rgvProtocols = new ArrayList<>(); |
| | | List<DeviceConfig> rgvList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Rgv))); |
| | | for (DeviceConfig device : rgvList) { |
| | | RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, device.getDeviceNo()); |
| | | if (rgvThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | if (forkLiftProtocol == null) { |
| | | RgvProtocol rgvProtocol = rgvThread.getStatus(); |
| | | if (rgvProtocol == null) { |
| | | continue; |
| | | } |
| | | forkLiftProtocols.add(forkLiftProtocol); |
| | | rgvProtocols.add(rgvProtocol); |
| | | } |
| | | |
| | | map.put("shuttle", shuttleProtocols); |
| | | map.put("forkLift", forkLiftProtocols); |
| | | // 获取双工位堆垛机数据 |
| | | ArrayList<DualCrnProtocol> dualCrnProtocols = new ArrayList<>(); |
| | | List<DeviceConfig> dualCrnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.DualCrn))); |
| | | for (DeviceConfig device : dualCrnList) { |
| | | DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, device.getDeviceNo()); |
| | | if (dualCrnThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | DualCrnProtocol dualCrnProtocol = dualCrnThread.getStatus(); |
| | | if (dualCrnProtocol == null) { |
| | | continue; |
| | | } |
| | | dualCrnProtocols.add(dualCrnProtocol); |
| | | } |
| | | |
| | | // 获取输送站点数据 |
| | | ArrayList<StationProtocol> stationProtocols = new ArrayList<>(); |
| | | List<DeviceConfig> stationList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Devp))); |
| | | for (DeviceConfig device : stationList) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, device.getDeviceNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | List<StationProtocol> stationProtocolList = stationThread.getStatus(); |
| | | if (stationProtocolList == null) { |
| | | continue; |
| | | } |
| | | stationProtocols.addAll(stationProtocolList); |
| | | } |
| | | |
| | | map.put("crnList", crnProtocols); |
| | | map.put("rgvList", rgvList); |
| | | map.put("dualCrnList", dualCrnProtocols); |
| | | map.put("stationList", stationProtocols); |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @GetMapping("/test") |
| | | public R test() { |
| | | notifyUtils.notify("task", 1, "9999", NotifyMsgType.SHUTTLE_MOVING, "data"); |
| | | notifyUtils.notify(String.valueOf(SlaveType.Shuttle), 2, "9999", NotifyMsgType.SHUTTLE_MOVE_COMPLETE); |
| | | @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()); |
| | | map.put("barcode", locMast.getBarcode()); |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @PostMapping("/getAllLocInformation") |
| | | @OpenApiLog(memo = "获取全部库位信息") |
| | | public R getAllLocInformation(@RequestBody GetAllLocInformationParam param) { |
| | | List<HashMap<String, Object>> list = new ArrayList<>(); |
| | | EntityWrapper<LocMast> wrapper = new EntityWrapper<>(); |
| | | |
| | | if (!Cools.isEmpty(param.getRow())) { |
| | | wrapper.eq("row1", param.getRow()); |
| | | } |
| | | |
| | | if (!Cools.isEmpty(param.getLev())) { |
| | | wrapper.eq("lev1", param.getLev()); |
| | | } |
| | | |
| | | List<LocMast> locMasts = locMastService.selectList(wrapper); |
| | | if (locMasts.isEmpty()) { |
| | | return R.ok().add(list); |
| | | } |
| | | |
| | | for (LocMast locMast : locMasts) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("locNo", locMast.getLocNo()); |
| | | map.put("locSts", locMast.getLocSts()); |
| | | map.put("barcode", locMast.getBarcode()); |
| | | map.put("row", locMast.getRow1()); |
| | | map.put("bay", locMast.getBay1()); |
| | | map.put("lev", locMast.getLev1()); |
| | | list.add(map); |
| | | } |
| | | |
| | | return R.ok().add(list); |
| | | } |
| | | |
| | | @PostMapping("/queryTask") |
| | | @OpenApiLog(memo = "查询任务") |
| | | public R queryTask(@RequestBody QueryTaskParam param) { |
| | | EntityWrapper<WrkMast> wrapper = new EntityWrapper<>(); |
| | | if (param.getTaskNo() != null) { |
| | | wrapper.eq("wms_wrk_no", param.getTaskNo()); |
| | | } |
| | | |
| | | if (param.getTaskType() != null) { |
| | | WrkIoType ioType = WrkIoType.get(param.getTaskType()); |
| | | if (ioType == null) { |
| | | return R.error("任务类型不存在"); |
| | | } |
| | | wrapper.eq("io_type", ioType.id); |
| | | } |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(wrapper); |
| | | return R.ok().add(wrkMasts); |
| | | } |
| | | |
| | | @GetMapping("/systemStatus") |
| | | public R systemStatus() { |
| | | return R.ok(); |
| | | } |
| | | |
| | | @GetMapping("/getSystemVersion") |
| | | public R getSystemVersion() { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("version", appVersion); |
| | | map.put("versionType", appVersionType); |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @GetMapping("/getFakeSystemRunStatus") |
| | | public R getFakeSystemRunStatus() { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | if (mainProcessPlugin.contains("Fake")) { |
| | | map.put("running", false); |
| | | map.put("isFake", true); |
| | | Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake")); |
| | | if (config != null) { |
| | | if (config.getValue().equals("Y")) { |
| | | map.put("running", true); |
| | | } |
| | | } |
| | | } else { |
| | | map.put("isFake", false); |
| | | } |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @PostMapping("/startFakeSystem") |
| | | @OpenApiLog(memo = "启动仿真模拟") |
| | | public R startFakeSystem() { |
| | | Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake")); |
| | | if (config != null) { |
| | | config.setValue("Y"); |
| | | configService.updateById(config); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/stopFakeSystem") |
| | | @OpenApiLog(memo = "停止仿真模拟") |
| | | public R stopFakeSystem() { |
| | | Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake")); |
| | | if (config != null) { |
| | | config.setValue("N"); |
| | | configService.updateById(config); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |