Browse Source

优化多选单个标签打印报错;优化多个资产盘点报表excel表

LinWuTai 10 months ago
parent
commit
25a7e0a260

+ 93 - 4
ruoyi-admin/src/main/java/com/ruoyi/inventory/controller/TbInventoryDetailController.java

@@ -15,6 +15,8 @@ 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.dto.AssetInventoryStatement2;
+import com.ruoyi.inventory.domain.dto.AssetInventoryStatementDetail;
 import com.ruoyi.inventory.domain.dto.InventoryCompareDTO;
 import com.ruoyi.inventory.domain.enums.InventoryPlanResult;
 import com.ruoyi.inventory.domain.enums.InventoryResult;
@@ -153,17 +155,17 @@ public class TbInventoryDetailController extends BaseController
     public void exportDetail(HttpServletResponse response, TbAssetInventory tbAssetInventory)
     {
         List<TbAssetInventory> tbAssetInventoryList = inventoryService.selectTbAssetInventoryList(tbAssetInventory);
-        List<AssetInventoryStatement> assetInventoryStatements = new ArrayList<>();
+        List<AssetInventoryStatement2> assetInventoryStatements = new ArrayList<>();
 
         for (TbAssetInventory assetInventory : tbAssetInventoryList) {
             String orderNumber = assetInventory.getOrderNumber();
 
             List<TbInventoryDetail> tbInventoryDetails = tbInventoryDetailService.selectTbInventoryDetailByOrderNumber(orderNumber);
-            List<AssetInventoryStatement> assetInventoryStatementList = getInventoryStatement(assetInventory, tbInventoryDetails);
-            assetInventoryStatements.addAll(assetInventoryStatementList);
+            AssetInventoryStatement2 assetInventoryStatement = getInventoryStatement2(assetInventory, tbInventoryDetails);
+            assetInventoryStatements.add(assetInventoryStatement);
         }
 
-        ExcelUtil<AssetInventoryStatement> util = new ExcelUtil<>(AssetInventoryStatement.class);
+        ExcelUtil<AssetInventoryStatement2> util = new ExcelUtil<>(AssetInventoryStatement2.class);
 
         util.exportExcel(response, assetInventoryStatements, "资产盘点报表");
     }
@@ -318,6 +320,93 @@ public class TbInventoryDetailController extends BaseController
         return assetInventoryStatements;
     }
 
+    private AssetInventoryStatement2 getInventoryStatement2(TbAssetInventory tbAssetInventory, List<TbInventoryDetail> list) {
+        AssetInventoryStatement2 assetInventoryStatement = new AssetInventoryStatement2();
+
+        // 设置盘点编码
+        assetInventoryStatement.setOrderNumber(tbAssetInventory.getOrderNumber());
+
+        // 设置计划名称
+        assetInventoryStatement.setOrderName(tbAssetInventory.getName());
+
+        // 设置盘点部门
+        assetInventoryStatement.setInventoryDepartmentName(tbAssetInventory.getInventoryDepartmentName());
+
+        // 设置盘点位置
+        assetInventoryStatement.setInventoryLocation(tbAssetInventory.getInventoryLocationName());
+
+        // 设置盘点时间
+        assetInventoryStatement.setInventoryDate(tbAssetInventory.getInventoryDate());
+
+        // 设置盘点计划结果
+        Integer inventoryPlanResult = tbAssetInventory.getInventoryResult();
+        String inventoryPlanResultName = InventoryPlanResult.getName(inventoryPlanResult);
+        assetInventoryStatement.setInventoryPlanResult(inventoryPlanResultName);
+
+        List<AssetInventoryStatementDetail> assetInventoryStatementDetailList = new ArrayList<>();
+
+        for (TbInventoryDetail inventoryDetail : list) {
+            AssetInventoryStatementDetail assetInventoryStatementDetail = new AssetInventoryStatementDetail();
+
+            // 解析资产信息
+            TbAssetInformation assetInformation = JSONUtil.toBean(inventoryDetail.getInventoryMetadata(), TbAssetInformation.class);
+
+            // 设置资产编码
+            assetInventoryStatementDetail.setAssetNumber(assetInformation.getNumber());
+
+            // 设置资产名称
+            assetInventoryStatementDetail.setAssetName(assetInformation.getName());
+
+            // 设置所在位置
+//            String ancestorLocationName = assetInformation.getAncestorLocationName();
+//            if (StrUtil.isBlank(ancestorLocationName)) {
+//                ancestorLocationName = "";
+//            }
+//            String parentLocationName = assetInformation.getParentLocationName();
+//            if (StrUtil.isBlank(parentLocationName)) {
+//                parentLocationName = "";
+//            }
+            String locationName = assetInformation.getLocationName();
+//            assetInventoryStatement.setAssetLocation(ancestorLocationName + parentLocationName + locationName);
+            assetInventoryStatementDetail.setAssetLocation(locationName);
+
+            // 设置资产分类
+            String categoryName = assetInformation.getCategoryName();
+            assetInventoryStatementDetail.setAssetCategory(categoryName);
+
+            // 设置盘点状态
+            Integer inventoryStatus = inventoryDetail.getInventoryStatus();
+            String inventoryStatusName = InventoryStatus.getName(inventoryStatus);
+            assetInventoryStatementDetail.setInventoryStatus(inventoryStatusName);
+
+            // 设置资产数量
+            assetInventoryStatementDetail.setQuantity(assetInformation.getQuantity());
+
+            // 设置盘点数量
+            assetInventoryStatementDetail.setInventoryQuantity(inventoryDetail.getInventoryQuantity());
+
+            // 设置计量单位
+            assetInventoryStatementDetail.setUnits(assetInformation.getUnits());
+
+            // 设置盘点结果
+            Integer inventoryResult = inventoryDetail.getInventoryResult();
+            String inventoryResultName = InventoryResult.getName(inventoryResult);
+            assetInventoryStatementDetail.setInventoryResult(inventoryResultName);
+
+            // 设置资产原值
+            assetInventoryStatementDetail.setOriginalValue(assetInformation.getOriginalValue());
+
+            // 设置备注
+            assetInventoryStatementDetail.setRemark(inventoryDetail.getRemark());
+
+            assetInventoryStatementDetailList.add(assetInventoryStatementDetail);
+        }
+
+        assetInventoryStatement.setAssetInventoryStatementDetailList(assetInventoryStatementDetailList);
+
+        return assetInventoryStatement;
+    }
+
     /**
      * 获取资产盘点明细详细信息
      */

