*
lsh
2025-11-25 c289447144f4599fe2e13d342c28a3c4d49f750f
src/main/java/com/zy/asrs/controller/RgvController.java
@@ -4,24 +4,31 @@
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.domain.param.EnergyGatheringRingParam;
import com.zy.asrs.domain.param.RgvCircularShuttleParam;
import com.zy.asrs.domain.param.RgvWrkMastParam;
import com.zy.asrs.domain.param.RingThroughParam;
import com.zy.asrs.entity.BasDevpPosition;
import com.zy.asrs.service.BasDevpPositionService;
import com.zy.core.cache.RgvErrCache;
import com.zy.core.cache.RgvStatusCache;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.cache.TaskProtocolCache;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.BasRgvErrMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.service.impl.MainServiceImpl;
import com.zy.asrs.utils.Utils;
import com.zy.core.cache.*;
import com.zy.core.enums.RgvModeType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.RgvSlave;
import com.zy.core.model.protocol.RgvProtocol;
import com.zy.core.model.protocol.RgvTaskProtocol;
import com.zy.core.model.protocol.TaskProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.RgvThread;
import com.zy.core.thread.SiemensDevpThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.*;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -35,6 +42,24 @@
    @Autowired
    private BasDevpPositionService basDevpPositionService;
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private BasRgvErrMapper basRgvErrMapper;
    @Autowired
    private BasRgvOptService basRgvOptService;
    @Autowired
    private BasRgvService basRgvService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private MainServiceImpl mainService;
    @Value("${constant-parameters.trackEntireLength}")
    private Long trackEntireLength;
    @GetMapping("/status/all")
//    @ManagerAuth(memo = "全部信息")
    public R allStatus(){
@@ -342,28 +367,37 @@
        return R.ok("任务生成成功");
    }
    @PostMapping("/ring/through/rgv/position/data")
