自动化立体仓库 - WCS系统
999
zhangc
7 天以前 1ae96bb74480c3deb4f2273e5800a7bc7e82feb2
src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -1,37 +1,49 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Arith;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.zy.asrs.domain.enums.CrnStatusType;
import com.zy.asrs.domain.enums.SiteStatusType;
import com.zy.asrs.domain.param.SystemSwitchParam;
import com.zy.asrs.domain.vo.*;
import com.zy.asrs.entity.BasCrnError;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasRgv;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.mapper.BasCrnErrorMapper;
import com.zy.asrs.mapper.LocMastMapper;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasRgvService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.CodeRes;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.RgvThread2;
import com.zy.core.Slave;
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.CrnModeType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.CrnSlave;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.RgvSlave;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.RgvProtocol;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.properties.SystemProperties;
import com.zy.core.thread.CrnThread;
import com.zy.core.thread.DevpThread;
import com.zy.core.thread.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
 * 主控图接口
@@ -48,8 +60,17 @@
    private WrkMastService wrkMastService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private LocMastMapper locMastMapper;
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
    @Autowired
    private BasRgvService basRgvService;
    public static AtomicInteger integer = new AtomicInteger();
    public static final ArrayList<Integer> barcodeNos = new ArrayList<Integer>() {{
        add(1112);add(1114);add(1122);add(1124);
    }};
    @PostMapping("/system/running/status")
    @ManagerAuth(memo = "系统运行状态")
@@ -71,7 +92,7 @@
                return R.error("口令错误");
            }
        }
        Thread.sleep(2000L);
        Thread.sleep(200L);
        SystemProperties.WCS_RUNNING_STATUS.set(param.getOperatorType()==1?Boolean.TRUE:Boolean.FALSE);
        return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
    }
@@ -91,12 +112,14 @@
                stations.putAll(devpThread.getStation());
            }
        }
        for (Map.Entry<Integer, StaProtocol> entry : stations.entrySet()) {
            SiteLatestDataVo vo = new SiteLatestDataVo();
            StaProtocol staProtocol = entry.getValue();
            vo.setSiteId(String.valueOf(entry.getKey())); // 站点编号
            vo.setWorkNo(staProtocol.getWorkNo()); // 工作号
            vo.setWorkNo(staProtocol.getWorkNo().intValue()); // 工作号
            vo.setSiteStatus(SiteStatusType.process(staProtocol));  // 状态
            vo.setNearbySta(staProtocol.getNearbySta());
            vos.add(vo);
        }
        return R.ok().add(vos);
@@ -110,27 +133,35 @@
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            if (crnThread == null) {
                log.error("{}号堆垛机连接失败", crn.getId());
                continue;
            }
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) {
                log.error("{}号堆垛机连接失败", crn.getId());
                continue;
            }
            CrnLatestDataVo vo = new CrnLatestDataVo();
            vo.setCrnId(crn.getId());   //  堆垛机编号
//            Short totalBay = locMastMapper.selectTotalBay();
            vo.setOffset((double) new Random().nextInt(560));     //  堆垛机偏移量
            vo.setBay((short) (crnProtocol.getBay() - crn.getOffset()));    //  当前列
            /**
             * 堆垛机状态判断
             */
            if (crnProtocol.getTaskNo()>0) {
                WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
                if (wrkMast != null) {
                    vo.setCrnStatusType(CrnStatusType.process(wrkMast.getIoType()));
                }
            if (crnProtocol.getAlarm() > 0) {
                vo.setCrnStatus(CrnStatusType.MACHINE_ERROR);
            } else {
                vo.setCrnStatusType(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.AUTO: CrnStatusType.UN_AUTO);
                if (crnProtocol.getTaskNo()>0) {
                    WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
                    if (wrkMast != null) {
                        vo.setCrnStatus(CrnStatusType.process(wrkMast.getIoType()));
                    } else {
                        vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO: CrnStatusType.MACHINE_UN_AUTO);
                    }
                } else {
                    vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO)? CrnStatusType.MACHINE_AUTO: CrnStatusType.MACHINE_UN_AUTO);
                }
            }
            vos.add(vo);
