From 3be9cfcb6b59366b936821966d20a998a6895f9f Mon Sep 17 00:00:00 2001
From: 黎星凯 <13949086503@163.com>
Date: 星期二, 30 四月 2024 14:38:13 +0800
Subject: [PATCH] bug41、42修改

---
 consum-base/src/main/java/com/consum/base/controller/LWhFormInventoryController.java |  230 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 159 insertions(+), 71 deletions(-)

diff --git a/consum-base/src/main/java/com/consum/base/controller/LWhFormInventoryController.java b/consum-base/src/main/java/com/consum/base/controller/LWhFormInventoryController.java
index d7eeeb0..7693076 100644
--- a/consum-base/src/main/java/com/consum/base/controller/LWhFormInventoryController.java
+++ b/consum-base/src/main/java/com/consum/base/controller/LWhFormInventoryController.java
@@ -1,36 +1,49 @@
 package com.consum.base.controller;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import javax.servlet.http.HttpServletResponse;
+
+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.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.core.utils.PageUtil;
+import com.consum.base.pojo.excel.InventoryExcelTemplate;
 import com.consum.base.pojo.query.LWhFormInventoryQry;
 import com.consum.base.pojo.request.FormInventoryParam;
 import com.consum.base.pojo.request.LWhFormInventoryParam;
 import com.consum.base.pojo.response.FormInventoryDetailVO;
 import com.consum.base.pojo.response.FormInventoryGoodsVO;
 import com.consum.base.pojo.response.FormInventoryVO;
-import com.consum.base.service.FinSysTenantUserServiceImpl;
-import com.consum.base.service.LWhFormInventoryCoreService;
-import com.consum.base.service.LWhFormInventoryServiceImpl;
+import com.consum.base.service.FinSysTenantUserService;
+import com.consum.base.service.LWhFormInventoryService;
 import com.consum.model.po.FinSysTenantUser;
 import com.consum.model.po.LWhFormInventory;
 import com.iplatform.model.po.S_user_core;
 import com.walker.db.page.GenericPager;
+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;
 import io.swagger.annotations.ApiResponse;
-import java.util.List;
-import java.util.Objects;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-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.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
 
 /**
  * @Description 鐩樼偣
@@ -43,12 +56,9 @@
 public class LWhFormInventoryController extends BaseController {
 
     @Autowired
-    private LWhFormInventoryServiceImpl lWhFormInventoryService;
+    private LWhFormInventoryService lWhFormInventoryService;
     @Autowired
-    private FinSysTenantUserServiceImpl finSysTenantUserService;
-    @Autowired
-    private LWhFormInventoryCoreService lWhFormInventoryCoreService;
-
+    private FinSysTenantUserService finSysTenantUserService;
 
     /**
      * @Description 鏂板
@@ -56,24 +66,30 @@
      * @Date 2023/10/31
      */
     @ApiOperation(value = "鏂板鐩樼偣", notes = "鏂板鐩樼偣")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "FormInventoryParam")
-    })
+    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "FormInventoryParam")})
     @PostMapping("/add")
-    public ResponseValue add(@RequestBody FormInventoryParam param) {
+    public ResponseValue add() {
+
+        FormInventoryParam param = CommonUtil.getObjFromReqBody(FormInventoryParam.class);
+        FormInventoryParam formInventoryParam = new FormInventoryParam();
+        CommonUtil.copyProperties(param, formInventoryParam);
+        param = formInventoryParam;
+
         FinSysTenantUser sysInfo = this.getSysInfo();
         if (sysInfo == null) {
             return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
         }
-        //鏍规嵁鐩樼偣浜篿d鏌ヨ鐩樼偣浜�
+        // 鏍规嵁鐩樼偣浜篿d鏌ヨ鐩樼偣浜�
+        // 鐩樼偣浜篿d涓簊ysUserId瀛楁鏌ヨ
         FinSysTenantUser finSysTenantUser = new FinSysTenantUser();
-        finSysTenantUser.setId(param.getOperatorUserId());
-        FinSysTenantUser operatorUser = finSysTenantUserService.get(finSysTenantUser);
-        //鏍规嵁鐩戠洏浜篿d鏌ヨ鐩戠洏浜�
+        finSysTenantUser.setSysUserId(param.getOperatorUserId());
+        FinSysTenantUser operatorUser =
+                finSysTenantUserService.select(finSysTenantUser).stream().findFirst().orElse(null);
+        // 鏍规嵁鐩戠洏浜篿d鏌ヨ鐩戠洏浜�
         FinSysTenantUser monitorUserInfo = new FinSysTenantUser();
         monitorUserInfo.setId(param.getMonitorUserId());
         FinSysTenantUser monitorUser = finSysTenantUserService.get(monitorUserInfo);
-        int result = this.lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
+        int result = lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
         if (result > 0) {
             return ResponseValue.success();
         }
@@ -86,23 +102,48 @@
      * @Date 2023/10/31
      */
     @ApiOperation(value = "鐩樼偣鍗曞垪琛ㄦ煡璇�", notes = "鐩樼偣鍗曞垪琛ㄦ煡璇�")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鐩樼偣鏉′欢", dataType = "LWhFormInventoryParam", required = true, paramType = "query")
-    })
+    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "鐩樼偣鏉′欢", dataType = "LWhFormInventoryParam",
+            required = true, paramType = "query")})
     @GetMapping("/list")
