From 40d95599c1ac6ef89d465e031132d9c627a7f0bc Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期三, 19 十一月 2025 13:38:54 +0800
Subject: [PATCH] #增加出入库模式

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 1274 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 830 insertions(+), 444 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 7a27c3c..e9dd9ac 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1,37 +1,48 @@
 package com.zy.asrs.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.Cools;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
-import com.zy.asrs.mapper.WaitPakinMapper;
+import com.zy.asrs.mapper.BasCrnErrorMapper;
 import com.zy.asrs.mapper.WrkMastMapper;
 import com.zy.asrs.service.*;
+import com.zy.asrs.utils.Utils;
+import com.zy.common.model.LocTypeDto;
+import com.zy.common.model.MatDto;
+import com.zy.common.model.SearchLocParam;
 import com.zy.common.model.StartupDto;
+import com.zy.common.service.CommonService;
+import com.zy.common.utils.CollectionUtils;
+import com.zy.common.utils.HttpHandler;
+import com.zy.common.utils.News;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.CrnThread;
+import com.zy.core.DevpThread;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.*;
-import com.zy.core.model.CrnSlave;
-import com.zy.core.model.DevpSlave;
-import com.zy.core.model.Task;
-import com.zy.core.model.command.CrnCommand;
+import com.zy.core.model.*;
+import com.zy.core.model.command.LedCommand;
+import com.zy.core.model.command.LiftCommand;
 import com.zy.core.model.protocol.CrnProtocol;
+import com.zy.core.model.protocol.LiftProtocol;
 import com.zy.core.model.protocol.StaProtocol;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.BarcodeThread;
-import com.zy.core.thread.CrnThread;
-import com.zy.core.thread.DevpThread;
+import com.zy.core.thread.LedThread;
+import com.zy.core.thread.SiemensDevpThread;
+import com.zy.system.service.ConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
+import java.util.*;
 
 /**
  * 绔嬩綋浠撳簱WCS绯荤粺涓绘祦绋嬩笟鍔�
@@ -41,6 +52,8 @@
 @Service("mainService")
 public class MainServiceImpl {
 
+    public static final long COMMAND_TIMEOUT = 5 * 1000;
+
     @Autowired
     private CommonService commonService;
     @Autowired
@@ -48,9 +61,11 @@
     @Autowired
     private WrkMastMapper wrkMastMapper;
     @Autowired
+    private WrkMastLogService wrkMastLogService;
+    @Autowired
     private WrkDetlService wrkDetlService;
     @Autowired
-    private WaitPakinMapper waitPakinMapper;
+    private WrkDetlLogService wrkDetlLogService;
     @Autowired
     private LocMastService locMastService;
     @Autowired
@@ -60,487 +75,454 @@
     @Autowired
     private BasDevpService basDevpService;
     @Autowired
-    private JdbcTemplate jdbcTemplate;
+    private LocDetlService locDetlService;
+    @Autowired
+    private BasErrLogService basErrLogService;
+    @Autowired
+    private BasCrnErrorMapper basCrnErrorMapper;
+    @Autowired
+    private WrkMastService wrkMastService;
+    @Autowired
+    private ConfigService configService;
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Value("${wms.url}")
+    private String wmsUrl;
 
     /**
+     * 缁勬墭
      * 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗o紝宸ヤ綔鐘舵�� 2
      */
