From 06346cdbdebfd83750aceb879664b72f0484cab0 Mon Sep 17 00:00:00 2001
From: 18516761980 <56479841@qq.com>
Date: 星期三, 17 八月 2022 16:48:02 +0800
Subject: [PATCH] Merge branch 'gzynasrs' of http://47.97.1.152:5880/r/zy-asrs into gzynasrs

---
 src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java |  274 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 265 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
index 7df6a4f..55923d4 100644
--- a/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -4,28 +4,36 @@
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.core.annotations.ManagerAuth;
 import com.core.common.*;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.entity.param.CombParam;
 import com.zy.asrs.entity.param.MobileAdjustParam;
 import com.zy.asrs.entity.param.OpenOrderPakinParam;
+import com.zy.asrs.entity.param.Review;
 import com.zy.asrs.service.*;
+import com.zy.asrs.task.AbstractHandler;
+import com.zy.asrs.task.core.ReturnT;
+import com.zy.asrs.task.handler.WorkLogHandler;
 import com.zy.asrs.utils.MatUtils;
+import com.zy.common.CodeRes;
 import com.zy.common.constant.MesConstant;
 import com.zy.common.entity.Parameter;
 import com.zy.common.model.DetlDto;
 import com.zy.common.model.MesCombParam;
+import com.zy.common.service.CommonService;
 import com.zy.common.utils.HttpHandler;
 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 org.springframework.transaction.interceptor.TransactionAspectSupport;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 /**
  * 绉诲姩绔湇鍔℃牳蹇冪被
@@ -33,7 +41,7 @@
  */
 @Slf4j
 @Service
-public class MobileServiceImpl implements MobileService {
+public class MobileServiceImpl extends AbstractHandler<String> implements MobileService{
 
     @Autowired
     private MatService matService;
@@ -63,6 +71,28 @@
     private LocMastService locMastService;
     @Autowired
     private LocDetlService locDetlService;
+    @Autowired
+    private StaDescService staDescService;
+    @Autowired
+    private CommonService commonService;
+    @Autowired
+    private NodeService nodeService;
+    @Autowired
+    private ManLocDetlService manLocDetlService;
+    @Autowired
+    private TestMastService testMastService;
+    @Autowired
+    private WorkLogHandler workLogHandler;
+
+    @Value("${mes.url}")
+    private String mesUrl;
+
+    @Value("${mes.startUpTestPACK}")
+    private String startUpTestPACK;
+
+    @Value("${mes.startUpTestPACK}")
+    private String suspendTestPACK;
+
 
     @Override
     @Transactional
@@ -75,6 +105,13 @@
                 eq("zpallet", param.getBarcode()).eq("io_status", "N")) > 0) {
             throw new CoolException(param.getBarcode() + "鏁版嵁姝e湪杩涜鍏ュ簱");
         }
+
+        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode()));
+        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode()));
+        if (countLoc > 0 || countWrk > 0) {
+            throw new CoolException("宸ヤ綔妗�/搴撳瓨鏉$爜鏁版嵁宸插瓨鍦�===>>" + param.getBarcode());
+        }
+
         Date now = new Date();
 
         // 鏃犲崟缁勬墭
@@ -167,6 +204,39 @@
             orderService.updateSettle(order.getId(), 2L, userId);
         }
 
+    }
+
+    @Override
+    public void onSale(CombParam param) {
+        // 鑾峰彇搴撲綅鍙�
+        String locno = param.getLocno();
+        Node node = nodeService.selectByUuid(locno);
+        if (Cools.isEmpty(node)) {
+            throw new CoolException(param.getLocno() + ":搴撲綅涓嶅瓨鍦�");
+        }
+
+        // 鑾峰彇鍟嗗搧鍒楄〃
+        for(CombParam.CombMat combMat : param.getCombMats()){
+            Mat mat = matService.selectByMatnr(combMat.getMatnr());
+            if (Cools.isEmpty(mat)){
+                throw new CoolException(combMat.getMatnr() + ":鍟嗗搧妗f涓嶅瓨鍦紒");
+            }
+            if (Cools.isEmpty(combMat.getAnfme()) || combMat.getAnfme()==0){
+                throw new CoolException(combMat.getMatnr() + ":鍟嗗搧鏁伴噺鏈夎锛�");
+            }
+            if (Cools.isEmpty(combMat.getBatch())){
+                throw new CoolException(combMat.getMatnr() + ":鍟嗗搧鎵瑰彿鏈夎锛�");
+            }
+            ManLocDetl manLocDetl = new ManLocDetl();
+            manLocDetl.setLocNo(locno);
+            manLocDetl.setNodeId(node.getId());
+            manLocDetl.setMatnr(combMat.getMatnr());
+            manLocDetl.setBatch(combMat.getBatch());
+            manLocDetl.setAnfme(combMat.getAnfme());
+            if (!manLocDetlService.insert(manLocDetl)) {
+                throw new CoolException("鍟嗗搧涓婃灦澶辫触锛�");
+            }
+        }
     }
 
     @Override
