1
zhang
昨天 9830ed887f809224be07de7badaaaa0e354aa573
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/controller/SiteController.java
@@ -1,17 +1,15 @@
package com.zy.acs.conveyor.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.acs.common.utils.RedisSupport;
import com.zy.acs.conveyor.controller.vo.SiteTableVo;
import com.zy.acs.conveyor.core.DevpThread;
import com.zy.acs.conveyor.core.cache.MessageQueue;
import com.zy.acs.conveyor.core.cache.OutputQueue;
import com.zy.acs.conveyor.core.cache.SlaveConnection;
import com.zy.acs.conveyor.core.enums.SlaveType;
import com.zy.acs.conveyor.core.enums.TaskType;
import com.zy.acs.conveyor.core.model.Task;
import com.zy.acs.conveyor.core.model.protocol.StaProtocol;
import com.zy.acs.conveyor.core.constant.RedisConveyorConstant;
import com.zy.acs.conveyor.core.model.SafeSignal;
import com.zy.acs.conveyor.core.model.StaProtocol;
import com.zy.acs.conveyor.core.properties.DevpSlave;
import com.zy.acs.conveyor.core.properties.OutputQueue;
import com.zy.acs.conveyor.core.properties.SlaveProperties;
import com.zy.acs.conveyor.core.service.StationService;
import com.zy.acs.conveyor.entity.Devp;
import com.zy.acs.conveyor.service.DevpService;
import com.zy.acs.framework.annotations.ManagerAuth;
@@ -19,10 +17,7 @@
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.*;
/**
 * 输送设备接口
@@ -34,8 +29,16 @@
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private DevpService devpService;
    @Autowired
    private StationService stationService;
    private final RedisSupport redis = RedisSupport.defaultRedisSupport;
    @PostMapping("/table/site")
@@ -45,8 +48,8 @@
        // 内存数据
        Map<Integer, StaProtocol> station = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            station.putAll(devpThread.getStation());
            Map<Integer, StaProtocol> stationMap = stationService.getStationMap(devp.getId());
            station.putAll(stationMap);
        }
        // 持久数据
        List<Devp> devps = devpService.selectList(new EntityWrapper<Devp>().orderBy("dev_no"));
@@ -64,11 +67,11 @@
            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.setEmptyMk(staProtocol.isEmptyMk() != staProtocol.isFullPlt() ? (staProtocol.isEmptyMk() ? "空" : "满") : "-");     // 空板信号
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
            vo.setLocType1(devp.getDevNo() == 102 ? "高" : "低");
            vo.setWeight(staProtocol.getWeight() == null ? 0D : staProtocol.getWeight());
            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() ? (staProtocol.isLow() ? "低" : "高") : "-");     //高低库位
            vo.setAllow((staProtocol.getAllowPut() ? "可放" : "不可放") + "/" + (staProtocol.getAllowTake() ? "可取" : "不可取"));
        }
        return R.ok().add(list);
@@ -96,8 +99,7 @@
    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());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            Map<Integer, StaProtocol> station = stationService.getStationMap(devp.getId());
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (siteId.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
@@ -107,10 +109,11 @@
                    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.setEmptyMk(staProtocol.isEmptyMk() != staProtocol.isFullPlt() ? (staProtocol.isEmptyMk() ? "空" : "满") : "-");     // 空板信号
                    vo.setStaNo(staProtocol.getStaNo());                // 目标站
                    vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
                    vo.setWeight(staProtocol.getWeight() == null ? 0D : staProtocol.getWeight());
                    vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() ? (staProtocol.isLow() ? "低" : "高") : "-");     //高低库位
                    vo.setAllow((staProtocol.getAllowPut() ? "可放" : "不可放") + "/" + (staProtocol.getAllowTake() ? "可取" : "不可取"));
                    return R.ok().add(vo);
                }
            }
@@ -122,11 +125,9 @@
    @ManagerAuth(memo = "修改站点数据")
    public R siteDetlUpdate(@RequestParam Integer siteId,
                            @RequestParam Integer workNo,
                            @RequestParam Integer staNo,
                            @RequestParam String pakMk) {
                            @RequestParam Integer staNo) {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            Map<Integer, StaProtocol> station = stationService.getStationMap(devp.getId());
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (siteId.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
@@ -141,20 +142,56 @@
                    if (staNo != null) {
                        staProtocol.setStaNo(staNo);
                    }
                    if (pakMk != null) {
                        staProtocol.setPakMk(pakMk.equals("Y"));
                    }
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(TaskType.WRITE, staProtocol));
                    if (result) {
                        return R.ok();
                    } else {
                        return R.error("下发命令失败");
                    }
                    redis.push(RedisConveyorConstant.CONVEYOR_TASK_FLAG, staProtocol);
                    return R.ok();
                }
            }
        }
        return R.error("plc已掉线");
    }
    @PostMapping("/detl/safe")
    @ManagerAuth(memo = "补充安全信号")
    public R safe(@RequestParam Integer siteId) {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            Map<Integer, StaProtocol> station = stationService.getStationMap(devp.getId());
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (siteId.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    boolean flag = true;
                    List<DevpSlave.Sta> putSta = devp.getPutSta();
                    List<DevpSlave.Sta> takeSta = devp.getTakeSta();
                    Optional<DevpSlave.Sta> first = takeSta.stream().filter(sta -> sta.getStaNo().equals(siteId)).findFirst();
                    int i = -1;
                    if (first.isPresent()) {
                        i = takeSta.indexOf(first.get());
                        if (i != -1) {
                            flag = false;
                        }
                    }
                    if (i == -1) {
                        first = putSta.stream().filter(sta -> sta.getStaNo().equals(siteId)).findFirst();
                        if (first.isPresent()) {
                            i = putSta.indexOf(first.get());
                            flag = true;
                        }
                    }
                    if (i == -1) {
                        return R.error("此站点无需安全信号");
                    }
                    staProtocol.setSafeSignal(new SafeSignal(i, (short) 0, flag));
                    redis.push(RedisConveyorConstant.CONVEYOR_SAFE_FLAG, staProtocol);
                    return R.ok();
                }
            }
        }
        return R.error("plc已掉线");
    }
}