From a378c8fbae0c40ae2b5387ba4ff052af27107aaf Mon Sep 17 00:00:00 2001
From: ZY <zc857179121@qq.com>
Date: 星期三, 25 九月 2024 07:52:16 +0800
Subject: [PATCH] 1

---
 src/main/java/com/zy/asrs/controller/PlaController.java |  156 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 118 insertions(+), 38 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/PlaController.java b/src/main/java/com/zy/asrs/controller/PlaController.java
index 982f65a..dc23bfc 100644
--- a/src/main/java/com/zy/asrs/controller/PlaController.java
+++ b/src/main/java/com/zy/asrs/controller/PlaController.java
@@ -3,20 +3,25 @@
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.core.annotations.ManagerAuth;
 import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.common.R;
+import com.core.common.SnowflakeIdWorker;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
 import com.zy.asrs.entity.param.GlobleParameter;
+import com.zy.asrs.entity.result.KeyValueVo;
 import com.zy.asrs.service.*;
 import com.zy.asrs.utils.PlaExcelListener;
 import com.zy.asrs.utils.SaasUtils;
+import com.zy.common.CodeRes;
 import com.zy.common.entity.PlaExcel;
 import com.zy.common.web.BaseController;
 import lombok.Synchronized;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -26,12 +31,10 @@
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @RestController
+@Slf4j
 public class PlaController extends BaseController {
 
     @Autowired
@@ -46,6 +49,11 @@
     private OrderDetlService orderDetlService;
     @Autowired
     private PlaLogService plaLogService;
+    @Autowired
+    private MatService matService;
+    @Autowired
+    private SnowflakeIdWorker snowflakeIdWorker;
+
 
     @RequestMapping(value = "/pla/list/auth")
     @ManagerAuth
@@ -55,8 +63,24 @@
                   @RequestParam Map<String, Object> param){
         excludeTrash(param);
         EntityWrapper<Pla> wrapper = new EntityWrapper<>();
+
+        if(!Cools.isEmpty(param.get("brand"))){
+            wrapper.eq("brand",param.get("brand"));
+            param.remove("brand");
+        }
+        // 娌℃湁閫夋嫨鐨勬椂鍊欓粯璁や笉鏄剧ず宸插嚭搴撶殑鐗╂枡
+        if (Cools.isEmpty(param.get("status"))) {
+            wrapper.ne("status", "鍏ㄩ儴鍑哄簱");
+        }
+
+        if (!Cools.isEmpty(param.get("batch")) && param.get("batch").toString().contains(",")){
+            String[] batchs = param.get("batch").toString().split(",");
+            wrapper.in("batch",batchs);
+            param.remove("batch");
+        }
+
         convert(param, wrapper);
-        wrapper.orderBy("modify_time",false);
+        wrapper.orderBy("batch",true).orderBy("package_no" ,true);
         allLike(Pla.class, param.keySet(), wrapper, condition);
         return R.ok(plaService.selectPage(new Page<>(curr, limit), wrapper));
     }
@@ -84,6 +108,7 @@
             BeanUtils.copyProperties(plaSave,plaLog);
             plaLog.setId(null);
             plaLog.setCreateTime(new Date());
+            plaLog.setModifyUser(getUser().getUsername());
             plaLogService.insert(plaLog);
 
         });