-    @Transactional
-    public void generateStoreWrkFile() {
+    public synchronized void generateStoreWrkFile(Integer mark) {
         // 鏍规嵁杈撻�佺嚎plc閬嶅巻
         for (DevpSlave devp : slaveProperties.getDevp()) {
             // 閬嶅巻鍏ュ簱鍙�
             for (DevpSlave.Sta inSta : devp.getInSta()) {
                 // 鑾峰彇鏉$爜鎵弿浠俊鎭�
                 BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
-                String barcode = barcodeThread.getBarcode();
-                // 鑾峰彇鍏ュ簱绔欎俊鎭�
-                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
-                StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
-                // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
-                if (staProtocol.isAutoing() && staProtocol.isLoading()
-                        && !staProtocol.isEmptyMk() && staProtocol.isInreq1() && staProtocol.getWorkNo()==0
-                        && staProtocol.isPakMk() && !Cools.isEmpty(barcode)) {
-                    // 鍒ゆ柇閲嶅宸ヤ綔妗�
-                    WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
-                    if (wrkMast != null) {
-                        log.warn("宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast.getWrkNo());
-                        continue;
-                    }
-                    // 鑾峰彇鍏ュ簱閫氱煡妗�
-                    List<WaitPakin> waitPakins = waitPakinMapper.selectList(new EntityWrapper<WaitPakin>().eq("barcode", barcode));
-                    if (waitPakins.isEmpty()) {
-                        log.warn("鏃犳鍏ュ簱鏉$爜鏁版嵁銆傛潯鐮佸彿={}", barcode);
-                        continue;
-                    }
-                    // 宸ヤ綔鍙�
-                    int workNo = commonService.getWorkNo(0);
-                    // 妫�绱㈠簱浣�
-                    List<String> matNos = waitPakins.stream().map(WaitPakin::getMatnr).distinct().collect(Collectors.toList());
-                    StartupDto startupDto = commonService.getLocNo(1, 1, inSta.getStaNo(), matNos);
-                    // 鎻掑叆宸ヤ綔鏄庣粏妗�
-                    wrkDetlService.createWorkDetail(workNo, waitPakins, barcode);
-
-                    // 鎻掑叆宸ヤ綔涓绘。
-                    wrkMast = new WrkMast();
-                    wrkMast.setWrkNo(workNo);
-                    wrkMast.setIoTime(new Date());
-                    wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵�侊細2.璁惧涓婅蛋
-                    wrkMast.setIoType(1); // 鍏ュ嚭搴撶姸鎬侊細1.鍏ュ簱
-                    wrkMast.setIoPri(10D); // 浼樺厛绾э細10
-                    wrkMast.setCrnNo(startupDto.getCrnNo());
-                    wrkMast.setSourceStaNo(startupDto.getSourceStaNo());
-                    wrkMast.setStaNo(startupDto.getStaNo());
-                    wrkMast.setLocNo(startupDto.getLocNo());
-                    wrkMast.setBarcode(barcode); // 鎵樼洏鐮�
-                    wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
-                    wrkMast.setPicking("N"); // 鎷f枡
-                    wrkMast.setExitMk("N"); // 閫�鍑�
-                    wrkMast.setEmptyMk("N"); // 绌烘澘
-                    wrkMast.setLinkMis("N");
-//                    wrkMast.setCtnType(sourceStaNo.getCtnType()); // 瀹瑰櫒绫诲瀷
-                    // 鎿嶄綔浜哄憳鏁版嵁
-                    wrkMast.setAppeTime(new Date());
-                    wrkMast.setModiTime(new Date());
-                    Integer insert = wrkMastMapper.insert(wrkMast);
-                    if (insert == 0) {
-                        throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
-                    }
-                    // 鏇存柊鐩爣搴撲綅鐘舵��
-                    LocMast locMast = locMastService.selectById(startupDto.getLocNo());
-                    locMast.setLocSts("S"); // S.鍏ュ簱棰勭害
-                    locMast.setModiTime(new Date());
-                    if (!locMastService.updateById(locMast)){
-                        throw new CoolException("鏀瑰彉搴撲綅鐘舵�佸け璐�");
-                    }
-
-                    // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
-
-                    // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
-                    barcodeThread.setBarcode("");
-                    staProtocol.setWorkNo(workNo);
-                    staProtocol.setStaNo(startupDto.getStaNo());
-                    staProtocol.setPakMk(false);
-                    staProtocol.setInreq1(false);
-                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol));
-                    if (!result) {
-                        throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
-                    }
-
+                if (barcodeThread == null) {
+                    continue;
                 }
 
+                // 鑾峰彇鍏ュ簱绔欎俊鎭�
+                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+                StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
+                if (staProtocol == null) {
+                    continue;
+                } else {
+                    staProtocol = staProtocol.clone();
+                }
+
+                //LED
+                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
+
+                // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
+                if (!staProtocol.isLoading()) {
+                    continue;
+                }
+
+                if (staProtocol.isAutoing()
+                        && staProtocol.isInEnable()
+                        && !staProtocol.isEmptyMk()
+                        && staProtocol.getWorkNo() == 9999
+                        && staProtocol.isPakMk()) {
+                    News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
+
+                    String barcode = barcodeThread.getBarcode();
+                    if (!Cools.isEmpty(barcode)) {
+                        News.info("" + mark + " - 1" + " - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", inSta.getBarcode(), barcode);
+                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
+                            News.info("" + mark + " - 2" + " - 鎵爜澶辫触1 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
+                            // led 寮傚父鏄剧ず
+                            if (ledThread != null) {
+                                String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
+                            }
+                            continue;
+                        }
+                    } else {
+                        News.info("" + mark + " - 3" + " - 鎵爜澶辫触2 ===>> {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{},绔欑偣:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
+                        // led 寮傚父鏄剧ず
+                        if (ledThread != null) {
+                            String errorMsg = "鎵爜澶辫触锛岃閲嶈瘯";
+                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
+                        }
+                        continue;
+                    }
+
+                    // 鍒ゆ柇閲嶅宸ヤ綔妗�
+                    WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
+                    //杩囨护鍒ゆ柇锛岄槻姝㈡嫞鏂欏啀鍏ュ簱璐х墿锛岀粡杩囧叆搴撶珯鍐嶅叆搴撴椂锛岃閫�鍥炲埌閫�搴撶珯
+                    WrkMast wrkMast1 = wrkMastMapper.selectPakInStepBarcode(barcode);
+                    if (wrkMast1 != null) {
+                        if (wrkMast1.getIoType() == 103 || wrkMast1.getIoType() == 107 || wrkMast1.getIoType() == 104) {
+                            continue;
+                        }
+                    }
+                    if (wrkMast != null) {
+                        News.error("" + mark + " - 4" + " - 宸ヤ綔妗d腑宸插瓨鍦ㄨ绔欑姸鎬佷负锛� 2.璁惧涓婅蛋 锛夌殑鏁版嵁,宸ヤ綔鍙�={}", wrkMast.getWrkNo());
+
+                        // led 寮傚父鏄剧ず
+                        if (ledThread != null) {
+                            String errorMsg = "宸ヤ綔妗e凡瀛樺湪璇ユ潯鐮佸彿===>>" + barcode;
+                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
+                        }
+                        continue;
+                    }
+
+                    LiftProtocol liftProtocol = devpThread.getLiftStatus();
+                    if(liftProtocol == null) {
+                        continue;
+                    }
+
+                    if (liftProtocol.getMode() != 1) {
+                        continue;
+                    }
+
+                    if (liftProtocol.getDeviceStatus() != 0) {
+                        continue;
+                    }
+
+                    if (liftProtocol.getWorkNo() > 0) {
+                        continue;
+                    }
+
+                    try {
+                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
+
+                        SearchLocParam param = new SearchLocParam();
+                        param.setBarcode(barcode);
+                        param.setIoType(1);
+                        param.setSourceStaNo(inSta.getStaNo());
+                        param.setLocType1(locTypeDto.getLocType1());
+                        String response = new HttpHandler.Builder()
+                                .setUri(wmsUrl)
+                                .setPath("/rpc/pakin/loc/v1")
+                                .setJson(JSON.toJSONString(param))
+                                .build()
+                                .doPost();
+                        JSONObject jsonObject = JSON.parseObject(response);
+                        if (jsonObject.getInteger("code").equals(200)) {
+                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+
+                            WrkMast currentWrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", dto.getWorkNo()));
+                            if (currentWrkMast == null) {
+                                throw new CoolException("WMS鐢熸垚浠诲姟鍚庯紝WCS鏌ヨ涓虹┖");
+                            }
+
+                            Integer staNo = Utils.getStaNoByLocNo(dto.getLocNo());
+
+                            LiftCommand command = new LiftCommand();
+                            command.setWorkNo(dto.getWorkNo());
+                            command.setSourceStaNo(inSta.getStaNo());
+                            command.setTargetStaNo(staNo);
+
+                            barcodeThread.setBarcode("");
+                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, command));
+                            if (!result) {
+                                throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+                            }
+
+                            currentWrkMast.setWrkSts(3L);// 3.璁惧鎵ц涓�
+                            currentWrkMast.setCrnStrTime(new Date());
+                            wrkMastService.updateById(currentWrkMast);
+                        } else {
+                            News.error("" + mark + " - 5" + " - 璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
+
+                            // led 寮傚父鏄剧ず
+                            if (ledThread != null) {
+                                String errorMsg = jsonObject.getString("msg");
+                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
+                            }
+                        }
+
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    }
+
+                } else {
+                    News.errorNoLog("" + mark + " - 6" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isAutoing() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                            + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk() + "銆佸伐浣滃彿锛�" + staProtocol.getWorkNo()
+                            + "銆侀攣瀹氭爣璁�" + staProtocol.isPakMk());
+                }
 
             }
         }
+        News.infoNoLog("" + mark + " - 0" + " - 缁勬墭  ===銆嬫墽琛屽畬鎴�");
 
     }
-
 
     /**
      * 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱
      */
-    public void stnToCrnStnPick(){
-        for (DevpSlave devp : slaveProperties.getDevp()) {
-            // 閬嶅巻鎷f枡鍏ュ簱鍙�
-            for (DevpSlave.Sta pickSta : devp.getPickSta()) {
-                // 鑾峰彇鎷f枡鍏ュ簱绔欎俊鎭�
-                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
-                StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
-
-                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInreq1()
-                    && staProtocol.getWorkNo() > 0 && staProtocol.isPakMk()){
-                    WrkMast wrkMast = wrkMastMapper.selectPickStep(staProtocol.getWorkNo());
-                    if (wrkMast == null) {
-                        // 鏃犳嫞鏂欐暟鎹�
+    public synchronized void stnToCrnStnPick(Integer mark) {
+        try {
+            for (DevpSlave devp : slaveProperties.getDevp()) {
+                // 閬嶅巻鎷f枡鍏ュ簱鍙�
+                for (DevpSlave.Sta pickSta : devp.getPickSta()) {
+                    // 鑾峰彇鎷f枡鍏ュ簱绔欎俊鎭�
+                    SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+                    StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
+                    if (staProtocol == null) {
                         continue;
-                    }
-                    if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 1070)
-                        || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo()) ) {
-                        continue;
-                    }
-                    // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
-                    if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) {
-                        throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
-                    }
-                    // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
-                    if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
-                        throw new CoolException("淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
-                    }
-                    // 鑾峰彇鐩爣绔�
-                    Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
-                            .eq("type_no", wrkMast.getIoType() - 50)
-                            .eq("stn_no", wrkMast.getStaNo()) // 浣滀笟绔欑偣 = 鎷f枡鍑哄簱鐨勭洰鏍囩珯
-                            .eq("crn_no", wrkMast.getCrnNo()); // 鍫嗗灈鏈哄彿
-                    StaDesc staDesc = staDescService.selectOne(wrapper);
-                    if (Cools.isEmpty(staDesc)) {
-                        throw new CoolException("鍏ュ簱璺緞涓嶅瓨鍦�");
-                    }
-                    // 鍫嗗灈鏈虹珯鐐�(鐩爣绔�)
-                    Integer staNo = staDesc.getCrnStn();
-                    // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
-                    wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
-                    wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
-                    wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 婧愮珯
-                    wrkMast.setStaNo(staNo); // 鐩爣绔�
-                    wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
-                    wrkMast.setSourceLocNo(""); // 婧愬簱浣嶆竻绌�
-                    wrkMast.setModiTime(new Date());
-                    if (wrkMastMapper.updateById(wrkMast) == 0) {
-                        throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
-                    }
-                    // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
-                    LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
-                    locMast.setLocSts("Q");
-                    locMast.setModiTime(new Date());
-                    if (!locMastService.updateById(locMast)) {
-                        throw new CoolException("淇敼搴撲綅鐘舵�佸け璐�");
+                    } else {
+                        staProtocol = staProtocol.clone();
                     }
 
-                    // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
-                    staProtocol.setWorkNo(wrkMast.getWrkNo());
-                    staProtocol.setStaNo(wrkMast.getStaNo());
-                    staProtocol.setPakMk(false);
-                    staProtocol.setInreq1(false);
-                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol));
-                    if (!result) {
-                        throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
-                    }
+                    if (staProtocol.isAutoing()
+                            && staProtocol.isLoading()
+                            && staProtocol.isInEnable()
+                            && staProtocol.getWorkNo() > 0
+                            && staProtocol.isPakMk()) {
+                        News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
 
-                }
-
-            }
-
-        }
-    }
-
-    /**
-     * 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯
-     */
-    public void crnStnToOutStn() {
-        for (DevpSlave devp : slaveProperties.getDevp()) {
-            // 閬嶅巻鎷f枡鍏ュ簱鍙�
-            for (DevpSlave.Sta outSta : devp.getOutSta()) {
-                // 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅
-                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
-                StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo());
-                if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
-                    // 鏌ヨ宸ヤ綔妗�
-                    WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
-                    if (wrkMast == null) {
-                        continue;
-                    }
-                    // 鍒ゆ柇宸ヤ綔妗f潯浠�
-                    if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
-                        continue;
-                    }
-                    // 鍒ゆ柇鍚婅溅鏄惁瀹為檯宸插畬鎴愶紝涓旂數鑴戠姸鎬佸湪move涓紝浠ュ鐢佃剳杩涜鏇存柊宸ヤ綔妗�
-                    CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
-                    CrnProtocol crnProtocol = crnThread.getCrnProtocol();
-                    if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) {
-                        // 绉诲姩涓�
-                        continue;
-                    }
-                    // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触 todo:luxiaotao
-                    if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
-                            && crnProtocol.statusType == CrnStatusType.IDLE
-                            && crnProtocol.forkPosType == CrnForkPosType.HOME) {
-                        wrkMast.setWrkSts(14L);
-                        wrkMast.setCrnEndTime(new Date());
-                        if (wrkMastMapper.updateById(wrkMast) == 0) {
-                            throw new CoolException("鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛屽伐浣滃彿"+wrkMast.getWrkNo());
+                        // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                        BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
+                        if (barcodeThread == null) {
+                            continue;
                         }
-                    }
+                        String barcode = barcodeThread.getBarcode();
+                        if (!Cools.isEmpty(barcode)) {
+                            News.info("" + mark + " - 1" + " - {}鍙锋潯鐮佹壂鎻忓櫒妫�娴嬫潯鐮佷俊鎭細{}", pickSta.getBarcode(), barcode);
+                            if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
+                                continue;
+                            }
+                        } else {
+                            continue;
+                        }
 
