From 2a370db9610af10873bd0292b5d5fd7246fd4039 Mon Sep 17 00:00:00 2001
From: futian.liu <liufutianyoo@163.com>
Date: 星期二, 12 十二月 2023 16:13:38 +0800
Subject: [PATCH] 新增用户提示区县错误

---
 consum-base/src/main/java/com/consum/base/controller/LWhFormScrappedController.java |  195 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 127 insertions(+), 68 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 6e6c912..e44488e 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,135 +1,194 @@
 package com.consum.base.controller;
 
-import com.consum.base.BaseController;
-import com.consum.base.pojo.*;
-import com.consum.base.service.LWhFormScrappedGoodsService;
-import com.consum.base.service.LWhFormScrappedServiceImpl;
-import com.consum.model.po.*;
-import com.consum.model.vo.LWhFormOutputVo;
-import com.consum.model.vo.LWhFormTransferVo;
-import com.iplatform.model.po.S_user_core;
-import com.walker.db.page.GenericPager;
-import com.walker.infrastructure.utils.CollectionUtils;
-import com.walker.web.ResponseValue;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
+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;
+import org.springframework.beans.factory.annotation.Autowired;
+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.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 鎶ュ簾鍗�
  * @Author 鍗㈠簡闃�
  * @Date 2023/11/1
  */
