From 7be83adcdc6ee45fce42d14d7da2be33b1bcc216 Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期四, 18 五月 2023 09:23:48 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java |  198 ++++++++++++++++++++++++-------------------------
 1 files changed, 98 insertions(+), 100 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
index 468575f..5334814 100644
--- a/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/OpenServiceImpl.java
@@ -1,7 +1,5 @@
 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.BaseRes;
@@ -16,22 +14,17 @@
 import com.zy.asrs.mapper.TagMapper;
 import com.zy.asrs.service.*;
 import com.zy.asrs.task.AbstractHandler;
-import com.zy.asrs.task.core.ReturnT;
 import com.zy.asrs.utils.MatUtils;
-import com.zy.common.constant.MesConstant;
+import com.zy.asrs.utils.PostMesDataUtils;
 import com.zy.common.model.DetlDto;
 import com.zy.common.model.enums.WorkNoType;
 import com.zy.common.service.CommonService;
-import com.zy.common.utils.HttpHandler;
 import com.zy.common.utils.NodeUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
@@ -70,15 +63,12 @@
     @Autowired
     private CommonService commonService;
     @Autowired
-    private ApiLogService apiLogService;
-    @Autowired
     private WrkMastService wrkMastService;
-
-    @Value("${mes.url}")
-    private String mesUrl;
 
     @Value("${mes.inPath}")
     private String inpath;
+    @Value("${mes.url}")
+    private String mesUrl;
 
     @Override
     @Transactional
@@ -579,6 +569,15 @@
     @Override
     @Transactional
     public void combPACK(CombParam param) {
+        if (Cools.isEmpty(param.getPackNo())){
+            throw new CoolException("缂哄皯鍙傛暟锛歱ackNo");
+        }else if (Cools.isEmpty(param.getPackName())){
+            throw new CoolException("缂哄皯鍙傛暟锛歱ackName");
+//        }else if (Cools.isEmpty(param.getSettingTimes())){
+//            throw new CoolException("缂哄皯鍙傛暟锛歴ettingTimes");
+        }else if (Cools.isEmpty(param.getRequestTime())){
+            throw new CoolException("缂哄皯鍙傛暟锛歳equestTime");
+        }
         if (Cools.isEmpty(param.getPackNo())) {
             throw new CoolException(BaseRes.PARAM);
         }
@@ -590,24 +589,32 @@
 
         int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getPackNo()));
         int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getPackNo()));
