From e84d4700e32dba450aa4d239779fc39f38ae4afa Mon Sep 17 00:00:00 2001
From: admin <841110950@qq.com>
Date: 星期三, 01 九月 2021 17:22:32 +0800
Subject: [PATCH] 1.0.8

---
 src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java |  313 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 197 insertions(+), 116 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
index 449f616..b67cfb9 100644
--- a/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -4,6 +4,7 @@
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
+import com.core.common.DateUtils;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.entity.param.EmptyPlateOutParam;
@@ -11,21 +12,31 @@
 import com.zy.asrs.entity.param.LocDetlAdjustParam;
 import com.zy.asrs.entity.param.StockOutParam;
 import com.zy.asrs.service.*;
+import com.zy.asrs.utils.VersionUtils;
 import com.zy.common.model.LocDetlDto;
 import com.zy.common.model.OutLocDto;
 import com.zy.common.model.StartupDto;
 import com.zy.common.service.CommonService;
+import com.zy.ints.entity.IoComplete;
+import com.zy.ints.entity.WaitMatchk;
+import com.zy.ints.entity.WaitMatout;
+import com.zy.ints.service.IoCompleteService;
+import com.zy.ints.service.WaitMatchkService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * Created by vincent on 2020/6/11
  */
 @Service
 public class WorkServiceImpl implements WorkService {
+    static int i =1;
 
     // 宸ヤ綔鍙风敓鎴愯鍒欓粯璁ょ被鍨�
     private static final int DEFAULT_WORK_NO_TYPE = 0;
@@ -54,6 +65,10 @@
     private WrkMastLogService wrkMastLogService;
     @Autowired
     private WrkDetlLogService wrkDetlLogService;
+    @Autowired
+    private WaitMatchkService waitMatchkService;
+    @Autowired
+    private IoCompleteService ioCompleteService;
 
     @Override
     @Transactional
@@ -63,11 +78,12 @@
             throw new CoolException(BaseRes.PARAM);
         }
         // 婧愮珯鐐圭姸鎬佹娴�
-        BasDevp sourceStaNo = basDevpService.checkSiteStatus(param.getDevpNo());
+        BasDevp sourceStaNo = basDevpService.checkSiteStatus(param.getDevpNo(), true);
         // 鐢熸垚宸ヤ綔鍙�
         int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
         // 妫�绱㈠簱浣�
-        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo());
+        List<String> matNos = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatNo).distinct().collect(Collectors.toList());
+        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo(), matNos, 0);
         // 鐢熸垚宸ヤ綔妗�
         WrkMast wrkMast = new WrkMast();
         wrkMast.setWrkNo(workNo);
@@ -110,8 +126,8 @@
         }
         // 鏇存柊鐩爣搴撲綅鐘舵��
         LocMast locMast = locMastService.selectById(dto.getLocNo());
-        if (locMast.getLocType().equals("O")){
-            locMast.setLocType("S"); // S.鍏ュ簱棰勭害
+        if (locMast.getLocSts().equals("O")){
+            locMast.setLocSts("S"); // S.鍏ュ簱棰勭害
             locMast.setModiUser(userId);
             locMast.setModiTime(new Date());
             if (!locMastService.updateById(locMast)){
@@ -131,25 +147,26 @@
         // 鑾峰彇搴撲綅鏄庣粏
         List<LocDetlDto> locDetlDtos = new ArrayList<>();
         for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
-            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())) {
+            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatNo(), paramLocDetl.getCount())) {
                 LocDetl sqlParam = new LocDetl();
                 sqlParam.setLocNo(paramLocDetl.getLocNo());
-                sqlParam.setMatnr(paramLocDetl.getMatnr());
+                sqlParam.setMatNo(paramLocDetl.getMatNo());
                 LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
                 if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount()));
             }
         }
         if (!locDetlDtos.isEmpty()) {
             // 鍚姩鍑哄簱寮�濮� 101.鍑哄簱
-            stockOut(staNo, locDetlDtos, 101, userId);
+            stockOut(staNo, locDetlDtos, null, userId);
         } else {
-            throw new CoolException("搴撲綅鐗╂枡涓嶅瓨鍦�");
+            throw new CoolException("搴撲綅浜у搧涓嶅瓨鍦�");
         }
     }
 
     @Override
     @Transactional
     public void stockOut(BasDevp staNo, List<LocDetlDto> locDetlDtos, Integer ioType, Long userId) {
+
         // 鍚堝苟鍚岀被椤�
         Set<String> locNos = new HashSet<>();
         locDetlDtos.forEach(dto -> locNos.add(dto.getLocDetl().getLocNo()));
@@ -161,15 +178,51 @@
                 LocDetlDto dto = iterator.next();
                 if (locNo.equals(dto.getLocDetl().getLocNo())) {
                     list.add(dto);
-                    iterator.remove();
+//                    iterator.remove();
                 }
             }
             dtos.add(new OutLocDto(locNo, list));
         }
