From fae8a9349499cd045bc73e8fd22aeae52618a46c Mon Sep 17 00:00:00 2001
From: WangHan <wwh_work@126,com>
Date: 星期四, 19 十二月 2024 10:02:02 +0800
Subject: [PATCH] 采购明细查询修改,查询本级及以下

---
 consum-base/src/main/java/com/consum/base/controller/BaseCategoryController.java |  301 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 259 insertions(+), 42 deletions(-)

diff --git a/consum-base/src/main/java/com/consum/base/controller/BaseCategoryController.java b/consum-base/src/main/java/com/consum/base/controller/BaseCategoryController.java
index ca157b1..552f22d 100644
--- a/consum-base/src/main/java/com/consum/base/controller/BaseCategoryController.java
+++ b/consum-base/src/main/java/com/consum/base/controller/BaseCategoryController.java
@@ -1,54 +1,61 @@
 package com.consum.base.controller;
 
-import com.consum.base.BaseController;
-import com.consum.base.pojo.BaseCategoryParam;
-import com.consum.base.pojo.ProjectTreeResult;
-import com.consum.base.service.BaseCategoryServiceImpl;
-import com.consum.base.service.BaseGoodsTemplateServiceImpl;
-import com.consum.base.util.FinSysTenantUtils;
-import com.consum.model.po.BaseCategory;
-import com.consum.model.po.FinSysTenant;
-import com.consum.model.po.FinSysTenantUser;
-import com.iplatform.model.po.S_user_core;
-import com.walker.db.page.GenericPager;
-import com.walker.infrastructure.tree.TreeNode;
-import com.walker.infrastructure.utils.StringUtils;
-import com.walker.web.ResponseValue;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.excel.EasyExcelFactory;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.alibaba.excel.exception.ExcelAnalysisException;
+import com.alibaba.excel.exception.ExcelDataConvertException;
+import com.consum.base.pojo.*;
+import com.consum.base.pojo.excel.ImportClassificationTemplate;
+import com.consum.model.po.*;
+import org.apache.commons.compress.utils.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.consum.base.BaseController;
+import com.consum.base.core.utils.CommonUtil;
+import com.consum.base.service.BaseCategoryService;
+import com.consum.base.service.BaseGoodsTemplateService;
+import com.iplatform.model.po.S_user_core;
+import com.walker.db.page.GenericPager;
+import com.walker.infrastructure.utils.StringUtils;
+import com.walker.web.ResponseValue;
+import io.swagger.annotations.Api;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * @Description 鐗╁搧鍒嗙被
  * @Author 鍗㈠簡闃�
  * @Date 2023/10/23
  */