+        int countPakin = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",param.getPackNo()));
         if (countLoc > 0 || countWrk > 0) {
             throw new CoolException("宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getPackNo());
+        }else if (countPakin>0){
+            throw new CoolException("閲嶅鐢宠" + param.getPackNo());
         }
 
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        java.util.Date date1=null;
-        try {
-            date1= sdf.parse(param.getRequestTime());
-        } catch (ParseException e) {
-            e.printStackTrace();
-        }
-        java.sql.Date requestTime = new java.sql.Date(date1.getTime());
-
-        // 鐢熸垚鍏ュ簱閫氱煡妗�
-//        Mat mat = matService.selectByMatnr(param.getPackName());
-//        if (Cools.isEmpty(mat)) {
+//         鐢熸垚鍏ュ簱閫氱煡妗�
+        Mat mat = matService.selectByMatnr(param.getPackName());
+        if (Cools.isEmpty(mat)) {
+            Tag tag = tagService.selectByName("鍏ㄩ儴", 1);
+            Mat matNew = new Mat();
+            matNew.setTagId(tag.getId());
+            matNew.setMatnr(param.getPackName());
+            matNew.setMaktx(param.getPackName());
+            matNew.setDeadWarn(480);//8灏忔椂  480鍒嗛挓
+            matNew.setCreateBy(9999L);//9999琛ㄧずerp涓嬪彂
+            matNew.setCreateTime(new Date());
+            matNew.setUpdateBy(9999L);//9999琛ㄧずerp涓嬪彂
+            matNew.setUpdateTime(new Date());
+            if (!matService.insert(matNew)){
+                throw new CoolException(param.getPackName() + "鍟嗗搧妗f鑷姩鐢熸垚澶辫触");
+            }
+            mat=matNew;
 //            throw new CoolException(param.getPackName() + "鍟嗗搧妗f涓嶅瓨鍦�");
-//        }
+        }
         WaitPakin waitPakin = new WaitPakin();
 //        waitPakin.sync(mat);
         waitPakin.setMatnr(param.getPackName());
@@ -616,12 +623,12 @@
         waitPakin.setIoStatus("N");     // 鍏ュ嚭鐘舵��
         waitPakin.setAnfme(1.0);  // 鏁伴噺
         waitPakin.setStatus("Y");    // 鐘舵��
-        waitPakin.setManuDate(requestTime.toString());
+        waitPakin.setManuDate(param.getRequestTime());
         waitPakin.setAppeUser(null);
         waitPakin.setAppeTime(new Date());
         waitPakin.setModiUser(null);
         waitPakin.setModiTime(new Date());
-        waitPakin.setDeadWarn(param.getSettingTimes());
+        waitPakin.setDeadWarn(mat.getDeadWarn());
         if (!waitPakinService.insert(waitPakin)) {
             throw new CoolException("淇濆瓨鍏ュ簱閫氱煡妗eけ璐�");
         }
@@ -629,6 +636,15 @@
     @Override
     @Transactional
     public void combPackOut(CombParam param) {
+        if (Cools.isEmpty(param.getPackNo())){
+            throw new CoolException("缂哄皯鍙傛暟锛歱ackNo");
+        }else if (Cools.isEmpty(param.getPackName())){
+            throw new CoolException("缂哄皯鍙傛暟锛歱ackName");
+        }else if (Cools.isEmpty(param.getSettingTimes())){
+            throw new CoolException("缂哄皯鍙傛暟锛歴ettingTimes");
+        }else if (Cools.isEmpty(param.getRequestTime())){
+            throw new CoolException("缂哄皯鍙傛暟锛歳equestTime");
+        }
         if (Cools.isEmpty(param.getPackNo())) {
             throw new CoolException(BaseRes.PARAM);
         }
@@ -638,16 +654,10 @@
                 .eq("barcode", param.getPackNo()));
         if (Cools.isEmpty(locMast)){
             throw new CoolException("鏈煡璇㈠埌PACK鐮佷负锛�"+param.getPackNo()+"鐨勮揣鐗�");
-        }else if (locMast.getLocSts().equals("F")){
+        }else if (!locMast.getLocSts().equals("F")){
             throw new CoolException("PACK鐮佷负锛�"+param.getPackNo()+"鐨勮揣鐗╁簱浣嶇姸鎬佷笉鏄�淔鈥�");
         }else if (locMast.getFireStatus()!=0){
             throw new CoolException("璀﹀憡锛侊紒锛丳ACK鐮佷负锛�"+param.getPackNo()+"鐨勫簱浣嶏細"+locMast.getLocNo()+"娑堥槻鐘舵�佸紓甯革紒锛侊紒");
-//        }else if (locMast.getFireStatus()!=0){
-//            throw new CoolException("璀﹀憡锛侊紒锛丳ACK鐮佷负锛�"+param.getPackNo()+"鐨勫簱浣嶏細"+locMast.getLocNo()+"娑堥槻鐘舵�佸紓甯革紒锛侊紒");
-//        }else if (locMast.getFireStatus()!=0){
-//            throw new CoolException("璀﹀憡锛侊紒锛丳ACK鐮佷负锛�"+param.getPackNo()+"鐨勫簱浣嶏細"+locMast.getLocNo()+"娑堥槻鐘舵�佸紓甯革紒锛侊紒");
-//        }else if (locMast.getFireStatus()!=0){
-//            throw new CoolException("璀﹀憡锛侊紒锛丳ACK鐮佷负锛�"+param.getPackNo()+"鐨勫簱浣嶏細"+locMast.getLocNo()+"娑堥槻鐘舵�佸紓甯革紒锛侊紒");
         }else {
             Date now = new Date();
             Integer ioType = 101;   //鍏ュ嚭搴撶被鍨�
@@ -700,13 +710,13 @@
                 if (locMast.getLocSts().equals("F")) {
                     locMast.setLocSts("R");
                     locMast.setModiTime(now);
-                    locMast.setPackStatus(5); //5:闈欑疆瀹屾垚
+                    locMast.setPackStatus(6); //6:闈欑疆瀹屾垚
                     CombParam combParam = new CombParam();
                     combParam.setPackNo(locMast.getBarcode());
                     combParam.setLocNo(locMast.getLocNo());
-                    combParam.setPackSts(6);
+                    combParam.setPackSts(7);
                     combParam.setRequestTime(DateUtils.convert(new Date()));
-                    postMesData(inpath,combParam);
+                    new PostMesDataUtils().postMesData("MES绯荤粺",mesUrl,inpath,combParam);
 
                     if (!locMastService.updateById(locMast)) {
                         throw new CoolException("棰勭害搴撲綅鐘舵�佸け璐ワ紝搴撲綅鍙凤細"+locMast.getLocNo());
@@ -752,13 +762,9 @@
                     throw new CoolException("鏇存柊娴嬭瘯鐘舵�佸け璐�");
                 }
                 locMast.setPackStatus(2);
-                CombParam combParam = new CombParam();
-                combParam.setPackNo(locMast.getBarcode());
-                combParam.setLocNo(locMast.getLocNo());
-                combParam.setPackSts(2);
-                combParam.setRequestTime(DateUtils.convert(new Date()));
-                postMesData(inpath,combParam);
                 if (!locMastService.update(locMast,new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo()))){
+
+
                     throw new CoolException("鏇存柊浜у搧鐘舵�佸け璐�");
                 }
             } else if (Cools.isEmpty(testMast.getStatus())){
@@ -793,12 +799,54 @@
                 Date date = new Date();
                 locMast.setPackStatus(3);
                 locMast.setModiTime(date);
-                CombParam combParam = new CombParam();
-                combParam.setPackNo(locMast.getBarcode());
-                combParam.setLocNo(locMast.getLocNo());
-                combParam.setPackSts(3);
-                combParam.setRequestTime(DateUtils.convert(new Date()));
-                postMesData(inpath,combParam);
+//                CombParam combParam = new CombParam();
+//                combParam.setPackNo(locMast.getBarcode());
+//                combParam.setLocNo(locMast.getLocNo());
+//                combParam.setPackSts(3);
+//                combParam.setRequestTime(DateUtils.convert(new Date()));
+//                new PostMesDataUtils().postMesData("MES绯荤粺",mesUrl,inpath,combParam);
+
+                if (!locMastService.update(locMast, new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo()))){
+                    throw new CoolException("鏇存敼浜у搧鐘舵�佸け璐�");
+                }
+            }else if (Cools.isEmpty(testMast.getStatus())){
+                throw new CoolException("鐘舵�佸紓甯�");
+            }else {
+                throw new CoolException("娴嬭瘯鐘舵�佷笉鏄� 3:娴嬭瘯涓�");
+            }
+        } else {
+            throw new CoolException("鐘舵�佸紓甯�");
+        }
+        return success;
+    }
+
+    @Override
+    @Transactional
+    public Boolean testNG(Review review) {
+        Boolean success=true;
+        Wrapper wrapper = new EntityWrapper<TestMast>()
+                .eq("loc_no", review.getLocNo())
+                .eq("barcode", review.getBarcode())
+                .eq("user_Id", review.getUserId());
+        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo()));
+        if (null == locMast ||locMast.getPackStatus()!=2){
+            throw new CoolException("浜у搧鐘舵�佷笉鏄� 2:娴嬭瘯涓�");
+        }else if (!review.getBarcode().equals(locMast.getBarcode())){
+            throw new CoolException("pack鐮佷笉鍚�");
+        }
+        TestMast testMast = testMastService.selectOne(wrapper);
+        if(null != testMast){
+            if (testMast.getStatus()==3){
+                Date date = new Date();
+                locMast.setPackStatus(4);
+                locMast.setModiTime(date);
+//                CombParam combParam = new CombParam();
+//                combParam.setPackNo(locMast.getBarcode());
+//                combParam.setLocNo(locMast.getLocNo());
+//                combParam.setPackSts(4);
+//                combParam.setRequestTime(DateUtils.convert(new Date()));
+//                new PostMesDataUtils().postMesData("MES绯荤粺",mesUrl,inpath,combParam);
+
                 if (!locMastService.update(locMast, new EntityWrapper<LocMast>().eq("loc_no", review.getLocNo()))){
                     throw new CoolException("鏇存敼浜у搧鐘舵�佸け璐�");
                 }
@@ -811,56 +859,6 @@
             throw new CoolException("鐘舵�佸紓甯�");
         }
         return success;
-    }
-
-    private ReturnT<String> postMesData(String mesPath, Object combParam){
-        if(combParam != null){
-            String response = "";
-            boolean success = false;
-            try {
-//                Map<String, Object> map = new HashMap<>();
-//                map.put("appkey","ea1f0459efc02a79f046f982767939ae");
-                response = new HttpHandler.Builder()
-//                        .setHeaders(map)
-                        .setUri(mesUrl)
-                        .setPath(mesPath)
-                        .setJson(JSON.toJSONString(combParam))
-                        .build()
-                        .doPost();
-                JSONObject jsonObject = JSON.parseObject(response);
-                if (jsonObject.getInteger("code").equals(200)) {
-                    if (jsonObject.getDate("isComplete").equals(true)){
-                        success = true;
-                    }else if (jsonObject.getDate("isComplete").equals(false)){
-                        success = false;
-                    }else {
-                        log.error("杩斿洖鍊煎嚭閿�!!!url锛歿}锛況equest锛歿}锛況esponse锛歿}", mesUrl+mesPath, JSON.toJSONString(combParam), response);
-                        throw new CoolException("杩斿洖鍊煎嚭閿�");
-                    }
-                } else {
-                    log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", mesUrl+mesPath, JSON.toJSONString(combParam), response);
-                    throw new CoolException("涓婃姤mes绯荤粺澶辫触");
-                }
-            } catch (Exception e) {
-                log.error("fail", e);
-//                      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                return FAIL.setMsg(e.getMessage());
-            } finally {
-                try {
-                    // 淇濆瓨鎺ュ彛鏃ュ織
-                    apiLogService.save(
-                            "鎴愬搧搴撳叆搴撲笂鎶�",
-                            mesUrl + mesPath,
-                            null,
-                            "127.0.0.1",
-                            JSON.toJSONString(combParam),
-                            response,
-                            success
-                    );
-                } catch (Exception e) { log.error("", e); }
-            }
-        }
-        return SUCCESS;
     }
     /*...........................璧e窞鏂板..............浠ヤ笂.............璧e窞鏂板...........................*/
 

--
Gitblit v1.9.1