package com.zy.asrs.controller;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.zy.asrs.domain.param.StationCommandBarcodeParam;
|
import com.zy.asrs.entity.BasDevp;
|
import com.zy.asrs.entity.DeviceConfig;
|
import com.zy.asrs.service.BasDevpService;
|
import com.zy.asrs.service.DeviceConfigService;
|
import com.zy.common.utils.RedisUtil;
|
import com.zy.core.enums.RedisKeyType;
|
import com.zy.core.enums.StationCommandType;
|
import com.zy.core.model.StationObjModel;
|
import com.zy.system.entity.Config;
|
import com.zy.system.service.ConfigService;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.core.common.Cools;
|
import com.core.common.R;
|
import com.zy.asrs.domain.param.StationCommandMoveParam;
|
import com.zy.core.cache.MessageQueue;
|
import com.zy.core.cache.SlaveConnection;
|
import com.zy.core.enums.SlaveType;
|
import com.zy.core.model.Task;
|
import com.zy.core.model.command.StationCommand;
|
import com.zy.core.thread.StationThread;
|
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("/station")
|
public class StationController {
|
|
@Value("${mainProcessPlugin}")
|
private String mainProcessPlugin;
|
@Autowired
|
private BasDevpService basDevpService;
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private ConfigService configService;
|
@Autowired
|
private DeviceConfigService deviceConfigService;
|
|
@PostMapping("/command/move")
|
public R commandMove(@RequestBody StationCommandMoveParam param) {
|
if (Cools.isEmpty(param)) {
|
return R.error("缺少参数");
|
}
|
|
Integer stationId = param.getStationId();
|
Integer taskNo = param.getTaskNo();
|
Integer targetStationId = param.getTargetStationId();
|
|
StationObjModel finalStation = findStation(stationId);
|
|
if(finalStation == null){
|
return R.error("站点不存在");
|
}
|
|
Integer devpNo = finalStation.getDeviceNo();
|
|
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, devpNo);
|
if (stationThread == null) {
|
return R.error("线程不存在");
|
}
|
|
StationCommand command = stationThread.getCommand(StationCommandType.MOVE, taskNo, stationId, targetStationId, 0);
|
MessageQueue.offer(SlaveType.Devp, devpNo, new Task(2, command));
|
return R.ok();
|
}
|
|
@PostMapping("/command/barcode")
|
public R commandBarcode(@RequestBody StationCommandBarcodeParam param) {
|
if (Cools.isEmpty(param) || Cools.isEmpty(param.getStationId())) {
|
return R.error("缺少参数");
|
}
|
|
if (!mainProcessPlugin.contains("Fake")) {
|
return R.error("当前系统未启用仿真插件");
|
}
|
|
Config enableFakeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
|
if (enableFakeConfig == null || !"Y".equals(enableFakeConfig.getValue())) {
|
return R.error("当前非仿真运行模式,禁止修改条码");
|
}
|
|
Integer stationId = param.getStationId();
|
StationObjModel finalStation = findStation(stationId);
|
if (finalStation == null) {
|
return R.error("站点不存在");
|
}
|
|
Integer devpNo = finalStation.getDeviceNo();
|
DeviceConfig deviceConfig = deviceConfigService.selectOne(new EntityWrapper<DeviceConfig>()
|
.eq("device_no", devpNo)
|
.eq("device_type", String.valueOf(SlaveType.Devp)));
|
if (deviceConfig == null || deviceConfig.getFake() == null || deviceConfig.getFake() != 1) {
|
return R.error("当前站点设备未启用仿真,禁止修改条码");
|
}
|
|
StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, devpNo);
|
if (stationThread == null) {
|
return R.error("线程不存在");
|
}
|
|
String barcode = param.getBarcode();
|
if (barcode == null) {
|
barcode = "";
|
}
|
|
StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9997, stationId, stationId, 0);
|
command.setBarcode(barcode.trim());
|
MessageQueue.offer(SlaveType.Devp, devpNo, new Task(2, command));
|
return R.ok();
|
}
|
|
@PostMapping("/command/reset")
|
public R commandReset(@RequestBody StationCommandMoveParam param) {
|
if (Cools.isEmpty(param)) {
|
return R.error("缺少参数");
|
}
|
|
Integer taskNo = param.getTaskNo();
|
redisUtil.set(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo, "cancel", 3);
|
return R.ok();
|
}
|
|
private StationObjModel findStation(Integer stationId) {
|
if (Cools.isEmpty(stationId)) {
|
return null;
|
}
|
|
List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>());
|
for (BasDevp basDevp : basDevps) {
|
List<StationObjModel> list = basDevp.getStationList$();
|
for (StationObjModel entity : list) {
|
if (entity.getStationId().equals(stationId)) {
|
return entity;
|
}
|
}
|
}
|
return null;
|
}
|
|
}
|