-                    // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
+//                        WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
+//                        if (wrkMast == null) {
+//                            // 鏃犳嫞鏂欐暟鎹�
+//                            continue;
+//                        }
 
-                    // 1.澶嶄綅鍫嗗灈鏈� 鏇存柊鍫嗗灈鏈轰俊鎭� 涓� 涓嬪彂plc鍛戒护 todo:luxiaotao
-                    crnProtocol.setStatus(CrnStatusType.IDLE);
-                    crnProtocol.setTaskNo((short)0);
-                    if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(4, crnProtocol))) {
-                        throw new CoolException("鏇存柊鍫嗗灈鏈轰俊鎭け璐�");
-                    }
+                        if ((wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107)
+                                || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
+                            continue;
+                        }
 
-                    // 2.涓嬪彂绔欑偣淇℃伅
-                    staProtocol.setWorkNo(wrkMast.getWrkNo());
-                    staProtocol.setStaNo(wrkMast.getStaNo());
-                    if (!MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol))) {
-                        throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+                        // 鑾峰彇鐩爣绔�
+                        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+                                .eq("type_no", wrkMast.getIoType() - 50)
+                                .eq("stn_no", pickSta.getStaNo()) // 浣滀笟绔欑偣 = 鎷f枡鍑哄簱鐨勭洰鏍囩珯
+                                .eq("crn_no", wrkMast.getCrnNo()); // 鍫嗗灈鏈哄彿
+                        StaDesc staDesc = staDescService.selectOne(wrapper);
+                        if (Cools.isEmpty(staDesc)) {
+                            //LED
+                            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
+                            // led 寮傚父鏄剧ず
+                            if (ledThread != null) {
+                                String errorMsg = "姝や负鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱.璇锋斁鍦�" + pickSta.getBackSta().shortValue() + "绔欑偣";
+                                MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(5, errorMsg));
+                            }
+                            continue;
+                        }
+
+                        LiftProtocol liftProtocol = devpThread.getLiftStatus();
+                        if(liftProtocol == null) {
+                            continue;
+                        }
+
+                        if (liftProtocol.getMode() != 1) {
+                            continue;
+                        }
+
+                        if (liftProtocol.getDeviceStatus() != 0) {
+                            continue;
+                        }
+
+                        if (liftProtocol.getWorkNo() > 0) {
+                            continue;
+                        }
+
+                        try {
+                            LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
+
+                            SearchLocParam param = new SearchLocParam();
+                            param.setBarcode(wrkMast.getBarcode());
+                            param.setSourceStaNo(pickSta.getStaNo());
+                            param.setLocType1(locTypeDto.getLocType1());
+                            String response = new HttpHandler.Builder()
+                                    .setUri(wmsUrl)
+                                    .setPath("/rpc/pakin/pick/loc/v1")
+                                    .setJson(JSON.toJSONString(param))
+                                    .build()
+                                    .doPost();
+                            JSONObject jsonObject = JSON.parseObject(response);
+                            if (jsonObject.getInteger("code").equals(200)) {
+                                WrkMast newWrkMast = wrkMastMapper.selectPakInStepBarcode(wrkMast.getBarcode());
+                                if (newWrkMast == null) {
+                                    // 鏃犳嫞鏂欐暟鎹�
+                                    News.error("" + mark + " - 3" + " - 鎷i�夌洏鐐瑰洖搴撹幏鍙栧伐浣滄。澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
+                                    continue;
+                                }
+
+                                if(newWrkMast.getWrkSts() != 53 && newWrkMast.getWrkSts() != 57) {
+                                    News.error("" + mark + " - 3" + " - 鎷i�夌洏鐐瑰洖搴撳伐浣滄。绫诲瀷寮傚父锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
+                                    continue;
+                                }
+
+                                if (wrkMast.getWrkSts() != 2) {
+                                    News.error("" + mark + " - 3" + " - 鎷i�夌洏鐐瑰洖搴撳伐浣滄。鐘舵�佸紓甯革紒锛侊紒 [plc缂栧彿锛歿}]", devp.getId());
+                                    continue;
+                                }
+
+                                Integer staNo = Utils.getStaNoByLocNo(newWrkMast.getLocNo());
+                                LiftCommand command = new LiftCommand();
+                                command.setWorkNo(newWrkMast.getWrkNo());
+                                command.setSourceStaNo(pickSta.getStaNo());
+                                command.setTargetStaNo(staNo);
+
+                                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, command));
+                                if (!result) {
+                                    throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+                                }
+
+                                newWrkMast.setWrkSts(3L);// 3.璁惧鎵ц涓�
+                                newWrkMast.setCrnStrTime(new Date());
+                                wrkMastService.updateById(newWrkMast);
+                            } else {
+                                News.error("" + mark + " - 5" + " - 璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/pick/loc/v1", JSON.toJSONString(param), response);
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+
+                    } else {
+                        News.errorNoLog("" + mark + " - 6" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isLoading() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable()
+                                + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk());
                     }
                 }