@@ -413,11 +483,15 @@
         BasDevp sta = basDevpService.checkSiteStatus(staNo);
         //鏍规嵁璁㈠崟鍙风敓鎴愬嚭搴撲换鍔″伐浣滄。
         Order order = orderService.selectOne(new EntityWrapper<Order>().eq("order_no", orderNo));
+        if (order.getSettle() != 1 && order.getSettle() != 2){
+            throw new CoolException("璇ヨ鍗曞凡澶勭悊");
+        }
+
         List<OrderDetl> orderDetls = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo));
         Date now = new Date();
         for(OrderDetl orderDetl : orderDetls){
             //鏌ヨ鎵�鏈夊簱浣嶇姸鎬佷负F鐨勫簱浣嶄俊鎭�
-            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),orderDetl.getOrderNo(),null);
+            List<LocDetl> locDetls = locDetlService.queryStock(orderDetl.getMatnr(),orderDetl.getBatch(),null,null);
             if (locDetls.size() == 0) {
                 throw new CoolException("搴撳瓨涓病鏈夎鐗╂枡");
             }
@@ -444,11 +518,11 @@
                 Double curOutQty = outQty >= locDetl.getAnfme() ? locDetl.getAnfme() : outQty;   //鏈鍑哄簱閲�
                 int ioType = sumCount <= curOutQty ? 101 : 103;
 
-//                stockOut(orderDetl, sta, locDetl, curOutQty, ioType, userId);
+                stockOut(orderDetl, sta, locDetl, curOutQty, ioType, userId, now);
                 order.setSettle(2L);
                 order.setUpdateBy(userId);
                 order.setUpdateTime(now);