//    @ManagerAuth(memo = "小车位置信息")
//    @ManagerAuth(memo = "环穿位置信息")
    public R ringThroughRgv(){
        List<RingThroughParam> result = new ArrayList<>();
        ConcurrentHashMap<Integer, RgvProtocol> allRgvStatus = RgvStatusCache.getAllRgvStatus();
        for (RgvProtocol rgvProtocol : allRgvStatus.values()){
        for (RgvSlave rgv : slaveProperties.getRgv()) {
//        for (int i = 1;i<2;i++) {
//            // 获取RGV信息
            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
            if (rgvThread == null) {
                continue;
            }
            RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(rgv.getId());
            RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(rgv.getId());
            if (rgvTaskProtocol == null) {
                continue;
            }
            RingThroughParam ringThroughParam = new RingThroughParam();
            ringThroughParam.setIndex(rgvProtocol.getRgvNo());
            ringThroughParam.setIndex(rgv.getId());
//            ringThroughParam.setIndex(i);
//            double[] doubles = Utils.RingThroughXY2(perimeter, NumUtils.GetRandomIntInRange(183));
//            double[] doubles = Utils.RingThroughXYRgv(perimeter, perimeter-rgvProtocol.RgvPos.doubleValue());
//            double[] doubles = Utils.getRgvPosNew(perimeter, rgvProtocol.RgvPos.doubleValue());
//            double[] doubles = Utils.RingThroughXY2(183.0, 100*i );
            double[] doubles = Utils.getRgvPosNew(trackEntireLength, rgvProtocol.RgvPos.doubleValue());
            ringThroughParam.setValueX(rgvProtocol.getRgvNo()*100*1D);
            ringThroughParam.setValueY(rgvProtocol.getRgvNo()*100*2D);
            ringThroughParam.setValueX(doubles[0]);
            ringThroughParam.setValueY(doubles[1]);
            ringThroughParam.setModeColor(rgvProtocol.modeType.color);
            ringThroughParam.setStatusColor(rgvProtocol.statusType.color);
            if (rgvProtocol.getModeType() == RgvModeType.AUTO){
                ringThroughParam.setAnimation(2);
            }
            result.add(ringThroughParam);
        }
        return R.ok().add(result);
@@ -374,40 +408,44 @@
    //  站点位置信息
    public R ringThroughDev(){
        List<RingThroughParam> result = new ArrayList<>();
        ArrayList<Integer> arrayList = new ArrayList<Integer>() {{
            add(1001);
            add(1002);
            add(1003);
            add(1004);
            add(1005);
            add(1006);
            add(1007);
            add(1008);
            add(1009);
            add(1010);
            add(1011);
            add(1012);
            add(1013);
            add(1014);
            add(1015);
            add(1016);
            add(1017);
            add(1018);
            add(1019);
            add(1020);
            add(1021);
            add(1022);
            add(1023);
        }};
        for (Integer staNo : arrayList){
        List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<>());
        for (BasDevpPosition basDevpPosition : basDevpPositions){
//            if (basDevpPosition.getDevRegion() == 0){
//                continue;
//            }
            RingThroughParam ringThroughParam = new RingThroughParam();
            ringThroughParam.setIndex(staNo);
            ringThroughParam.setModeColor("#FFFFFF");
            ringThroughParam.setStatusColor("#FFFFFF");
            try{
                BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no",basDevpPosition.getDevNo()));
                if (basDevp.getAutoing().equals("Y")){
                    if (basDevp.getLoading().equals("Y")){
                        ringThroughParam.setModeColor("#ab1839");
                        ringThroughParam.setStatusColor("#ab1839");
                    }
                    if (basDevp.getLoading().equals("N")){
                        ringThroughParam.setModeColor("#27AE60");
                        ringThroughParam.setStatusColor("#27AE60");
                    }
                } else {
                    ringThroughParam.setModeColor("#C0392B");
                    ringThroughParam.setStatusColor("#C0392B");
                }
            } catch (Exception e){
                System.out.println(e.getMessage());
                ringThroughParam.setModeColor("#000000");
                ringThroughParam.setStatusColor("#000000");
            }
            ringThroughParam.setIndex(basDevpPosition.getDevNo());
//            double[] doubles = Utils.RingThroughXYSta(perimeter, perimeter-basDevpPosition.getPlcPosition());
//            ringThroughParam.setValueX(doubles[0]>50? doubles[0]+6:doubles[0]-1);
//            ringThroughParam.setValueY(doubles[1]>50? doubles[1]+6:doubles[1]-1);
//            double[] doubles = Utils.getRgvPosNew(basDevpPosition.getDevNo(),perimeter, basDevpPosition.getPlcPosition());
            ringThroughParam.setValueX(staNo*100*1D);
            ringThroughParam.setValueY(staNo*100*2D);
            double[] doubles = Utils.getRgvPosNew(basDevpPosition.getDevNo(),trackEntireLength, basDevpPosition.getPlcPosition());
            ringThroughParam.setValueX(doubles[0]);
            ringThroughParam.setValueY(doubles[1]);
            result.add(ringThroughParam);
        }
        return R.ok().add(result);
@@ -416,30 +454,178 @@
    @PostMapping("/ring/through/track/position/data")
//    @ManagerAuth(memo = "轨道PLC状态信息")
    public R wnergyGatheringRingParamTrack(){
        return R.ok();
        List<EnergyGatheringRingParam> result = new ArrayList<>();
        try{
            for (DevpSlave devp : slaveProperties.getDevp()) {
                if (devp.getId()!=1){
                    break;
                }
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                if (devpThread.isResult()){
                    if (true){
                        EnergyGatheringRingParam energyGatheringRingParam = new EnergyGatheringRingParam();
                        energyGatheringRingParam.setTrackColor("rgba(0, 230, 118, 0.5)");
                        energyGatheringRingParam.setRadiationColor("rgba(0, 230, 118, 0.5)");
                        result.add(energyGatheringRingParam);
                    } else {
                        EnergyGatheringRingParam energyGatheringRingParam = new EnergyGatheringRingParam();
                        energyGatheringRingParam.setTrackColor("rgba(0, 230, 118, 0.5)");
                        energyGatheringRingParam.setRadiationColor("rgba(0, 230, 118, 0.5)");
                        result.add(energyGatheringRingParam);
                    }
                }
            }
            if (result.isEmpty()){
                EnergyGatheringRingParam energyGatheringRingParam = new EnergyGatheringRingParam();
                energyGatheringRingParam.setTrackColor("rgba(0, 0, 0, 81)");
                energyGatheringRingParam.setRadiationColor("rgba(0, 0, 0, 81)");
                result.add(energyGatheringRingParam);
            }
        } catch (Exception e){
            EnergyGatheringRingParam energyGatheringRingParam = new EnergyGatheringRingParam();
            energyGatheringRingParam.setTrackColor("rgba(0, 0, 0, 81)");
            energyGatheringRingParam.setRadiationColor("rgba(0, 0, 0, 81)");
            result.add(energyGatheringRingParam);
        }
        return R.ok().add(result);
    }
    @PostMapping("/ring/through/task/wrk/mast/position/data")
//    @ManagerAuth(memo = "作业信息")
    public R ringThroughTaskWrkMast(){
        return R.ok();
        List<RgvWrkMastParam> result = new ArrayList<>();
        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>());
        for (WrkMast wrkMast : wrkMasts){
            RgvWrkMastParam rgvWrkMastParam = new RgvWrkMastParam(wrkMast);
            if (Cools.isEmpty(rgvWrkMastParam.getRgvNo())){
                rgvWrkMastParam.setRgvSts("未绑定");
            } else {
                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvWrkMastParam.getRgvNo());
                if (rgvThread == null) {
                    rgvWrkMastParam.setRgvSts("未知");
                } else {
                    RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(rgvWrkMastParam.getRgvNo());
                    RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(rgvWrkMastParam.getRgvNo());
                    if (rgvTaskProtocol == null) {
                        rgvWrkMastParam.setRgvSts("未知");
                    } else {
                        rgvWrkMastParam.setRgvSts(rgvProtocol.statusType.desc);
                    }
                }
            }
            result.add(rgvWrkMastParam);
        }
        return R.ok().add(result);
    }
    @PostMapping("/ring/through/task/wrk/mast/position/data/v1")
//    @ManagerAuth(memo = "作业信息")
    public R ringThroughTaskWrkMastV1(){
        return R.ok();
        List<BasRgvOpt> result = new ArrayList<>();
        for (int i = 1 ; i<11; i ++){
            BasRgvOpt basRgvOpt = basRgvOptService.selectOne(new EntityWrapper<BasRgvOpt>().eq("rgv_no", i).orderBy("id", false));
            if (basRgvOpt!=null){
                result.add(basRgvOpt);
            }
        }
        return R.ok().add(result);
    }
    @PostMapping("/task/rgv/circular/shuttle/mast/position/data")
//    @ManagerAuth(memo = "作业信息")
    public R rgvCircularShuttle(){
        return R.ok();
        List<RgvCircularShuttleParam> result = new ArrayList<>();
//        List<BasCircularShuttle> basCircularShuttleList = basCircularShuttleService.selectList(new EntityWrapper<>());
//        for (BasCircularShuttle basCircularShuttle : basCircularShuttleList){
//            RgvCircularShuttleParam rgvCircularShuttleParam = new RgvCircularShuttleParam(basCircularShuttle);
//            if (!Cools.isEmpty(rgvCircularShuttleParam.getRgvNo())){
//                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvCircularShuttleParam.getRgvNo());
//                if (rgvThread != null) {
//                    RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
//                    if (rgvProtocol != null) {
//                        rgvCircularShuttleParam.setPosition(rgvProtocol.getRgvPos());
//                        if (rgvCircularShuttleParam.getStatus()==0){
//                            rgvCircularShuttleParam.setStatus$(rgvProtocol.statusType.desc);
//                        }
//                        if (rgvProtocol.getAlarmList().isEmpty()){
//                            rgvCircularShuttleParam.setError(0);
//                            rgvCircularShuttleParam.setError$("-");
//                        } else {
//                            StringBuilder alarmList = new StringBuilder();
//                            for (Integer alarm : rgvProtocol.getAlarmList()){
//                                BasRgvErr rgvErr = basRgvErrMapper.selectById(alarm);
//                                alarmList.append((rgvErr==null || rgvErr.getErrName()==null)? "未知异常:"+alarm:rgvErr.getErrName());
//                                if (alarm.equals(rgvProtocol.getAlarmList().get(rgvProtocol.getAlarmList().size() - 1))){
//                                    break;
//                                }
//                                alarmList.append("---");
//                            }
//                            rgvCircularShuttleParam.setError$(alarmList.toString());
//                        }
//                    }
//                }
//            }
//            result.add(rgvCircularShuttleParam);
//        }
        return R.ok().add(result);
    }
    @PostMapping("/task/rgv/circular/shuttle/mast/position/data/v1")
//    @ManagerAuth(memo = "作业信息")
    public R rgvCircularShuttleV1(){
//        List<BasRgvErrLog> result = new ArrayList<>();
//        for (int i = 1 ; i<11; i ++){
//            BasRgvErrLog basRgvErrLog = basRgvErrLogService.selectOne(new EntityWrapper<BasRgvErrLog>().eq("rgv_no", i).orderBy("id", false));
//            if (basRgvErrLog!=null){
//                result.add(basRgvErrLog);
//            }
//        }
        return R.ok();
    }
    @PostMapping("/disable/rgv/status")
//    @ManagerAuth(memo = "修改RGV状态")
    public R rgvDisableStatus(@RequestParam Integer rgvNo,
                              @RequestParam Integer status){
//        log.info("/disable/rgv/status===》修改RGV状态!!!rgvNo:{},status:{},data:{}",rgvNo,status,new Date());
//        BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_no", rgvNo));
//        if (basCircularShuttle == null){
//            return R.error().add("未找到此RGV,异常!!!");
//        }
//        basCircularShuttle.setStatus(status);
//        basCircularShuttleService.updateById(basCircularShuttle);
        return R.ok();
    }
    @PostMapping("/disable/task/delete")
//    @ManagerAuth(memo = "删除任务")
    public R taskDisabledelete(@RequestParam Long wrkNo){
//        log.info("/disable/task/delete===》删除任务!!!wrkNo:{},data:{}",wrkNo,new Date());
        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo));
        if (Cools.isEmpty(wrkMast)){
            return R.error().add("未找到此任务,异常!!!");
        }
        wrkMastService.deleteById(wrkMast);
        return R.ok();
    }
    @PostMapping("/disable/task/delete1")
//    @ManagerAuth(memo = "初始化任务")
    public R taskDisabledelete1(@RequestParam Long wrkNo){
        Date now = new Date();
//        log.info("/disable/task/delete1===》初始化任务!!!wrkNo:{},data:{}",wrkNo,new Date());
        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo));
        if (Cools.isEmpty(wrkMast)){
            return R.error().add("未找到此任务,异常!!!");
        }
        wrkMast.setWrkSts(1L);
//        wrkMast.setRgvNo(0);
        wrkMast.setAppeTime(now);
        wrkMast.setLogErrTime(now);
        if (wrkMastService.updateById(wrkMast)){
            return R.ok();
        }
        return R.error("初始化失败!!!");
    }
}