自动化立体仓库 - WCS系统
123
ZY
3 天以前 364b9ccc44bc6863280c5cc00aa8512cfff548d4
src/main/java/com/zy/asrs/controller/SiteController.java
@@ -1,9 +1,14 @@
package com.zy.asrs.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.domain.vo.PlcErrorTableVo;
import com.zy.asrs.domain.vo.SiteTableVo;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.service.BasDevpService;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
@@ -12,11 +17,12 @@
import com.zy.core.model.Task;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.DevpThread;
import com.zy.core.thread.SiemensDevpThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -30,74 +36,118 @@
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private BasDevpService basDevpService;
    @GetMapping("/io/mode/info/site")
    @ManagerAuth(memo = "入出库模式")
    public R ioMode() {
        List<Map<String, Object>> res = new ArrayList<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<String, Object> map2 = new HashMap<>();
            map2.put("floor", 2);
            map2.put("modeVal", devpThread.ioModeOf1F1.id);
            map2.put("modeDesc", devpThread.ioModeOf1F1.desc);
            res.add(map2);
        }
        return R.ok().add(res);
    }
    @PostMapping("/table/site")
    @ManagerAuth(memo = "站点信息表")
    public R siteTable(){
    public R siteTable() {
        List<SiteTableVo> list = new ArrayList<>();
        // 内存数据
        Map<Integer, StaProtocol> station = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                StaProtocol staProtocol = entry.getValue();
                SiteTableVo vo = new SiteTableVo();
                vo.setDevNo(entry.getKey());    // 站点编号
                vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
                vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  自动
                vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 有物
                vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 可入
                vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 可出
                vo.setInreq1(staProtocol.isInreq1()?"Y":"N");       // 需求1
                vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 空板信号
                vo.setStaNo(staProtocol.getStaNo());                // 目标站
                list.add(vo);
            station.putAll(devpThread.getStation());
        }
        // 持久数据
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>().orderBy("dev_no"));
        for (BasDevp devp : basDevps) {
            SiteTableVo vo = new SiteTableVo();
            vo.setDevNo(devp.getDevNo());    // 站点编号
            list.add(vo);
            StaProtocol staProtocol = station.get(devp.getDevNo());
            if (null == staProtocol) {
                continue;
            }
            vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
            vo.setAutoing(staProtocol.isAutoing() ? "Y" : "N");     //  自动
            vo.setLoading(staProtocol.isLoading() ? "Y" : "N");     // 有物
            vo.setInEnable(staProtocol.isInEnable() ? "Y" : "N");   // 可入
            vo.setOutEnable(staProtocol.isOutEnable() ? "Y" : "N"); // 可出
            vo.setPakMk(staProtocol.isPakMk() ? "Y" : "N");       // 入库标记
            vo.setEmptyMk(staProtocol.isEmptyMk() ? "Y" : "N");     // 空板信号
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
            vo.setLocType1(devp.getDevNo() == 102 ? "高" : "低");
        }
        return R.ok().add(list);
    }
    @GetMapping("/list/auth")
    @ManagerAuth(memo = "站点信息表")
    public R crnList() {
        List<SiteTableVo> list = new ArrayList<>();
        // 内存数据
        Map<Integer, StaProtocol> station = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            station.putAll(devpThread.getStation());
        }
        // 持久数据
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>().orderBy("dev_no"));
        for (BasDevp devp : basDevps) {
            SiteTableVo vo = new SiteTableVo();
            vo.setDevNo(devp.getDevNo());    // 站点编号
            list.add(vo);
            StaProtocol staProtocol = station.get(devp.getDevNo());
            if (null == staProtocol) {
                continue;
            }
            vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
            vo.setAutoing(staProtocol.isAutoing() ? "Y" : "N");     //  自动
            vo.setLoading(staProtocol.isLoading() ? "Y" : "N");     // 有物
            vo.setInEnable(staProtocol.isInEnable() ? "Y" : "N");   // 可入
            vo.setOutEnable(staProtocol.isOutEnable() ? "Y" : "N"); // 可出
            vo.setPakMk(staProtocol.isPakMk() ? "Y" : "N");       // 入库标记
            vo.setEmptyMk(staProtocol.isEmptyMk() ? "Y" : "N");     // 空板信号
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
            vo.setLocType1(devp.getDevNo() == 102 ? "高" : "低");
        }
        return R.ok().add(list);
    }
    @PostMapping("/table/plc/errors")
    @ManagerAuth(memo = "输送设备plc异常信息表")
    public R plcErrorTable(){
    public R plcErrorTable() {
        List<PlcErrorTableVo> list = new ArrayList<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            for(Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                PlcErrorTableVo vo = new PlcErrorTableVo();
                vo.setNo(entry.getKey());   //  序号
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (!Cools.isEmpty(staPlcErr(entry))) {
                    list.add(staPlcErr(entry).get(0));
                }
                vo.setPlcDesc("");  //  todo:luxiaotao plc错误描述
                vo.setError("");    //  todo:luxiaotao 异常信息
                list.add(vo);
            }
        }
        list.sort((o1, o2) -> {
            if (o1.getNo().compareTo(o2.getNo()) > 0){
                return 1;
            }else if (o1.getNo().compareTo(o2.getNo()) < 0){
                return 0;
            }else{
                return -1;
            }
        });
        return R.ok().add(list);
    }
    @PostMapping("/output/site")
    @ManagerAuth(memo = "站点设备报文日志输出")
    public R siteOutput(){
    public R siteOutput() {
        StringBuilder str = new StringBuilder();
        String s;
        int i = 0;
        while((s = OutputQueue.DEVP.poll()) != null && i <=10) {
        while ((s = OutputQueue.DEVP.poll()) != null && i <= 10) {
            str.append("\n").append(s);
            i++;
        }
@@ -109,7 +159,7 @@
    /****************************************************************/
    @GetMapping("/detl/{siteId}")
    public R siteDetl(@PathVariable("siteId") Integer siteId){
    public R siteDetl(@PathVariable("siteId") Integer siteId) {
        SiteTableVo vo = new SiteTableVo();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
@@ -119,13 +169,15 @@
                    StaProtocol staProtocol = entry.getValue();
                    vo.setDevNo(entry.getKey());    // 站点编号
                    vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
                    vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  自动
                    vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 有物
                    vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 可入
                    vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 可出
                    vo.setInreq1(staProtocol.isInreq1()?"Y":"N");       // 需求1
                    vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 空板信号
                    vo.setAutoing(staProtocol.isAutoing() ? "Y" : "N");     //  自动
                    vo.setLoading(staProtocol.isLoading() ? "Y" : "N");     // 有物
                    vo.setInEnable(staProtocol.isInEnable() ? "Y" : "N");   // 可入
                    vo.setOutEnable(staProtocol.isOutEnable() ? "Y" : "N"); // 可出
                    vo.setPakMk(staProtocol.isPakMk() ? "Y" : "N");       // 需求1
                    vo.setEmptyMk(staProtocol.isEmptyMk() ? "Y" : "N");     // 空板信号
                    vo.setStaNo(staProtocol.getStaNo());                // 目标站
                    vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
                    vo.setCar(staProtocol.isCar() ? "有" : "无");
                    return R.ok().add(vo);
                }
            }
@@ -135,21 +187,46 @@
    @PostMapping("/detl/update")
    @ManagerAuth(memo = "修改站点数据")
    public R siteDetlUpdate(@RequestParam Integer siteId,
    public R siteDetlUpdate(@RequestParam Integer devNo,
                            @RequestParam Short workNo,
                            @RequestParam Short staNo){
                            @RequestParam Short staNo,
                            @RequestParam(required = false) String pakMk,
                            @RequestParam(required = false) Boolean inEnable,
                            @RequestParam(required = false) Boolean outEnable
    ) {
        BasDevp basDevp = basDevpService.selectById(devNo);
        if (basDevp == null) {
            return R.error("站点不存在");
        }
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (siteId.equals(entry.getKey())) {
                if (devNo.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    if (workNo != null) {
                        staProtocol.setWorkNo(workNo);
                    }
                    if (staNo != null) {
                        staProtocol.setStaNo(staNo);
                    }
                    if (pakMk != null) {
                        staProtocol.setPakMk(pakMk.equals("Y"));
                    }
                    if (inEnable != null) {
                        staProtocol.setInEnable(inEnable);
                        basDevp.setInEnable(inEnable ? "Y" : "N");
                    }
                    if (outEnable != null) {
                        staProtocol.setOutEnable(outEnable);
                        basDevp.setOutEnable(outEnable ? "Y" : "N");
                    }
                    basDevpService.updateById(basDevp);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    if (result) {
                        return R.ok();
@@ -159,8 +236,209 @@
                }
            }
        }
        return R.error("plc已掉线");
        return R.error("更新失败");
    }
    @PostMapping("/detl/out")
    @ManagerAuth(memo = "修改站点数据")
    public R siteDetlout(@RequestParam Integer devNo,
                         @RequestParam Short workNo,
                         @RequestParam Short staNo,
                         @RequestParam(required = false) String pakMk,
                         @RequestParam(required = false) Boolean inEnable,
                         @RequestParam(required = false) Boolean outEnable
    ) {
        BasDevp basDevp = basDevpService.selectById(devNo);
        if (basDevp == null) {
            return R.error("站点不存在");
        }
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (devNo.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    if (pakMk != null) {
                        staProtocol.setPakMk(pakMk.equals("Y"));
                    }
                    if (inEnable != null) {
                        staProtocol.setInEnable(inEnable);
                        basDevp.setInEnable(inEnable ? "Y" : "N");
                    }
                    if (outEnable != null) {
                        staProtocol.setOutEnable(outEnable);
                        basDevp.setOutEnable(outEnable ? "Y" : "N");
                    }
                    staProtocol.setWorkNo((short) 0);
                    staProtocol.setStaNo((short) 0);
                    basDevpService.updateById(basDevp);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                    if (result) {
                        return R.ok();
                    } else {
                        return R.error("下发命令失败");
                    }
                }
            }
        }
        return R.error("更新失败");
    }
    @PostMapping("/detl/in")
    @ManagerAuth(memo = "修改站点数据")
    public R siteDetlint(@RequestParam Integer devNo,
                         @RequestParam Short workNo,
                         @RequestParam Short staNo,
                         @RequestParam(required = false) String pakMk,
                         @RequestParam(required = false) Boolean inEnable,
                         @RequestParam(required = false) Boolean outEnable
    ) {
        BasDevp basDevp = basDevpService.selectById(devNo);
        if (basDevp == null) {
            return R.error("站点不存在");
        }
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库口
            for (DevpSlave.Sta inSta : devp.getInSta()) {
                if (!devNo.equals(inSta.getBackSta())) {
                    continue;
                }
                // 获取入库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(inSta.getBackSta());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                staProtocol.setWorkNo((short) 9999);
                staProtocol.setStaNo(inSta.getStaNo().shortValue());
                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                if (result) {
                    return R.ok();
                } else {
                    return R.error("下发命令失败");
                }
            }
        }
        return R.error("更新失败");
    }
    public List<PlcErrorTableVo> staPlcErr(Map.Entry<Integer, StaProtocol> entry) {
        List<PlcErrorTableVo> list = new ArrayList<>();
        StaProtocol staProtocol = entry.getValue();
        if (staProtocol.getBreakerErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("断路器故障");
            vo.setError("断路器故障");
            list.add(vo);
        }
        if (staProtocol.getInfraredErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("光电异常");
            vo.setError("光电异常");
            list.add(vo);
        }
        if (staProtocol.getOutTimeErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("运行超时");
            vo.setError("运行超时");
            list.add(vo);
        }
        if (staProtocol.getSeizeSeatErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("占位超时");
            vo.setError("占位超时");
            list.add(vo);
        }
        if (staProtocol.getWrkYgoodsN()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("有任务无货故障");
            vo.setError("有任务无货故障");
            list.add(vo);
        }
        if (staProtocol.getInverterErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("变频器故障");
            vo.setError("变频器故障");
            list.add(vo);
        }
        if (staProtocol.getContactErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("电机接触器故障");
            vo.setError("电机接触器故障");
            list.add(vo);
        }
        if (staProtocol.getUpcontactErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("顶升电机接触器故障");
            vo.setError("顶升电机接触器故障");
            list.add(vo);
        }
        if (staProtocol.isFrontErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("前超限");
            vo.setError("前超限");
            list.add(vo);
        }
        if (staProtocol.isBackErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("后超限");
            vo.setError("后超限");
            list.add(vo);
        }
        if (staProtocol.isHighErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("高超限");
            vo.setError("高超限");
            list.add(vo);
        }
        if (staProtocol.isLeftErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("左超限");
            vo.setError("左超限");
            list.add(vo);
        }
        if (staProtocol.isRightErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("右超限");
            vo.setError("右超限");
            list.add(vo);
        }
        if (staProtocol.isBarcodeErr()) {
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("扫码失败");
            vo.setError("扫码失败");
            list.add(vo);
        }
        return list;
    }
}