#
Junjie
昨天 9d24c64b9d81ae166f4c150f038793304d7161fa
#
7个文件已修改
203 ■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/BasMapController.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/ZyStationConnectDriver.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/api/ZyStationConnectApi.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java 130 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/real/ZyRgvRealConnect.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/BasMapController.java
@@ -6,15 +6,21 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasMapService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.utils.MapExcelUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.common.web.BaseController;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.StationObjModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -28,6 +34,10 @@
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    @Autowired
    private RedisUtil redisUtil;
@@ -151,12 +161,13 @@
    private MapExcelUtils mapExcelUtils;
    @PostMapping("/basMap/crn/upload")
    public R uploadExcel2(@RequestParam("file") MultipartFile file) throws IOException {
    public R uploadExcel(@RequestParam("file") MultipartFile file) throws IOException {
        // 保存上传的文件到临时位置
        String filePath = System.getProperty("java.io.tmpdir") + file.getOriginalFilename();
        file.transferTo(new File(filePath));
        HashMap<Integer, List<List<HashMap<String, Object>>>> dataMap = mapExcelUtils.readExcel(filePath);
        HashMap<Integer, List<StationObjModel>> deviceStationMap = new HashMap<>();
        for (Map.Entry<Integer, List<List<HashMap<String, Object>>>> entry : dataMap.entrySet()) {
            Integer lev = entry.getKey();
@@ -182,6 +193,16 @@
                    }else if (nodeType.equals("RGB(0,112,192)")) {
                        //输送线
                        nodeData.put("type", "devp");
                        JSONObject value = JSON.parseObject(String.valueOf(map.get("value")));
                        Integer deviceNo = value.getInteger("deviceNo");
                        StationObjModel stationObjModel = new StationObjModel();
                        stationObjModel.setDeviceNo(deviceNo);
                        stationObjModel.setStationId(value.getInteger("stationId"));
                        List<StationObjModel> stationList = deviceStationMap.getOrDefault(deviceNo, new ArrayList<>());
                        stationList.add(stationObjModel);
                        deviceStationMap.put(deviceNo, stationList);
                    }else if (nodeType.equals("RGB(0,176,240)")) {
                        //RGV
                        nodeData.put("type", "rgv");
@@ -213,7 +234,27 @@
            basMap.setUpdateTime(new Date());
            basMap.setLev(lev);
            basMapService.insertOrUpdate(basMap);
        }
        deviceStationMap.forEach((deviceNo, stationList) -> {
            BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("devp_no", deviceNo));
            if (basDevp == null){
                basDevp = new BasDevp();
                basDevp.setDevpNo(deviceNo);
                basDevp.setCreateTime(new Date());
                basDevp.setStatus(1);
            }
            basDevp.setStationList(JSON.toJSONString(stationList));
            basDevp.setUpdateTime(new Date());
            basDevpService.insertOrUpdate(basDevp);
            DeviceConfig deviceConfig = deviceConfigService.selectOne(new EntityWrapper<DeviceConfig>().eq("device_no", deviceNo).eq("device_type", String.valueOf(SlaveType.Devp)));
            if (deviceConfig != null){
                deviceConfig.setFakeInitStatus(JSON.toJSONString(stationList));
                deviceConfigService.updateById(deviceConfig);
            }
        });
        return R.ok();
    }