+
             }
+        } catch (Exception e) {
+            e.printStackTrace();
         }
+        News.infoNoLog("" + mark + " - 0" + " - 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱  ===銆嬫墽琛屽畬鎴�");
     }
 
     /**
-     * 鍏ュ嚭搴�  ===>>  鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂
+     * 鎵ц鍑哄簱浠诲姟
      */
-    public void crnIoExecute(){
-        for (CrnSlave crn : slaveProperties.getCrn()) {
-            // 鑾峰彇鍫嗗灈鏈轰俊鎭�
-            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
-            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
-            BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
-            if (basCrnp == null) {
-                log.error("{}鍙峰爢鍨涙満灏氭湭鍦ㄦ暟鎹簱杩涜缁存姢锛�", crn.getId());
-                continue;
-            }
-            // 鍙湁褰撳爢鍨涙満绌洪棽 骞朵笖 鏃犱换鍔℃椂鎵嶇户缁墽琛�
-            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0) {
-                // 濡傛灉鏈�杩戜竴娆℃槸鍏ュ簱妯″紡
-                if (crnProtocol.getLastIo().equals("I")) {
-                    if (basCrnp.getInEnable().equals("Y")) {
-                        this.crnStnToLoc(crn); //  鍏ュ簱
-                        crnProtocol.setLastIo("O");
-                    } else if (basCrnp.getOutEnable().equals("Y")) {
-                        this.locToCrnStn(crn); //  鍑哄簱
-                        crnProtocol.setLastIo("I");
-                    }
-                }
-                // 濡傛灉鏈�杩戜竴娆℃槸鍑哄簱妯″紡
-                else if (crnProtocol.getLastIo().equals("O")) {
-                    if (basCrnp.getOutEnable().equals("Y")) {
-                        this.locToCrnStn(crn); //  鍑哄簱
-                        crnProtocol.setLastIo("I");
-                    } else if (basCrnp.getInEnable().equals("Y")) {
-                        this.crnStnToLoc(crn); //  鍏ュ簱
-                        crnProtocol.setLastIo("O");
-                    }
-                }
-            }
-            // 搴撲綅绉昏浆
-            this.locToLoc(crn);
+    public synchronized void executeOutTask() {
+        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
+        if(devpThread == null) {
+            return;
         }
+
+        LiftProtocol liftProtocol = devpThread.getLiftStatus();
+        if(liftProtocol == null) {
+            return;
+        }
+
+        if (liftProtocol.getMode() != 1) {
+            return;
+        }
+
+        if (liftProtocol.getDeviceStatus() != 0) {
+            return;
+        }
+
+        if (liftProtocol.getWorkNo() > 0) {
+            return;
+        }
+
+        //妫�娴嬪嚭搴撶珯鏄惁鍙嚭
+        StaProtocol staProtocol = devpThread.getStation().get(100);
+        if (staProtocol == null) {
+            return;
+        }
+
+        if (!staProtocol.isAutoing()) {
+            return;
+        }
+
+        if (staProtocol.isLoading()) {
+            return;
+        }
+
+        if (!staProtocol.isOutEnable()) {
+            return;
+        }
+
+        //妫�鏌ユ槸鍚︽湁姝e湪鎵ц鐨勪换鍔�
+        List<WrkMast> workingWrkMast = wrkMastService.selectList(new EntityWrapper<WrkMast>().in("wrk_sts", 3, 12));
+        if (!workingWrkMast.isEmpty()) {
+            return;
+        }
+
+        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 11).orderBy("create_time"));
+        if (wrkMasts.isEmpty()) {
+            return;
+        }
+
+        WrkMast wrkMast = wrkMasts.get(0);
+        Integer sourceStaNo = Utils.getStaNoByLocNo(wrkMast.getSourceLocNo());
+
+        LiftCommand command = new LiftCommand();
+        command.setWorkNo(wrkMast.getWrkNo());
+        command.setSourceStaNo(sourceStaNo);
+        command.setTargetStaNo(100);
+
+        boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, command));
+        if (!result) {
+            throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+        }
+
+        wrkMast.setWrkSts(12L);// 12.璁惧鎵ц涓�
+        wrkMast.setCrnStrTime(new Date());
+        wrkMastService.updateById(wrkMast);
     }
 
     /**
-     * 鍏ュ簱  ===>>  鍫嗗灈鏈虹珯鍒板簱浣�
+     * 妫�娴嬩换鍔″畬鎴�
      */