-    public ResponseValue queryList(LWhFormInventoryQry param) {
+    public ResponseValue queryList() {
+        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
+        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
+        CommonUtil.copyProperties(param, param2);
+        param = param2;
+
         FinSysTenantUser sysInfo = this.getSysInfo();
         if (sysInfo == null) {
             return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
         }
-        GenericPager<LWhFormInventory> pager = this.lWhFormInventoryService.queryList(param, sysInfo);
+        GenericPager<LWhFormInventory> pager = lWhFormInventoryService.queryList(param, sysInfo);
         return ResponseValue.success(pager);
+    }
+
+    /**
+     * 鏌ヨ姝よ处鍙疯鑹诧紝鏄惁鐜板湪杩樺彲浠ュ鍔犵洏鐐逛换鍔�
+     *
+     * @return
+     */
+    @ApiOperation(value = "鏌ヨ姝よ处鍙疯鑹诧紝鏄惁鐜板湪杩樺彲浠ュ鍔犵洏鐐逛换鍔�", notes = "鏌ヨ姝よ处鍙疯鑹诧紝鏄惁鐜板湪杩樺彲浠ュ鍔犵洏鐐逛换鍔�")
+    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "鐩樼偣鏉′欢", dataType = "LWhFormInventoryParam",
+            required = true, paramType = "query")})
+    @GetMapping("/isAddInventory")
+    public ResponseValue isAddInventory() {
+        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
+        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
+        CommonUtil.copyProperties(param, param2);
+        param = param2;
+        FinSysTenantUser sysInfo = this.getSysInfo();
+        if (sysInfo == null) {
+            return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
+        }
+        Integer res = lWhFormInventoryService.isAddInventory(param, sysInfo);
+        return ResponseValue.success(res);
     }
 
     @ApiOperation(value = "鐩樼偣鍗曠墿鍝佸垪琛ㄦ煡璇�", notes = "鐩樼偣鍗曠墿鍝佸垪琛ㄦ煡璇�", response = FormInventoryVO.class)
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "id", value = "鐩樼偣鍗昳d", dataType = "Long", required = true, paramType = "query")
-    })
+            @ApiImplicitParam(name = "id", value = "鐩樼偣鍗昳d", dataType = "Long", required = true, paramType = "query")})
     @ApiResponse(code = 200, message = "鎴愬姛", response = FormInventoryVO.class)
     @GetMapping("/query")
     public ResponseValue queryInventBaseGoodTemplate(Long id) {
@@ -113,10 +154,12 @@
         if (id == null) {
             return ResponseValue.error("鍙傛暟涓嶈兘涓虹┖");
         }
-        FormInventoryVO formInventoryVO = this.lWhFormInventoryService.queryInventBaseGoodTemplate(id);
+        // 閫氳繃鏈烘瀯鏌ヨ鐩稿叧鐨勬ā鏉夸俊鎭�
+        FormInventoryVO formInventoryVO = lWhFormInventoryService.queryInventBaseGoodTemplate(id);
 
-        this.lWhFormInventoryService.saveInventory(formInventoryVO, id);
-        return ResponseValue.success(formInventoryVO);
+        // 淇濆瓨鍚庤繑鍥炶褰曚俊鎭�
+        FormInventoryVO result = lWhFormInventoryService.saveInventory(formInventoryVO, id);
+        return ResponseValue.success(result);
     }
 
     /**
@@ -125,11 +168,14 @@
      * @Date 2023/10/31
      */
     @ApiOperation(value = "缂栬緫鐩樼偣", notes = "缂栬緫鐩樼偣")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "FormInventoryParam")
-    })
+    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "FormInventoryParam")})
     @PostMapping("/edit")