src/main/java/com/zy/core/network/ZyStationConnectDriver.java
@@ -22,6 +22,8 @@
@Slf4j
public class ZyStationConnectDriver implements ThreadHandler {
    private static final ZyStationFakeConnect zyStationFakeConnect = new ZyStationFakeConnect();
    private boolean connected = false;
    private DeviceConfig deviceConfig;
    private RedisUtil redisUtil;
@@ -44,7 +46,8 @@
        if (deviceConfig.getFake() == 0) {
            zyStationConnectApi = new ZyStationRealConnect(deviceConfig, redisUtil);
        } else {
            zyStationConnectApi = new ZyStationFakeConnect(deviceConfig, redisUtil);
            zyStationFakeConnect.addFakeConnect(deviceConfig, redisUtil);
            zyStationConnectApi = zyStationFakeConnect;
        }
        boolean connect = zyStationConnectApi.connect();
@@ -95,10 +98,10 @@
        if (zyStationConnectApi == null) {
            return null;
        }
        return zyStationConnectApi.getStatus();
        return zyStationConnectApi.getStatus(deviceConfig.getDeviceNo());
    }
    public CommandResponse sendCommand(StationCommand command) {
        return zyStationConnectApi.sendCommand(command);
        return zyStationConnectApi.sendCommand(deviceConfig.getDeviceNo(), command);
    }
}
src/main/java/com/zy/core/network/api/ZyStationConnectApi.java
@@ -12,8 +12,8 @@
    boolean disconnect();
    List<ZyStationStatusEntity> getStatus();//设备状态
    List<ZyStationStatusEntity> getStatus(Integer deviceNo);//设备状态
    CommandResponse sendCommand(StationCommand command);//下发命令
    CommandResponse sendCommand(Integer deviceNo, StationCommand command);//下发命令
}
src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
@@ -14,6 +14,7 @@
import com.zy.core.network.api.ZyStationConnectApi;
import com.zy.core.network.entity.ZyStationStatusEntity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -27,17 +28,22 @@
 */