-    private void crnStnToLoc(CrnSlave slave){
-        for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
-            boolean flag = false;
-            // 鑾峰彇鍫嗗灈鏈哄叆搴撶珯淇℃伅
-            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
-            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
-            // 鏌ヨ绔欑偣璇︾粏淇℃伅
-            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
-            if (staDetl == null) {
-                log.error("鍏ュ簱 ===>> 鍫嗗灈鏈虹珯鐐瑰湪鏁版嵁搴撲笉瀛樺湪, 绔欑偣缂栧彿={}", crnStn.getStaNo());
-                continue;
-            }
-            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staDetl.getCanining().equals("Y")) {
-                flag = true;
-            }
-            if (!flag) {
-                continue;
-            }
-            // 鑾峰彇宸ヤ綔鐘舵�佷负2锛堣澶囦笂璧帮級鐨勫叆搴撳伐浣滄。
-            WrkMast wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getWorkNo());
-            if(null == wrkMast) {
-                log.error("鏌ヨ鏃犲緟鍏ュ簱鏁版嵁--wrk_sts=2, 宸ヤ綔鍙�={}", staProtocol.getWorkNo());
-                continue;
-            }
-            // 鑾峰彇搴撲綅淇℃伅
-            LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
-            if (locMast == null) {
-                log.error("鏌ヨ搴撳瓨鏃犳暟鎹�--搴撲綅鍙穥}", wrkMast.getLocNo());
-                continue;
-            }
-            if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
-                log.error("鍏ュ簱鎿嶄綔搴撲綅鐘舵�佷笉绗﹀悎--鐘舵��, 搴撲綅鍙�={}锛屽簱浣嶇姸鎬�={}", wrkMast.getLocNo(), locMast.getLocSts());
+    public synchronized void deviceFinished() {
+        // 鏍规嵁plc閬嶅巻
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            if (devpThread == null) {
                 continue;
             }
 
-            // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
-            CrnCommand crnCommand = new CrnCommand();
-            crnCommand.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙�
-            crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 宸ヤ綔鍙�
-            crnCommand.setAckFinish((short) 0);  // 浠诲姟瀹屾垚纭浣�
-            crnCommand.setTaskMode(CrnTaskModeType.PAKIN); // 浠诲姟妯″紡:  搴撲綅绉昏浆
-            crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 婧愬簱浣嶆帓
-            crnCommand.setSourcePosY(crnStn.getBay().shortValue());     // 婧愬簱浣嶅垪
-            crnCommand.setSourcePosZ(crnStn.getLev().shortValue());     // 婧愬簱浣嶅眰
-            crnCommand.setDestinationPosX(locMast.getRow1().shortValue());     // 鐩爣搴撲綅鎺�
-            crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 鐩爣搴撲綅鍒�
-            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 鐩爣搴撲綅灞�
-            if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
-                log.error("鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
-            } else {
-                // 淇敼宸ヤ綔妗g姸鎬� 2.璁惧涓婅蛋 => 3.鍚婅溅鍏ュ簱涓�
-                Date now = new Date();
-                wrkMast.setWrkSts(3L);
-                wrkMast.setCrnStrTime(now);
-                wrkMast.setModiTime(now);
-                if (wrkMastMapper.updateById(wrkMast) == 0) {
-                    log.error("淇敼宸ヤ綔妗g姸鎬� 2.璁惧涓婅蛋 => 3.鍚婅溅鍏ュ簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
-                }
+            LiftProtocol liftProtocol = devpThread.getLiftStatus();
+            if (liftProtocol == null) {
+                continue;
             }
-        }
-    }
 
-    /**
-     * 鍑哄簱  ===>>  搴撲綅鍒板爢鍨涙満绔�
-     */
-    private void locToCrnStn(CrnSlave slave){
-        for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
-            // 鑾峰彇宸ヤ綔鐘舵�佷负11锛堢敓鎴愬嚭搴揑D锛夌殑鍑哄簱宸ヤ綔妗�
-            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId());
+            if (liftProtocol.getWorkNo() <= 0) {
+                continue;
+            }
+
+            if (liftProtocol.getMode() != 1) {
+                continue;
+            }
+
+            if (liftProtocol.getDeviceStatus() != 0) {
+                continue;
+            }
+
+            WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", liftProtocol.getWorkNo()));
             if (wrkMast == null) {
                 continue;
             }
-            // 宸ヤ綔妗g姸鎬佸垽鏂�
-            if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null){
-                log.error("鏌ヨ宸ヤ綔妗f暟鎹笉绗﹀悎鏉′欢--鍏ュ嚭绫诲瀷/绔欑偣, 宸ヤ綔鍙�={}锛屾簮搴撲綅={}锛屽叆鍑虹被鍨�={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
-                continue;
-            }
-            // 鑾峰彇婧愬簱浣嶄俊鎭�
-            LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
-            if (!sourceSta.getLocSts().equals("R") &&!sourceSta.getLocSts().equals("P")) {
-                log.error("鍑哄簱鎿嶄綔搴撲綅鐘舵�佷笉绗﹀悎--鐘舵��, 搴撲綅鍙�={}锛屽簱浣嶇姸鎬�={}", wrkMast.getLocNo(), sourceSta.getLocSts());
-                continue;
-            }
-            // 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅
-            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
-            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
-            // 鏌ヨ绔欑偣璇︾粏淇℃伅
-            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
-            if (staDetl == null) {
-                log.error("鍑哄簱 ===>> 鍫嗗灈鏈虹珯鐐瑰湪鏁版嵁搴撲笉瀛樺湪, 绔欑偣缂栧彿={}", crnStn.getStaNo());
-                continue;
-            }
-            // 鍒ゆ柇鍫嗗灈鏈哄嚭搴撶珯鐘舵��
-            if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting().equals("Y")
-                    && staProtocol.getWorkNo() == 0) {
-                // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
 
-                // 1.鍫嗗灈鏈哄紑濮嬬Щ鍔�
-                CrnCommand crnCommand = new CrnCommand();
-                crnCommand.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙�
-                crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 宸ヤ綔鍙�
-                crnCommand.setAckFinish((short) 0);  // 浠诲姟瀹屾垚纭浣�
-                crnCommand.setTaskMode(CrnTaskModeType.PAKOUT); // 浠诲姟妯″紡:  搴撲綅绉昏浆
-                crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 婧愬簱浣嶆帓
-                crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 婧愬簱浣嶅垪
-                crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 婧愬簱浣嶅眰
-                crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 鐩爣搴撲綅鎺�
-                crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 鐩爣搴撲綅鍒�
-                crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 鐩爣搴撲綅灞�
-                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
-                    log.error("鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
-                } else {
-                    // 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓�
-                    Date now = new Date();
-                    wrkMast.setWrkSts(12L);
-                    wrkMast.setCrnStrTime(now);
-                    wrkMast.setModiTime(now);
-                    if (wrkMastMapper.updateById(wrkMast) == 0) {
-                        log.error("淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * 搴撲綅绉昏浆
-     */
-    private void locToLoc(CrnSlave slave){
-        // 鑾峰彇宸ヤ綔妗d俊鎭�
-        WrkMast wrkMast = wrkMastMapper.selectLocMove(slave.getId());
-        if (null == wrkMast) {
-            return;
-        }
-        // 鑾峰彇婧愬簱浣嶄俊鎭�
-        LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
-        if (null == sourceSta) {
-            log.error("宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈡簮搴撲綅澶辫触锛佸伐浣滃彿={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo());
-            return;
-        }
-        // 婧愬簱浣�  搴撲綅鐘舵�佸垽鏂�
-        if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("S")) {
-            return;
-        }
-        // 鑾峰彇鐩爣搴撲綅淇℃伅
-        LocMast sta = locMastService.selectById(wrkMast.getLocNo());
-        if (null == sta) {
-            log.error("宸ヤ綔妗e簱浣嶇Щ杞け璐ワ紝鍘熷洜锛氭绱㈢洰鏍囧簱浣嶅け璐ワ紒宸ヤ綔鍙�={}锛屾簮搴撲綅={}", wrkMast.getWrkNo(), wrkMast.getLocNo());
-            return;
-        }
-        // 鑾峰彇鍫嗗灈鏈轰俊鎭� 骞� 鍒ゆ柇鏄惁鍙叆鍑�
-        BasCrnp basCrnp = basCrnpService.selectById(slave.getId());
-        if (!basCrnp.getInEnable().equals("Y") && !basCrnp.getOutEnable().equals("Y")) {
-            return;
-        }
-        // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
-        CrnCommand crnCommand = new CrnCommand();
-        crnCommand.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙�
-        crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 宸ヤ綔鍙�
-        crnCommand.setAckFinish((short) 0);  // 浠诲姟瀹屾垚纭浣�
-        crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 浠诲姟妯″紡:  搴撲綅绉昏浆
-        crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 婧愬簱浣嶆帓
-        crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 婧愬簱浣嶅垪
-        crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 婧愬簱浣嶅眰
-        crnCommand.setDestinationPosX(sta.getRow1().shortValue());     // 鐩爣搴撲綅鎺�
-        crnCommand.setDestinationPosY(sta.getBay1().shortValue());     // 鐩爣搴撲綅鍒�
-        crnCommand.setDestinationPosZ(sta.getLev1().shortValue());     // 鐩爣搴撲綅灞�
-        if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
-            log.error("鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
-        }
-    }
-
-    /**
-     * 鎵ц瀵瑰伐浣滄。鐨勫畬鎴愭搷浣�
-     */
-    public void storeFinished() {
-        for (CrnSlave crn : slaveProperties.getCrn()) {
-            // 鑾峰彇鍫嗗灈鏈轰俊鎭�
-            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
-            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
-            //  鐘舵�侊細绛夊緟纭 骞朵笖  浠诲姟瀹屾垚浣� = 1
-            if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.taskFinish == 1 && crnProtocol.getTaskNo() != 0) {
-                // 鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。
-                WrkMast wrkMast = wrkMastMapper.selectPakInStep3(crnProtocol.getTaskNo().intValue());
-                if (wrkMast == null) {
-                    log.error("鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗘湭鎵惧埌宸ヤ綔妗c�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo());
-                    continue;
-                }
-                // 鍏ュ簱 + 搴撲綅杞Щ  ==> 4.鍏ュ簱瀹屾垚
-                if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && wrkMast.getIoType() == 11)){
-                    wrkMast.setWrkSts(4L);
-                // 鍑哄簱 + 鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓細12.鍚婅溅鍑哄簱涓� ==> 14.鍑哄簱瀹屾垚
-                } else if (wrkMast.getWrkSts() == 12) {
-                    wrkMast.setWrkSts(14L);
-                }
-                Date now = new Date();
-                wrkMast.setCrnEndTime(now);
-                wrkMast.setModiTime(now);
-                // 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満
-                if (wrkMastMapper.updateById(wrkMast) > 0) {
-                    // 鍛戒护涓嬪彂鍖� -------------------------------------------------------------------------
-                    // 鍫嗗灈鏈哄浣�
-                    if (!MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(3, new CrnCommand()))) {
-                        log.error("鍫嗗灈鏈哄浣嶅懡浠や笅鍙戝け璐ワ紝宸ヤ綔鍙�={}", wrkMast.getWrkNo());
-                    }
-                }
+            if (wrkMast.getWrkSts() == 3) {
+                wrkMast.setWrkSts(4L);
+                wrkMast.setCrnEndTime(new Date());
+                wrkMast.setIoTime(new Date());
+                wrkMastService.updateById(wrkMast);
+            }else if (wrkMast.getWrkSts() == 12) {
+                wrkMast.setWrkSts(14L);
+                wrkMast.setCrnEndTime(new Date());
+                wrkMast.setIoTime(new Date());
+                wrkMastService.updateById(wrkMast);
+            }else {
+                News.error("鏈煡鐨勫伐浣滅姸鎬�");
             }
         }
     }
@@ -548,10 +530,414 @@
     /**
      * 鍫嗗灈鏈哄紓甯镐俊鎭褰�
      */
-    public void recCrnErr(){
+    public synchronized void recCrnErr(Integer mark) {
+        Date now = new Date();
+        for (CrnSlave crn : slaveProperties.getCrn()) {
+            // 鑾峰彇鍫嗗灈鏈轰俊鎭�
+            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
+            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
+            if (crnProtocol == null) {
+                continue;
+            }
+            if (true) {
+//            if (crnProtocol.getModeType() != CrnModeType.STOP) {
+                // 鏈変换鍔�
+                if (crnProtocol.getTaskNo() != 0) {
 
+                    BasErrLog latest = basErrLogService.findLatestByTaskNo(crn.getId(), crnProtocol.getTaskNo().intValue());
+                    // 鏈夊紓甯�
+                    if (latest == null) {
+                        News.warnNoLog("" + mark + " - 1" + " - 寮�濮嬫墽琛岋細鍫嗗灈鏈哄紓甯镐俊鎭褰� 锛� 鏈変换鍔★紝鏈夊紓甯�");
+                        if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
+                            WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo());
+                            if (wrkMast == null) {
+                                continue;
+                            }
+                            BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
+                            String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName();
+                            BasErrLog basErrLog = new BasErrLog(
+                                    null,    // 缂栧彿
+                                    wrkMast.getWrkNo(),    // 宸ヤ綔鍙�
+                                    now,    // 鍙戠敓鏃堕棿
+                                    null,    // 缁撴潫鏃堕棿
+                                    wrkMast.getWrkSts(),    // 宸ヤ綔鐘舵��
+                                    wrkMast.getIoType(),    // 鍏ュ嚭搴撶被鍨�
+                                    crn.getId(),    // 鍫嗗灈鏈�
+                                    null,    // plc
+                                    wrkMast.getLocNo(),    // 鐩爣搴撲綅
+                                    wrkMast.getStaNo(),    // 鐩爣绔�
+                                    wrkMast.getSourceStaNo(),    // 婧愮珯
+                                    wrkMast.getSourceLocNo(),    // 婧愬簱浣�
+                                    wrkMast.getBarcode(),    // 鏉$爜
+                                    (int) crnProtocol.getAlarm(),    // 寮傚父鐮�
+                                    errName,    // 寮傚父
+                                    1,    // 寮傚父鎯呭喌
+                                    now,    // 娣诲姞鏃堕棿
+                                    null,    // 娣诲姞浜哄憳
+                                    now,    // 淇敼鏃堕棿
+                                    null,    // 淇敼浜哄憳
+                                    "浠诲姟涓紓甯�"    // 澶囨敞
+                            );
+                            if (!basErrLogService.insert(basErrLog)) {
+                                News.error("" + mark + " - 2" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), errName);
+                            }
+                        }
+                    } else {
+                        // 寮傚父淇
+                        if (crnProtocol.getAlarm() == null || crnProtocol.getAlarm() == 0) {
+                            latest.setEndTime(now);
+                            latest.setUpdateTime(now);
+                            latest.setStatus(2);
+                            if (!basErrLogService.updateById(latest)) {
+                                News.error("" + mark + " - 3" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
+                            }
+                        }
+                    }
+                    // 鏃犱换鍔�
+                } else {
+                    BasErrLog latest = basErrLogService.findLatest(crn.getId());
+                    // 鏈夊紓甯�
+                    if (crnProtocol.getAlarm() != null && crnProtocol.getAlarm() > 0) {
+                        News.warnNoLog("" + mark + " - 4" + " - 寮�濮嬫墽琛岋細鍫嗗灈鏈哄紓甯镐俊鎭褰� 锛� 鏃犱换鍔★紝鏈夊紓甯�");
+                        // 璁板綍鏂板紓甯�
+                        if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm().intValue())) {
+                            BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm());
+                            String errName = crnError == null ? String.valueOf(crnProtocol.getAlarm()) : crnError.getErrName();
+                            BasErrLog basErrLog = new BasErrLog(
+                                    null,    // 缂栧彿
+                                    null,    // 宸ヤ綔鍙�
+                                    now,    // 鍙戠敓鏃堕棿
+                                    null,    // 缁撴潫鏃堕棿
+                                    null,    // 宸ヤ綔鐘舵��
+                                    null,    // 鍏ュ嚭搴撶被鍨�
+                                    crn.getId(),    // 鍫嗗灈鏈�
+                                    null,    // plc
+                                    null,    // 鐩爣搴撲綅
+                                    null,    // 鐩爣绔�
+                                    null,    // 婧愮珯
+                                    null,    // 婧愬簱浣�
+                                    null,    // 鏉$爜
+                                    (int) crnProtocol.getAlarm(),    // 寮傚父鐮�
+                                    errName,    // 寮傚父
+                                    1,    // 寮傚父鎯呭喌
+                                    now,    // 娣诲姞鏃堕棿
+                                    null,    // 娣诲姞浜哄憳
+                                    now,    // 淇敼鏃堕棿
+                                    null,    // 淇敼浜哄憳
+                                    "鏃犱换鍔″紓甯�"    // 澶囨敞
+                            );
+                            if (!basErrLogService.insert(basErrLog)) {
+                                News.error("" + mark + " - 5" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), errName);
+                            }
+                        }
+                        // 鏃犲紓甯�
+                    } else {
+                        // 寮傚父淇
+                        if (latest != null && latest.getStatus() == 1) {
+                            latest.setEndTime(now);
+                            latest.setUpdateTime(now);
+                            latest.setStatus(2);
+                            if (!basErrLogService.updateById(latest)) {
+                                News.error("" + mark + " - 6" + " - 鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
+                            }
+                        }
+                    }
+                }
+            }
+
+        }
+        News.infoNoLog("" + mark + " - 0" + " - 鍫嗗灈鏈哄紓甯镐俊鎭褰曟墽琛屽畬鎴�");
     }
 
