| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.zy.common.Cools; |
| | | import com.zy.common.R; |
| | | import com.zy.common.SpringUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.param.UpdateFakeThreadStatusParam; |
| | | import com.zy.core.properties.DeviceConfig; |
| | |
| | | import java.io.*; |
| | | import java.net.ServerSocket; |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Slf4j |
| | |
| | | } |
| | | List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig(); |
| | | for (DeviceConfig device : deviceConfigs) { |
| | | excuteFakeCommand(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo()); |
| | | excuteFakeCommand(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), device); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | } |
| | | |
| | | private void excuteFakeCommand(String key) { |
| | | private void excuteFakeCommand(String key, DeviceConfig deviceConfig) { |
| | | if (!fakeCommandMap.containsKey(key)) { |
| | | return; |
| | | } |
| | |
| | | fakeStatus.put("hasLift", true); |
| | | fakeStatus.put("deviceStatus", 1);//设备空闲 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | }else if (commandType.equals("liftDown")) { |
| | | } else if (commandType.equals("liftDown")) { |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | |
| | |
| | | fakeStatus.put("hasLift", false); |
| | | fakeStatus.put("deviceStatus", 1);//设备空闲 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | }else if (commandType.equals("charge")) { |
| | | } else if (commandType.equals("charge")) { |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | |
| | |
| | | batteryPower = batteryPower + 1; |
| | | fakeStatus.put("batteryPower", batteryPower); |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | if(batteryPower >= 100) { |
| | | if (batteryPower >= 100) { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | fakeStatus.put("deviceStatus", 1);//设备空闲 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | }else if (commandType.equals("stopCharge")) { |
| | | } else if (commandType.equals("stopCharge")) { |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | |
| | |
| | | fakeStatus.put("hasCharge", false); |
| | | fakeStatus.put("deviceStatus", 1);//设备空闲 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | }else if (commandType.equals("updateFloor")) { |
| | | } else if (commandType.equals("updateFloor")) { |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | |
| | |
| | | fakeStatus.put("currentCode", JSON.toJSONString(point)); |
| | | fakeStatus.put("deviceStatus", 1);//设备空闲 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | }else if (commandType.equals("move")) { |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | Thread.sleep(2000); |
| | | } else if (commandType.equals("move")) { |
| | | boolean firstMove = true; |
| | | |
| | | String baseCommandKey = RedisKeyType.FAKE_SHUTTLE_MOVE_EXECUTE_COMMAND_LIST.key + deviceConfig.getDeviceNo() + "_"; |
| | | Set<String> keys = redisUtil.searchKeys(baseCommandKey); |
| | | |
| | | if (!keys.isEmpty()) { |
| | | firstMove = false; |
| | | } |
| | | |
| | | JSONObject body = command.getJSONObject("commandBody"); |
| | | String pathList = body.getString("path"); |
| | | List<JSONObject> list = JSON.parseArray(pathList, JSONObject.class); |
| | | for (JSONObject path : list) { |
| | | while (true) { |
| | | JSONObject realFakeStatus = fakeStatusMap.get(key); |
| | | Integer errorCode = realFakeStatus.getInteger("errorCode"); |
| | | if (errorCode > 0) { |
| | | continue; |
| | | } |
| | | |
| | | String finalKey = baseCommandKey + System.currentTimeMillis(); |
| | | redisUtil.set(finalKey, list); |
| | | |
| | | if(!firstMove) { |
| | | return; |
| | | } |
| | | |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | Thread.sleep(2000); |
| | | |
| | | while (true) { |
| | | Set<String> searchKeys = redisUtil.searchKeys(baseCommandKey); |
| | | if(searchKeys.isEmpty()) { |
| | | break; |
| | | } |
| | | |
| | | String currentCode = fakeStatus.getString("currentCode"); |
| | | JSONObject point = JSON.parseObject(currentCode); |
| | | point.put("x", path.getInteger("xp")); |
| | | point.put("y", path.getInteger("yp")); |
| | | point.put("z", path.getInteger("z")); |
| | | fakeStatus.put("currentCode", JSON.toJSONString(point)); |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | Thread.sleep(2000); |
| | | TreeSet<String> treeSet = new TreeSet<>(); |
| | | for (String tmpKey : searchKeys) { |
| | | treeSet.add(tmpKey); |
| | | } |
| | | |
| | | String first = treeSet.first(); |
| | | |
| | | Object object = redisUtil.get(first); |
| | | if(object == null) { |
| | | break; |
| | | } |
| | | |
| | | List<JSONObject> executePathList = (List<JSONObject>) object; |
| | | for (JSONObject path : executePathList) { |
| | | while (true) { |
| | | JSONObject realFakeStatus = fakeStatusMap.get(key); |
| | | Integer errorCode = realFakeStatus.getInteger("errorCode"); |
| | | if (errorCode > 0) { |
| | | continue; |
| | | } |
| | | break; |
| | | } |
| | | |
| | | String currentCode = fakeStatus.getString("currentCode"); |
| | | JSONObject point = JSON.parseObject(currentCode); |
| | | point.put("x", path.getInteger("xp")); |
| | | point.put("y", path.getInteger("yp")); |
| | | point.put("z", path.getInteger("z")); |
| | | fakeStatus.put("currentCode", JSON.toJSONString(point)); |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | Thread.sleep(2000); |
| | | } |
| | | redisUtil.del(first); |
| | | } |
| | | |
| | | fakeStatus.put("deviceStatus", 1);//设备空闲 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | } |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }).start(); |