Quellcode durchsuchen

查询和导出全单位盘点资产对比分析报表接口

“study” vor 1 Jahr
Ursprung
Commit
e933779bf6

+ 121 - 2
ruoyi-admin/src/main/java/com/ruoyi/inventory/controller/TbInventoryDetailController.java

@@ -12,10 +12,12 @@ import cn.hutool.core.util.StrUtil;
 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.dto.AssetInventoryStatement;
 import com.ruoyi.inventory.domain.enums.InventoryResult;
 import com.ruoyi.inventory.domain.enums.InventoryStatus;
 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;
@@ -61,6 +63,45 @@ public class TbInventoryDetailController extends BaseController
     }
 
     @Autowired
+    private TbInventoryDetailMapper tbInventoryDetailMapper;
+
+    /**
+     * 查询全单位资产对比分析报表
+     * @return
+     */
+    @PreAuthorize("@ss.hasPermi('inventory:compare:list')")
+    @GetMapping("/compareList")
+    public TableDataInfo compareList(){
+        startPage();
+        List<TbAssetInventory> tbAssetInventoryList = tbInventoryDetailService.selectTbInventoryCompareList();
+        if(tbAssetInventoryList.size() == 0){
+            throw new RuntimeException("该组织不存在盘点完毕的盘点");
+        }
+        if(tbAssetInventoryList.size() == 1){
+            throw new RuntimeException("该组织只存在一个盘点,不能进行盘点间类别数量损耗对比");
+        }
+
+        //最近一次盘点
+        String orderNumber = tbAssetInventoryList.get(0).getOrderNumber();
+        if (StrUtil.isBlank(orderNumber)) {
+            throw new RuntimeException("盘点计划编码不能为空");
+        }
+        List<TbInventoryDetail> tbInventoryDetailList1 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
+        List<AssetInventoryStatement> inventoryStatement1 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList1);
+
+        //最近一次的上一次盘点
+        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> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1, inventoryStatement2);
+        return getDataTable(tbInventoryCompareList);
+    }
+
+    @Autowired
     private TbAssetInventoryMapper tbAssetInventoryMapper;
 
     /**
@@ -86,12 +127,11 @@ public class TbInventoryDetailController extends BaseController
 
         util.exportExcel(response, assetInventoryStatements, DateUtil.format(tbAssetInventory.getInventoryDate(), "yyyy年MM月dd日"), tbAssetInventory.getName());
     }
-
     /**
      * 导出资产盘点记录列表
      */
     @PreAuthorize("@ss.hasPermi('inventory:inventory:export')")
-    @Log(title = "资产盘点报表", businessType = BusinessType.EXPORT)
+    @Log(title = "全单位资产对比分析报表", businessType = BusinessType.EXPORT)
     @PostMapping("/export/detail")
     public void exportDetail(HttpServletResponse response, TbAssetInventory tbAssetInventory)
     {
@@ -112,6 +152,45 @@ 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();
+        if(tbAssetInventoryList.size() == 0){
+            throw new RuntimeException("该组织不存在盘点完毕的盘点");
+        }
+        if(tbAssetInventoryList.size() == 1){
+            throw new RuntimeException("该组织只存在一个盘点,不能进行盘点间类别数量损耗对比");
+        }
+
+        //最近一次盘点
+        String orderNumber = tbAssetInventoryList.get(0).getOrderNumber();
+        if (StrUtil.isBlank(orderNumber)) {
+            throw new RuntimeException("盘点计划编码不能为空");
+        }
+        List<TbInventoryDetail> tbInventoryDetailList1 = tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
+        List<AssetInventoryStatement> inventoryStatement1 = getInventoryStatement(tbAssetInventoryList.get(0), tbInventoryDetailList1);
+
+        //最近一次的上一次盘点
+        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> tbInventoryCompareList = getTbInventoryCompareList(inventoryStatement1, inventoryStatement2);
+
+        ExcelUtil<TbInventoryCompare> util = new ExcelUtil<>(TbInventoryCompare.class);
+
+        util.exportExcel(response, tbInventoryCompareList , "全单位资产对比分析报表");
+    }
+
+    /**
      * 获取盘点报表
      *
      * @param tbAssetInventory 盘点计划信息
@@ -234,4 +313,44 @@ public class TbInventoryDetailController extends BaseController
         return toAjax(tbInventoryDetailService.deleteTbInventoryDetailByIds(ids));
     }
 
+    /**
+     * 获取全单位资产对比分析报表
+     * @param inventoryStatement1
+     * @param inventoryStatement2
+     * @return
+     */
+    private List<TbInventoryCompare> getTbInventoryCompareList
+            (List<AssetInventoryStatement> inventoryStatement1,List<AssetInventoryStatement> inventoryStatement2){
+        List<TbInventoryCompare> tbInventoryCompareList = new ArrayList<>();
+
+        for (AssetInventoryStatement assetInventoryStatement : inventoryStatement1) {
+            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;
+                    }
+                }
+                tbInventoryCompareList.add(tbInventoryCompare);
+            }
+        }
+        return tbInventoryCompareList;
+    }
 }

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

