From 903825e4434a91ef5d29f8565551dbcc0a4eadaa Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期三, 03 四月 2024 12:49:40 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java |  234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 234 insertions(+), 0 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
index 3ddd277..b804446 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
@@ -1,8 +1,24 @@
 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绯荤粺涓绘祦绋嬩笟鍔�
@@ -13,6 +29,224 @@
 @Transactional
 public class MainServiceImpl {
 
+    @Autowired
+    private TaskService taskService;
+    @Autowired
+    private AnalyzeService analyzeService;
+    @Autowired
+    private MotionService motionService;
 
+    /**
+     * 缁勬墭
+     * 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗o紝宸ヤ綔鐘舵�� 2
+     */
+    public synchronized void generateInboundWrk() {
+
+    }
+
+    // 瑙f瀽鍏ュ簱宸ヤ綔妗�
+    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("鏇存柊宸ヤ綔妗eけ璐ワ紒锛侊紒 [宸ヤ綔鍙凤細{}]", 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("鏇存柊宸ヤ綔妗eけ璐ワ紒锛侊紒 [宸ヤ綔鍙凤細{}]", 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);
+//        }
+    }
 
 }

--
Gitblit v1.9.1