+ 43 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/AssetInventoryStatement2.java

@@ -0,0 +1,43 @@
+package com.ruoyi.inventory.domain.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.common.annotation.Excel;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 资产盘点报表
+ *
+ * @author 原动力林武泰
+ * @date 2023年12月27日
+ */
+@Data
+public class AssetInventoryStatement2 {
+    @Excel(name = "计划编码")
+    private String orderNumber;
+
+    @Excel(name = "计划名称")
+    private String orderName;
+
+    /** 盘点日期 */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    @Excel(name = "盘点日期", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date inventoryDate;
+
+    /** 盘点位置 */
+    @Excel(name = "盘点位置")
+    private String inventoryLocation;
+
+    /** 盘点部门 */
+    @Excel(name = "盘点部门")
+    private String inventoryDepartmentName;
+
+    /** 盘点部门 */
+    @Excel(name = "盘点计划结果")
+    private String inventoryPlanResult;
+
+    @Excel(name = "盘点计划详细")
+    private List<AssetInventoryStatementDetail> assetInventoryStatementDetailList;
+}

+ 50 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/AssetInventoryStatementDetail.java

@@ -0,0 +1,50 @@
+package com.ruoyi.inventory.domain.dto;
+
+import com.ruoyi.common.annotation.Excel;
+import lombok.Data;
+
+@Data
+public class AssetInventoryStatementDetail {
+    /** 资产编码 */
+    @Excel(name = "资产编码")
+    private String assetNumber;
+
+    /** 资产名称 */
+    @Excel(name = "资产名称", width = 24)
+    private String assetName;
+
+    /** 所在位置 */
+    @Excel(name = "所在位置", width = 30)
+    private String assetLocation;
+
+    /** 资产分类 */
+    @Excel(name = "资产分类")
+    private String assetCategory;
+
+    /** 盘点状态 */
+    @Excel(name = "盘点状态")
+    private String inventoryStatus;
+
+    /** 资产数量 */
+    @Excel(name = "账面数量")
+    private Integer quantity;
+
+    /** 盘点数量 */
+    @Excel(name = "实盘数量")
+    private Integer inventoryQuantity;
+
+    /** 计量单位 */
+    @Excel(name = "计量单位")
+    private String units;
+
+    /** 盘点结果 */
+    @Excel(name = "盘点结果")
+    private String inventoryResult;
+
+    /**原值*/
+    private Double originalValue;
+
+    /** 备注 */
+    @Excel(name = "备注")
+    private String remark;
+}

+ 36 - 32
ruoyi-admin/src/main/java/com/ruoyi/inventory/service/impl/TbAssetInventoryServiceImpl.java

@@ -313,45 +313,49 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
         }
 
         // 意外盘点资产EPC