+@Api(value = "鎶ュ簾鍗�", tags = "鎶ュ簾鍗�")
 @RestController
 @RequestMapping("/pc/l/wh/form/scrapped")
 public class LWhFormScrappedController extends BaseController {
 
     @Autowired
-    private LWhFormScrappedServiceImpl lWhFormScrappedService;
-    @Autowired
-    private LWhFormScrappedGoodsService scrappedGoodsService;
+    private LWhFormScrappedService lWhFormScrappedService;
 
     /**
-     * @Description  鏂板鎶ュ簾鍗�
+     * @Description 鏂板鎶ュ簾鍗�
      * @Author 鍗㈠簡闃�
      * @Date 2023/11/1
      */
+    @ApiOperation(value = "鏂板鎶ュ簾鍗�", notes = "鏂板鎶ュ簾鍗�")
+    @ApiImplicitParams({@ApiImplicitParam(name = "param")})
     @PostMapping("/add")
-    public ResponseValue add(@RequestBody LWhFormScrappedParam param) {
+    public ResponseValue add() {
+        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, this.getCurrentUser(),sysInfo);
-        if (result > 0) return ResponseValue.success(1);
+        int result = this.lWhFormScrappedService.add(param, this.getCurrentUser(), sysInfo);
+        if (result > 0) {
+            return ResponseValue.success(1);
+        }
         return ResponseValue.error("鏂板澶辫触锛�");
     }
 
     /**
-     * @Description  鍒楄〃鏌ヨ
+     * @Description 鍒楄〃鏌ヨ
      * @Author 鍗㈠簡闃�
      * @Date 2023/11/02
+     *       <p>
+     *       </>1.鏌ヨ鎶ュ簾鍗� 2.鏌ヨ鎶ュ簾鍗曠墿鍝�
      */
-    //1.鏌ヨ鎶ュ簾鍗�
-    //2.鏌ヨ鎶ュ簾鍗曠墿鍝�
+    @ApiOperation(value = "鍒楄〃鏌ヨ", notes = "鍒楄〃鏌ヨ")
+    @ApiImplicitParams({
+        @ApiImplicitParam(name = "param", value = "鏌ヨ鏉′欢", dataType = "LWhFormScrappedQry", paramType = "query")})
     @GetMapping("/list")
-    public ResponseValue queryList(LWhFormScrappedParam param) {
+    public ResponseValue queryList() {
+        LWhFormScrappedQry param = CommonUtil.getObjFromReq(LWhFormScrappedQry.class);
+        LWhFormScrappedQry query = new LWhFormScrappedQry();
+        CommonUtil.copyProperties(param, query);
+        param = query;
+
         FinSysTenantUser sysInfo = getSysInfo();
         if (sysInfo == null) {
             return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
         }
-
-        GenericPager genericPager = lWhFormScrappedService.queryList(param,sysInfo);
-        List<LWhFormScrapped> datas = genericPager.getDatas();
-        ArrayList<LWhFormScrappedExtend> newDatas = new ArrayList<>();
-        if (!CollectionUtils.isEmpty(datas)) {
-            datas.forEach(item -> {
-                // 鏌ヨ鎶ュ簾鍗曠墿鍝�
-                LWhFormScrappedGoods scrappedGoods = new LWhFormScrappedGoods();
-                scrappedGoods.setFormScrappedId(item.getId());
-                List<LWhFormScrappedGoods> scrappedGoodsList = scrappedGoodsService.select(scrappedGoods);
-                LWhFormScrappedExtend formScrappedExtend = new LWhFormScrappedExtend();
-                BeanUtils.copyProperties(item, formScrappedExtend);
-                formScrappedExtend.setScrappedGoodsList(scrappedGoodsList);
-                newDatas.add(formScrappedExtend);
+        PageUtil genericPager = lWhFormScrappedService.queryList(param, sysInfo);
+        List<LWhFormScrapped> data = genericPager.getDatas();
+        List<LWhFormScrappedVO> result = Lists.newArrayList();
+        if (!CollectionUtils.isEmpty(data)) {
+            data.forEach(item -> {
+                LWhFormScrappedVO lWhFormScrappedVO = new LWhFormScrappedVO();
+                BeanUtils.copyProperties(item, lWhFormScrappedVO);
+                // 鏌ヨ鍨嬪彿鏁伴噺
+                List<GoodsTemplateCountVO> scrappedCount =
+                    lWhFormScrappedService.getScrappedCountByBusinessId(item.getId());
+                lWhFormScrappedVO.setGoodTemplateInfo(scrappedCount);
+                result.add(lWhFormScrappedVO);
             });
         }
-        try {
-            Field fieldDatas = GenericPager.class.getDeclaredField("datas");
-            fieldDatas.setAccessible(true);
-            fieldDatas.set(genericPager, newDatas);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-//        genericPager.setDatas(newDatas);
+        genericPager.setDatas(result);
         return ResponseValue.success(genericPager);
     }
 
     /**
-     * @Description  鏍规嵁id鏌ヨ璇︽儏
+     * @Description 鏍规嵁id鏌ヨ璇︽儏
      * @Author 鍗㈠簡闃�
      * @Date 2023/11/2
      */
+    @ApiOperation(value = "鏍规嵁id鏌ヨ璇︽儏", notes = "鏍规嵁id鏌ヨ璇︽儏")
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "鎶ュ簾鍗昳d", dataType = "Long", paramType = "query")})
     @GetMapping("/detail")
     public ResponseValue getById(Long id) {
         if (id == null) {
             return ResponseValue.error("鎶ュ簾鍗昳d涓虹┖");
         }
-        LWhFormScrappedExtend scrappedExtend = this.lWhFormScrappedService.getById(id);
+        LWhFormScrappedExtendVO scrappedExtend = this.lWhFormScrappedService.getById(id);
         return ResponseValue.success(scrappedExtend);
     }
 
     /**
      * 鎶ュ簾鏄庣粏
-     * @param param
+     *
+     * @param
      * @return
      */
+    @ApiOperation(value = "鎶ュ簾鏄庣粏", notes = "鎶ュ簾鏄庣粏")
+    @ApiImplicitParams({
+        @ApiImplicitParam(name = "param", value = "鏌ヨ鏉′欢", dataType = "LWhFormScrappedQry", paramType = "query")})
     @GetMapping("/list/detailList")
-    public ResponseValue queryDetailList(LWhFormScrappedParam param) {
+    public ResponseValue queryDetailList() {
+        LWhFormScrappedQry param = CommonUtil.getObjFromReq(LWhFormScrappedQry.class);
+        LWhFormScrappedQry query = new LWhFormScrappedQry();
+        CommonUtil.copyProperties(param, query);
+        param = query;
+
         FinSysTenantUser sysInfo = this.getSysInfo();
         if (sysInfo == null) {
             return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
         }
-        GenericPager<Map<String, Object>> genericPager = lWhFormScrappedService.queryDetailList(param,sysInfo);
-        return ResponseValue.success(genericPager);
+        PageUtil pageUtil = lWhFormScrappedService.queryDetailList(param, sysInfo);
+        return ResponseValue.success(pageUtil);
     }
 
-    /**
-     * @Description  瀵煎嚭鎶ュ簾鐧昏鍗�
-     * @Author 鍗㈠簡闃�
-     * @Date 2023/11/2
-     */
-    @GetMapping("/export")
-    public ResponseValue export(Long id) {
+    @ApiOperation(value = "瀵煎嚭鎶ュ簾鍗�", notes = "瀵煎嚭鎶ュ簾鍗�")
+    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "鎶ュ簾鍗昳d", dataType = "Long", paramType = "query")})
+    @GetMapping("/list/export")
+    public ResponseValue<String> export(Long id, HttpServletResponse response) throws Exception {
         if (id == null) {
-            return ResponseValue.error("鎶ュ簾鍗昳d涓虹┖");
+            throw new RuntimeException("鎶ュ簾鍗昳d涓虹┖");
         }
-        LWhFormScrappedExtend scrappedExtend = this.lWhFormScrappedService.export(id,this.getSysInfo());
-        return ResponseValue.success(scrappedExtend);
-    }
 
+        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("鎶ュ簾鐧昏鍗�", response, sheets);
+        return ResponseValue.success("瀵煎嚭鎴愬姛", filePath);
+
+    }
 
 }
-

--
Gitblit v1.9.1