#
Junjie
5 天以前 82c36e2b434fa7a1c16b0448aa4cf1483107f79c
src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -1,8 +1,10 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
@@ -15,17 +17,14 @@
import com.zy.asrs.domain.vo.RgvLatestDataVo;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.CodeRes;
import com.zy.common.model.MapNode;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.CrnModeType;
import com.zy.core.enums.MapNodeType;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.RgvStatusType;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.WrkIoType;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.properties.SystemProperties;
@@ -55,7 +54,7 @@
    @Autowired
    private BasCrnpErrService basCrnpErrService;
    @Autowired
    private BasMapService basMapService;
    private WrkLastnoService wrkLastnoService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
@@ -91,6 +90,9 @@
    public R stationLatestData() {
        List<StationLatestDataVo> vos = new ArrayList<>();
        WrkLastno inTaskRange = wrkLastnoService.selectById(WrkIoType.IN.id);
        WrkLastno outTaskRange = wrkLastnoService.selectById(WrkIoType.OUT.id);
        List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Devp)));
        for (DeviceConfig deviceConfig : devpList) {
@@ -119,12 +121,38 @@
                vo.setError(stationProtocol.getError()); // 错误码
                vo.setBarcode(stationProtocol.getBarcode()); // 条码
                String stationStatus = StationStatusType.process(stationProtocol).toString().toLowerCase().replaceAll("_", "-");
                if (stationProtocol.isAutoing() && stationProtocol.isLoading() && stationProtocol.getTaskNo() > 0) {
                    String taskClass = getStationTaskClass(stationProtocol.getTaskNo(), inTaskRange, outTaskRange);
                    if (taskClass != null) {
                        stationStatus = taskClass;
                    }
                }
                vo.setStationStatus(stationStatus);
                vos.add(vo);
            }
        }
        return R.ok().add(vos);
    }
    private String getStationTaskClass(Integer taskNo, WrkLastno inTaskRange, WrkLastno outTaskRange) {
        if (taskNo == null || taskNo <= 0) {
            return null;
        }
        if (isInRange(taskNo, inTaskRange)) {
            return "machine-pakin";
        }
        if (isInRange(taskNo, outTaskRange)) {
            return "machine-pakout";
        }
        return null;
    }
    private boolean isInRange(Integer taskNo, WrkLastno taskRange) {
        if (taskRange == null || taskRange.getSNo() == null || taskRange.getENo() == null) {
            return false;
        }
        return taskNo >= taskRange.getSNo() && taskNo <= taskRange.getENo();
    }
    @PostMapping("/latest/data/crn")
@@ -193,6 +221,7 @@
            }
            RgvLatestDataVo vo = new RgvLatestDataVo();
            vo.setRgvNo(rgvProtocol.getRgvNo());
            vo.setTaskNo(rgvProtocol.getTaskNo());
            vo.setTrackSiteNo(String.valueOf(rgvProtocol.getRgvPos()));
            vo.setRgvStatus(RgvStatusType.get(rgvProtocol.getStatus()));
            vos.add(vo);
@@ -291,4 +320,18 @@
        return R.ok().add(mapNodeList);
    }
    @RequestMapping(value = "/map/locList")
    public R mapLocList() {
        Object object = redisUtil.get(RedisKeyType.LOC_MAST_MAP_LIST.key);
        if (object != null) {
            JSONArray data = JSON.parseArray(object.toString());
            return R.ok().add(data);
        }
        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
        wrapper.eq("lev1", 1);
        List<LocMast> locMasts = locMastService.selectList(wrapper);
        redisUtil.set(RedisKeyType.LOC_MAST_MAP_LIST.key, JSON.toJSONString(locMasts), 60 * 60 * 24);
        return R.ok().add(locMasts);
    }
}