Преглед изворни кода

优化查询和导出盘点资产对比分析报表接口

“study” пре 1 година
родитељ
комит
2d36ed2da7

+ 18 - 18
ruoyi-admin/src/main/java/com/ruoyi/inventory/controller/TbAssetInventoryController.java

@@ -171,22 +171,22 @@ public class TbAssetInventoryController extends BaseController
         QRCodeUtils.createCodeToOutputStream(qrDTO, response.getOutputStream());
     }
 
-    /**
-     * 查询部门资产报表(两次盘点间的资产损耗)
-     * @param depId 部门ID
-     * @return
-     */
-//    我粘贴过来的 @PreAuthorize("@ss.hasPermi('inventory:inventory:query')")
-    @GetMapping("/getDepAssetLossTb")
-    public AjaxResult getDepAssetLossTb(String depId){
-        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
-        return success(results);
-    }
-
-    @PostMapping("/exportDepAssetLossTb/{deptId}")
-    public void exportDepAssetLossTb(HttpServletResponse response, @PathVariable("deptId") String depId){
-        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
-        ExcelUtil<DepAssetLossResultDto> util = new ExcelUtil<DepAssetLossResultDto>(DepAssetLossResultDto.class);
-        util.exportExcel(response, results, "近两次资产盘点损耗统计");
-    }
+//    /**
+//     * 查询部门资产报表(两次盘点间的资产损耗)
+//     * @param depId 部门ID
+//     * @return
+//     */
+////    我粘贴过来的 @PreAuthorize("@ss.hasPermi('inventory:inventory:query')")
+//    @GetMapping("/getDepAssetLossTb")
+//    public AjaxResult getDepAssetLossTb(String depId){
+//        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
+//        return success(results);
+//    }
+//
+//    @PostMapping("/exportDepAssetLossTb/{deptId}")
+//    public void exportDepAssetLossTb(HttpServletResponse response, @PathVariable("deptId") String depId){
+//        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
+//        ExcelUtil<DepAssetLossResultDto> util = new ExcelUtil<DepAssetLossResultDto>(DepAssetLossResultDto.class);
+//        util.exportExcel(response, results, "近两次资产盘点损耗统计");
+//    }
 }

+ 85 - 48
ruoyi-admin/src/main/java/com/ruoyi/inventory/controller/TbInventoryDetailController.java

@@ -13,6 +13,7 @@ import cn.hutool.json.JSONUtil;
 import com.ruoyi.asset.domain.TbAssetInformation;
 import com.ruoyi.inventory.domain.TbAssetInventory;
 import com.ruoyi.inventory.domain.TbInventoryCompare;
+import com.ruoyi.inventory.domain.TbInventoryCompareResult;
 import com.ruoyi.inventory.domain.dto.AssetInventoryStatement;
 import com.ruoyi.inventory.domain.enums.InventoryResult;
 import com.ruoyi.inventory.domain.enums.InventoryStatus;
@@ -20,14 +21,7 @@ import com.ruoyi.inventory.mapper.TbAssetInventoryMapper;
 import com.ruoyi.inventory.mapper.TbInventoryDetailMapper;
 import org.springframework.security.access.prepost.PreAuthorize;
 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.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -66,16 +60,19 @@ public class TbInventoryDetailController extends BaseController
     private TbInventoryDetailMapper tbInventoryDetailMapper;
 
     /**
-     * 查询全单位资产对比分析报表
+     * 查询全单位或者部门的资产对比分析报表
      * @return
      */
     @PreAuthorize("@ss.hasPermi('inventory:compare:list')")
-    @GetMapping("/compareList")
-    public TableDataInfo compareList(){
+    @GetMapping("/getDepAssetLossTb")
+    public TableDataInfo compareList(@RequestParam(required = false) String deptId){
         startPage();
-        List<TbAssetInventory> tbAssetInventoryList = tbInventoryDetailService.selectTbInventoryCompareList();
+        TbInventoryCompareResult tbInventoryCompareResult = new TbInventoryCompareResult();
+        List<TbInventoryCompareResult> tbInventoryCompareResultList = new ArrayList<>();
+
+        List<TbAssetInventory> tbAssetInventoryList = tbInventoryDetailService.selectTbInventoryCompareList(deptId);
         if(tbAssetInventoryList.size() == 0){
-            throw new RuntimeException("该组织不存在盘点完毕的盘点");
+            throw new RuntimeException("该组织不存在盘点完毕的盘点或者该部门不存在盘点完毕的盘点");
         }
         if(tbAssetInventoryList.size() == 1){
             throw new RuntimeException("该组织只存在一个盘点,不能进行盘点间类别数量损耗对比");
@@ -88,17 +85,37 @@ public class TbInventoryDetailController extends BaseController
         }
         List<TbInventoryDetail> tbInventoryDetailList1 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
         List<AssetInventoryStatement> inventoryStatement1 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList1);
+        List<TbInventoryCompare> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1);
+        double total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult.setAssetResultList(tbInventoryCompareList);
+        tbInventoryCompareResult.setInventoryDepartment(tbAssetInventoryList.get(0).getInventoryDepartmentName());
+        tbInventoryCompareResult.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult);
 
         //最近一次的上一次盘点
