From 9ff5e64187837a3bbd78370c1cfaadf2329f97f0 Mon Sep 17 00:00:00 2001
From: 18516761980 <4761516tqsxp>
Date: 星期六, 19 三月 2022 12:47:13 +0800
Subject: [PATCH] .

---
 src/main/java/zy/cloud/wms/manager/controller/ReceiveDetlController.java |  176 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 156 insertions(+), 20 deletions(-)

diff --git a/src/main/java/zy/cloud/wms/manager/controller/ReceiveDetlController.java b/src/main/java/zy/cloud/wms/manager/controller/ReceiveDetlController.java
index c69d7d2..f3000b3 100644
--- a/src/main/java/zy/cloud/wms/manager/controller/ReceiveDetlController.java
+++ b/src/main/java/zy/cloud/wms/manager/controller/ReceiveDetlController.java
@@ -5,27 +5,34 @@
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.baomidou.mybatisplus.plugins.Page;
+import com.core.common.DateUtils;
+import org.springframework.transaction.annotation.Transactional;
+import zy.cloud.wms.manager.entity.*;
+import zy.cloud.wms.manager.entity.dto.PutShelfDTO;
+import zy.cloud.wms.manager.service.*;
 import com.core.annotations.ManagerAuth;
 import com.core.common.BaseRes;
 import com.core.common.Cools;
-import com.core.common.DateUtils;
 import com.core.common.R;
+import zy.cloud.wms.common.web.BaseController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import zy.cloud.wms.common.web.BaseController;
-import zy.cloud.wms.manager.entity.ReceiveDetl;
-import zy.cloud.wms.manager.service.ReceiveDetlService;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @RestController
 public class ReceiveDetlController extends BaseController {
 
     @Autowired
     private ReceiveDetlService receiveDetlService;
+    @Autowired
+    private LocDetlService locDetlService;
+    @Autowired
+    private NodeService nodeService;
+    @Autowired
+    private ReceiveLogService receiveLogService;
+    @Autowired
+    private ReceiveService receiveService;
 
     @RequestMapping(value = "/receiveDetl/{id}/auth")
     @ManagerAuth
@@ -43,7 +50,6 @@
         EntityWrapper<ReceiveDetl> wrapper = new EntityWrapper<>();
         excludeTrash(param);
         convert(param, wrapper);
-        hostEq(wrapper);
         if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
         return R.ok(receiveDetlService.selectPage(new Page<>(curr, limit), wrapper));
     }
@@ -56,7 +62,7 @@
                 wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                 wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
             } else {
-                wrapper.eq(entry.getKey(), val);
+                wrapper.like(entry.getKey(), val);
             }
         }
     }
@@ -80,13 +86,9 @@
 
     @RequestMapping(value = "/receiveDetl/delete/auth")
     @ManagerAuth