@@ -141,16 +172,42 @@
    @PostMapping("/latest/data/barcode")
    @ManagerAuth(memo = "条码扫描仪实时数据")
    public R barcodeLatestData(){
        integer.getAndIncrement();
        List<BarcodeDataVo> list = new ArrayList<>();
        for (int i=1;i<=1;i++){
            BarcodeDataVo vo = new BarcodeDataVo();
            vo.setBarcodeId("1");
            if (integer.get()%5 != 0) {
                vo.setCodeValue("0");
            } else {
                vo.setCodeValue(String.valueOf(new Random().nextInt(5000)));
        List<SiteLatestDataVo> vos = new ArrayList<>();
        Map<Integer, StaProtocol> stations = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            if (null != devpThread) {
                stations.putAll(devpThread.getStation());
            }
        }
        for (Map.Entry<Integer, StaProtocol> entry : stations.entrySet()) {
            int index = barcodeNos.indexOf(entry.getValue().getSiteId());
            if (index == -1) {
                continue;
            }
            BarcodeDataVo vo = new BarcodeDataVo();
            vo.setBarcodeId(index);
            vo.setCodeValue(entry.getValue().getBarcode());
            list.add(vo);
        }
        return R.ok().add(list);
    }
    @PostMapping("/latest/data/scale")
    @ManagerAuth(memo = "磅秤实时数据")
    public R scaleLatestData(){
        List<ScaleDataVo> list = new ArrayList<>();
        for (Slave scale : slaveProperties.getScale()) {
            ScaleThread scaleThread = (ScaleThread) SlaveConnection.get(SlaveType.Scale, scale.getId());
            if (null == scaleThread) {
                continue;
            }
            ScaleDataVo vo = new ScaleDataVo();
            vo.setScaleId(scale.getId());
            vo.setValue(String.valueOf(Arith.multiplys(1, scaleThread.getScale(), 1)));
            list.add(vo);
        }
        return R.ok().add(list);
@@ -177,7 +234,7 @@
                        return R.error("数据库维护异常");
                    }
                    vo.setSiteId(siteId);   // 站点编号
                    vo.setWorkNo(staProtocol.getWorkNo());   // 工作号
                    vo.setWorkNo(staProtocol.getWorkNo().intValue());   // 工作号
                    if (staProtocol.getWorkNo() > 0) {
                        WrkMast wrkMast = wrkMastService.selectById(staProtocol.getWorkNo());
@@ -214,10 +271,17 @@
        CrnDetailVo vo = new CrnDetailVo();
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
            if (crnSlave.getId().equals(crnNo)) {
                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId());
                SiemensCrnThread crnThread = (SiemensCrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId());
                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                vo.setCrnNo(crnNo);
                vo.setWorkNo(crnProtocol.getTaskNo());
                vo.setCrnStatus(crnProtocol.getStatusType().desc);
                if (crnProtocol.getAlarm() > 0) {
                    BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
                    vo.setError(crnError == null ? "未知异常" : crnError.getErrName());
                }
                if (crnProtocol.getTaskNo() > 0) {
                    WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
                    if (wrkMast != null) {
@@ -231,9 +295,10 @@
                        vo.setError("");    // todo
                    }
                }
                return R.ok().add(vo);
            }
        }
        return R.ok().add(vo);
        return R.error();
    }
    @Deprecated
@@ -250,4 +315,18 @@
        return R.ok();
    }
    @GetMapping("/barcode/output/site")
    public R crnOutput(){
        ArrayList<JSONObject> jsonObjects = new ArrayList<>(OutputQueue.BARCODE);
        jsonObjects.sort(new Comparator<JSONObject>() {
            @Override
            public int compare(JSONObject o1, JSONObject o2) {
                Date o1Time = DateUtils.convert(o1.getString("time"), DateUtils.yyyyMMddHHmmss_F);
                Date o2Time = DateUtils.convert(o2.getString("time"), DateUtils.yyyyMMddHHmmss_F);
                return (int) (o2Time.getTime() - o1Time.getTime());
            }
        });
        return R.ok().add(JSON.toJSONString(jsonObjects));
    }
}