+@Api(value = "鐗╁搧鍒嗙被", tags = "鐗╁搧鍒嗙被")
 @RestController
 @RequestMapping("/pc/base/category")
 public class BaseCategoryController extends BaseController {
 
     @Autowired
-    private BaseCategoryServiceImpl baseCategoryService;
+    private BaseCategoryService baseCategoryService;
 
     @Autowired
-    private BaseGoodsTemplateServiceImpl baseGoodsTemplateService;
-
-    private boolean multiRoot = true;
-    private TreeNode dummyRoot = null;
-    private Map<Long, TreeNode> rootMap = new TreeMap();
-    private Map<Long, TreeNode> childMap = new TreeMap();
-    private long defaultParentId = 0L;
+    private BaseGoodsTemplateService baseGoodsTemplateService;
 
     /**
-     * @Description  鑾峰彇鍒嗙被鏍�
+     * @Description 鑾峰彇鍒嗙被鏍�
      * @Author 鍗㈠簡闃�
      * @Date 2023/10/30
      */
     @GetMapping("/select/tree")
-    public ResponseValue tree(String categoryName) {
-        List<ProjectTreeResult> tree = this.baseCategoryService.tree(categoryName);
+    public ResponseValue trees() {
+        List<ProjectTreeResult> tree = this.baseCategoryService.tree();
         return ResponseValue.success(tree);
     }
 
@@ -58,21 +65,28 @@
      * @Date 2023/10/23
      */
     @PostMapping("/add")
-    public ResponseValue add(@RequestBody BaseCategoryParam param) {
+    public ResponseValue add() {
+        BaseCategoryParam param = CommonUtil.getObjFromReqBody(BaseCategoryParam.class);
+        BaseCategoryParam param2 = new BaseCategoryParam();
+        CommonUtil.copyProperties(param, param2);
+        param = param2;
         if (StringUtils.isEmpty(param.getCategoryName())) {
             return ResponseValue.error("鍒嗙被鍚嶇О涓虹┖");
         }
         if (param.getOrderNumber() == null) {
             return ResponseValue.error("椤哄簭鍙蜂负绌�");
         }
-        //鍒ゆ柇鍚屼竴鐖剁被id涓嬪垎绫诲悕绉版槸鍚﹂噸澶�
-        BaseCategory category = this.baseCategoryService.getByCategoryNameAndFatherCategoryId(param.getCategoryName(), param.getFatherCategoryId());
+        // 鍒ゆ柇鍚屼竴鐖剁被id涓嬪垎绫诲悕绉版槸鍚﹂噸澶�
+        BaseCategory category = this.baseCategoryService.getByCategoryNameAndFatherCategoryId(param.getCategoryName(),
+                param.getFatherCategoryId());
         if (category != null) {
             return ResponseValue.error("鍒嗙被鍚嶇О宸插瓨鍦�");
         }
 
         int result = this.baseCategoryService.add(param, this.getCurrentUser());
-        if (result > 0) return ResponseValue.success(1);
+        if (result > 0) {
+            return ResponseValue.success(1);
+        }
         return ResponseValue.error("鏂板澶辫触锛�");
     }
 
@@ -82,7 +96,12 @@
      * @Date 2023/10/23
      */
     @GetMapping("/list")
-    public ResponseValue queryBaseCategoryList(BaseCategoryParam param) {
+    public ResponseValue queryBaseCategoryList() {
+        BaseCategoryParam param = CommonUtil.getObjFromReq(BaseCategoryParam.class);
+        BaseCategoryParam param2 = new BaseCategoryParam();
+        CommonUtil.copyProperties(param, param2);
+        param = param2;
+
         S_user_core currentUser = this.getCurrentUser();
         if (currentUser == null) {
             return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
@@ -97,7 +116,12 @@
      * @Date 2023/10/23
      */
     @PostMapping("/edit")
-    public ResponseValue edit(@RequestBody BaseCategory baseCategory) {
+    public ResponseValue edit() {
+        BaseCategory baseCategory = CommonUtil.getObjFromReqBody(BaseCategory.class);
+        BaseCategory param2 = new BaseCategory();
+        CommonUtil.copyProperties(baseCategory, param2);
+        baseCategory = param2;
+
         Long id = baseCategory.getId();
         if (id == null || id.longValue() <= 0) {
             return ResponseValue.error("缂栬緫鐨勭墿鍝佸垎绫讳笉瀛樺湪");
@@ -119,16 +143,22 @@
 
     /**
      * 淇敼鐘舵��
+     *
      * @author 鍗㈠簡闃�
      * @date 2023/10/23
      */
-    //鍒嗙被涓嬫湁姝e父鐘舵�佺殑鐗╁搧鏃讹紝涓嶅厑璁哥鐢�
+    // 鍒嗙被涓嬫湁姝e父鐘舵�佺殑鐗╁搧鏃讹紝涓嶅厑璁哥鐢�
     @PostMapping("/updStatus")
-    public ResponseValue updateStatus(@RequestBody BaseCategory baseCategory) {
-        if (baseCategory == null || baseCategory.getId() == null || baseCategory.getStates() == null) {
+    public ResponseValue updateStatus() {
+        BaseCategory baseCategory = CommonUtil.getObjFromReqBody(BaseCategory.class);
+        BaseCategory param2 = new BaseCategory();
+        CommonUtil.copyProperties(baseCategory, param2);
+        baseCategory = param2;
+
+        if (baseCategory.getId() == null || baseCategory.getStates() == null) {
             return ResponseValue.error("鍙傛暟閿欒");
         }
-        //鏍规嵁鍒嗙被id鍜岀姸鎬佹煡璇㈢墿鍝佹ā鐗�
+        // 鏍规嵁鍒嗙被id鍜岀姸鎬佹煡璇㈢墿鍝佹ā鐗�
         List<BaseCategory> list = this.baseGoodsTemplateService.getByCategoryId(baseCategory.getId());
         if (baseCategory.getStates() == 2 && !CollectionUtils.isEmpty(list)) {
             return ResponseValue.error("鍒嗙被涓嬫湁姝e父鐘舵�佺殑鐗╁搧锛屼笉鍏佽绂佺敤");
@@ -144,17 +174,23 @@
      * @Date 2023/10/23
      */
     @DeleteMapping("/del")
-    public ResponseValue updateById(@RequestBody BaseCategory baseCategory) {
+    public ResponseValue updateById() {
+        BaseCategory baseCategory = CommonUtil.getObjFromReqBody(BaseCategory.class);
+        BaseCategory param2 = new BaseCategory();
+        CommonUtil.copyProperties(baseCategory, param2);
+        baseCategory = param2;
+
         if (baseCategory.getId() == null) {
             return ResponseValue.error("鍒嗙被id涓虹┖");
         }
-        int num = this.baseCategoryService.updateById(baseCategory,this.getCurrentUser());
+        int num = this.baseCategoryService.updateById(baseCategory, this.getCurrentUser());
 
         return num > 0 ? ResponseValue.success(1) : ResponseValue.error("鍒犻櫎澶辫触锛�");
     }
 
     /**
      * 鏍规嵁鐗╁搧id鏌ヨ鑺傜偣璇︽儏
+     *
      * @author 鍗㈠簡闃�
      * @Date 2023/10/23
      */
@@ -164,7 +200,9 @@
             return ResponseValue.error("鍒嗙被id涓虹┖");
         }
         BaseCategory baseCategory = this.baseCategoryService.getById(id);
-        if (baseCategory == null) return ResponseValue.error("鏌ヨ澶辫触锛�");
+        if (baseCategory == null) {
+            return ResponseValue.error("鏌ヨ澶辫触锛�");
+        }
         return ResponseValue.success("鏌ヨ鎴愬姛!", baseCategory);
     }
 
@@ -184,5 +222,184 @@
         return ResponseValue.success(baseCategories);
     }
 
-}
+    /**
+     * 瀵煎叆鐗╁搧鍒嗙被
+     *
+     * @param file
+     * @return
+     * @throws IOException
+     */
+    @PostMapping("/import")
+    public ResponseValue importData(MultipartFile file) {
+        String originalFilename = file.getOriginalFilename();
+//        if (!".xls".endsWith(originalFilename)) {
+//            return ResponseValue.error("鏂囦欢鏍煎紡鏈夎!");
+//        }
+        FinSysTenantUser sysInfo = this.getSysInfo();
+        if (sysInfo == null) {
+            return ResponseValue.error("褰撳墠鐧诲綍鐢ㄦ埛涓虹┖");
+        }
+        // 褰撳墠鐧诲綍鐢ㄦ埛
+        S_user_core currentUser = this.getCurrentUser();
+        try {
+            EasyExcelFactory.read(file.getInputStream(), ImportClassificationTemplate.class,
+                    new AnalysisEventListener<ImportClassificationTemplate>() {
 
+                        /**
+                         * 姣忔潯瀛樺偍鐨刲ist
+                         */
+                        final List<ImportClassificationTemplate> importData = Lists.newArrayList();
+
+                        /**
+                         * 璇诲彇鐨勮鍙�
+                         */
+                        Integer rowIndex = 0;
+
+                        /**
+                         * 琛ㄥご淇℃伅
+                         * @param headMap
+                         * @param context
+                         */
+                        @Override
+                        public void invokeHeadMap(Map headMap, AnalysisContext context) {
+                            // 楠岃瘉琛ㄥご鏁伴噺
+                            logger.info("瑙f瀽鍒嗗彂鍗曠殑琛ㄥご闀垮害: {}", headMap.size());
+                            if (headMap.size() != 4) {
+                                throw new ExcelAnalysisException("涓婁紶鐨勬枃浠朵笉绗�!");
+                            }
+                        }
+
+                        /**
+                         * 鏁版嵁澶勭悊
+                         * @param data
+                         * @param analysisContext
+                         */
+                        @Override
+                        public void invoke(ImportClassificationTemplate data, AnalysisContext analysisContext) {
+                            rowIndex++;
+                            // 璺宠繃
+                            if (data.getCategoryOne().contains("璇存槑锛�")) {
+                                return;
+                            }
+                            if (StrUtil.isEmpty(data.getCategoryOne())) {
+                                throw new ExcelAnalysisException("绗�" + rowIndex + "鏉℃暟鎹紝涓�绾у垎绫讳笉鑳戒负绌猴細" + data.getCategoryOne());
+                            }
+                            if (StrUtil.isEmpty(data.getCategoryTwo())) {
+                                throw new ExcelAnalysisException("绗�" + rowIndex + "鏉℃暟鎹紝浜岀骇鍒嗙被涓嶈兘涓虹┖锛�" + data.getCategoryTwo());
+                            }
+                            if (StrUtil.isEmpty(data.getCategoryThree())) {
+                                throw new ExcelAnalysisException("绗�" + rowIndex + "鏉℃暟鎹紝鍝佺被鍚嶇О涓嶈兘涓虹┖锛�" + data.getCategoryThree());
+                            }
+                            if (StrUtil.isEmpty(data.getType())) {
+                                throw new ExcelAnalysisException("绗�" + rowIndex + "鏉℃暟鎹紝绠$悊鍒嗙被涓嶈兘涓虹┖锛�" + data.getType());
+                            }
+                            importData.add(data);
+                        }
+
+                        /**
+                         * 鏁版嵁澶勭悊瀵煎叆涓绘柟娉�
+                         * @param analysisContext
+                         */
+                        @Override
+                        public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+                            for (ImportClassificationTemplate data : importData) {
+                                String h1 = data.getCategoryOne();
+                                String h2 = data.getCategoryTwo();
+                                String h3 = data.getCategoryThree();
+                                String type = data.getType();
+                                BaseCategoryParam baseCategoryParam1 = new BaseCategoryParam();
+                                baseCategoryParam1.setFatherCategoryId(0L);
+                                baseCategoryParam1.setCategoryName(h1);
+                                GenericPager<BaseCategory> baseCategoryGenericPager = baseCategoryService.queryBaseCategoryList2(baseCategoryParam1);
+                                List<BaseCategory> datas = baseCategoryGenericPager.getDatas();
+
+                                // 涓�绾у垎绫�
+                                BaseCategory D1 = null;
+                                if (!CollectionUtil.isEmpty(datas)) {
+                                    D1 = datas.get(0);
+                                } else {
+                                    // 鏂板鐖剁骇
+                                    BaseCategoryParam param = new BaseCategoryParam();
+                                    param.setCategoryName(h1);
+                                    param.setStates(1);
+                                    int getIndex = baseCategoryService.selIndexByPid(0L);
+                                    param.setOrderNumber(getIndex + 1);
+                                    baseCategoryService.add(param, currentUser);
+                                    GenericPager<BaseCategory> baseCategoryGenericPager2 = baseCategoryService.queryBaseCategoryList2(baseCategoryParam1);
+                                    List<BaseCategory> datas2 = baseCategoryGenericPager2.getDatas();
+                                    D1 = datas2.get(0);
+                                }
+
+                                // 2銆佷簩绾у垎绫� 鏌ヨ绗簩灞傛暟鎹�
+                                BaseCategoryParam baseCategoryParam2 = new BaseCategoryParam();
+                                baseCategoryParam2.setCategoryName(h2);
+                                baseCategoryParam2.setFatherCategoryId(D1.getId());
+                                GenericPager<BaseCategory> baseCategoryGenericPager2 = baseCategoryService.queryBaseCategoryList2(baseCategoryParam2);
+                                List<BaseCategory> datas2 = baseCategoryGenericPager2.getDatas();
+                                BaseCategory D2 = null;
+                                if (!CollectionUtil.isEmpty(datas2)) {
+                                    D2 = datas2.get(0);
+                                } else {
+                                    // 鏂板鐖�2绾�
+                                    BaseCategoryParam param = new BaseCategoryParam();
+                                    param.setCategoryName(h2);
+                                    param.setStates(1);
+                                    param.setFatherCategoryId(D1.getId());
+                                    int getIndex = baseCategoryService.selIndexByPid(D1.getId());
+                                    param.setOrderNumber(getIndex + 1);
+                                    baseCategoryService.add(param, currentUser);
+                                    GenericPager<BaseCategory> baseCategoryGenericPager4 = baseCategoryService.queryBaseCategoryList2(baseCategoryParam2);
+                                    List<BaseCategory> datas4 = baseCategoryGenericPager4.getDatas();
+                                    D2 = datas4.get(0);
+                                }
+
+                                // 3銆佷笁绾у垎绫�(濡傛灉宸茬粡瀛樺湪锛岄偅涔堜笉澶勭悊锛屼笉瀛樺湪鏂板)
+                                BaseCategoryParam baseCategoryParam3 = new BaseCategoryParam();
+                                baseCategoryParam3.setCategoryName(h3);
+                                baseCategoryParam3.setClassification(type);
+                                baseCategoryParam3.setFatherCategoryId(D2.getId());
+                                GenericPager<BaseCategory> baseCategoryGenericPager3 = baseCategoryService.queryBaseCategoryList2(baseCategoryParam3);
+                                List<BaseCategory> datas3 = baseCategoryGenericPager3.getDatas();
+                                if (!CollectionUtil.isEmpty(datas3)) {
+                                } else {
+                                    // 鏂板鐖�2绾�
+                                    BaseCategoryParam param = new BaseCategoryParam();
+                                    param.setCategoryName(h3);
+                                    param.setStates(1);
+                                    param.setFatherCategoryId(D2.getId());
+                                    int getIndex = baseCategoryService.selIndexByPid(D2.getId());
+                                    param.setOrderNumber(getIndex + 1);
+                                    param.setClassification(type);
+                                    baseCategoryService.add(param, currentUser);
+                                    //GenericPager<BaseCategory> baseCategoryGenericPager4 = baseCategoryService.queryBaseCategoryList2(baseCategoryParam3);
+                                    //List<BaseCategory> datas4 = baseCategoryGenericPager4.getDatas();
+                                    //D3 = datas4.get(0);
+                                }
+                            }
+                        }
+
+                        @Override
+                        public void onException(Exception exception, AnalysisContext analysisContext) throws Exception {
+                            if (exception instanceof ExcelDataConvertException) {
+                                ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception;
+                                Integer row = excelDataConvertException.getRowIndex() + 1;
+                                Integer column = excelDataConvertException.getColumnIndex() + 1;
+                                throw new ExcelAnalysisException("绗�" + row + "琛岋紝绗�" + column + "鍒楄В鏋愬紓甯革紝璇锋纭~鍐�");
+                            } else {
+                                throw new ExcelAnalysisException(exception.getMessage());
+                            }
+                        }
+                    }).sheet(0).doRead();
+        } catch (ExcelAnalysisException e) {
+            return ResponseValue.error(e.getMessage());
+        }catch (RuntimeException e) {
+            e.printStackTrace();
+            return ResponseValue.error("绯荤粺閿欒");
+        }catch (Exception e) {
+            e.printStackTrace();
+            return ResponseValue.error("绯荤粺閿欒");
+        }
+        return ResponseValue.success("瀵煎叆鎴愬姛!");
+    }
+
+}

--
Gitblit v1.9.1