From 24c4699005da96f45562d7057d80c103b8e428a2 Mon Sep 17 00:00:00 2001
From: WangHan <wwh_work@126,com>
Date: 星期五, 03 一月 2025 10:32:34 +0800
Subject: [PATCH] 子级分类在用删除

---
 consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java |  177 ++++++++++++++++++++++-------------------------------------
 1 files changed, 66 insertions(+), 111 deletions(-)

diff --git a/consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java b/consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java
index df5e542..08ea887 100644
--- a/consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java
+++ b/consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java
@@ -1,36 +1,12 @@
 package com.consum.base.controller;
 
-import cn.afterturn.easypoi.excel.ExcelExportUtil;
-import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
-import com.consum.base.BaseController;
-import com.consum.base.core.utils.CommonUtil;
-import com.consum.base.core.utils.MapUtils;
-import com.consum.base.core.utils.MapperUtil;
-import com.consum.base.core.utils.PageUtil;
-import com.consum.base.pojo.LWhFormScrappedParam;
-import com.consum.base.pojo.excel.ScrappedInfoExcelTemplate;
-import com.consum.base.pojo.query.LWhFormScrappedQry;
-import com.consum.base.pojo.response.FromTransferTemplateInfoVO;
-import com.consum.base.pojo.response.LWhFormScrappedExtendVO;
-import com.consum.base.pojo.response.LWhFormScrappedVO;
-import com.consum.base.service.LWhFormScrappedServiceImpl;
-import com.consum.model.po.FinSysTenantUser;
-import com.consum.model.po.LWhFormScrapped;
-import com.walker.infrastructure.utils.CollectionUtils;
-import com.walker.infrastructure.utils.DateUtils;
-import com.walker.web.ResponseValue;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+
 import javax.servlet.http.HttpServletResponse;
+
 import org.apache.commons.compress.utils.Lists;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.BeanUtils;
@@ -39,6 +15,29 @@
 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.core.utils.PageUtil;
+import com.consum.base.pojo.LWhFormScrappedParam;
+import com.consum.base.pojo.excel.ScrappedInfoExcelTemplate;
+import com.consum.base.pojo.query.LWhFormScrappedQry;
+import com.consum.base.pojo.response.GoodsTemplateCountVO;
+import com.consum.base.pojo.response.LWhFormScrappedExtendVO;
+import com.consum.base.pojo.response.LWhFormScrappedVO;
+import com.consum.base.service.LWhFormScrappedService;
+import com.consum.model.po.FinSysTenantUser;
+import com.consum.model.po.LWhFormScrapped;
+import com.walker.infrastructure.utils.CollectionUtils;
+import com.walker.infrastructure.utils.DateUtils;
+import com.walker.web.ResponseValue;
+
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 
 /**
  * @Description 鎶ュ簾鍗�
@@ -51,8 +50,7 @@
 public class LWhFormScrappedController extends BaseController {
 
     @Autowired
-    private LWhFormScrappedServiceImpl lWhFormScrappedService;
-
+    private LWhFormScrappedService lWhFormScrappedService;
 
     /**
      * @Description 鏂板鎶ュ簾鍗�
@@ -60,9 +58,7 @@
      * @Date 2023/11/1
      */
     @ApiOperation(value = "鏂板鎶ュ簾鍗�", notes = "鏂板鎶ュ簾鍗�")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "param")
