#
zjj
2024-07-19 5d0f7a5aa4ee994782f3f3bcc66e23653a6ac40a
src/main/java/com/zy/asrs/controller/SiteController.java
@@ -2,28 +2,33 @@
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.entity.BasExt;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasExtService;
import com.zy.asrs.utils.CommandUtils;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.ExtSlave;
import com.zy.core.model.Task;
import com.zy.core.model.protocol.ExtProtocol;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.DevpThread;
import com.zy.core.thread.BarcodeThread;
import com.zy.core.thread.MelsecExtThread;
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;
import java.util.*;
/**
 * 输送设备接口
@@ -37,6 +42,9 @@
    private SlaveProperties slaveProperties;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private BasExtService basExtService;
    @GetMapping("/io/mode/info/site")
    @ManagerAuth(memo = "入出库模式")
@@ -111,8 +119,30 @@
            vo.setPakMk(staProtocol.isPakMk()?"Y":"N");       // 入库标记
            vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 空板信号
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
            vo.setFullPlt(staProtocol.isFullPlt()?"Y":"N");
            vo.setLow(staProtocol.isLow()?"Y":"N");
            vo.setCar(staProtocol.isCar()?"Y":"N");
//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
            vo.setLocType1(devp.getDevNo()==102 ? "高" : "低");
            vo.setBarcode(staProtocol.getBarcode());
        }
        return R.ok().add(list);
    }
    @GetMapping("/list/ext/auth")
    @ManagerAuth(memo = "机械臂信息")
    public R extList(){
        List<SiteTableVo> list = new ArrayList<>();
        // 持久数据
        List<BasExt> basExts = basExtService.selectList(new EntityWrapper<BasExt>().orderBy("ext_no"));
        for (BasExt ext : basExts) {
            SiteTableVo vo = new SiteTableVo();
            vo.setDevNo(ext.getExtNo());    // 站点编号
            vo.setInEnable(ext.getExtTask());   // 可入  可取
            vo.setOutEnable(ext.getExtPut()); // 可出     可放
            list.add(vo);
        }
        return R.ok().add(list);
    }
@@ -126,29 +156,12 @@
            Map<Integer, StaProtocol> station = devpThread.getStation();
            for(Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                StaProtocol staProtocol = entry.getValue();
//                if (staProtocol) {
//                    PlcErrorTableVo vo = new PlcErrorTableVo();
//                    vo.setNo(entry.getKey());   //  序号
//
//                    vo.setPlcDesc("");  //  todo:luxiaotao plc错误描述
//                    vo.setError("");    //  todo:luxiaotao 异常信息
//                    list.add(vo);
//                }
            }
                if (!Cools.isEmpty(staPlcErr(entry))){
                    list.add(staPlcErr(entry).get(0)) ;
                }
            }
        }
        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);
    }
@@ -188,6 +201,7 @@
                    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);
                }
            }
@@ -197,15 +211,22 @@
    @PostMapping("/detl/update")
    @ManagerAuth(memo = "修改站点数据")
    public R siteDetlUpdate(@RequestParam Integer siteId,
    public R siteDetlUpdate(@RequestParam Integer devNo,
                            @RequestParam Short workNo,
                            @RequestParam Short staNo,
                            @RequestParam String pakMk){
                            @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;
@@ -221,7 +242,16 @@
                    if (pakMk != null) {
                        staProtocol.setPakMk(pakMk.equals("Y"));
                    }
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    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 = CommandUtils.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol), false);
                    if (result) {
                        return R.ok();
                    } else {
@@ -230,8 +260,207 @@
                }
            }
        }
        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 = CommandUtils.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol), false);
                    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 = CommandUtils.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol), false);
                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;
    }
}