@@ -95,8 +120,8 @@
     public R delete(@RequestBody List<Pla> plas) {
         System.out.println(plas.toString());
         plas.forEach(pla -> {
-            if(!pla.getStatus().equals(GlobleParameter.PLA_STATUS_00) || pla.getStatus().equals(GlobleParameter.PLA_STATUS_0)){
-                throw new CoolException("闈炲緟鍏ュ簱鐨勬暟鎹棤娉曡鍒犻櫎");
+            if(!pla.getStatus().equals(GlobleParameter.PLA_STATUS_00) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_0) && !pla.getStatus().equals(GlobleParameter.PLA_STATUS_1)){
+                throw new CoolException("宸插叆搴撶殑鏁版嵁鏃犳硶琚垹闄�");
             }
             Pla plaSave = plaService.selectById(pla.getId());
             pla.setModifyTime(new Date());
@@ -106,6 +131,7 @@
             BeanUtils.copyProperties(plaSave,plaLog);
             plaLog.setId(null);
             plaLog.setCreateTime(new Date());
+            plaLog.setModifyUser(getUser().getUsername());
             plaLogService.insert(plaLog);
 
         });
@@ -133,7 +159,11 @@
         for (Pla pla : plas){
 
             if(pla.getStockFreeze() == 0){
-                throw new CoolException("搴撳瓨宸茶鍐荤粨锛岃閲嶆柊閫夋嫨搴撳瓨");
+//                throw new CoolException("搴撳瓨宸茶鍐荤粨锛岃閲嶆柊閫夋嫨搴撳瓨");
+                System.out.println(pla.getStockFreezeBy() + "," + getUser().getUsername());
+                if(!Cools.eq(pla.getStockFreezeBy(),getUser().getUsername())){
+                    throw new CoolException("璇ュ簱瀛樺凡琚叾浠栫敤鎴峰喕缁擄紝璇烽噸鏂伴�夋嫨");
+                }
             }
 
             allOrderWeight += pla.getOrderWeight();
@@ -156,7 +186,7 @@
             plaService.updateById(pla);
             plaQtyService.insert(plaQty);
             //鐢熸垚鎷h揣鍗�
-            addPakOUT(plaQty);
+            addPakOUT(plaQty,getUserId());
 
         };
 
@@ -198,7 +228,8 @@
             pla.setModifyTime(new Date());
             pla.setWeightAnfme(0.0);
             plaService.updateById(pla);
-            SaasUtils.insertLog(1,pla.getLocNo(),pla.getBatch()+","+pla.getPackageNo(),anfme,getUser().getUsername());
+            SaasUtils.insertLog(1,pla.getLocNo(),pla.getBrand(),anfme,getUser().getUsername(),
+                    null,pla.getBatch(),pla.getPackageNo(),pla.getOwner(),pla.getWorkshop(),null);
         });
 
         return R.ok();
@@ -213,7 +244,8 @@
         }
         for (Pla pla : plas){
             if (pla.getStockFreeze() == 0){
-                throw new CoolException("搴撳瓨宸茶鍐荤粨锛�");
+                continue;
+//                throw new CoolException("搴撳瓨宸茶鍐荤粨锛�");
             }
             pla.setStockFreeze(0);
             pla.setStockFreezeBy(getUser().getUsername());
@@ -232,7 +264,8 @@
         }
         for (Pla pla : plas){
             if (pla.getStockFreeze() == 1){
-                throw new CoolException("搴撲綅鏈喕缁擄紝鏃犻渶瑙e喕");
+                continue;
+//                throw new CoolException("搴撲綅鏈喕缁擄紝鏃犻渶瑙e喕");
             }
             if(!Cools.eq(pla.getStockFreezeBy(),getUser().getUsername())){
                 throw new CoolException("鏃犳硶瑙e喕鍏朵粬鐢ㄦ埛鍐荤粨鐨勫簱浣�");
@@ -245,6 +278,33 @@
 
         }
         return R.ok("瑙i櫎鍐荤粨鎴愬姛");
+    }
+
+    @RequestMapping(value = "/matMaktxQuery/auth")
+    @ManagerAuth
+    public R queryMat(String condition) {
+        EntityWrapper<Mat> wrapper = new EntityWrapper<>();
+        wrapper.like("maktx", condition);
+        Page<Mat> page = matService.selectPage(new Page<>(0, 10), wrapper);
+        List<Map<String, Object>> result = new ArrayList<>();
+        for (Mat mat : page.getRecords()){
+            Map<String, Object> map = new HashMap<>();
+            map.put("id", mat.getMaktx());
+            map.put("value", mat.getMaktx());
+            result.add(map);
+        }
+        return R.ok(result);
+    }
+
+    @RequestMapping(value = "/pla/statis/auth")
+    @ManagerAuth
+    public R statis(@RequestParam(defaultValue = "1")Integer curr,
+                    @RequestParam(defaultValue = "10")Integer limit,
+                    @RequestParam Map<String, Object> param) {
+
+        Page<Pla> stockStatis = plaService.getStockStatisAll(toPage(curr, limit, param, Pla.class));
+
+        return R.ok().add(stockStatis);
     }
 
     /**
@@ -272,33 +332,48 @@
         try {
             EasyExcel.read(file.getInputStream(), PlaExcel.class, listener).sheet().doRead();
         }catch (Exception e){
-            throw new CoolException("瀵煎叆鐨勬暟鎹牸寮忛敊璇紝鍘熷洜锛�" + e.getMessage());
+            e.printStackTrace();
+            int index = listener.getIndex() - 1;
+            throw new CoolException("瀵煎叆鐨勬暟鎹牸寮忛敊璇紝鍘熷洜锛�" + e.getMessage() + "锛岀" + index + "锛屾暟鎹牸寮忎笉瀵�");
         }
+        log.info("瀵煎叆淇敼淇℃伅杈撳嚭锛�" + listener.getRecordLog());
         return R.ok("鎴愬姛鍚屾"+listener.getTotal()+"鏉la鐗╂枡鏁版嵁");
     }
 
-//    // 鎵撳嵃
-//    @RequestMapping(value = "/pla/print/auth")
-//    @ManagerAuth(memo = "pla缂栫爜鎵撳嵃")
-//    public R matCodePrint(@RequestParam(value = "param[]") String[] param) {
-//        if(Cools.isEmpty(param)) {
-//            return R.parse(CodeRes.EMPTY);
-//        }
-//        List<MatPrint> res = new ArrayList<>();
-//        for (String matnr : param){
-//            Mat mat = matService.selectByMatnr(matnr);
-//            // 鎵撳嵃鏁版嵁娉ㄥ叆
-//            MatPrint print = new MatPrint();
-//            print.setMatnr(mat.getMatnr());
-//            print.setBarcode(mat.getBarcode());
-//            print.setMaktx(mat.getMaktx());
-//            print.setSpecs(mat.getSpecs());
-//            print.setUnit(mat.getUnit());
-//            print.setMemo(mat.getMemo());
-//            res.add(print);
-//        }
-//        return R.ok().add(res);
-//    }
+    // 鎵撳嵃
+    @RequestMapping(value = "/pla/print/auth")
+    @ManagerAuth(memo = "pla缂栫爜鎵撳嵃")
+    public R matCodePrint(@RequestBody List<Pla> plas) {
+        if(Cools.isEmpty(plas)) {
+            return R.parse(CodeRes.EMPTY);
+        }
+        List<Pla> res = new ArrayList<>();
+        for (Pla pla : plas){
+            res.add(pla);
+        }
+        return R.ok().add(res);
+    }
+
+    /*************************************** xm-select ***********************************************/
+
+    // xm-select 鎼滅储鎵瑰彿
+    @RequestMapping("/pla/batch/all/get/kv")
+    @ManagerAuth
+    public R getMatDataKV(@RequestParam(required = false) String condition) {
+        Wrapper<Pla> wrapper = new EntityWrapper<Pla>().setSqlSelect("batch")
+                .andNew().like("batch", condition)
+                .groupBy("batch")
+                .orderBy("batch",false);
+        List<Pla> plas = plaService.selectPage(new Page<Pla>(1, 30), wrapper).getRecords();
+        List<KeyValueVo> valueVos = new ArrayList<>();
+        for (Pla pla : plas) {
+            KeyValueVo vo = new KeyValueVo();
+            vo.setName(pla.getBatch());
+            vo.setValue(pla.getBatch());
+            valueVos.add(vo);
+        }
+        return R.ok().add(valueVos);
+    }
 
     private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
         for (Map.Entry<String, Object> entry : map.entrySet()){
@@ -317,15 +392,16 @@
         }
     }
 
