package com.zy.core.controller; import com.zy.common.R; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.SlaveType; import com.zy.core.model.param.AddFakeDeviceParam; import com.zy.core.model.param.DeleteDeviceParam; import com.zy.core.properties.DeviceConfig; import com.zy.core.thread.FakeThread; import com.zy.core.thread.ForkLiftThread; import com.zy.core.thread.ShuttleThread; import com.zy.core.utils.DeviceMsgUtils; import com.zy.core.utils.FakeDeviceUtils; 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.HashMap; import java.util.List; @RestController @RequestMapping("/open") public class OpenController { @Value("${deviceMsgConfig.gatewayId}") private Integer gatewayId; @Value("${deviceMsgConfig.gatewayPort}") private Integer gatewayPort; @Autowired private DeviceMsgUtils deviceMsgUtils; @Autowired private FakeDeviceUtils fakeDeviceUtils; @GetMapping("/getSystemInfo") public R getSystemInfo() { HashMap map = new HashMap<>(); map.put("gatewayId", gatewayId); map.put("gatewayPort", gatewayPort); return R.ok().add(map); } @GetMapping("/getFakeThreadList") public R getFakeThreadList() { FakeThread fakeThread1 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1); FakeThread fakeThread2 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 2); HashMap map = new HashMap<>(); map.put("fakeNyShuttleStatusMap", fakeThread1.getFakeStatusMap()); map.put("fakeZyForkLiftStatusMap", fakeThread2.getFakeStatusMap()); return R.ok().add(map); } @GetMapping("/getDeviceList") public R getDeviceList() { List deviceList = new ArrayList<>(); List configList = new ArrayList<>(); List deviceConfigs = deviceMsgUtils.getDeviceConfig(); configList.addAll(deviceConfigs); List fakeDeviceConfig = fakeDeviceUtils.getFakeDeviceConfig(); configList.addAll(fakeDeviceConfig); for (DeviceConfig config : configList) { SlaveType slaveType = SlaveType.findInstance(config.getDeviceType()); if(slaveType == null){ continue; } if(slaveType.equals(SlaveType.Shuttle)) { ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(slaveType, config.getDeviceNo()); if(shuttleThread == null){ continue; } deviceList.add(shuttleThread.getDeviceConfig()); } else if (slaveType.equals(SlaveType.ForkLift)) { ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(slaveType, config.getDeviceNo()); if(forkLiftThread == null){ continue; } deviceList.add(forkLiftThread.getDeviceConfig()); } } return R.ok().add(deviceList); } @PostMapping("/addFakeDevice") public R addFakeDevice(@RequestBody AddFakeDeviceParam param) { DeviceConfig deviceConfig = new DeviceConfig(); deviceConfig.setDeviceNo(param.getDeviceNo()); deviceConfig.setIp(param.getIp()); deviceConfig.setPort(param.getPort()); deviceConfig.setDeviceType(param.getDeviceType()); deviceConfig.setThreadImpl(param.getThreadImpl()); deviceConfig.setFake(true); fakeDeviceUtils.addFakeDevice(deviceConfig); return R.ok(); } @PostMapping("/deleteFakeDevice") public R deleteFakeDevice(@RequestBody DeleteDeviceParam param) { fakeDeviceUtils.deleteFakeDevice(param.getDeviceNo(), param.getDeviceType()); return R.ok(); } }