#
luxiaotao1123
2024-04-03 b67f13b04339ac0cd1a10b07d58e9c30c53b97a2
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package com.zy.asrs.wcs.core.service.impl;
 
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.kernel.AnalyzeService;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.service.MotionService;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol;
import com.zy.asrs.wcs.rcs.thread.DevpThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
 
/**
 * 立体仓库WCS系统主流程业务
 * Created by vincent on 2020/8/6
 */
@Slf4j
@Service("mainService")
@Transactional
public class MainServiceImpl {
 
    @Autowired
    private TaskService taskService;
    @Autowired
    private AnalyzeService analyzeService;
    @Autowired
    private MotionService motionService;
 
    /**
     * 组托
     * 入库站,根据条码扫描生成入库工作档,工作状态 2
     */
    public synchronized void generateInboundWrk() {
 
    }
 
    // 解析入库工作档
    public synchronized void analyzeInBoundTask() {
        for (Task task : taskService.selectWaitAnalyzeInBoundTask()) {
            // generate motion list
            List<Motion> motionList = analyzeService.generateMotion(task);
            if (motionList.isEmpty()) {
                continue;
            }
            motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()));
 
            // 更新工作主档
            task.setTaskSts(TaskStsType.ANALYZE_INBOUND.sts); // 工作状态
            task.setUpdateTime(new Date());
            if (!taskService.updateById(task)) {
                News.error("更新工作档失败!!! [工作号:{}]", task.getTaskNo());
            }
        }
    }
 
    /**
     * 出库 ====>> 同一时间一台穿梭车只能有一个出库任务
     */
    public synchronized void generateOutboundWrkMast() {
        List<Task> tasks = taskService.selectPakOut();
        if (tasks.isEmpty()) {
            return;
        }
 
        for (Task task : tasks) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
            StaProtocol staProtocol = devpThread.getStation().get(Integer.parseInt(task.getOriginSite()));//源站
            StaProtocol staProtocol1 = devpThread.getStation().get(Integer.parseInt(task.getDestSite()));//目标站
            if (staProtocol == null || staProtocol1 == null) {
                continue;
            } else {
                staProtocol = staProtocol.clone();
                staProtocol1 = staProtocol1.clone();
            }
 
//            // 查询站点详细信息
//            BasDevp staDetl = basDevpService.selectById(outSta.getStaNo());
//            if (staDetl == null) {
//                log.error("出库 ===>> 站点在数据库不存在, 站点编号={}", outSta.getStaNo());
//                continue;
//            }
            // 判断堆垛机出库站状态
            if (staProtocol.isAutoing() && !staProtocol.isLoading() && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
 
                if (!(staProtocol1.isAutoing() && !staProtocol1.isLoading() && staProtocol1.getWorkNo() == 0 && staProtocol1.isOutEnable())) {
                    continue;
                }
 
//                //同库位组校验
//                List<String> outerLoc = Utils.getGroupOuterLoc(wrkMast.getSourceLocNo());
//                List<LocMast> outerLocMasts = locMastService.selectNotEmptyLocNos(outerLoc);
//                if (!outerLocMasts.isEmpty()) {
//                    News.info("{}任务,浅库位存在货物,系统等待中", wrkMast.getWrkNo());
//                    continue;//浅库位存在未执行任务
//                }
 
                // generate motion list
                List<Motion> motionList = analyzeService.generateMotion(task);
                if (Cools.isEmpty(motionList)) {
                    log.error("出库 ===>> 暂时没有空闲小车, 任务号={}", task.getTaskNo());
                    continue;
                }
                motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()));
 
                // 更新工作主档
                task.setTaskSts(TaskStsType.ANALYZE_OUTBOUND.sts); // 工作状态
                task.setUpdateTime(new Date());
                if (!taskService.updateById(task)) {
                    News.error("更新工作档失败!!! [工作号:{}]", task.getTaskNo());
                }
 
            }
        }
    }
 
    /**
     * 四向穿梭车电量检测 ===>> 发起充电
     */
    public synchronized void loopShuttleCharge() {
//        ShuttleChargeType shuttleCharge = ShuttleChargeType.CHARGE_1;
//        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
//            // 判断充电位是否被占用
//            if (wrkChargeService.hasShuttleInChargeLoc(shuttleCharge.locNo, shuttle.getId())) {
//                continue;
//            }
//
//            //获取四向穿梭车线程
//            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
//            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
//            if (shuttleProtocol == null) {
//                continue;
//            }
//            if (motionService.selectCount(new EntityWrapper<Motion>()
//                    .eq("device_ctg", DeviceCtgType.SHUTTLE.val())
//                    .eq("device", shuttle.getId())
//                    .eq("motion_sts", MotionStsType.EXECUTING.val())) > 0) {
//                continue;
//            }
//
//            //判断当前小车是否满足需要充电要求
//            if (!shuttleProtocol.isRequireCharge()) {
//                continue;
//            }
//
//            WrkCharge wrkCharge = wrkChargeService.selectWorking(null);
//            if (wrkCharge != null) {//已有充电任务
//                continue;
//            }
//
//            String chargeLocNo = shuttleCharge.locNo;
//            wrkCharge = new WrkCharge();
//            wrkCharge.setShuttleNo(shuttle.getId());
//            wrkCharge.setCharge(shuttleCharge.id);
//            wrkCharge.setWrkNo(commonService.getChargeWorkNo(4));
//            wrkCharge.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
//            wrkCharge.setWrkSts(WrkMastStsType.NEW_CHARGE.sts);   // 充电任务
//            wrkCharge.setIoType(WrkIoTypeType.CHARGE.sts);
//            wrkCharge.setIoPri((double) 10);
//            wrkCharge.setLocNo(chargeLocNo);
//            wrkCharge.setMemo("charge");
//            wrkCharge.setAppeTime(new Date());
//
//            // generate motion list
//            List<Motion> motionList = analyzeService.generateChargeMotion(wrkCharge);
//            if (Cools.isEmpty(motionList)) {
//                News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId());
//                continue;
//            }
//            motionService.batchInsert(motionList, wrkCharge.getUuid(), wrkCharge.getWrkNo());
//
//            wrkCharge.setWrkSts(WrkMastStsType.ANALYZE_CHARGE.sts);
//
//            if (!wrkChargeService.insert(wrkCharge)) {
//                News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId());
//                continue;
//            }
//
//            News.info("保存{}号四向穿梭车充电任务成功!!!", shuttle.getId());
//        }
    }
 
    /**
     * 四向穿梭车电量检测 ===>> 满电后回到待机位
     */
    public synchronized void loopShuttleToStandbyCauseCharge() {
//        ShuttleChargeType shuttleCharge = ShuttleChargeType.CHARGE_1;
//        Integer enoughPower = 90;
//        Config config = configService.selectOne(new EntityWrapper<Config>()
//                .eq("code", "chargeMaxValue")
//                .eq("status", 1));
//        if (config != null) {
//            enoughPower = Integer.parseInt(config.getValue());
//        }
//
//        for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
//            //获取四向穿梭车线程
//            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
//            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
//            if (shuttleProtocol == null) {
//                continue;
//            }
//            // 是否存在充电任务
//            WrkCharge wrkCharge = wrkChargeService.selectWorking(shuttle.getId());
//            if (wrkCharge == null) {
//                continue;
//            }
//
//            if (motionService.selectCount(new EntityWrapper<Motion>()
//                    .eq("device_ctg", DeviceCtgType.SHUTTLE.val())
//                    .eq("device", shuttle.getId())
//                    .eq("motion_sts", MotionStsType.EXECUTING.val())) > 0) {
//                continue;
//            }
//            // 不处于充电中
//            if (!shuttleProtocol.getPlcOutputCharge()) {
//                continue;
//            }
//            // 在充电位
//            if (!shuttleProtocol.getCurrentLocNo().equals(shuttleCharge.locNo)) {
//                continue;
//            }
//            // 电量是否达到满电要求
//            if (shuttleProtocol.getBatteryPower$().intValue() < enoughPower) {
//                continue;
//            }
//            // 已有迁移任务
//            if (wrkChargeService.selectMoveWorking(shuttle.getId()) != null) {
//                continue;
//            }
//
//            // 待机位
//            String standByLocNo = ShuttleTempLocType.query(shuttleProtocol.getShuttleNo().intValue(), 2, Utils.getLev(shuttleCharge.locNo)).locNo;
//
//            shuttleDispatcher.generateShuttleChargeWrkComplete(shuttleProtocol.getShuttleNo().intValue(), standByLocNo);
//
//            wrkCharge.setWrkSts(WrkMastStsType.COMPLETE_CHARGE.sts);
//            wrkCharge.setIoTime(new Date());
//            wrkChargeMapper.updateById(wrkCharge);
//        }
    }
 
}