-    public ResponseValue edit(@RequestBody FormInventoryParam param) {
+    public ResponseValue edit() {
+        FormInventoryParam param = CommonUtil.getObjFromReqBody(FormInventoryParam.class);
+        FormInventoryParam formInventoryParam = new FormInventoryParam();
+        CommonUtil.copyProperties(param, formInventoryParam);
+        param = formInventoryParam;
+
         LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(param.getId()));
         if (lWhFormInventory == null) {
             return ResponseValue.error("缂栬緫澶辫触锛�");
@@ -141,8 +187,18 @@
         if (num == 0) {
             return ResponseValue.error("缂栬緫澶辫触锛�");
         }
-        ResponseValue add = this.add(param);
-        if (add.getCode() == ResponseValue.CODE_SUCCESS) {
+
+        // 鏍规嵁鐩樼偣浜篿d鏌ヨ鐩樼偣浜�
+        FinSysTenantUser finSysTenantUser = new FinSysTenantUser();
+        finSysTenantUser.setId(param.getOperatorUserId());
+        FinSysTenantUser operatorUser = finSysTenantUserService.get(finSysTenantUser);
+        // 鏍规嵁鐩戠洏浜篿d鏌ヨ鐩戠洏浜�
+        FinSysTenantUser monitorUserInfo = new FinSysTenantUser();
+        monitorUserInfo.setId(param.getMonitorUserId());
+        FinSysTenantUser monitorUser = finSysTenantUserService.get(monitorUserInfo);
+        int result = lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
+
+        if (result > 0) {
             return ResponseValue.success();
         }
 
@@ -154,8 +210,7 @@
      */
     @ApiOperation(value = "鏍规嵁id鍒犻櫎鐩樼偣", notes = "鏍规嵁id鍒犻櫎鐩樼偣")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "id", value = "鐩樼偣鍗昳d", dataType = "Long", required = true, paramType = "query")
-    })
+            @ApiImplicitParam(name = "id", value = "鐩樼偣鍗昳d", dataType = "Long", required = true, paramType = "query")})
     @DeleteMapping("/del")
     public ResponseValue delById(Long id) {
         if (id == null) {
@@ -176,7 +231,6 @@
         return ResponseValue.success(1);
     }
 
-
     /**
      * 鏆傚瓨
      *
@@ -184,16 +238,19 @@
      * @date 2023/10/31
      */
     @ApiOperation(value = "鐩樼偣鏆傚瓨", notes = "鐩樼偣鏆傚瓨")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "LWhFormInventoryDto")
-    })
+    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "LWhFormInventoryDto")})
     @PostMapping("/temporary/storage")
-    public ResponseValue temporaryStorage(@RequestBody LWhFormInventoryParam dto) {
-        if (dto == null) {
+    public ResponseValue updateTemporaryStorage() {
+        LWhFormInventoryParam param = CommonUtil.getObjFromReqBody(LWhFormInventoryParam.class);
+        LWhFormInventoryParam formInventoryParam = new LWhFormInventoryParam();
+        CommonUtil.copyProperties(param, formInventoryParam);
+        param = formInventoryParam;
+
+        if (param == null) {
             return ResponseValue.error("鍙傛暟閿欒");
         }
 
-        int num = this.lWhFormInventoryService.updateInventoryInfo(dto, 1);
+        int num = lWhFormInventoryService.updateInventoryInfo(param, 1, null, null);
         return num > 0 ? ResponseValue.success(1) : ResponseValue.error("鏆傚瓨澶辫触锛�");
     }
 
@@ -204,22 +261,22 @@
      * @date 2023/10/31
      */
     @ApiOperation(value = "瀹屾垚鐩樼偣", notes = "瀹屾垚鐩樼偣")
-    @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "LWhFormInventoryDto")
-    })
+    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "鐩樼偣鍗曚俊鎭�", dataType = "LWhFormInventoryDto")})
     @PostMapping("/finish")
-    public ResponseValue finishPd(@RequestBody LWhFormInventoryParam dto) {
-        if (dto == null) {
+    public ResponseValue updateFinishPd() {
+        LWhFormInventoryParam param = CommonUtil.getObjFromReqBody(LWhFormInventoryParam.class);
+        LWhFormInventoryParam formInventoryParam = new LWhFormInventoryParam();
+        CommonUtil.copyProperties(param, formInventoryParam);
+        param = formInventoryParam;
+
+        if (param == null) {
             return ResponseValue.error("鍙傛暟閿欒");
         }
-
-        int num = this.lWhFormInventoryService.updateInventoryInfo(dto, 2);
-
         S_user_core currentUser = this.getCurrentUser();
         FinSysTenantUser sysInfo = this.getSysInfo();
+        int num = lWhFormInventoryService.updateInventoryInfo(param, 2, currentUser, sysInfo);
 
-        String inOutFormByInventoryId = lWhFormInventoryCoreService.createInOutFormByInventoryId(dto.getId(), currentUser, sysInfo);
-        return num > 0 ? ResponseValue.success(1) : ResponseValue.error(inOutFormByInventoryId);
+        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("鐩樼偣澶辫触锛�");
     }
 
     /**
@@ -229,22 +286,25 @@
      */
     @ApiOperation(value = "寮傚父鏄庣粏鍒楄〃鏌ヨ", notes = "寮傚父鏄庣粏鍒楄〃鏌ヨ")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "param", value = "鐩樼偣鏉′欢", dataType = "LWhFormInventoryParam", paramType = "query")
-    })
+            @ApiImplicitParam(name = "param", value = "鐩樼偣鏉′欢", dataType = "LWhFormInventoryParam", paramType = "query")})
     @GetMapping("/list/PdDetail")
