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.param.*;
|
import com.zy.asrs.entity.ApiLog;
|
import com.zy.asrs.entity.DeviceConfig;
|
import com.zy.asrs.entity.LocMast;
|
import com.zy.asrs.entity.WrkMast;
|
import com.zy.asrs.service.ApiLogService;
|
import com.zy.asrs.service.DeviceConfigService;
|
import com.zy.asrs.service.LocMastService;
|
import com.zy.asrs.service.WrkMastService;
|
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.enums.SlaveType;
|
import com.zy.core.enums.WrkIoType;
|
import com.zy.core.model.protocol.CrnProtocol;
|
import com.zy.core.model.protocol.RgvProtocol;
|
import com.zy.core.thread.CrnThread;
|
import com.zy.core.thread.RgvThread;
|
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.web.bind.annotation.*;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
|
@Slf4j
|
@RestController
|
@RequestMapping("/openapi")
|
public class OpenController {
|
|
@Value("${mainProcessPlugin}")
|
private String mainProcessPlugin;
|
@Autowired
|
private CommonService commonService;
|
@Autowired
|
private NotifyUtils notifyUtils;
|
@Autowired
|
private ApiLogService apiLogService;
|
@Autowired
|
private LocMastService locMastService;
|
@Autowired
|
private WrkMastService wrkMastService;
|
@Autowired
|
private ConfigService configService;
|
@Autowired
|
private DeviceConfigService deviceConfigService;
|
|
//移库任务
|
@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();
|
}
|
return R.error("生成移库任务失败");
|
}
|
|
//入库任务
|
@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();
|
}
|
return R.error("生成入库任务失败");
|
}
|
|
//出库任务
|
@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();
|
}
|
return R.error("生成出库任务失败");
|
}
|
|
@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();
|
}
|
return R.error("任务完成失败");
|
}
|
|
@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("任务取消失败");
|
}
|
|
@RequestMapping("/deviceStatus")
|
// @OpenApiLog(memo = "获取设备状态")
|
public R getDeviceStatus() {
|
HashMap<String, Object> map = new HashMap<>();
|
//获取堆垛机数据
|
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;
|
}
|
|
CrnProtocol crnProtocol = crnThread.getStatus();
|
if (crnProtocol == null) {
|
continue;
|
}
|
crnProtocols.add(crnProtocol);
|
}
|
|
//获取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;
|
}
|
|
RgvProtocol rgvProtocol = rgvThread.getStatus();
|
if (rgvProtocol == null) {
|
continue;
|
}
|
rgvProtocols.add(rgvProtocol);
|
}
|
|
map.put("crn", crnList);
|
map.put("rgv", rgvList);
|
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());
|
|
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);
|
}
|
|
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);
|
apiLogService.insert(new ApiLog(
|
null
|
, "查询任务"
|
, "/queryTask"
|
, null
|
, null
|
, null
|
, JSON.toJSONString(param)
|
, JSON.toJSONString(wrkMasts)
|
, null
|
, null
|
, 1
|
, new Date()
|
, null
|
, null
|
));
|
|
return R.ok().add(wrkMasts);
|
}
|
|
@GetMapping("/systemStatus")
|
public R systemStatus() {
|
return R.ok();
|
}
|
|
@GetMapping("/getFakeSystemRunStatus")
|
public R getFakeSystemRunStatus() {
|
HashMap<String, Object> map = new HashMap<>();
|
if(mainProcessPlugin.equals("FakeProcess")) {
|
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();
|
}
|
|
}
|