| | |
| | | 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; |
| | |
| | | @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) { |
| | |
| | | Integer taskNo = param.getTaskNo(); |
| | | Integer targetStationId = param.getTargetStationId(); |
| | | |
| | | StationObjModel finalStation = 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)){ |
| | | finalStation = entity; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(finalStation != null){ |
| | | break; |
| | | } |
| | | } |
| | | StationObjModel finalStation = findStation(stationId); |
| | | |
| | | if(finalStation == null){ |
| | | return R.error("站点不存在"); |
| | |
| | | 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.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; |
| | | } |
| | | |
| | | } |