-    public R delete(@RequestParam String param){
-        List<ReceiveDetl> list = JSONArray.parseArray(param, ReceiveDetl.class);
-        if (Cools.isEmpty(list)){
-            return R.error();
-        }
-        for (ReceiveDetl entity : list){
-            receiveDetlService.delete(new EntityWrapper<>(entity));
+    public R delete(@RequestParam(value="ids[]") Long[] ids){
+         for (Long id : ids){
+            receiveDetlService.deleteById(id);
         }
         return R.ok();
     }
@@ -95,9 +97,8 @@
     @ManagerAuth
     public R export(@RequestBody JSONObject param){
         EntityWrapper<ReceiveDetl> wrapper = new EntityWrapper<>();
-        hostEq(wrapper);
         List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
-        Map<String, Object> map = excludeTrash(param.getJSONObject("orderDetl"));
+        Map<String, Object> map = excludeTrash(param.getJSONObject("receiveDetl"));
         convert(map, wrapper);
         List<ReceiveDetl> list = receiveDetlService.selectList(wrapper);
         return R.ok(exportSupport(list, fields));
@@ -108,7 +109,6 @@
     public R query(String condition) {
         EntityWrapper<ReceiveDetl> wrapper = new EntityWrapper<>();
         wrapper.like("id", condition);
-        hostEq(wrapper);
         Page<ReceiveDetl> page = receiveDetlService.selectPage(new Page<>(0, 10), wrapper);
         List<Map<String, Object>> result = new ArrayList<>();
         for (ReceiveDetl receiveDetl : page.getRecords()){
@@ -130,4 +130,140 @@
         return R.ok();
     }
 
+    /**
+     * 涓婃灦鍔ㄤ綔,鎻掑叆搴撳瓨鏄庣粏,鏇存柊鍗曟嵁鏄庣粏
+     * @param putShelfDTO
+     * @return
+     */
+    @RequestMapping("/receiveDetl/addIn")
+    @ManagerAuth
+    public R addIn(@RequestBody PutShelfDTO putShelfDTO){
+        /**
+         * 鎺х涓庢暟鎹垵濮嬪寲
+         */
+        if (Cools.isEmpty(putShelfDTO.getId(),putShelfDTO.getRemain(),putShelfDTO.getSelect())){
+            return R.error("杈撳叆鏁版嵁鏈夎,璇烽噸鏂拌緭鍏�");
+        }
+        Date date = new Date();
+        double remain = Double.parseDouble(putShelfDTO.getRemain());
+        double anfme = Double.parseDouble(putShelfDTO.getAnfme());
+        double inQty = Double.parseDouble(putShelfDTO.getInQty());
+        if (anfme - (remain + inQty) < 0){
+            return R.error("鏈鍏ュ簱鏁伴噺澶т簬鎵�闇�鍏ュ簱鏁伴噺");
+        }
+        Node targetLoc = nodeService.selectOne(new EntityWrapper<Node>()
+                .eq("id", putShelfDTO.getSelect()));
+
+
+        /**
+         * 鏇存柊搴撳瓨
+         */
+        LocDetl checkLoc = locDetlService.selectOne(new EntityWrapper<LocDetl>()
+                .eq("loc_no", targetLoc.getName())
+                .eq("matnr", putShelfDTO.getMatnr())
+                .eq("batch", putShelfDTO.getBatch()));
+        if (Cools.isEmpty(checkLoc)) {
+            LocDetl locDetl = new LocDetl();
+            locDetl.setHostId(getHostId());
+            locDetl.setLocNo(targetLoc.getName());
+            locDetl.setNodeId(targetLoc.getId());
+            locDetl.setAnfme(remain);
+            locDetl.setMatnr(putShelfDTO.getMatnr());
+            locDetl.setMaktx(putShelfDTO.getMaktx());
+            locDetl.setCreateBy(getUserId());
+            locDetl.setCreateTime(date);
+            locDetl.setUpdateBy(getUserId());
+            locDetl.setUpdateTime(date);
+            locDetl.setBatch(putShelfDTO.getBatch());
+            locDetlService.insert(locDetl);
+        }else {
+            checkLoc.setAnfme(checkLoc.getAnfme() + remain);
+            locDetlService.update(checkLoc,new EntityWrapper<LocDetl>()
+                    .eq("loc_no", targetLoc.getName())
+                    .eq("matnr", putShelfDTO.getMatnr())
+                    .eq("batch", putShelfDTO.getBatch()));
+        }
+
+        /**
+         * 鍙嶅啓璁㈠崟鏁伴噺
+         */
+
+        ReceiveDetl targetRece = receiveDetlService.selectOne(new EntityWrapper<ReceiveDetl>()
+                .eq("id", putShelfDTO.getId()));
+        targetRece.setInQty((int) (targetRece.getInQty() + remain));
+        receiveDetlService.update(targetRece,new EntityWrapper<ReceiveDetl>()
+                .eq("id",targetRece.getId()));
+
+        /**
+         * 涓婃灦瀹屾垚涔嬪悗,瀛樻斁鏁版嵁鑷充笂鏋剁粺璁¤〃 man_receive_log
+         */
+        ReceiveLog receiveLog = new ReceiveLog();
+        receiveLog.setOrderNo(putShelfDTO.getOrderNo());
+        receiveLog.setNodeId(targetLoc.getId());
+        receiveLog.setNodeName(targetLoc.getName());
+        receiveLog.setMatnr(putShelfDTO.getMatnr());
+        receiveLog.setAnfme(remain);
+        receiveLog.setBatch(putShelfDTO.getBatch());
+        receiveLog.setCreateBy(getUserId());
+        receiveLog.setUpdateBy(getUserId());
+        receiveLog.setIoType(1);
+        receiveLogService.insert(receiveLog);
+        return R.ok("娣诲姞鎴愬姛");
+    }
+
+    /**
+     * 鎾ら攢涓婃灦鎿嶄綔
+     */
+    @RequestMapping("/receiveDetl/renew/auth")
+    @ManagerAuth
+    @Transactional
+    public R renew(@RequestBody ReceiveDetl receiveDetl){
+        /**
+         * 鎺х
+         */
+        if (receiveDetl.getInQty() <= 0){
+            return R.error("娌℃湁涓婃灦璁板綍,鏃犳硶鎾ゅ洖");
+        }
+        Receive receive = receiveService.selectOne(new EntityWrapper<Receive>()
+                .eq("id", receiveDetl.getOrderId()));
+        if (Cools.isEmpty(receive)) {
+            return R.error("鎵句笉鍒拌鍗曟嵁,璇疯仈绯荤鐞嗗憳");
+        }
+        if (receive.getSettle() == 4){
+            return R.error("璇ュ崟鎹凡缁忓畬缁�");
+        }
+
+        /**
+         * 淇敼搴撳瓨鏁伴噺,鍚屾椂鎾ゅ洖涓婃灦瀹屾垚鍚�,灏嗘搷浣滆褰曞弽鍐欏洖涓婃灦缁熻琛� man_receive_log
+         */
+        List<ReceiveLog> receiveLogs = receiveLogService.selectList(new EntityWrapper<ReceiveLog>()
+                .eq("order_no", receiveDetl.getOrderNo())
+                .eq("matnr", receiveDetl.getMatnr())
+                .eq("batch", receiveDetl.getBatch())
+                .eq("io_type", 1));
+        if (Cools.isEmpty(receiveLogs)) {
+            return R.error("鎵句笉鍒板叆搴撹褰�");
+        }
+        for (ReceiveLog receiveLog : receiveLogs) {
+            locDetlService.delete(new EntityWrapper<LocDetl>()
+                    .eq("loc_no",receiveLog.getNodeName())
+                    .eq("matnr",receiveLog.getMatnr())
+                    .eq("batch",receiveLog.getBatch()));
+            receiveLog.setIoType(101);
+            receiveLog.setCreateBy(getUserId());
+            receiveLog.setUpdateBy(getUserId());
+            receiveLogService.insert(receiveLog);
+        }
+
+        /**
+         * 鍙嶅啓鍥炲叆搴撴。
+         */
+        receiveDetl.setInQty(0);
+        receiveDetl.setUpdateTime(new Date());
+        receiveDetl.setUpdateBy(getUserId());
+        receiveDetlService.update(receiveDetl,new EntityWrapper<ReceiveDetl>()
+                .eq("id",receiveDetl.getId()));
+        return R.ok("鎾ゅ洖鎴愬姛");
+    }
+
 }

--
Gitblit v1.9.1