From 78e0773dba0613bf4fb18a20e0cef5086e1b834f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 24 十二月 2020 10:37:21 +0800
Subject: [PATCH] #newVersion

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  197 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 194 insertions(+), 3 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 103fc4c..ef829aa 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -6,13 +6,16 @@
 import com.core.common.Cools;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
+import com.zy.asrs.mapper.BasCrnErrorMapper;
 import com.zy.asrs.mapper.WaitPakinMapper;
 import com.zy.asrs.mapper.WrkMastMapper;
 import com.zy.asrs.service.*;
+import com.zy.asrs.utils.VersionUtils;
 import com.zy.common.model.MatDto;
 import com.zy.common.model.StartupDto;
 import com.zy.common.service.CommonService;
 import com.zy.common.utils.CollectionUtils;
+import com.zy.core.CrnThread;
 import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.*;
@@ -26,8 +29,7 @@
 import com.zy.core.model.protocol.StaProtocol;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.BarcodeThread;
-import com.zy.core.CrnThread;
-import com.zy.core.thread.DevpThread;
+import com.zy.core.DevpThread;
 import com.zy.core.thread.LedThread;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -91,6 +93,12 @@
     private BasCrnpService basCrnpService;
     @Autowired
     private BasDevpService basDevpService;
+    @Autowired
+    private LocDetlService locDetlService;
+    @Autowired
+    private BasErrLogService basErrLogService;
+    @Autowired
+    private BasCrnErrorMapper basCrnErrorMapper;
     @Autowired
     private JdbcTemplate jdbcTemplate;
 
@@ -718,8 +726,115 @@
     /**
      * 鍫嗗灈鏈哄紓甯镐俊鎭褰�
      */
+    @Async
     public void recCrnErr(){
+        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) {
+                        if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm1() > 0) {
+                            WrkMast wrkMast = wrkMastMapper.selectById(crnProtocol.getTaskNo());
+                            BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1());
+                            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(),    // 鏉$爜
+                                    crnProtocol.getAlarm1().intValue(),    // 寮傚父鐮�
+                                    crnError.getErrName(),    // 寮傚父
+                                    1,    // 寮傚父鎯呭喌
+                                    now,    // 娣诲姞鏃堕棿
+                                    null,    // 娣诲姞浜哄憳
+                                    now,    // 淇敼鏃堕棿
+                                    null,    // 淇敼浜哄憳
+                                    "浠诲姟涓紓甯�"    // 澶囨敞
+                            );
+                            if (!basErrLogService.insert(basErrLog)) {
+                                log.error("鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), crnError.getErrName());
+                            }
+                        }
+                    } else {
+                        // 寮傚父淇
+                        if (crnProtocol.getAlarm1() == null || crnProtocol.getAlarm1() == 0) {
+                            latest.setEndTime(now);
+                            latest.setUpdateTime(now);
+                            latest.setStatus(2);
+                            if (!basErrLogService.updateById(latest)) {
+                                log.error("鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
+                            }
+                        }
+                    }
+                // 鏃犱换鍔�
+                } else {
+                    BasErrLog latest = basErrLogService.findLatest(crn.getId());
+                    // 鏈夊紓甯�
+                    if (crnProtocol.getAlarm1() != null && crnProtocol.getAlarm1() > 0) {
+                        // 璁板綍鏂板紓甯�
+                        if (latest == null || (latest.getErrCode() != crnProtocol.getAlarm1().intValue())) {
+                            BasCrnError crnError = basCrnErrorMapper.selectById(crnProtocol.getAlarm1());
+                            BasErrLog basErrLog = new BasErrLog(
+                                    null,    // 缂栧彿
+                                    null,    // 宸ヤ綔鍙�
+                                    now,    // 鍙戠敓鏃堕棿
+                                    null,    // 缁撴潫鏃堕棿
+                                    null,    // 宸ヤ綔鐘舵��
+                                    null,    // 鍏ュ嚭搴撶被鍨�
+                                    crn.getId(),    // 鍫嗗灈鏈�
+                                    null,    // plc
+                                    null,    // 鐩爣搴撲綅
+                                    null,    // 鐩爣绔�
+                                    null,    // 婧愮珯
+                                    null,    // 婧愬簱浣�
+                                    null,    // 鏉$爜
+                                    crnProtocol.getAlarm1().intValue(),    // 寮傚父鐮�
+                                    crnError.getErrName(),    // 寮傚父
+                                    1,    // 寮傚父鎯呭喌
+                                    now,    // 娣诲姞鏃堕棿
+                                    null,    // 娣诲姞浜哄憳
+                                    now,    // 淇敼鏃堕棿
+                                    null,    // 淇敼浜哄憳
+                                    "鏃犱换鍔″紓甯�"    // 澶囨敞
+                            );
+                            if (!basErrLogService.insert(basErrLog)) {
+                                log.error("鍫嗗灈鏈簆lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", crn.getId(), crnError.getErrName());
+                            }
+                        }
+                    // 鏃犲紓甯�
+                    } else {
+                        // 寮傚父淇
+                        if (latest != null && latest.getStatus() == 1) {
+                            latest.setEndTime(now);
+                            latest.setUpdateTime(now);
+                            latest.setStatus(2);
+                            if (!basErrLogService.updateById(latest)) {
+                                log.error("鍫嗗灈鏈簆lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", crn.getId(), latest.getId());
+                            }
+                        }
+                    }
+                }
+            }
 