-        Set<String> unCountEpcSet = new HashSet<>();
-        for (String epc : epcSet) {
-            String unCountEpc = TbAssetInformation.encodeChildEpc2Epc(epc);
-            // 存入未盘点资产epc中
-            unCountEpcSet.add(unCountEpc);
-        }
+        if (!epcSet.isEmpty()) {
+            Set<String> unCountEpcSet = new HashSet<>();
 
-        // 根据意外资产epc获取资产信息
-        List<TbAssetInformation> tbAssetInformationList = informationMapper.selectTbAssetInformationByEpcList(unCountEpcSet);
-        for (TbAssetInformation tbAssetInformation : tbAssetInformationList) { // 盘点异常
-            // 盘点意外的资产信息
-            TbInventoryDetail tbInventoryDetail = TbInventoryDetail.errCounted(orderNumber, tbAssetInformation);
+            for (String epc : epcSet) {
+                String unCountEpc = TbAssetInformation.encodeChildEpc2Epc(epc);
+                // 存入未盘点资产epc中
+                unCountEpcSet.add(unCountEpc);
+            }
 
-            Integer assetQuantity = tbAssetInformation.getQuantity();
+            // 根据意外资产epc获取资产信息
+            List<TbAssetInformation> tbAssetInformationList = informationMapper.selectTbAssetInformationByEpcList(unCountEpcSet);
 
-            // 实际盘点数量统计
-            int inventoryQuantity;
+            for (TbAssetInformation tbAssetInformation : tbAssetInformationList) { // 盘点异常
+                // 盘点意外的资产信息
+                TbInventoryDetail tbInventoryDetail = TbInventoryDetail.errCounted(orderNumber, tbAssetInformation);
 
-            // 获取该资产的所有epc
-            Set<String> assetEpcSet = epcSet
-                    .stream()
-                    .filter(epc -> TbAssetInformation.encodeChildEpc2Epc(epc).equals(tbAssetInformation.getEpc()))
-                    .collect(Collectors.toSet());
+                Integer assetQuantity = tbAssetInformation.getQuantity();
 
-            inventoryQuantity = assetEpcSet.size();
-            // 删除已盘点epc
-            epcSet.removeAll(assetEpcSet);
+                // 实际盘点数量统计
+                int inventoryQuantity;
 
-            // 设置盘点数量
-            tbInventoryDetail.setInventoryQuantity(inventoryQuantity);
-            if (inventoryQuantity > assetQuantity) { // 盘盈: 实际盘点数量 大于 资产账面数量
-                tbInventoryDetail.setInventoryResult(INVENTORY_PROFIT.getCode());
-            } else if (inventoryQuantity == assetQuantity) { // 正常: 实际盘点数量 等于 资产账面数量
-                tbInventoryDetail.setInventoryResult(INVENTORY_NORMAL.getCode());
-            } else {  // 盘亏: 实际盘点数量 小于 资产账面数量
-                tbInventoryDetail.setInventoryResult(INVENTORY_SHORTAGES.getCode());
-            }
+                // 获取该资产的所有epc
+                Set<String> assetEpcSet = epcSet
+                        .stream()
+                        .filter(epc -> TbAssetInformation.encodeChildEpc2Epc(epc).equals(tbAssetInformation.getEpc()))
+                        .collect(Collectors.toSet());
 
-            tbInventoryDetailMapper.insertTbInventoryDetail(tbInventoryDetail);
+                inventoryQuantity = assetEpcSet.size();
+                // 删除已盘点epc
+                epcSet.removeAll(assetEpcSet);
+
+                // 设置盘点数量
+                tbInventoryDetail.setInventoryQuantity(inventoryQuantity);
+                if (inventoryQuantity > assetQuantity) { // 盘盈: 实际盘点数量 大于 资产账面数量
+                    tbInventoryDetail.setInventoryResult(INVENTORY_PROFIT.getCode());
+                } else if (inventoryQuantity == assetQuantity) { // 正常: 实际盘点数量 等于 资产账面数量
+                    tbInventoryDetail.setInventoryResult(INVENTORY_NORMAL.getCode());
+                } else {  // 盘亏: 实际盘点数量 小于 资产账面数量
+                    tbInventoryDetail.setInventoryResult(INVENTORY_SHORTAGES.getCode());
+                }
+
+                tbInventoryDetailMapper.insertTbInventoryDetail(tbInventoryDetail);
+            }
         }
 
         // 设置盘点状态:盘点完毕