public class ZyStationFakeConnect implements ZyStationConnectApi {
    private final List<ZyStationStatusEntity> statusList = new CopyOnWriteArrayList<>();
    private static int LOCK_STATION = 0;
    private final DeviceConfig deviceConfig;
    private HashMap<Integer, List<ZyStationStatusEntity>> deviceStatusMap = new HashMap<>();
    private HashMap<Integer, DeviceConfig> deviceConfigMap = new HashMap<>();
    private RedisUtil redisUtil;
    // 允许并行执行多个命令任务(固定线程池)。如需更高并发可调整大小。
    private final ExecutorService executor = Executors
            .newFixedThreadPool(9999);
    public ZyStationFakeConnect(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.deviceConfig = deviceConfig;
    public void addFakeConnect(DeviceConfig deviceConfig, RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
        if (deviceConfigMap.containsKey(deviceConfig.getDeviceNo())) {
            return;
        }
        deviceConfigMap.put(deviceConfig.getDeviceNo(), deviceConfig);
        deviceStatusMap.put(deviceConfig.getDeviceNo(), new CopyOnWriteArrayList<>());
    }
    @Override
@@ -52,12 +58,17 @@
    }
    @Override
    public List<ZyStationStatusEntity> getStatus() {
        if (this.statusList.isEmpty()) {
    public List<ZyStationStatusEntity> getStatus(Integer deviceNo) {
        List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
        if (statusList == null) {
            return new ArrayList<>();
        }
        DeviceConfig deviceConfig = deviceConfigMap.get(deviceNo);
        if (statusList.isEmpty()) {
            List<ZyStationStatusEntity> init = JSON.parseArray(deviceConfig.getFakeInitStatus(), ZyStationStatusEntity.class);
            if (init != null) {
                statusList.addAll(init);
                for (ZyStationStatusEntity status : this.statusList) {
                for (ZyStationStatusEntity status : statusList) {
                    status.setAutoing(true);// 模拟自动运行
                    status.setLoading(false);// 模拟有物
                    status.setInEnable(true);// 模拟可入
@@ -72,14 +83,14 @@
            }
        }
        return this.statusList;
        return statusList;
    }
    @Override
    public CommandResponse sendCommand(StationCommand command) {
    public CommandResponse sendCommand(Integer deviceNo, StationCommand command) {
        executor.submit(() -> {
            try {
                handleCommand(command);
                handleCommand(deviceNo, command);
            } catch (Exception e) {
                e.printStackTrace();
            }
@@ -87,7 +98,7 @@
        return new CommandResponse(true, "命令已受理(异步执行)");
    }
    private void handleCommand(StationCommand command) {
    private void handleCommand(Integer deviceNo, StationCommand command) {
        News.info("[WCS Debug] 站点仿真模拟已启动,命令数据={}", JSON.toJSONString(command));
        Integer taskNo = command.getTaskNo();
        Integer stationId = command.getStationId();
@@ -96,7 +107,7 @@
        if(taskNo == 0 && targetStationId == 0){
            //清空站点
            resetStation(stationId);
            resetStation(deviceNo, stationId);
            return;
        }
@@ -108,13 +119,13 @@
        if (taskNo == 9998 && targetStationId == 0) {
            //生成出库站点仿真数据
            generateFakeOutStationData(stationId);
            generateFakeOutStationData(deviceNo, stationId);
            return;
        }
        if (taskNo > 0 && taskNo != 9999 && taskNo != 9998 && stationId == targetStationId) {
            //下发任务数据-不允许只是下发数据
            generateStationData(taskNo, stationId, targetStationId);
            generateStationData(deviceNo, taskNo, stationId, targetStationId);
        }
        String startLev = String.valueOf(stationId).substring(0, 1);
@@ -127,7 +138,8 @@
        }
    }
    private void generateFakeOutStationData(Integer stationId) {
    private void generateFakeOutStationData(Integer deviceNo, Integer stationId) {
        List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
        ZyStationStatusEntity status = statusList.stream()
                .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null);
        if (status == null) {
@@ -139,7 +151,8 @@
        }
    }
    private void generateStationData(Integer taskNo, Integer stationId, Integer targetStationId) {
    private void generateStationData(Integer deviceNo, Integer taskNo, Integer stationId, Integer targetStationId) {
        List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
        ZyStationStatusEntity status = statusList.stream()
                .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null);
        if (status == null) {
@@ -152,7 +165,8 @@
        }
    }
    private void resetStation(Integer stationId) {
    private void resetStation(Integer deviceNo, Integer stationId) {
        List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
        ZyStationStatusEntity status = statusList.stream()
                .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null);
        if (status == null) {
@@ -273,6 +287,7 @@
    private boolean stationMove(List<NavigateNode> navigateNodes, Integer taskNo, Integer targetStationId, boolean clearData, boolean generateBarcode) {
        Integer lastStationId = null;
        Integer targetStationDeviceNo = null;
        long executeTime = System.currentTimeMillis();
        int i = 0;
@@ -283,12 +298,18 @@
            NavigateNode navigateNode = navigateNodes.get(i);
            JSONObject valueObject = JSON.parseObject(navigateNode.getNodeValue());
            Integer currentStationId = valueObject.getInteger("stationId");
            Integer currentStationDeviceNo = valueObject.getInteger("deviceNo");
            if (currentStationId.equals(targetStationId)) {
                targetStationDeviceNo = currentStationDeviceNo;
            }
            Integer nextStationId = null;
            Integer nextStationDeviceNo = null;
            try {
                NavigateNode nextNode = navigateNodes.get(i + 1);
                JSONObject nextValueObject = JSON.parseObject(nextNode.getNodeValue());
                nextStationId = nextValueObject.getInteger("stationId");
                nextStationDeviceNo = nextValueObject.getInteger("deviceNo");
            } catch (Exception e) {
            }
@@ -305,7 +326,7 @@
                if (fakeAllowCheckBlock && System.currentTimeMillis() - executeTime > 1000 * 10) {
                    //认定堵塞
                    boolean result = runBlockStation(taskNo, currentStationId, taskNo, currentStationId);
                    boolean result = runBlockStation(taskNo, currentStationId, currentStationDeviceNo, taskNo, currentStationId);
                    if(!result) {
                        continue;
                    }
@@ -314,7 +335,7 @@
            }
            if (i == 0) {
                boolean result = initStationMove(taskNo, currentStationId, taskNo, targetStationId, true, null);
                boolean result = initStationMove(taskNo, currentStationId, currentStationDeviceNo, taskNo, targetStationId, true, null);
                if (!result) {
                    continue;
                }
@@ -325,7 +346,7 @@
            }
            if(nextStationId != null) {
                boolean result = stationMoveToNext(taskNo, currentStationId, nextStationId, taskNo, targetStationId);
                boolean result = stationMoveToNext(taskNo, currentStationId, currentStationDeviceNo, nextStationId, nextStationDeviceNo, taskNo, targetStationId);
                if (!result) {
                    continue;
                }
@@ -346,7 +367,7 @@
                    if (Thread.currentThread().isInterrupted()) {
                        break;
                    }
                    boolean result = generateStationBarcode(taskNo, targetStationId);
                    boolean result = generateStationBarcode(taskNo, targetStationId, targetStationDeviceNo);
                    sleep(1000);
                    if (!result) {
                        continue;
@@ -366,7 +387,7 @@
                    if (Thread.currentThread().isInterrupted()) {
                        break;
                    }
                    boolean result = clearStation(taskNo, targetStationId);
                    boolean result = clearStation(taskNo, targetStationId, targetStationDeviceNo);
                    sleep(1000);
                    if (!result) {
                        continue;
@@ -408,8 +429,13 @@
        return true;
    }
    public synchronized boolean updateStationData(Integer lockTaskNo, Integer stationId, Integer taskNo, Integer targetStaNo, Boolean isLoading, String barcode, Boolean runBlock) {
    public synchronized boolean updateStationData(Integer lockTaskNo, Integer stationId, Integer deviceNo, Integer taskNo, Integer targetStaNo, Boolean isLoading, String barcode, Boolean runBlock) {
        if (LOCK_STATION != lockTaskNo) {
            return false;
        }
        List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
        if (statusList == null) {
            return false;
        }
@@ -436,16 +462,21 @@
            currentStatus.setBarcode(barcode);
        }
        if(runBlock != null) {
        if (runBlock != null) {
            currentStatus.setRunBlock(runBlock);
        }
        return true;
    }
    public synchronized boolean initStationMove(Integer lockTaskNo, Integer currentStationId, Integer taskNo, Integer targetStationId, Boolean isLoading, String barcode) {
    public synchronized boolean initStationMove(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo, Integer taskNo, Integer targetStationId, Boolean isLoading, String barcode) {
        boolean executeResult = lockExecute(lockTaskNo, () -> {
            List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
            if (statusList == null) {
                return false;
            }
            ZyStationStatusEntity currentStatus = statusList.stream()
                .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
                    .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
            if (currentStatus == null) {
                return false;
@@ -457,7 +488,7 @@
                }
            }
            boolean result = updateStationData(taskNo, currentStationId, taskNo, targetStationId, isLoading, barcode, false);
            boolean result = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, taskNo, targetStationId, isLoading, barcode, false);
            if (!result) {
                return false;
            }
@@ -467,12 +498,22 @@
        return executeResult;
    }
    public synchronized boolean stationMoveToNext(Integer lockTaskNo, Integer currentStationId, Integer nextStationId, Integer taskNo, Integer targetStaNo) {
    public synchronized boolean stationMoveToNext(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo, Integer nextStationId, Integer nextStationDeviceNo, Integer taskNo, Integer targetStaNo) {
        boolean executeResult = lockExecute(lockTaskNo, () -> {
            List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
            if (statusList == null) {
                return false;
            }
            List<ZyStationStatusEntity> nextStatusList = deviceStatusMap.get(nextStationDeviceNo);
            if (statusList == null) {
                return false;
            }
            ZyStationStatusEntity currentStatus = statusList.stream()
                    .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
            ZyStationStatusEntity nextStatus = statusList.stream()
            ZyStationStatusEntity nextStatus = nextStatusList.stream()
                    .filter(item -> item.getStationId().equals(nextStationId)).findFirst().orElse(null);
            if (currentStatus == null || nextStatus == null) {
@@ -483,12 +524,12 @@
                return false;
            }
            boolean result = updateStationData(lockTaskNo, nextStationId, taskNo, targetStaNo, true, null, false);
            boolean result = updateStationData(lockTaskNo, nextStationId, nextStationDeviceNo, taskNo, targetStaNo, true, null, false);
            if (!result) {
                return false;
            }
            boolean result2 = updateStationData(lockTaskNo, currentStationId, 0, 0, false, "", false);
            boolean result2 = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, 0, 0, false, "", false);
            if (!result2) {
                return false;
            }
@@ -498,8 +539,13 @@
        return executeResult;
    }
    public synchronized boolean generateStationBarcode(Integer lockTaskNo, Integer currentStationId) {
    public synchronized boolean generateStationBarcode(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo) {
        boolean executeResult = lockExecute(lockTaskNo, () -> {
            List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
            if (statusList == null) {
                return false;
            }
            ZyStationStatusEntity currentStatus = statusList.stream()
                    .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
@@ -510,7 +556,7 @@
            String barcodeTime = String.valueOf(System.currentTimeMillis());
            String barcode = barcodeTime.substring(5);
            boolean result = updateStationData(lockTaskNo, currentStationId, null, null, null, barcode, null);
            boolean result = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, null, null, null, barcode, null);
            if (!result) {
                return false;
            }
@@ -520,8 +566,13 @@
        return executeResult;
    }
    public synchronized boolean clearStation(Integer lockTaskNo, Integer currentStationId) {
    public synchronized boolean clearStation(Integer deviceNo, Integer lockTaskNo, Integer currentStationId) {
        boolean executeResult = lockExecute(lockTaskNo, () -> {
            List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
            if (statusList == null) {
                return false;
            }
            ZyStationStatusEntity currentStatus = statusList.stream()
                    .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
@@ -529,7 +580,7 @@
                return false;
            }
            boolean result = updateStationData(lockTaskNo, currentStationId, 0, 0, false, "", false);
            boolean result = updateStationData(deviceNo, lockTaskNo, currentStationId, 0, 0, false, "", false);
            if (!result) {
                return false;
            }
@@ -539,8 +590,13 @@
        return executeResult;
    }
    public synchronized boolean runBlockStation(Integer lockTaskNo, Integer currentStationId, Integer taskNo, Integer blockStationId) {
    public synchronized boolean runBlockStation(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo, Integer taskNo, Integer blockStationId) {
        boolean executeResult = lockExecute(lockTaskNo, () -> {
            List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
            if (statusList == null) {
                return false;
            }
            ZyStationStatusEntity currentStatus = statusList.stream()
                    .filter(item -> item.getStationId().equals(currentStationId)).findFirst().orElse(null);
@@ -548,7 +604,7 @@
                return false;
            }
            boolean result = updateStationData(lockTaskNo, currentStationId, taskNo, blockStationId, true, "", true);
            boolean result = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, taskNo, blockStationId, true, "", true);
            if (!result) {
                return false;
            }
src/main/java/com/zy/core/network/real/ZyRgvRealConnect.java
@@ -11,22 +11,13 @@
import com.alibaba.fastjson.JSON;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasCrnpOpt;
import com.zy.asrs.entity.BasRgv;
import com.zy.asrs.entity.BasRgvOpt;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.DeviceDataLog;
import com.zy.asrs.service.BasCrnpOptService;
import com.zy.asrs.service.BasRgvOptService;
import com.zy.asrs.service.BasRgvService;
import com.zy.asrs.service.DeviceDataLogService;
import com.zy.asrs.utils.Utils;
import com.zy.core.News;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.RgvStatusType;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.RgvCommand;
import com.zy.core.model.protocol.RgvProtocol;
import com.zy.core.network.api.ZyRgvConnectApi;
import com.zy.core.network.entity.ZyRgvStatusEntity;
src/main/java/com/zy/core/network/real/ZyStationRealConnect.java
@@ -73,7 +73,7 @@
    }
    @Override
    public List<ZyStationStatusEntity> getStatus() {
    public List<ZyStationStatusEntity> getStatus(Integer deviceNo) {
        if (statusList == null) {
            BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
            if (basDevpService == null) {
@@ -132,7 +132,7 @@
    }
    @Override
    public CommandResponse sendCommand(StationCommand command) {
    public CommandResponse sendCommand(Integer deviceNo, StationCommand command) {
        CommandResponse commandResponse = new CommandResponse(false);
        if (null == command) {
            commandResponse.setMessage("命令为空");
@@ -204,4 +204,4 @@
        }
        return -1;
    }
}
}
src/main/resources/application.yml
@@ -71,7 +71,7 @@
deviceLogStorage:
  # 设备日志存储方式 mysql file
  type: file
  type: mysql
  # file类型存储地址
  loggingPath: /stock/out/@pom.build.finalName@/deviceLogs
  # 日志过期时间 单位天