-    })
+    @ApiImplicitParams({@ApiImplicitParam(name = "param")})
     @PostMapping("/add")
     public ResponseValue add() {
         LWhFormScrappedParam param = CommonUtil.getObjFromReqBody(LWhFormScrappedParam.class);
@@ -70,26 +66,7 @@
         CommonUtil.copyProperties(param, query);
         param = query;
         FinSysTenantUser sysInfo = this.getSysInfo();
-        int result = this.lWhFormScrappedService.add(param, 0, this.getCurrentUser(), sysInfo);
-        if (result > 0) {
-            return ResponseValue.success(1);
-        }
-        return ResponseValue.error("鏂板澶辫触锛�");
-    }
-
-    @ApiOperation(value = "鏂板鎶ュ簾鍗�", notes = "鏂板鎶ュ簾鍗�")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "param")
-    })
-    @PostMapping("/deprAdd")
-    public ResponseValue deprAdd() {
-        LWhFormScrappedParam param = CommonUtil.getObjFromReqBody(LWhFormScrappedParam.class);
-        LWhFormScrappedParam query = new LWhFormScrappedParam();
-        CommonUtil.copyProperties(param, query);
-        param = query;
-
-        FinSysTenantUser sysInfo = this.getSysInfo();
-        int result = this.lWhFormScrappedService.add(param, 1, this.getCurrentUser(), sysInfo);
+        int result = this.lWhFormScrappedService.add(param, this.getCurrentUser(), sysInfo);
         if (result > 0) {
             return ResponseValue.success(1);
         }
@@ -99,12 +76,13 @@
     /**
      * @Description 鍒楄〃鏌ヨ
      * @Author 鍗㈠簡闃�
-     * @Date 2023/11/02 1.鏌ヨ鎶ュ簾鍗� 2.鏌ヨ鎶ュ簾鍗曠墿鍝�
+     * @Date 2023/11/02
+     *       <p>
+     *       </>1.鏌ヨ鎶ュ簾鍗� 2.鏌ヨ鎶ュ簾鍗曠墿鍝�
      */
     @ApiOperation(value = "鍒楄〃鏌ヨ", notes = "鍒楄〃鏌ヨ")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鏌ヨ鏉′欢", dataType = "LWhFormScrappedQry", paramType = "query")
-    })
+        @ApiImplicitParam(name = "param", value = "鏌ヨ鏉′欢", dataType = "LWhFormScrappedQry", paramType = "query")})
     @GetMapping("/list")
     public ResponseValue queryList() {
         LWhFormScrappedQry param = CommonUtil.getObjFromReq(LWhFormScrappedQry.class);
@@ -123,19 +101,10 @@
             data.forEach(item -> {
                 LWhFormScrappedVO lWhFormScrappedVO = new LWhFormScrappedVO();
                 BeanUtils.copyProperties(item, lWhFormScrappedVO);
-                List<FromTransferTemplateInfoVO> list = Lists.newArrayList();
                 // 鏌ヨ鍨嬪彿鏁伴噺
-                String sql =
-                    "SELECT fsg.id,fsg.BASE_GOODS_TEMPLATE_ID goodsTemplatesId,fsg.GOODS_TEMPLATE_NAME goodsName,sum(counts) count FROM l_wh_form_scrapped fs left join l_wh_form_scrapped_goods fsg on fs.id = fsg.FORM_SCRAPPED_ID "
-                        + "where fsg.FORM_SCRAPPED_ID =:id group by fsg.BASE_GOODS_TEMPLATE_ID";
-                Map<String, Object> paramMap = new HashMap<>();
-                paramMap.put("id", item.getId());
-                List<Map<String, Object>> procureModelList = lWhFormScrappedService.select(sql, paramMap, new MapperUtil());
-                for (Map<String, Object> map : procureModelList) {
-                    FromTransferTemplateInfoVO fromTransferTemplateInfoVO = MapUtils.convertMapToObj(map, FromTransferTemplateInfoVO.class);
-                    list.add(fromTransferTemplateInfoVO);
-                }
-                lWhFormScrappedVO.setGoodTemplateInfo(list);
+                List<GoodsTemplateCountVO> scrappedCount =
+                    lWhFormScrappedService.getScrappedCountByBusinessId(item.getId());
+                lWhFormScrappedVO.setGoodTemplateInfo(scrappedCount);
                 result.add(lWhFormScrappedVO);
             });
         }
@@ -149,9 +118,7 @@
      * @Date 2023/11/2
      */
     @ApiOperation(value = "鏍规嵁id鏌ヨ璇︽儏", notes = "鏍规嵁id鏌ヨ璇︽儏")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "id", value = "鎶ュ簾鍗昳d", dataType = "Long", paramType = "query")
-    })
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "鎶ュ簾鍗昳d", dataType = "Long", paramType = "query")})
     @GetMapping("/detail")
     public ResponseValue getById(Long id) {
         if (id == null) {
@@ -169,8 +136,7 @@
      */
     @ApiOperation(value = "鎶ュ簾鏄庣粏", notes = "鎶ュ簾鏄庣粏")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鏌ヨ鏉′欢", dataType = "LWhFormScrappedQry", paramType = "query")
-    })
+        @ApiImplicitParam(name = "param", value = "鏌ヨ鏉′欢", dataType = "LWhFormScrappedQry", paramType = "query")})
     @GetMapping("/list/detailList")
     public ResponseValue queryDetailList() {
         LWhFormScrappedQry param = CommonUtil.getObjFromReq(LWhFormScrappedQry.class);
@@ -186,54 +152,43 @@
         return ResponseValue.success(pageUtil);
     }
 