+    /**
+     * 鍑哄簱  ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�
+     */
+    public synchronized void ledExecute(Integer mark) {
 
+        for (LedSlave led : slaveProperties.getLed()) {
+            // 鑾峰彇杈撻�佺嚎plc绾跨▼
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
+            // 鍛戒护闆嗗悎
+            List<LedCommand> commands = new ArrayList<>();
+//            // 宸ヤ綔妗i泦鍚�
+//            List<WrkMast> wrkMasts = new ArrayList<>();
+            List<Integer> workNoList = new ArrayList<>();
+            for (Integer staNo : led.getStaArr()) {
+                // 鑾峰彇鍙夎溅绔欑偣
+                StaProtocol staProtocol = devpThread.getStation().get(staNo);
+                if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
+                    continue;
+                } else {
+                    staProtocol = staProtocol.clone();
+                }
+                Integer wrkNo = null;
+                Integer ioType = null;
+                Integer targetStaNo = null;
+                String sourceLocNo = null;
+                String locNo = null;
+                String barcode = null;
 
+                // 鑾峰彇宸ヤ綔妗f暟鎹�
+                WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
+//                if (null == wrkMast || wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) { continue; }
+                if (null == wrkMast) {
+                    List<WrkMastLog> wrkMastLogs = wrkMastLogService.selectList(new EntityWrapper<WrkMastLog>()
+                            .eq("wrk_no", staProtocol.getWorkNo())
+                            .orderBy("modi_time", false)
+                    );
+                    if (wrkMastLogs.isEmpty()) {
+                        continue;
+                    }
+
+                    WrkMastLog wrkMastLog = wrkMastLogs.get(0);
+                    wrkNo = wrkMastLog.getWrkNo();
+                    ioType = wrkMastLog.getIoType();
+                    sourceLocNo = wrkMastLog.getSourceLocNo();
+                    locNo = wrkMastLog.getLocNo();
+                    targetStaNo = wrkMastLog.getStaNo();
+                    barcode = wrkMastLog.getBarcode();
+                }else {
+                    wrkNo = wrkMast.getWrkNo();
+                    ioType = wrkMast.getIoType();
+                    sourceLocNo = wrkMast.getSourceLocNo();
+                    locNo = wrkMast.getLocNo();
+                    targetStaNo = wrkMast.getStaNo();
+                    barcode = wrkMast.getBarcode();
+                }
+                News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�:鍑哄簱  ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�");
+                workNoList.add(wrkNo);
+                // 缁勮鍛戒护
+                LedCommand ledCommand = new LedCommand();
+                ledCommand.setWorkNo(wrkNo);
+                ledCommand.setIoType(ioType);
+                // 鍑哄簱妯″紡
+                switch (ioType) {
+                    case 1:
+                        ledCommand.setTitle("鍏ㄦ澘鍏ュ簱");
+                        break;
+                    case 10:
+                        ledCommand.setTitle("绌烘澘鍏ュ簱");
+                        break;
+                    case 101:
+                        ledCommand.setTitle("鍏ㄦ澘鍑哄簱");
+                        break;
+                    case 103:
+                        ledCommand.setTitle("鎷f枡鍑哄簱");
+                        break;
+                    case 104:
+                        ledCommand.setTitle("骞舵澘鍑哄簱");
+                        break;
+                    case 107:
+                        ledCommand.setTitle("鐩樼偣鍑哄簱");
+                        break;
+                    case 110:
+                        ledCommand.setTitle("绌烘澘鍑哄簱");
+                        ledCommand.setEmptyMk(true);
+                        break;
+                    case 53:
+                        ledCommand.setTitle("鎷f枡鍏ュ簱");
+                        break;
+                    case 57:
+                        ledCommand.setTitle("鐩樼偣鍏ュ簱");
+                        break;
+                    case 54:
+                        ledCommand.setTitle("骞舵澘鍏ュ簱");
+                        break;
+                    default:
+                        News.error("" + mark + " - 1" + " - 浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkNo, ioType);
+                        break;
+                }
+                ledCommand.setSourceLocNo(sourceLocNo);
+                ledCommand.setLocNo(locNo);
+                ledCommand.setStaNo(targetStaNo);
+                ledCommand.setBarcode(barcode);
+//                ledCommand.setSourceStaNo(wrkMast.getSourceStaNo());
+                if (ioType != 110 && ioType != 10) {
+                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkNo);
+
+                    if (!wrkDetls.isEmpty()) {
+                        WrkDetl wrkDetl = wrkDetls.get(0);
+                        double anfme = 0D;
+                        double weight = 0D;
+                        for (WrkDetl detl : wrkDetls) {
+                            anfme += detl.getAnfme();
+                            weight += detl.getWeight();
+                            wrkDetl.setAnfme(anfme);
+                            wrkDetl.setWeight(weight);
+                        }
+
+                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
+                                .eq("loc_no", wrkMast.getSourceLocNo()));
+                        double totalAnfme = 0D;
+                        double totalWeight = 0D;
+                        for (LocDetl locDetl : locDetls) {
+                            totalAnfme += locDetl.getAnfme();
+                            totalWeight += locDetl.getWeight();
+                        }
+                        wrkDetl.setStockNum(totalAnfme);
+                        wrkDetl.setStockNum2(totalWeight);
+
+                        ledCommand.getMatDtos().add(new MatDto(
+                                wrkDetl.getMatnr()
+                                , wrkDetl.getMaktx()
+                                , wrkDetl.getAnfme()
+                                , wrkDetl.getWeight()
+                                , wrkDetl.getStockNum()
+                                , wrkDetl.getStockNum2()
+                                , wrkDetl.getSpecs()
+                                , wrkDetl.getSku()
+                                , wrkDetl.getZpallet()
+                                , wrkDetl.getModel()
+                                , wrkDetl.getSupp()
+                                , wrkDetl.getKpCstmrName()
+                                , wrkDetl.getOrderNo()
+                                , wrkDetl.getCstateid$()
+                        ));
+
+                    }else {
+                        List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectTodayByWrkNo(wrkNo);
+                        if(!wrkDetlLogs.isEmpty()) {
+                            WrkDetlLog wrkDetlLog = wrkDetlLogs.get(0);
+
+                            double anfme = 0D;
+                            double weight = 0D;
+                            for (WrkDetlLog detl : wrkDetlLogs) {
+                                anfme += detl.getAnfme();
+                                weight += detl.getWeight();
+                                wrkDetlLog.setAnfme(anfme);
+                                wrkDetlLog.setWeight(weight);
+                            }
+
+                            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
+                                    .eq("loc_no", sourceLocNo));
+                            double totalAnfme = 0D;
+                            double totalWeight = 0D;
+                            for (LocDetl locDetl : locDetls) {
+                                totalAnfme += locDetl.getAnfme();
+                                totalWeight += locDetl.getWeight();
+                            }
+                            wrkDetlLog.setStockNum(totalAnfme);
+                            wrkDetlLog.setStockNum2(totalWeight);
+
+                            ledCommand.getMatDtos().add(new MatDto(
+                                    wrkDetlLog.getMatnr()
+                                    , wrkDetlLog.getMaktx()
+                                    , wrkDetlLog.getAnfme()
+                                    , wrkDetlLog.getWeight()
+                                    , wrkDetlLog.getStockNum()
+                                    , wrkDetlLog.getStockNum2()
+                                    , wrkDetlLog.getSpecs()
+                                    , wrkDetlLog.getSku()
+                                    , wrkDetlLog.getZpallet()
+                                    , wrkDetlLog.getModel()
+                                    , wrkDetlLog.getSupp()
+                                    , wrkDetlLog.getKpCstmrName()
+                                    , wrkDetlLog.getOrderNo()
+                                    , wrkDetlLog.getCstateid$()
+                            ));
+                        }
+                    }
+
+                }
+                commands.add(ledCommand);
+            }
+            Set<Integer> workNos = new HashSet<>(workNoList);
+            // 鑾峰彇LED绾跨▼
+            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
+            // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护
+            if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
+                continue;
+            }
+//             鍛戒护涓嬪彂 -------------------------------------------------------------------------------
+//            if (!commands.isEmpty()) {
+//                if (led.getId() < 7) {
+//                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
+//                        News.error(""+mark+" - 2"+" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+//                        continue;
+//                    } else {
+//                        ledThread.setLedMk(false);
+//                    }
+//                } else {
+//                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
+//                        News.error(""+mark+" - 3"+" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+//                        continue;
+//                    } else {
+//                        ledThread.setLedMk(false);
+//                    }
+//                }
+//
+//            }
+            // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
+            if (!commands.isEmpty()) {
+                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, commands))) {
+                    News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    continue;
+                } else {
+                    ledThread.setLedMk(false);
+                }
+            }
+
+            try {
+                // 淇敼涓绘。led鏍囪
+                for (Integer wrkNo : workNoList) {
+                    WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", wrkNo));
+                    if (wrkMast != null) {
+                        wrkMast.setOveMk("Y");
+                        wrkMast.setModiTime(new Date());
+                        if (wrkMastMapper.updateById(wrkMast) == 0) {
+                            News.errorNoLog("" + mark + " - 4" + " - 鏇存柊宸ヤ綔妗eけ璐�");
+                            throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
+                        }
+                    }
+                }
+
+                // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
+                ledThread.setWorkNos(workNos);
+
+            } catch (Exception e) {
+                e.printStackTrace();
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            }
+
+        }
+        News.infoNoLog("" + mark + " - 0" + " - 鍑哄簱  ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣ㄦ墽琛屽畬鎴�");
+    }
+
+    /**
+     * 鍏朵粬  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅
+     */
+    public synchronized void ledReset(Integer mark) {
+
+        News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�:鍏朵粬  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅");
+        for (LedSlave led : slaveProperties.getLed()) {
+
+            // 鑾峰彇杈撻�佺嚎plc绾跨▼
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
+            // 鍛戒护闆嗗悎
+            boolean reset = true;
+            for (Integer staNo : led.getStaArr()) {
+                // 鑾峰彇鍙夎溅绔欑偣
+                StaProtocol staProtocol = devpThread.getStation().get(staNo);
+                if (staProtocol == null) {
+                    continue;
+                }
+                if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
+                    reset = false;
+                    break;
+                }
+            }
+            // 鑾峰彇led绾跨▼
+            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
+            // led鏄剧ず榛樿鍐呭
+            if (reset && !ledThread.isLedMk()) {
+                ledThread.setLedMk(true);
+                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
+                    News.error("" + mark + " - 1" + " - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                } else {
+
+                }
+            }
+        }
+        News.infoNoLog("" + mark + " - 0" + " - 鎵ц瀹屾垚锛氬叾浠�  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅");
+    }
 }

--
Gitblit v1.9.1