+        TbInventoryCompareResult tbInventoryCompareResult2 = new TbInventoryCompareResult();
         orderNumber = tbAssetInventoryList.get(1).getOrderNumber();
         if (StrUtil.isBlank(orderNumber)) {
             throw new RuntimeException("盘点计划编码不能为空");
         }
         List<TbInventoryDetail> tbInventoryDetailList2 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
         List<AssetInventoryStatement> inventoryStatement2 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList2);
+        List<TbInventoryCompare> tbInventoryCompareList2 = getTbInventoryCompareList(inventoryStatement2);
+        total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList2) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult2.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult2.setAssetResultList(tbInventoryCompareList2);
+        tbInventoryCompareResult2.setInventoryDepartment(tbAssetInventoryList.get(1).getInventoryDepartmentName());
+        tbInventoryCompareResult2.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult2);
 
-        List<TbInventoryCompare> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1, inventoryStatement2);
-        return getDataTable(tbInventoryCompareList);
+        return getDataTable(tbInventoryCompareResultList);
     }
 
     @Autowired
@@ -152,16 +169,19 @@ public class TbInventoryDetailController extends BaseController
     }
 
     /**
-     * 导出全单位资产对比分析报表
+     * 导出全单位或者部门的资产对比分析报表
      * @param response
      */
     @PreAuthorize("@ss.hasPermi('inventory:compare:export')")
     @Log(title = "全单位资产对比分析报表", businessType = BusinessType.EXPORT)
-    @PostMapping("/export/compare")
-    public void exportCompare(HttpServletResponse response){
-        List<TbAssetInventory> tbAssetInventoryList = tbInventoryDetailService.selectTbInventoryCompareList();
+    @PostMapping("/exportDepAssetLossTb")
+    public void exportCompare(HttpServletResponse response,@RequestParam(required = false) String deptId){
+        TbInventoryCompareResult tbInventoryCompareResult = new TbInventoryCompareResult();
+        List<TbInventoryCompareResult> tbInventoryCompareResultList = new ArrayList<>();
+
+        List<TbAssetInventory> tbAssetInventoryList = tbInventoryDetailService.selectTbInventoryCompareList(deptId);
         if(tbAssetInventoryList.size() == 0){
-            throw new RuntimeException("该组织不存在盘点完毕的盘点");
+            throw new RuntimeException("该组织不存在盘点完毕的盘点或者该部门不参在盘点完毕的盘点");
         }
         if(tbAssetInventoryList.size() == 1){
             throw new RuntimeException("该组织只存在一个盘点,不能进行盘点间类别数量损耗对比");
@@ -174,20 +194,39 @@ public class TbInventoryDetailController extends BaseController
         }
         List<TbInventoryDetail> tbInventoryDetailList1 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
         List<AssetInventoryStatement> inventoryStatement1 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList1);
+        List<TbInventoryCompare> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1);
+        double total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult.setAssetResultList(tbInventoryCompareList);
+        tbInventoryCompareResult.setInventoryDepartment(tbAssetInventoryList.get(0).getInventoryDepartmentName());
+        tbInventoryCompareResult.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult);
 
         //最近一次的上一次盘点
+        TbInventoryCompareResult tbInventoryCompareResult2 = new TbInventoryCompareResult();
         orderNumber = tbAssetInventoryList.get(1).getOrderNumber();
         if (StrUtil.isBlank(orderNumber)) {
             throw new RuntimeException("盘点计划编码不能为空");
         }
         List<TbInventoryDetail> tbInventoryDetailList2 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
         List<AssetInventoryStatement> inventoryStatement2 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList2);