-    private R addPakOUT(PlaQty plaQty){
+    @Synchronized
+    private R addPakOUT(PlaQty plaQty,Long userId){
         ManPakOut manPakOut=new ManPakOut();
-        manPakOut.setWrkNo(plaQty.getOrderNo()+"-"+System.currentTimeMillis());
+        manPakOut.setWrkNo(plaQty.getOrderNo()+"-"+String.valueOf(snowflakeIdWorker.nextId()));
         manPakOut.setWrkSts((long)1);
         manPakOut.setAnfme(plaQty.getOrderWeight());
         manPakOut.setMaktx(plaQty.getBrand());
         manPakOut.setLocNo(plaQty.getLocNo());
         manPakOut.setBatch(plaQty.getBatch());
-        manPakOut.setBarcode(plaQty.getPackageNo());
+        manPakOut.setBarcode(plaQty.getPackageNo() + "");
         manPakOut.setUuid(String.valueOf(System.currentTimeMillis()));
         manPakOut.setCreateTime(new Date());
         manPakOut.setUpdateTime(new Date());
@@ -334,6 +410,10 @@
         manPakOut.setStatus(0);
         manPakOut.setDocId(plaQty.getOrderDetlId());
         manPakOut.setNodeId(plaQty.getId());
+        manPakOut.setCustName(plaQty.getCustomer());
+        manPakOut.setCreateBy(userId);
+        //棰勮鍙戣揣鏃堕棿
+        manPakOut.setSpecs(plaQty.getPakoutTime());
         //manPakOut.setNodeId(plaQty.getOrderDetlId());
         manPakOutService.insert(manPakOut);
         return R.ok();

--
Gitblit v1.9.1