+        //鐢熸垚鐩樼偣鏂囨。
+        for (LocDetlDto locDetlDto : locDetlDtos) {
+
+            String id="";
+            //鑾峰彇褰撳墠鏃堕棿鎴�
+            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
+            String temp = sf.format(new Date());
+            //鑾峰彇6浣嶉殢鏈烘暟
+            int random=(int) ((Math.random()+1)*1000);
+            id=temp+random;
+
+//            String replace = UUID.randomUUID().toString().replace("-", "");
+            LocDetl locDetl = locDetlDto.getLocDetl();
+            //鐢熸垚鐩樼偣妗�
+            WaitMatchk waitMatchk = new WaitMatchk();
+            waitMatchk.setBillNo(id);//璁㈠崟缂栧彿
+            waitMatchk.setLocNo(locDetl.getLocNo());//搴撲綅鍙�
+            waitMatchk.setStockQty(locDetl.getQty());
+            waitMatchk.setMatNo(locDetl.getMatNo());//浜у搧缂栧彿
+            waitMatchk.setMatName(locDetl.getMatName());//閾插钩鍚嶇О
+            waitMatchk.setSeqNo(i);
+            waitMatchk.setIoTime(new Date());
+            waitMatchk.setZpallet(locDetl.getZpallet());
+            waitMatchk.setAppeUser(userId); // 鎿嶄綔浜哄憳鏁版嵁
+            waitMatchk.setAppeTime(new Date());
+            waitMatchk.setModiUser(userId);
+            waitMatchk.setModiTime(new Date());
+            if (!waitMatchkService.insert(waitMatchk)){
+                throw new CoolException("淇濆瓨鐩樼偣妗eけ璐�");
+            }
+            i++;
+        }
+
         // 鐢熸垚宸ヤ綔妗�
         for (OutLocDto dto : dtos) {
+
             // 鍒ゆ柇鍏ュ嚭搴撶被鍨嬶細101.鍏ㄦ澘鍑哄簱 or 103.鎷f枡鍑哄簱
-            ioType = (dto.isAll() && (ioType==101||ioType==103))?101:103;
+            if (ioType == null) {
+                ioType = dto.isAll() ? 101 : 103;
+            }
             // 鑾峰彇搴撲綅
             LocMast locMast = locMastService.selectById(dto.getLocNo());
             // 鑾峰彇璺緞
@@ -183,6 +236,8 @@
             }
             // 鐢熸垚宸ヤ綔鍙�
             int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
+
+
             // 鐢熸垚宸ヤ綔妗�
             WrkMast wrkMast = new WrkMast();
             wrkMast.setWrkNo(workNo);
@@ -213,16 +268,9 @@
                 WrkDetl wrkDetl = new WrkDetl();
                 wrkDetl.setWrkNo(workNo);
                 wrkDetl.setIoTime(new Date());
-                wrkDetl.setMatnr(detlDto.getLocDetl().getMatnr());
-                Double anfme = ioType==101?detlDto.getCount():detlDto.getLocDetl().getAnfme();
-                wrkDetl.setAnfme(anfme); // 鏁伴噺
-                wrkDetl.setZmatid(detlDto.getLocDetl().getZmatid());
-                wrkDetl.setTbpos(detlDto.getLocDetl().getTbpos());
-                wrkDetl.setTbnum(detlDto.getLocDetl().getTbnum());
-                wrkDetl.setLgnum(detlDto.getLocDetl().getLgnum());
-                wrkDetl.setAltme(detlDto.getLocDetl().getAltme());
-                wrkDetl.setBname(detlDto.getLocDetl().getBname());
-                wrkDetl.setMaktx(detlDto.getLocDetl().getMaktx());
+                Double qty = ioType==101?detlDto.getLocDetl().getQty():detlDto.getCount();
+                wrkDetl.setQty(qty); // 鏁伴噺
+                VersionUtils.setWrkDetl(wrkDetl, detlDto.getLocDetl()); // 鐗堟湰鎺у埗
                 wrkDetl.setAppeTime(new Date());
                 wrkDetl.setAppeUser(userId);
                 wrkDetl.setModiTime(new Date());