-    public ResponseValue queryPdDetailList(LWhFormInventoryQry param) {
+    public ResponseValue queryPdDetailList() {
+        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
+        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
+        CommonUtil.copyProperties(param, param2);
+        param = param2;
+
         FinSysTenantUser sysInfo = this.getSysInfo();
         if (sysInfo == null) {
             return ResponseValue.error("鐧诲綍鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
         }
-        PageUtil<FormInventoryDetailVO> result = this.lWhFormInventoryService.queryPdDetailList(param, sysInfo);
+        PageUtil<FormInventoryDetailVO> result = lWhFormInventoryService.queryPdDetailList(param, sysInfo);
         return ResponseValue.success(result);
     }
 
     @ApiOperation(value = "鏍规嵁id鏌ヨ鐩樼偣鐗╁搧璇︾粏淇℃伅", notes = "鏍规嵁id鏌ヨ鐩樼偣鐗╁搧璇︾粏淇℃伅")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "id", value = "鐩樼偣id", dataType = "Long", required = true, paramType = "query")
-    })
+            @ApiImplicitParam(name = "id", value = "鐩樼偣id", dataType = "Long", required = true, paramType = "query")})
     @GetMapping("/detail")
     public ResponseValue selectDetailById(Long id) {
         FinSysTenantUser sysInfo = this.getSysInfo();
@@ -255,16 +315,44 @@
 
         LWhFormInventory lWhFormInventory = new LWhFormInventory();
         lWhFormInventory.setId(id);
-        LWhFormInventory item = this.lWhFormInventoryService.get(lWhFormInventory);
+        LWhFormInventory item = lWhFormInventoryService.get(lWhFormInventory);
         if (Objects.isNull(item)) {
             return ResponseValue.error("鐩樼偣鍗曚笉瀛樺湪");
         }
         BeanUtils.copyProperties(item, formInventoryVO);
-        List<FormInventoryGoodsVO> formInventoryGoodsVOS = this.lWhFormInventoryService.selectDetailById(id);
+        List<FormInventoryGoodsVO> formInventoryGoodsVOS = lWhFormInventoryService.selectDetailById(id);
         formInventoryVO.setFormInventoryGoodsList(formInventoryGoodsVOS);
         return ResponseValue.success(formInventoryVO);
     }
 
+    @ApiOperation(value = "鐩樼偣鍗曞鍑�", notes = "鐩樼偣鍗曞鍑�")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "鐩樼偣鍗昳d", dataType = "Long", required = true, paramType = "query")})
+    @GetMapping("/list/export")
+    public ResponseValue<String> export(Long id, HttpServletResponse response) throws Exception {
+
+        List<InventoryExcelTemplate> exportList = lWhFormInventoryService.getExportList(id);
+        if (CollectionUtils.isEmpty(exportList)) {
+            throw new RuntimeException("鏁版嵁涓虹┖");
+        }
+        TemplateExportParams params = new TemplateExportParams("import/浣庡�兼槗鑰楀搧鐩樼偣琛�.xls");
+        params.setHeadingStartRow(2);
+
+        Optional<InventoryExcelTemplate> first = exportList.stream().findFirst();
+        InventoryExcelTemplate inventoryExcelTemplate = first.get();
+        Long createTime = inventoryExcelTemplate.getCreateTime();
+        String operatorName = inventoryExcelTemplate.getOperatorName();
+        String monitorName = inventoryExcelTemplate.getMonitorName();
+        Long endTime = inventoryExcelTemplate.getEndTime();
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("date", DateUtils.toShowDate(createTime));
+        map.put("endDate", DateUtils.toShowDate(endTime));
+        map.put("monitorName", monitorName);
+        map.put("name", operatorName);
+        Workbook workbook = ExcelExportUtil.exportExcel(params, InventoryExcelTemplate.class, exportList, map);
+        String filePath = downLoadExcel("浣庡�兼槗鑰楀搧鐩樼偣琛�", workbook);
+        return ResponseValue.success("瀵煎嚭鎴愬姛", filePath);
+    }
 
 }
-

--
Gitblit v1.9.1