+        List<TbInventoryCompare> tbInventoryCompareList2 = getTbInventoryCompareList(inventoryStatement2);
+        total = 0.0;
+        for (TbInventoryCompare tbInventoryCompare : tbInventoryCompareList2) {
+            total = tbInventoryCompare.getLossVal()+total;
+        }
+        tbInventoryCompareResult2.setDate(tbAssetInventoryList.get(0).getInventoryDate());
+        tbInventoryCompareResult2.setAssetResultList(tbInventoryCompareList2);
+        tbInventoryCompareResult2.setInventoryDepartment(tbAssetInventoryList.get(1).getInventoryDepartmentName());
+        tbInventoryCompareResult2.setLossTotal(total);
+        tbInventoryCompareResultList.add(tbInventoryCompareResult2);
 
-        List<TbInventoryCompare> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1, inventoryStatement2);
-
-        ExcelUtil<TbInventoryCompare> util = new ExcelUtil<>(TbInventoryCompare.class);
+        ExcelUtil<TbInventoryCompareResult> util = new ExcelUtil<>(TbInventoryCompareResult.class);
 
-        util.exportExcel(response, tbInventoryCompareList , "全单位资产对比分析报表");
+        util.exportExcel(response, tbInventoryCompareResultList , "资产对比分析报表");
     }
 
     /**
@@ -261,6 +300,9 @@ public class TbInventoryDetailController extends BaseController
             // 设置盘点时间
             assetInventoryStatement.setInventoryDate(tbAssetInventory.getInventoryDate());
 
+            // 设置资产原值
+            assetInventoryStatement.setOriginalValue(assetInformation.getOriginalValue());
+
             // 设置备注
             assetInventoryStatement.setRemark(inventoryDetail.getRemark());
 
@@ -315,39 +357,34 @@ public class TbInventoryDetailController extends BaseController
 
     /**
      * 获取全单位资产对比分析报表
-     * @param inventoryStatement1
-     * @param inventoryStatement2
+     * @param inventoryStatementList
      * @return
      */
     private List<TbInventoryCompare> getTbInventoryCompareList