@@ -233,8 +281,8 @@
             }
             // 淇敼搴撲綅鐘舵��:   F.鍦ㄥ簱 ====>>> R.鍑哄簱棰勭害/P.鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓�
             locMast = locMastService.selectById(dto.getLocNo());
-            if (locMast.getLocType().equals("F")) {
-                locMast.setLocType(ioType==101?"R":"P");
+            if (locMast.getLocSts().equals("F")) {
+                locMast.setLocSts(ioType==101?"R":"P");
                 locMast.setModiUser(userId);
                 locMast.setModiTime(new Date());
                 if (!locMastService.updateById(locMast)) {
@@ -250,23 +298,23 @@
     @Transactional
     public String emptyPlateIn(Integer devpNo, Long userId) {
         // 婧愮珯鐐圭姸鎬佹娴�
-        BasDevp sourceStaNo = basDevpService.checkSiteStatus(devpNo);
+        BasDevp sourceStaNo = basDevpService.checkSiteStatus(devpNo, true);
         // 鐢熸垚宸ヤ綔鍙�
         int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
         // 妫�绱㈠簱浣�
-        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 10, devpNo);
+        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 10, devpNo, null, 0);
         // 鐢熸垚宸ヤ綔妗�
         WrkMast wrkMast = new WrkMast();
         wrkMast.setWrkNo(workNo);
         wrkMast.setIoTime(new Date());
         wrkMast.setWrkSts(1L); // 宸ヤ綔鐘舵�侊細鐢熸垚鍏ュ簱ID
         wrkMast.setIoType(10); // 鍏ュ嚭搴撶姸鎬侊細10.绌烘澘鍏ュ簱
-        wrkMast.setIoPri(13D); // 浼樺厛绾э細10
+        wrkMast.setIoPri(10D); // 浼樺厛绾э細10
         wrkMast.setCrnNo(dto.getCrnNo());
         wrkMast.setSourceStaNo(dto.getSourceStaNo());
         wrkMast.setStaNo(dto.getStaNo());
         wrkMast.setLocNo(dto.getLocNo());
-        wrkMast.setFullPlt("N"); // 婊℃澘锛歒
+        wrkMast.setFullPlt("N"); // 婊℃澘
         wrkMast.setPicking("N"); // 鎷f枡
         wrkMast.setExitMk("N"); // 閫�鍑�
         wrkMast.setEmptyMk("Y"); // 绌烘澘
@@ -290,8 +338,8 @@
         }
         // 鏇存柊鐩爣搴撲綅鐘舵��
         LocMast locMast = locMastService.selectById(dto.getLocNo());
-        if (locMast.getLocType().equals("O")){
-            locMast.setLocType("S"); // S.鍏ュ簱棰勭害
+        if (locMast.getLocSts().equals("O")){
+            locMast.setLocSts("S"); // S.鍏ュ簱棰勭害
             locMast.setModiUser(userId);
             locMast.setModiTime(new Date());
             if (!locMastService.updateById(locMast)){
@@ -352,8 +400,8 @@
                 throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�");
             }
             // 鏇存柊搴撲綅鐘舵�� D.绌烘澘 -> R.鍑哄簱棰勭害
-            if (locMast.getLocType().equals("D")){
-                locMast.setLocType("R");
+            if (locMast.getLocSts().equals("D")){
+                locMast.setLocSts("R");
                 locMast.setModiUser(userId);
                 locMast.setModiTime(new Date());
                 if (!locMastService.updateById(locMast)) {
@@ -372,19 +420,19 @@
         // 鑾峰彇搴撲綅鏄庣粏
         List<LocDetlDto> locDetlDtos = new ArrayList<>();
         for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
-            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr())) {
+            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatNo())) {
                 LocDetl sqlParam = new LocDetl();
                 sqlParam.setLocNo(paramLocDetl.getLocNo());
-                sqlParam.setMatnr(paramLocDetl.getMatnr());
+                sqlParam.setMatNo(paramLocDetl.getMatNo());
                 LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
-                if (null != one) locDetlDtos.add(new LocDetlDto(one, one.getAnfme()));
+                if (null != one) locDetlDtos.add(new LocDetlDto(one, one.getQty()));
             }
         }
         if (!locDetlDtos.isEmpty()) {
             // 鍚姩鍑哄簱寮�濮� 107.鐩樼偣鍑哄簱
             stockOut(staNo, locDetlDtos, 107, userId);
         } else {
-            throw new CoolException("搴撲綅鐗╂枡涓嶅瓨鍦�");
+            throw new CoolException("搴撲綅浜у搧涓嶅瓨鍦�");
         }
     }
 
@@ -417,7 +465,8 @@
         wrkMast.setFullPlt("N"); // 婊℃澘锛歒
         wrkMast.setPicking("N"); // 鎷f枡
         wrkMast.setExitMk("N"); // 閫�鍑�
-        wrkMast.setEmptyMk(sourceLoc.getLocType().equals("D")?"Y":"N"); // 绌烘澘
+        wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 绌烘澘
+        wrkMast.setBarcode(sourceLoc.getBarcode()); // 鎵樼洏鐮�
         wrkMast.setLinkMis("N");
         wrkMast.setAppeUser(userId);
         wrkMast.setAppeTime(new Date());
@@ -433,15 +482,8 @@
             WrkDetl wrkDetl = new WrkDetl();
             wrkDetl.setWrkNo(workNo);
             wrkDetl.setIoTime(new Date());
-            wrkDetl.setMatnr(locDetl.getMatnr());
-            wrkDetl.setAnfme(locDetl.getAnfme());
-            wrkDetl.setZmatid(locDetl.getZmatid());
-            wrkDetl.setTbpos(locDetl.getTbpos());
-            wrkDetl.setTbnum(locDetl.getTbnum());
-            wrkDetl.setLgnum(locDetl.getLgnum());
-            wrkDetl.setAltme(locDetl.getAltme());
-            wrkDetl.setBname(locDetl.getBname());
-            wrkDetl.setMaktx(locDetl.getMaktx());
+            wrkDetl.setQty(locDetl.getQty());
+            VersionUtils.setWrkDetl(wrkDetl, locDetl); // 鐗堟湰鎺у埗
             wrkDetl.setAppeTime(new Date());
             wrkDetl.setAppeUser(userId);
             wrkDetl.setModiTime(new Date());
@@ -451,26 +493,26 @@
             }
         }
         // 淇敼婧愬簱浣嶇姸鎬�
-        if (sourceLoc.getLocType().equals("D") || sourceLoc.getLocType().equals("F")) {
-            sourceLoc.setLocType("R"); // R.鍑哄簱棰勭害
+        if (sourceLoc.getLocSts().equals("D") || sourceLoc.getLocSts().equals("F")) {
+            sourceLoc.setLocSts("R"); // R.鍑哄簱棰勭害
             sourceLoc.setModiUser(userId);
             sourceLoc.setModiTime(new Date());
             if (!locMastService.updateById(sourceLoc)){
                 throw new CoolException("鏇存柊婧愬簱浣嶇姸鎬佸け璐�");
             }
         } else {
-            throw new CoolException("婧愬簱浣嶅嚭搴撳け璐ワ紝鐘舵�侊細"+sourceLoc.getLocType$());
+            throw new CoolException("婧愬簱浣嶅嚭搴撳け璐ワ紝鐘舵�侊細"+sourceLoc.getLocSts$());
         }
         // 淇敼鐩爣搴撲綅鐘舵��
-        if (loc.getLocType().equals("O")) {
-            loc.setLocType("S"); // S.鍏ュ簱棰勭害
+        if (loc.getLocSts().equals("O")) {
+            loc.setLocSts("S"); // S.鍏ュ簱棰勭害
             loc.setModiTime(new Date());
             loc.setModiUser(userId);
             if (!locMastService.updateById(loc)) {
                 throw new CoolException("鏇存柊鐩爣搴撲綅鐘舵�佸け璐�");
             }
         } else {
-            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細"+loc.getLocType$());
+            throw new CoolException("绉昏浆澶辫触锛岀洰鏍囧簱浣嶇姸鎬侊細"+loc.getLocSts$());
         }
     }
 
@@ -491,7 +533,38 @@
         } else if (wrkMast.getWrkSts() > 10) {
             wrkMast.setWrkSts(14L);
         }