-    /**
-     * @Description 瀵煎嚭鎶ュ簾鐧昏鍗�
-     * @Author 鍗㈠簡闃�
-     * @Date 2023/11/2
-     */
+    @ApiOperation(value = "瀵煎嚭鎶ュ簾鍗�", notes = "瀵煎嚭鎶ュ簾鍗�")
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "鎶ュ簾鍗昳d", dataType = "Long", paramType = "query")})
     @GetMapping("/list/export")
-    public void export(Long id, HttpServletResponse response) {
+    public ResponseValue<String> export(Long id, HttpServletResponse response) throws Exception {
         if (id == null) {
             throw new RuntimeException("鎶ュ簾鍗昳d涓虹┖");
         }
-        try {
-            OutputStream outputStream = response.getOutputStream();
-            List<ScrappedInfoExcelTemplate> export = lWhFormScrappedService.export(id);
-            if (CollectionUtils.isEmpty(export)) {
-                throw new RuntimeException("鏁版嵁涓虹┖");
-            }
-            TemplateExportParams exportParams = new TemplateExportParams("import/鎶ュ簾鐧昏鍗�.xlsx");
-            exportParams.setHeadingStartRow(2);
 
-            Optional<ScrappedInfoExcelTemplate> first = export.stream().findFirst();
-            ScrappedInfoExcelTemplate scrappedInfoExcelTemplate = first.get();
-            Long dealTime = scrappedInfoExcelTemplate.getDealTime();
-            String operatorName = scrappedInfoExcelTemplate.getOperatorName();
-            String businessFormCode = scrappedInfoExcelTemplate.getBusinessFormCode();
-
-            int countNum = export.stream().filter(item -> item.getNum() != null).mapToInt(ScrappedInfoExcelTemplate::getNum).sum();
-            int totalAmount = export.stream().filter(item -> item.getTotalAmount() != null).mapToInt(ScrappedInfoExcelTemplate::getTotalAmount).sum();
-
-            Map<String, Object> map = new HashMap<>();
-            map.put("code", businessFormCode);
-            map.put("date", DateUtils.toShowDate(dealTime));
-            map.put("name", operatorName);
-            map.put("countNum", countNum);
-            map.put("totalAmount", totalAmount);
-
-            Workbook sheets = ExcelExportUtil.exportExcel(exportParams, ScrappedInfoExcelTemplate.class, export, map);
-            // 璁剧疆鍝嶅簲澶�
-            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
-            response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("鎶ュ簾鍗曠櫥璁�.xlsx", "utf-8"));
-            sheets.write(outputStream);
-            sheets.close();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
+        List<ScrappedInfoExcelTemplate> export = lWhFormScrappedService.export(id);
+        if (CollectionUtils.isEmpty(export)) {
+            throw new RuntimeException("鏁版嵁涓虹┖");
         }
+        TemplateExportParams exportParams = new TemplateExportParams("import/鎶ュ簾鐧昏鍗�.xlsx");
+        exportParams.setHeadingStartRow(2);
 
+        Optional<ScrappedInfoExcelTemplate> first = export.stream().findFirst();
+        ScrappedInfoExcelTemplate scrappedInfoExcelTemplate = first.get();
+        Long dealTime = scrappedInfoExcelTemplate.getDealTime();
+        String operatorName = scrappedInfoExcelTemplate.getOperatorName();
+        String businessFormCode = scrappedInfoExcelTemplate.getBusinessFormCode();
+
+        int countNum =
+            export.stream().filter(item -> item.getNum() != null).mapToInt(ScrappedInfoExcelTemplate::getNum).sum();
+        double totalAmount = export.stream().filter(item -> item.getTotalAmount() != null)
+            .mapToDouble(ScrappedInfoExcelTemplate::getAmount).sum();
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("code", businessFormCode);
+        map.put("date", DateUtils.toShowDate(dealTime));
+        map.put("name", operatorName);
+        map.put("countNum", countNum);
+        map.put("totalAmount", totalAmount);
+
+        Workbook sheets = ExcelExportUtil.exportExcel(exportParams, ScrappedInfoExcelTemplate.class, export, map);
+        String filePath = downLoadExcel("鎶ュ簾鐧昏鍗�", sheets);
+        return ResponseValue.success("瀵煎嚭鎴愬姛", filePath);
 
     }
 
-
 }
-

--
Gitblit v1.9.1