-                if(orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
+                if(!orderService.update(order, new EntityWrapper<Order>().eq("order_no", orderNo))){
                     throw new CoolException("鏇存柊璁㈠崟鐘舵�佸け璐�");
                 }
                 orderDetl.setWorkQty(orderDetl.getWorkQty() + curOutQty);
@@ -459,7 +533,7 @@
                 if(!Cools.isEmpty(orderDetl.getBatch())){
                     wrapper.eq("batch", orderDetl.getBatch());
                 }
-                if(orderDetlService.update(orderDetl, wrapper)){
+                if(!orderDetlService.update(orderDetl, wrapper)){
                     throw new CoolException("鏇存柊璁㈠崟鏄庣粏澶辫触");
                 }
             }
@@ -471,6 +545,188 @@
     @Transactional
     public void stockOut(OrderDetl orderDetl, BasDevp staNo, LocDetl locDetl,
                          Double curOutQty, Integer ioType, Long userId, Date now) {
+        // 鑾峰彇搴撲綅
+        LocMast locMast = locMastService.selectById(locDetl.getLocNo());
+        // 鑾峰彇璺緞
+        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+                .eq("type_no", ioType)
+                .eq("stn_no", staNo.getDevNo())
+                .eq("crn_no", locMast.getCrnNo());
 
+        StaDesc staDesc = staDescService.selectOne(wrapper);
+        if (Cools.isEmpty(staDesc)) {
+            throw new CoolException("鍑哄簱璺緞涓嶅瓨鍦�");
+        }
+        // 鐢熸垚宸ヤ綔鍙�
+        int workNo = commonService.getWorkNo(2);
+        // 鐢熸垚宸ヤ綔妗�
+        WrkMast wrkMast = new WrkMast();
+        wrkMast.setWrkNo(workNo);
+        wrkMast.setIoTime(now);
+        wrkMast.setWrkSts(11L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
+        wrkMast.setIoType(ioType); // 鍏ュ嚭搴撶姸鎬�
+        wrkMast.setIoPri(13D); // 浼樺厛绾э細13
+        wrkMast.setCrnNo(locMast.getCrnNo());
+        wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 婧愮珯
+        wrkMast.setStaNo(staDesc.getStnNo()); // 鐩爣绔�
+        wrkMast.setSourceLocNo(locDetl.getLocNo()); // 婧愬簱浣�
+        wrkMast.setFullPlt("Y"); // 婊℃澘锛歒
+        wrkMast.setPicking("N"); // 鎷f枡
+        wrkMast.setExitMk("N"); // 閫�鍑�
+        wrkMast.setEmptyMk("N"); // 绌烘澘
+        wrkMast.setLinkMis("N");
+        wrkMast.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁
+        wrkMast.setAppeTime(now);
+        wrkMast.setModiUser(userId);
+        wrkMast.setModiTime(now);
+        wrkMast.setBarcode(locMast.getBarcode());
+        if (!wrkMastService.insert(wrkMast)) {
+            throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐ワ紝鍑哄簱搴撲綅鍙凤細" + locDetl.getLocNo());
+        }
+
+        WrkDetl wrkDetl = new WrkDetl();
+        wrkDetl.sync(locDetl);
+        wrkDetl.setWrkNo(workNo);
+        wrkDetl.setIoTime(now);
+        wrkDetl.setAnfme(curOutQty); // 鏁伴噺
+        wrkDetl.setOrderNo(orderDetl.getOrderNo());
+        wrkDetl.setAppeTime(now);
+        wrkDetl.setAppeUser(userId);
+        wrkDetl.setModiTime(now);
+        wrkDetl.setModiUser(userId);
+        if (!wrkDetlService.insert(wrkDetl)) {
+            throw new CoolException("淇濆瓨宸ヤ綔妗f槑缁嗗け璐�");
+        }
+
+        // 淇敼搴撲綅鐘舵��:   F.鍦ㄥ簱 ====>>> R.鍑哄簱棰勭害/P.鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓�
+        locMast = locMastService.selectById(locDetl.getLocNo());
+        if (locMast.getLocSts().equals("F")) {
+            locMast.setLocSts(ioType == 101 ? "R" : "P");
+            locMast.setModiUser(userId);
+            locMast.setModiTime(new Date());
+            if (!locMastService.updateById(locMast)) {
+                throw new CoolException("棰勭害搴撲綅鐘舵�佸け璐ワ紝搴撲綅鍙凤細" + locDetl.getLocNo());
+            }
+        } else {
+            throw new CoolException(locDetl.getLocNo() + "搴撲綅涓嶆槸鍦ㄥ簱鐘舵��");
+        }
     }
+
+    /*...........................璧e窞鏂板..............浠ヤ笅.............璧e窞鏂板...........................*/
+    @Override
+    @Transactional
+    public void startUpTestPACK(TestMast testMast) {
+
+        //鍚姩娴嬭瘯璇锋眰
+//        ReturnT<String> result=startUpTestPACK1(testMast);
+//        if (!result.isSuccess()) {
+//            log.error("娴嬭瘯鐢宠澶辫触", testMast.getBarcode());
+//            throw new CoolException("娴嬭瘯鐢宠澶辫触");
+//        }
+        LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", testMast.getLocNo()));
+        if (Cools.isEmpty(locMast)) {
+            throw new CoolException(BaseRes.PARAM);
+        }
+
+        Date now = new Date();
+        testMast.setStatus(1);
+        testMast.setModiTime(now);
+        testMast.setAppeTime(now);
+        if (!testMastService.insert(testMast)){
+            throw new CoolException("娣诲姞testMast澶辫触");
+        }
+        locMast.setPackStatus(1);
+        locMast.setModiTime(now);
+        if (!locMastService.update(locMast,new EntityWrapper<LocMast>().eq("loc_no", testMast.getLocNo()))){
+            throw new CoolException("鐢宠娴嬭瘯澶辫触");
+        }
+    }
+    @Override
+    @Transactional
+    public void suspendTestPACK() {
+        ReturnT<String> result=suspendTestPACK1();
+        if (!result.isSuccess()) {
+            log.error("鏆傚仠娴嬭瘯澶辫触");
+        }
+    }
+    @Transactional
+    public ReturnT<String> startUpTestPACK1(TestMast testMast){
+        try {
+            CombParam combParam = new CombParam();
+            combParam.setPackNo(testMast.getLocNo());
+            combParam.setPackName(testMast.getUserId());
+            combParam.setLocno(testMast.getBarcode());
+            combParam.setRequestTime(DateUtils.convert(new Date()));
+            return postMesData(startUpTestPACK,combParam);
+        }catch (Exception e) {
+            log.error("fail", e);
+            e.printStackTrace();
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return FAIL.setMsg(e.getMessage());
+        }
+    }
+    @Transactional
+    public ReturnT<String> suspendTestPACK1(){
+        try {
+            Review review=new Review();
+            review.setPause(true);
+            review.setRequestTime(DateUtils.convert(new Date()));
+            return postMesData(suspendTestPACK,review);
+        }catch (Exception e) {
+            log.error("fail", e);
+            e.printStackTrace();
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return FAIL.setMsg(e.getMessage());
+        }
+    }
+
+    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锛歿}", MesConstant.URL+MesConstant.PAKIN_URL, JSON.toJSONString(combParam), response);
+                        throw new CoolException("杩斿洖鍊煎嚭閿�");
+                    }
+                } else {
+                    log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PAKIN_URL, 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(
+                            "鎴愬搧搴撳叆搴撲笂鎶�",
+                            MesConstant.URL + MesConstant.PAKIN_URL,
+                            null,
+                            "127.0.0.1",
+                            JSON.toJSONString(combParam),
+                            response,
+                            success
+                    );
+                } catch (Exception e) { log.error("", e); }
+            }
+        }
+        return SUCCESS;
+    }
+    /*...........................璧e窞鏂板..............浠ヤ笂.............璧e窞鏂板...........................*/
 }

--
Gitblit v1.9.1