-        wrkMast.setModiTime(new Date());
+        //鏌ヨ鏄庣粏
+        List<WrkDetl> detls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", workNo));
+        int i=1;
+        for (WrkDetl detl : detls) {
+            //鐢熸垚鍥炴姤妗�
+            IoComplete ioComplete = new IoComplete();
+            ioComplete.setBillNo(detl.getBillNo());
+            ioComplete.setMatNo(detl.getMatNo());
+            ioComplete.setMatName(detl.getMatName());
+            ioComplete.setSeqNo(i);
+            ioComplete.setQty(detl.getQty());
+            ioComplete.setZpallet(detl.getZpallet());
+            ioComplete.setAppeUser(userId);
+            if (wrkMast.getWrkSts()==4L){
+                ioComplete.setTaskType(1);
+                ioComplete.setLocNo(wrkMast.getLocNo());
+            }else if (wrkMast.getWrkSts()==14L){
+                ioComplete.setTaskType(2);
+                ioComplete.setLocNo(wrkMast.getSourceLocNo());
+            }
+            ioComplete.setAppeTime(new Date());
+            if (!ioCompleteService.insert(ioComplete)){
+                throw new CoolException("鐢熸垚鍥炴姤妗eけ璐�");
+            }
+            i++;
+        }
+        // 瀹屾垚鎿嶄綔浜哄憳璁板綍
+        wrkMast.setManuType("鎵嬪姩瀹屾垚");
+        Date now = new Date();
+        wrkMast.setCrnStrTime(DateUtils.calculate(now, 1L, TimeUnit.SECONDS, true));
+        wrkMast.setCrnEndTime(now);
+        wrkMast.setModiTime(now);
         wrkMast.setModiUser(userId);
         if (!wrkMastService.updateById(wrkMast)) {
             throw new CoolException("淇敼宸ヤ綔妗eけ璐�");
@@ -501,55 +574,59 @@
     @Override
     @Transactional
     public void adjustLocDetl(LocDetlAdjustParam param, Long userId) {
+        //鏍规嵁搴撲綅鍙锋壘瀵诲簱浣�
         LocMast locMast = locMastService.selectById(param.getLocNo());
+        //鍒ゆ柇
         if (Cools.isEmpty(locMast)) {
             throw new CoolException("搴撲綅涓嶅瓨鍦�");
         }
+        //鏌ヨ搴撲綅鐘舵��
+        if (locMast.getLocSts().equals("O")){
+            //鏇存柊搴撲綅鐘舵��
+            locMast.setLocSts("F");
+//            boolean b = locMastService.updateById(locMast);
+            if (!locMastService.updateById(locMast)){
+                throw new CoolException("鏇存柊搴撲綅鐘舵�佸け璐�");
+            }
+        }
+
         for (LocDetlAdjustParam.LocDetlAdjust adjust : param.getList()) {
-            if (Cools.isEmpty(adjust.getMatnr())) {
+            if (Cools.isEmpty(adjust.getMatNo())) {
                 throw new CoolException(BaseRes.PARAM);
             }
             LocDetl sqlParam = new LocDetl();
             sqlParam.setLocNo(locMast.getLocNo());
-            sqlParam.setMatnr(adjust.getMatnr());
+            sqlParam.setMatNo(adjust.getMatNo());
             LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
             // 淇濆瓨鏂板簱瀛樻槑缁�
             if (Cools.isEmpty(one)) {
                 if (adjust.getCount() == 0){
                     continue;
                 }
-                MatCode matCode = matCodeService.selectById(adjust.getMatnr());
+                MatCode matCode = matCodeService.selectById(adjust.getMatNo());
                 LocDetl locDetl = new LocDetl();
                 locDetl.setLocNo(locMast.getLocNo());
-                locDetl.setMatnr(matCode.getMatNo());
-                locDetl.setMaktx(matCode.getMatName()); // 鐗╂枡鎻忚堪
-                locDetl.setAnfme(adjust.getCount()); // 鏁伴噺
-                locDetl.setAltme(matCode.getStr1()); // 鍗曚綅
-                // todo:luxiaoao
-                locDetl.setLgnum("寰呭畾"); // 浠撳簱鍙�
-                locDetl.setTbnum(0); // 杞偍璇锋眰缂栧彿
-                locDetl.setTbpos(0); // 琛岄」鐩�
-                locDetl.setZmatid("寰呭畾"); // 鐗╂枡鏍囩ID
-                locDetl.setZpallet("寰呭畾"); // 鎵樼洏鏉$爜
-
+                locDetl.setQty(adjust.getCount()); // 鏁伴噺
+                VersionUtils.setLocDetl(locDetl, matCode); // 鐗堟湰鎺у埗
                 locDetl.setModiUser(userId); // 鎿嶄綔浜哄憳淇℃伅
                 locDetl.setModiTime(new Date());
                 locDetl.setAppeUser(userId);
                 locDetl.setAppeTime(new Date());
+                locDetl.setZpallet(param.getZpallet());//鎵樼洏鍙�
                 if (!locDetlService.insert(locDetl)) {
                     throw new CoolException("淇濆瓨搴撳瓨鏄庣粏澶辫触");
                 }
                 // 淇濆瓨璋冩暣璁板綍
                 AdjDetl adjDetl = new AdjDetl();
                 adjDetl.setLocNo(locDetl.getLocNo());
-                adjDetl.setMatNo(locDetl.getMatnr());
+                adjDetl.setMatNo(locDetl.getMatNo());
                 adjDetl.setOriQty(0.0D);
                 adjDetl.setAdjQty(adjust.getCount());
                 adjDetlService.save(adjDetl, userId);
             // 淇敼鍘熷簱瀛樻槑缁�
             } else {
                 // 濡傛灉鏁伴噺淇敼锛屽垯鏇存柊搴撳瓨鏄庣粏
-                if (!adjust.getCount().equals(one.getAnfme())) {
+                if (!adjust.getCount().equals(one.getQty())) {
                     // 褰撴暟閲忚淇敼涓� 0 鏃讹紝鐩存帴娓呴櫎搴撳瓨鏄庣粏
                     if (adjust.getCount() == 0) {
                         if (!locDetlService.delete(new EntityWrapper<>(one))) {
@@ -557,23 +634,32 @@
                         }
                     } else {
                         LocDetl sqlParam1 = new LocDetl();
-                        sqlParam1.setAnfme(adjust.getCount());
+                        sqlParam1.setQty(adjust.getCount());
                         sqlParam1.setModiTime(new Date());
                         sqlParam1.setModiUser(userId);
                         if (!locDetlService.update(sqlParam1, new EntityWrapper<LocDetl>()
                                 .eq("loc_no", locMast.getLocNo())
-                                .eq("matnr", adjust.getMatnr()))) {
+                                .eq("mat_no", adjust.getMatNo()))) {
                             throw new CoolException("淇敼搴撳瓨鏄庣粏澶辫触");
                         }
                     }
                     // 淇濆瓨璋冩暣璁板綍
                     AdjDetl adjDetl = new AdjDetl();
                     adjDetl.setLocNo(locMast.getLocNo());
-                    adjDetl.setMatNo(adjust.getMatnr());
-                    adjDetl.setOriQty(one.getAnfme());
+                    adjDetl.setMatNo(adjust.getMatNo());
+                    adjDetl.setOriQty(one.getQty());
                     adjDetl.setAdjQty(adjust.getCount());
                     adjDetlService.save(adjDetl, userId);
                 }
+            }
+        }
+        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", param.getLocNo()));
+        if (locDetls.isEmpty()) {
+            locMast.setLocSts("D");
+            locMast.setModiUser(userId);
+            locMast.setModiTime(new Date());
+            if (!locMastService.updateById(locMast)) {
+                throw new CoolException("鏇存柊搴撲綅鐘舵�佸け璐�");
             }
         }
     }
@@ -586,11 +672,11 @@
             throw new CoolException(workNo+"宸ヤ綔妗d笉瀛樺湪");
         }
         String locNo = ""; // 寰呬慨鏀圭洰鏍囧簱浣�
-        String locType = ""; // 寰呬慨鏀圭洰鏍囧簱浣嶇姸鎬�
+        String locSts = ""; // 寰呬慨鏀圭洰鏍囧簱浣嶇姸鎬�
         // 鍏ュ簱鍙栨秷锛堜慨鏀圭洰鏍囧簱浣嶏級
         if (wrkMast.getWrkSts() < 4) {
             locNo = wrkMast.getLocNo();
-            locType = "O";
+            locSts = "O";
             /**
              * 搴撲綅杞Щ
              * 鍙栨秷鍚� 婧愬簱浣� ==>> F.鍦ㄥ簱
@@ -602,7 +688,7 @@
                 if (Cools.isEmpty(locMast)) {
                     throw new CoolException("鍙栨秷搴撲綅杞Щ澶辫触锛屾簮搴撲綅涓嶅瓨鍦�:"+ wrkMast.getSourceLocNo());
                 }
-                locMast.setLocType("F");
+                locMast.setLocSts("F");
                 locMast.setModiTime(new Date());
                 locMast.setModiUser(userId);
                 locMastService.updateById(locMast);
@@ -612,19 +698,19 @@
             locNo = wrkMast.getSourceLocNo();
             // 鍑哄簱 ===>> F.鍦ㄥ簱
             if (wrkMast.getIoType() > 100 && wrkMast.getIoType() != 110) {
-                locType = "F";
+                locSts = "F";
             // 绌烘澘鍑哄簱 ===>> D.绌烘《/绌烘爤鏉�
             } else if (wrkMast.getIoType() == 110) {
-                locType = "D";
+                locSts = "D";
             // 搴撲綅杞Щ ===>> D.绌烘《/绌烘爤鏉�
             } else if (wrkMast.getIoType() == 11) {
-                locType = "F";
+                locSts = "F";
                 // 搴撲綅杞Щ锛氱洰鏍囧簱浣�
                 LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                 if (Cools.isEmpty(locMast)) {
                     throw new CoolException("鍙栨秷搴撲綅杞Щ澶辫触锛岀洰鏍囧簱浣嶄笉瀛樺湪:"+ wrkMast.getSourceLocNo());
                 }
-                locMast.setLocType("O");
+                locMast.setLocSts("O");
                 locMast.setModiTime(new Date());
                 locMast.setModiUser(userId);
                 locMastService.updateById(locMast);
@@ -632,20 +718,38 @@
         } else {
             throw new CoolException("褰撳墠宸ヤ綔鐘舵�佹棤娉曞彇娑�");
         }
-        // 鍒犻櫎宸ヤ綔妗�
+        // 鍙栨秷鎿嶄綔浜哄憳璁板綍
+        wrkMast.setManuType("鎵嬪姩鍙栨秷");
+        wrkMast.setModiUser(userId);
+        wrkMast.setModiTime(new Date());
+        if (!wrkMastService.updateById(wrkMast)) {
+            throw new CoolException("鍙栨秷宸ヤ綔妗eけ璐�");
+        }
+        // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+        if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
+            throw new CoolException("淇濆瓨宸ヤ綔鍘嗗彶妗eけ璐�, workNo = " + wrkMast.getWrkNo());
+        }
+        // 鍒犻櫎宸ヤ綔涓绘。
         boolean wrkMastRes = wrkMastService.deleteById(wrkMast);
-        // 鍒犻櫎宸ヤ綔妗f槑缁�
-        boolean wrkDetlRes = wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", workNo));
+
+        if (wrkMast.getIoType() != 10 && wrkMast.getIoType() != 110) {
+            // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
+            if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
+                throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏鍘嗗彶妗eけ璐�, workNo = " + wrkMast.getWrkNo());
+            }
+            // 鍒犻櫎宸ヤ綔妗f槑缁�
+            boolean wrkDetlRes = wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", workNo));
+        }
         // 淇敼搴撲綅鐘舵��
         LocMast locMast = locMastService.selectById(locNo);
         if (Cools.isEmpty(locMast)) {
             throw new CoolException("鍙栨秷宸ヤ綔妗eけ璐ワ紝搴撲綅涓嶅瓨鍦�:"+ locNo);
         }
-        locMast.setLocType(locType);
+        locMast.setLocSts(locSts);
         locMast.setModiTime(new Date());
         locMast.setModiUser(userId);
         boolean locMastRes = locMastService.updateById(locMast);
-        if (!wrkMastRes || !wrkDetlRes || !locMastRes) {
+        if (!wrkMastRes || !locMastRes) {
             throw new CoolException("淇濆瓨鏁版嵁澶辫触");
         }
     }
@@ -657,31 +761,25 @@
         if (Cools.isEmpty(wrkMast)){
             throw new CoolException(workNo+"宸ヤ綔妗d笉瀛樺湪");
         }
-        List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()));
-        String locNo = wrkMast.getSourceLocNo();
-        // 鎷f枡浣滀笟鍒ゆ柇
-        if (wrkMast.getIoType() != 103) {
-            throw new CoolException("鍏ュ嚭搴撶被鍨嬩笉鏄�103.鎷f枡鍑哄簱");
+        // 鍏ュ嚭搴撶被鍨嬪垽鏂�
+        if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107) {
+            throw new CoolException("褰撳墠鍏ュ嚭搴撶被鍨嬫棤娉曡繘琛屾搷浣�");
         }
         // 宸ヤ綔鐘舵�佸垽鏂�
         if (wrkMast.getWrkSts() < 11 || wrkMast.getWrkSts() == 15) {
-            throw new CoolException("褰撳墠宸ヤ綔鐘舵�佷笉鑳芥嫞鏂欏叆搴�");
+            throw new CoolException("褰撳墠宸ヤ綔鐘舵�佹棤娉曡繘琛屾搷浣�");
         }
         // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
-//        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
-//            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
-//        }
-        // 鍒犻櫎宸ヤ綔鏄庣粏妗�
-//        if (!wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkMast.getWrkNo()))) {
-//            throw new CoolException("鍒犻櫎宸ヤ綔鏄庣粏妗f。鍘嗗彶妗eけ璐�");
-//        }
+        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
+            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
+        }
         // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
         if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
             throw new CoolException("淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
         }
         // 鑾峰彇鐩爣绔�
         Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
-                .eq("type_no", 53)  // type_no: 53.鎷f枡鍐嶅叆搴�
+                .eq("type_no", wrkMast.getIoType() - 50)
                 .eq("stn_no", wrkMast.getStaNo()) // 浣滀笟绔欑偣 = 鎷f枡鍑哄簱鐨勭洰鏍囩珯
                 .eq("crn_no", wrkMast.getCrnNo()); // 鍫嗗灈鏈哄彿
         StaDesc staDesc = staDescService.selectOne(wrapper);
@@ -691,7 +789,7 @@
         // 鍫嗗灈鏈虹珯鐐�(鐩爣绔�)
         Integer staNo = staDesc.getCrnStn();
         // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
-        wrkMast.setIoType(53); // 鍏ュ嚭搴撶被鍨�: 53.鎷f枡鍐嶅叆搴�
+        wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
         wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
         wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 婧愮珯
         wrkMast.setStaNo(staNo); // 鐩爣绔�
@@ -702,26 +800,9 @@
         if (!wrkMastService.updateById(wrkMast)) {
             throw new CoolException("鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
         }
-//        // 鏇存柊/鍒犻櫎鎷f枡搴撳瓨鏄庣粏
-//        for (WrkDetl wrkDetl : wrkDetls) {
-//            LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locNo).eq("matnr", wrkDetl.getMatnr()));
-//            // 搴撳瓨鏁伴噺璁$畻
-//            locDetl.setAnfme(locDetl.getAnfme() - wrkDetl.getAnfme());
-//            if (locDetl.getAnfme() > 0) {
-//                locDetl.setModiTime(new Date());
-//                locDetl.setModiUser(userId);
-//                if (!locDetlService.updateById(locDetl)) {
-//                    throw new CoolException("鏇存柊搴撳瓨鏄庣粏澶辫触");
-//                }
-//            } else {
-//                if (!locDetlService.delete(new EntityWrapper<>(locDetl))) {
-//                    throw new CoolException("鍒犻櫎搴撳瓨鏄庣粏澶辫触");
-//                }
-//            }
-//        }
         // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
         LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
-        locMast.setLocType("Q");
+        locMast.setLocSts("Q");
         locMast.setModiTime(new Date());
         locMast.setModiUser(userId);
         if (!locMastService.updateById(locMast)) {

--
Gitblit v1.9.1