| | |
| | | package com.zy.core.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.zy.common.R; |
| | | import com.zy.common.exception.CoolException; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.ThreadHandler; |
| | |
| | | import com.zy.core.thread.impl.LfdZyForkLiftMasterThread; |
| | | import com.zy.core.thread.impl.NyShuttleThread; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | @Component |
| | | public class FakeDeviceUtils { |
| | | |
| | | @Value("${deviceMsgConfig.gatewayId}") |
| | | private Integer gatewayId; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private DeviceMsgUtils deviceMsgUtils; |
| | | |
| | | public String getFakeDeviceConfig() { |
| | | public synchronized boolean applyShuttleConnect(Integer deviceNo) { |
| | | Object object = redisUtil.get(RedisKeyType.FAKE_SHUTTLE_APPLY_CONNECT.key); |
| | | if(object != null) { |
| | | return false; |
| | | } |
| | | |
| | | return redisUtil.set(RedisKeyType.FAKE_SHUTTLE_APPLY_CONNECT.key, deviceNo, 10); |
| | | } |
| | | |
| | | public List<DeviceConfig> getFakeDeviceConfig() { |
| | | List<DeviceConfig> list = new ArrayList<>(); |
| | | Object obj = redisUtil.get(RedisKeyType.FAKE_DEVICE_CONFIG.key); |
| | | if(null == obj){ |
| | | return null; |
| | | return list; |
| | | } |
| | | return obj.toString(); |
| | | |
| | | List<DeviceConfig> deviceConfigs = JSON.parseArray(obj.toString(), DeviceConfig.class); |
| | | for (DeviceConfig deviceConfig : deviceConfigs) { |
| | | if(deviceConfig.getGatewayId().equals(gatewayId)){ |
| | | list.add(deviceConfig); |
| | | } |
| | | } |
| | | return list; |
| | | |
| | | } |
| | | |
| | | public void addFakeDevice(DeviceConfig deviceConfig) { |
| | |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(slaveType, deviceNo); |
| | | if(shuttleThread == null){ |
| | | throw new CoolException("设备线程不存在"); |
| | | } |
| | | |
| | | if (!shuttleThread.isFake()) { |
| | | throw new CoolException("不允许删除真实设备线程"); |
| | | } |
| | | |
| | | shuttleThread.stopThread(); |