-            (List<AssetInventoryStatement> inventoryStatement1,List<AssetInventoryStatement> inventoryStatement2){
+            (List<AssetInventoryStatement> inventoryStatementList){
         List<TbInventoryCompare> tbInventoryCompareList = new ArrayList<>();
 
-        for (AssetInventoryStatement assetInventoryStatement : inventoryStatement1) {
+        for (AssetInventoryStatement assetInventoryStatement : inventoryStatementList) {
             String inventoryStatus = assetInventoryStatement.getInventoryStatus();
-            String assetName = assetInventoryStatement.getAssetName();
-            String inventoryLocation = assetInventoryStatement.getAssetLocation();
             if(inventoryStatus.equals("已盘点")) {
                 TbInventoryCompare tbInventoryCompare = new TbInventoryCompare();
-                for (AssetInventoryStatement inventoryStatement : inventoryStatement2) {
-                    if (!inventoryStatement.getInventoryStatus().equals("已盘点")) {
-                        break;
-                    }
-                    String assetName2 = assetInventoryStatement.getAssetName();
-                    String inventoryLocation2 = assetInventoryStatement.getAssetLocation();
-                    if (assetName2.equals(assetName) && inventoryLocation2.equals(inventoryLocation)) {
-                        Integer inventoryQuantity1 = assetInventoryStatement.getInventoryQuantity();
-                        Integer inventoryQuantity2 = inventoryStatement.getInventoryQuantity();
-                        tbInventoryCompare.setInventoryName(assetName);
-                        tbInventoryCompare.setInventoryLocationName(inventoryLocation);
-                        tbInventoryCompare.setFirstInventoryNumber(inventoryQuantity1);
-                        tbInventoryCompare.setSecondInventoryNumber(inventoryQuantity2);
-                        tbInventoryCompare.setLossNumber(inventoryQuantity1 - inventoryQuantity2);
-                        tbInventoryCompare.setUnits(inventoryStatement.getUnits());
-                        tbInventoryCompare.setInventoryDate(inventoryStatement.getInventoryDate());
-                        break;
-                    }
+                String assetName = assetInventoryStatement.getAssetName();
+                String inventoryLocation = assetInventoryStatement.getAssetLocation();
+                Integer quantity = assetInventoryStatement.getQuantity();
+                Integer inventoryQuantity = assetInventoryStatement.getInventoryQuantity();
+                tbInventoryCompare.setInventoryName(assetName);
+                tbInventoryCompare.setInventoryLocationName(inventoryLocation);
+                tbInventoryCompare.setExpectInventoryNumber(quantity);
+                tbInventoryCompare.setRealityInventoryNumber(inventoryQuantity);
+                if(quantity>inventoryQuantity){
+                    tbInventoryCompare.setLossNumber(quantity - inventoryQuantity);
+                    tbInventoryCompare.setLossVal(assetInventoryStatement.getOriginalValue()*(quantity - inventoryQuantity));
+
+                }else {
+                    tbInventoryCompare.setLossNumber(0);
+                    tbInventoryCompare.setLossVal(0.0);
                 }
+                tbInventoryCompare.setUnits(assetInventoryStatement.getUnits());
                 tbInventoryCompareList.add(tbInventoryCompare);
             }
         }

+ 9 - 9
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/TbInventoryCompare.java

@@ -16,17 +16,17 @@ import java.util.Date;
 @NoArgsConstructor
 @Builder
 public class TbInventoryCompare extends BaseEntity {
-    @Excel(name = "盘点物品名称")
+    @Excel(name = "资产名称")
     private String inventoryName;
 
-    @Excel(name = "盘点位置")
+    @Excel(name = "资产位置")
     private String inventoryLocationName;
 
-    @Excel(name = "最近盘点的资产数量")
-    private Integer firstInventoryNumber;
+    @Excel(name = "账面资产数量")
+    private Integer expectInventoryNumber;
 
-    @Excel(name = "最近盘点前一次盘点的资产数量")
-    private Integer secondInventoryNumber;
+    @Excel(name = "实点资产数量")
+    private Integer realityInventoryNumber;
 
     @Excel(name = "数量损耗")
     private Integer lossNumber;
@@ -35,8 +35,8 @@ public class TbInventoryCompare extends BaseEntity {
     @Excel(name = "计量单位")
     private String units;
 
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "最近的盘点日期", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date inventoryDate;
+    @Excel(name = "资产损耗金额")
+    private Double lossVal;
+
 
 }

+ 3 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/AssetInventoryStatement.java

@@ -69,6 +69,9 @@ public class AssetInventoryStatement {
     @Excel(name = "盘点部门")
     private String inventoryDepartmentName;
 
+    /**原值*/
+    private Double originalValue;
+
     /** 备注 */
     @Excel(name = "备注")
     private String remark;

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/inventory/mapper/TbAssetInventoryMapper.java

@@ -40,7 +40,7 @@ public interface TbAssetInventoryMapper
      * 查询全单位盘点资产对比分析列表
      * @return
      */
-    public List<TbAssetInventory> selectTbAssetInventoryListBy();
+    public List<TbAssetInventory> selectTbAssetInventoryListBy(String deptId);
     /**
      * 新增资产盘点记录
      *

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/inventory/service/ITbInventoryDetailService.java

@@ -37,7 +37,7 @@ public interface ITbInventoryDetailService
      * 查询全单位盘点资产对比分析列表
      * @return
      */
-    public List<TbAssetInventory> selectTbInventoryCompareList();
+    public List<TbAssetInventory> selectTbInventoryCompareList(String deptId);
     /**
      * 新增资产盘点明细
      * 

+ 2 - 2
ruoyi-admin/src/main/java/com/ruoyi/inventory/service/impl/TbInventoryDetailServiceImpl.java

@@ -58,8 +58,8 @@ public class TbInventoryDetailServiceImpl implements ITbInventoryDetailService
     }
 
     @Override
-    public List<TbAssetInventory> selectTbInventoryCompareList(){
-        return tbAssetInventoryMapper.selectTbAssetInventoryListBy();
+    public List<TbAssetInventory> selectTbInventoryCompareList(String deptId){
+        return tbAssetInventoryMapper.selectTbAssetInventoryListBy(deptId);
     }
 
 

+ 3 - 1
ruoyi-admin/src/main/resources/mapper/inventory/TbAssetInventoryMapper.xml

@@ -61,10 +61,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
-    <select id="selectTbAssetInventoryListBy" resultType="TbAssetInventory">
+    <select id="selectTbAssetInventoryListBy" parameterType="string" resultType="TbAssetInventory">
         <include refid="selectTbAssetInventory"/>
         where a.inventory_status = "2"
         and a.inventory_result != "0"
+        <if test="deptId != null  and  deptId != ''">and inventory_department = #{deptId}</if>
         order by a.updated_time DESC
     </select>
 
@@ -201,6 +202,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select order_number orderNumber,inventory_date inventDate
         from tb_asset_inventory
         where inventory_status = 2 and inventory_department = #{depId}
+        and inventory_result != "0"
         order by inventory_date desc
     </select>
     <!-- limit #{whichOne},1 -->