@@ -0,0 +1,42 @@
+package com.ruoyi.inventory.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+
+import java.util.Date;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class TbInventoryCompare extends BaseEntity {
+    @Excel(name = "盘点物品名称")
+    private String inventoryName;
+
+    @Excel(name = "盘点位置")
+    private String inventoryLocationName;
+
+    @Excel(name = "最近盘点的资产数量")
+    private Integer firstInventoryNumber;
+
+    @Excel(name = "最近盘点前一次盘点的资产数量")
+    private Integer secondInventoryNumber;
+
+    @Excel(name = "数量损耗")
+    private Integer lossNumber;
+
+    /** 计量单位 */
+    @Excel(name = "计量单位")
+    private String units;
+
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "最近的盘点日期", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date inventoryDate;
+
+}

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

@@ -34,6 +34,11 @@ public interface TbAssetInventoryMapper
     public List<TbAssetInventory> selectTbAssetInventoryList(TbAssetInventory tbAssetInventory);
 
     /**
+     * 查询全单位盘点资产对比分析列表
+     * @return
+     */
+    public List<TbAssetInventory> selectTbAssetInventoryListBy();
+    /**
      * 新增资产盘点记录
      * 
      * @param tbAssetInventory 资产盘点记录

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

@@ -1,6 +1,9 @@
 package com.ruoyi.inventory.service;
 
 import java.util.List;
+
+import com.ruoyi.inventory.domain.TbAssetInventory;
+import com.ruoyi.inventory.domain.TbInventoryCompare;
 import com.ruoyi.inventory.domain.TbInventoryDetail;
 import com.ruoyi.inventory.domain.dto.AssetInventoryStatement;
 
@@ -31,6 +34,11 @@ public interface ITbInventoryDetailService
     public List<TbInventoryDetail> selectTbInventoryDetailList(TbInventoryDetail tbInventoryDetail);
 
     /**
+     * 查询全单位盘点资产对比分析列表
+     * @return
+     */
+    public List<TbAssetInventory> selectTbInventoryCompareList();
+    /**
      * 新增资产盘点明细
      * 
      * @param tbInventoryDetail 资产盘点明细

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

@@ -10,6 +10,7 @@ import com.ruoyi.asset.domain.TbAssetInformation;
 import com.ruoyi.asset.mapper.TbAssetInformationMapper;
 import com.ruoyi.asset.mapper.TbLocationMapper;
 import com.ruoyi.inventory.domain.TbAssetInventory;
+import com.ruoyi.inventory.domain.TbInventoryCompare;
 import com.ruoyi.inventory.mapper.TbAssetInventoryMapper;
 import com.ruoyi.utils.RecursionUtil;
 import org.apache.commons.collections.map.HashedMap;
@@ -56,6 +57,11 @@ public class TbInventoryDetailServiceImpl implements ITbInventoryDetailService
         return tbInventoryDetailMapper.selectTbInventoryDetailByOrderNumber(orderNumber);
     }
 
+    @Override
+    public List<TbAssetInventory> selectTbInventoryCompareList(){
+        return tbAssetInventoryMapper.selectTbAssetInventoryListBy();
+    }
+
 
     /**
      * 查询资产盘点明细列表

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

@@ -60,7 +60,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="recordStatus != null "> and a.record_status = #{recordStatus}</if>
         </where>
     </select>
-    
+
+    <select id="selectTbAssetInventoryListBy" resultType="TbAssetInventory">
+        <include refid="selectTbAssetInventory"/>
+        where a.inventory_status = "2"
+        and a.inventory_result != "0"
+        order by a.updated_time DESC
+    </select>
+
     <select id="selectTbAssetInventoryById" parameterType="Long" resultType="TbAssetInventory">
         <include refid="selectTbAssetInventory"/>
         where a.id = #{id}