自动化立体仓库 - WCS系统
*
lsh
2024-10-18 2f80aaf62144f6ea315334335ad46fbe0ab911e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.zy.asrs.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.BasCircularShuttle;
import com.zy.asrs.entity.BasDevpPosition;
import com.zy.asrs.entity.BasRgv;
import com.zy.asrs.entity.BasSte;
import com.zy.asrs.service.BasCircularShuttleService;
import com.zy.asrs.service.BasDevpPositionService;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.utils.SortTheExecutionOfTheCarUtil;
import com.zy.asrs.utils.Utils;
import com.zy.core.DevpThread;
import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.RgvSlave;
import com.zy.core.model.SteSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.SteCommand;
import com.zy.core.model.protocol.RgvProtocol;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.model.protocol.SteProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.RgvThread;
import com.zy.core.thread.SiemensDevpThread;
import com.zy.core.thread.SteThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 立体仓库WCS系统主流程业务
 * Created by vincent on 2020/8/6
 */
@Slf4j
@Service("mainService")
@Transactional
public class MainServiceImpl {
 
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private BasRgvServiceImpl basRgvService;
    @Autowired
    private BasDevpPositionService basDevpPositionService;
    @Autowired
    private BasCircularShuttleService basCircularShuttleService;
    /**
     * 站点任务检测  下发小车取放任务
     */
    public synchronized void updateStePosition() {
        try{
            boolean sign = false;
            Integer rgvNo = 0;
            List<BasCircularShuttle> basCircularShuttleList = basCircularShuttleService.selectList(new EntityWrapper<BasCircularShuttle>().orderBy("rgv_id", true));
            for (BasCircularShuttle basCircularShuttle : basCircularShuttleList){
                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo());
                RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
                if (rgvProtocol.modeType != RgvModeType.AUTO || (rgvProtocol.getStatusType() != RgvStatusType.IDLE && rgvProtocol.getStatusType() != RgvStatusType.SOS1001) ){
                    sign = true;
                } else {
                    rgvNo = basCircularShuttle.getRgvNo();
                    break;
                }
            }
            if (sign && rgvNo!=0){
                int[][] ints = new int[basCircularShuttleList.size()][2];
                for (BasCircularShuttle basCircularShuttle : basCircularShuttleList){
                    ints[basCircularShuttle.getRgvNo()-1] = new int[]{basCircularShuttle.getRgvNo(),basCircularShuttle.getRgvId()};
                }
                String[] oldList = new String[ints.length];
                for (int[] rgv : ints){
                    oldList[rgv[0]-1] = Arrays.toString(rgv);
                }
                int[][] rgvList = SortTheExecutionOfTheCarUtil.ReorderSteId(ints, rgvNo);
                String[] newList = new String[rgvList.length];
                for (int[] rgv : rgvList){
                    newList[rgv[0]-1] = Arrays.toString(rgv);
                }
 
                log.info("更新小车排序信息:原始小车号rgvNo={},小车重新排序信息={},小车原始排序信息={}",rgvNo,Arrays.toString(newList),Arrays.toString(oldList));
                for (BasCircularShuttle basCircularShuttle : basCircularShuttleList){
                    int[] rgv = rgvList[basCircularShuttle.getRgvNo() - 1];
                    basCircularShuttle.setRgvId(rgv[1]);
                    basCircularShuttleService.updateById(basCircularShuttle);
                }
            }
 
        } catch (Exception e) {
            log.error("自动更新小车排序信息失败,异常:"+e);
        }
    }
    /**
     * 站点任务检测  下发小车取放任务
     */
    public synchronized void DevpTaskNoRun() {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历空板入库口
            for (DevpSlave.Sta sta : devp.getInSta()) {
                // 获取空板入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(sta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
            }
        }
    }
 
    public synchronized void loopSteCharge() {
        for (RgvSlave rgv : slaveProperties.getRgv()) {
            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgv.getId());
            RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
            BasRgv basRgv = basRgvService.selectById(rgv.getId());
            if (Cools.isEmpty(rgvProtocol, basRgv)) { continue; }
            try {
                // 在线 空闲   无作业标记   不在充电
                if (rgvProtocol.getMode() == 0
                        || !rgvProtocol.statusType.equals(RgvStatusType.IDLE)
                        || basRgv.getPakMk().equals("Y")
//                        || steProtocol.getChargeStatus() == 1
                ) {
                    continue;
                }
            } catch (Exception e) {
                News.error("fail", e);
            }
        }
    }
}