+        }
     }
 
 
@@ -856,7 +971,7 @@
                 ledCommand.setStaNo(wrkMast.getStaNo());
                 if (wrkMast.getIoType() != 110) {
                     List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
-                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMatnr(), wrkDetl.getAnfme())));
+                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme())));
                 }
                 commands.add(ledCommand);
             }
@@ -930,4 +1045,80 @@
         }
     }
 
+    /**
+     * 鍫嗗灈鏈烘紨绀�  ===>> 搴撲綅绉昏浆
+     */
+    @Async
+    public void crnDemoOfLocMove(Integer crn){
+        for (int i = 0; i < 5; i++) {
+
+            LocMast sourceLoc = locMastService.queryDemoSourceLoc(crn);
+            LocMast loc = locMastService.queryDemoLoc(crn);
+            if (null == sourceLoc || null == loc) {
+                break;
+            }
+            String sourceLocNo = sourceLoc.getLocNo();
+            String locNo = loc.getLocNo();
+
+            // 鑾峰彇宸ヤ綔鍙�
+            int workNo = commonService.getWorkNo(0);
+            // 淇濆瓨宸ヤ綔妗�
+            WrkMast wrkMast = new WrkMast();
+            wrkMast.setWrkNo(workNo);
+            wrkMast.setIoTime(new Date());
+            wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+            wrkMast.setIoType(11); // 鍏ュ嚭搴撶姸鎬侊細 11.搴撴牸绉昏浇
+            wrkMast.setIoPri(13D);
+            wrkMast.setCrnNo(crn);
+            wrkMast.setSourceLocNo(sourceLocNo); // 婧愬簱浣�
+            wrkMast.setLocNo(locNo); // 鐩爣搴撲綅
+            wrkMast.setFullPlt("N"); // 婊℃澘锛歒
+            wrkMast.setPicking("N"); // 鎷f枡
+            wrkMast.setExitMk("N"); // 閫�鍑�
+            wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 绌烘澘
+            wrkMast.setBarcode(sourceLoc.getBarcode()); // 鎵樼洏鐮�
+            wrkMast.setLinkMis("N");
+            wrkMast.setAppeTime(new Date());
+            wrkMast.setModiTime(new Date());
+            int res = wrkMastMapper.insert(wrkMast);
+            if (res == 0) {
+                throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
+            }
+            // 宸ヤ綔妗f槑缁嗕繚瀛�
+            List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
+            for (LocDetl locDetl : locDetls) {
+                WrkDetl wrkDetl = new WrkDetl();
+                wrkDetl.setWrkNo(workNo);
+                wrkDetl.setIoTime(new Date());
+                wrkDetl.setAnfme(locDetl.getAnfme());
+                VersionUtils.setWrkDetl(wrkDetl, locDetl); // 鐗堟湰鎺у埗
+                wrkDetl.setAppeTime(new Date());
+                wrkDetl.setModiTime(new Date());
+                if (!wrkDetlService.insert(wrkDetl)) {
+                    throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+                }
+            }
+            // 淇敼婧愬簱浣嶇姸鎬�
+            if (sourceLoc.getLocSts().equals("D") || sourceLoc.getLocSts().equals("F")) {
+                sourceLoc.setLocSts("R"); // R.鍑哄簱棰勭害
+                sourceLoc.setModiTime(new Date());
+                if (!locMastService.updateById(sourceLoc)){
+                    throw new CoolException("鏇存柊婧愬簱浣嶇姸鎬佸け璐�");
+                }
+            } else {
+                throw new CoolException("婧愬簱浣嶅嚭搴撳け璐�");
+            }
+            // 淇敼鐩爣搴撲綅鐘舵��
+            if (loc.getLocSts().equals("O")) {
+                loc.setLocSts("S"); // S.鍏ュ簱棰勭害
+                loc.setModiTime(new Date());
+                if (!locMastService.updateById(loc)) {
+                    throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
+                }
+            } else {
+                throw new CoolException("绉昏浆澶辫触");
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.1