소스 검색

部门资产报表-查询与导出(修订版)

asce 1 년 전
부모
커밋
955b62526e

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

@@ -179,8 +179,9 @@ public class TbAssetInventoryController extends BaseController
 //    我粘贴过来的 @PreAuthorize("@ss.hasPermi('inventory:inventory:query')")
     @GetMapping("/getDepAssetLossTb")
     public AjaxResult getDepAssetLossTb(String depId){
+        List<DepAssetLossResultDto> results = tbAssetInventoryService.inventoryDepAssetById(depId);
 
-        return success(tbAssetInventoryService.inventoryDepAssetById(depId));
+        return success(results);
     }
 
     @GetMapping("/exportDepAssetLossTb")

+ 16 - 0
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/AssetInvOrderDto.java

@@ -0,0 +1,16 @@
+package com.ruoyi.inventory.domain.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class AssetInvOrderDto {
+
+    private String orderNumber;
+    private String inventDate;
+}

+ 0 - 2
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/DepAssetLossDto.java

@@ -32,7 +32,5 @@ public class DepAssetLossDto  {
     /** 损耗值 */
     private double lossVal;
 
-    /** 最近一次盘点时间 */
-    private String time;
 
 }

+ 5 - 1
ruoyi-admin/src/main/java/com/ruoyi/inventory/domain/dto/DepAssetLossResultDto.java

@@ -17,10 +17,14 @@ public class DepAssetLossResultDto {
     private double totalLossVal;
 
     /**
+     * 盘点时间
+     */
+    private String date;
+
+    /**
      * 资产盘点结果集
      */
     private List<DepAssetLossDto> assetResultList;
 
 
-
 }

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

@@ -3,6 +3,7 @@ package com.ruoyi.inventory.mapper;
 import java.util.List;
 import com.ruoyi.inventory.domain.TbAssetInventory;
 import com.ruoyi.inventory.domain.TbInventoryDetail;
+import com.ruoyi.inventory.domain.dto.AssetInvOrderDto;
 import com.ruoyi.inventory.domain.dto.DepAssetLossDto;
 import com.ruoyi.inventory.domain.dto.TbAssetInventoryDTO;
 import org.apache.ibatis.annotations.Param;
@@ -75,7 +76,7 @@ public interface TbAssetInventoryMapper
      */
     public List<TbAssetInventoryDTO> selectTbAssetInventoryDTOList(TbAssetInventoryDTO dto);
 
-    public List<String> getDepAssetByOrderNumber(String orderNumber);
+    List<String> getDepAssetByOrderNumber(String orderNumber);
 
-    public String getOrderNumberByDepId(String depId, String whichOne);
+    List<AssetInvOrderDto> getOrderNumberByDepId(@Param("depId") String depId);
 }

+ 72 - 73
ruoyi-admin/src/main/java/com/ruoyi/inventory/service/impl/TbAssetInventoryServiceImpl.java

@@ -1,9 +1,11 @@
 package com.ruoyi.inventory.service.impl;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.ruoyi.asset.domain.TbAssetInformation;
@@ -11,10 +13,7 @@ import com.ruoyi.asset.domain.TbLocation;
 import com.ruoyi.asset.mapper.TbAssetInformationMapper;
 import com.ruoyi.asset.mapper.TbLocationMapper;
 import com.ruoyi.inventory.domain.TbInventoryDetail;
-import com.ruoyi.inventory.domain.dto.DepAssetLossDto;
-import com.ruoyi.inventory.domain.dto.DepAssetLossResultDto;
-import com.ruoyi.inventory.domain.dto.TakeStockDTO;
-import com.ruoyi.inventory.domain.dto.TbAssetInventoryDTO;
+import com.ruoyi.inventory.domain.dto.*;
 import com.ruoyi.inventory.mapper.TbInventoryDetailMapper;
 import com.ruoyi.utils.IDUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -481,77 +480,25 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
         但是,语法不支持,会报错:This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
         暂时选择以下方法解决,但要连接四次数据库,很可能需要优化
         */
-        //前前一次盘点计划编码
-        String old_num = tbAssetInventoryMapper.getOrderNumberByDepId(depId, "0");
-        //前一次盘点计划编码
-        String new_num = tbAssetInventoryMapper.getOrderNumberByDepId(depId, "1");
 
-        //前两次盘点资产详细信息-元数据
-        List<String> old_asset_list = tbAssetInventoryMapper.getDepAssetByOrderNumber(old_num);
-        List<String> new_asset_list = tbAssetInventoryMapper.getDepAssetByOrderNumber(new_num);
+        //历史盘点计划编码和日期
+        List<AssetInvOrderDto> invs = tbAssetInventoryMapper.getOrderNumberByDepId(depId);
+        //前前一次盘点计划编码和日期
+//        TbAssetInventoryDTO old_inv = tbAssetInventoryMapper.getOrderNumberByDepId(depId);
 
-        List<TbAssetInformation> old_assetInfos = new ArrayList<>();
-        List<TbAssetInformation> new_assetInfos = new ArrayList<>();
+        if (ObjectUtil.isEmpty(invs) || invs.size()==0) return null;
 
-        //json数据 --> java对象
-        for (String asset : old_asset_list) {
-            System.out.println(asset);
-            old_assetInfos.add(JSONUtil.toBean(asset, TbAssetInformation.class));
-        }
-        for (String asset : new_asset_list) {
-            System.out.println(asset);
-            new_assetInfos.add(JSONUtil.toBean(asset, TbAssetInformation.class));
-        }
-
-        Map<String, DepAssetLossDto> old_assetMap = new HashMap<>();
-        Map<String, DepAssetLossDto> new_assetMap = new HashMap<>();
-        //各资产损耗值map
-        HashMap<String, Double> old_lossValMap = new HashMap<>();
-        HashMap<String, Double> new_lossValMap = new HashMap<>();
-
-        //统计两次盘点计划每一样资产(同资产名)的相关信息
-        handleAssetInfo(old_assetInfos,old_assetMap,old_lossValMap);
-        handleAssetInfo(new_assetInfos,new_assetMap,new_lossValMap);
+        AssetInvOrderDto new_inv = invs.get(0);
+        System.out.println("new-盘点计划:"+new_inv);
+        AssetInvOrderDto old_inv = null;
+        if (invs.size()>1) old_inv = invs.get(1);
 
-        //将map中统计好的资产信息转到list
-        ArrayList<DepAssetLossDto> old_assetResultList = new ArrayList<>();
-        ArrayList<DepAssetLossDto> new_assetResultList = new ArrayList<>();
-
-        Set<Map.Entry<String, DepAssetLossDto>> old_entrySet = old_assetMap.entrySet();
-        Set<Map.Entry<String, DepAssetLossDto>> new_entrySet = new_assetMap.entrySet();
-        for (Map.Entry<String, DepAssetLossDto> entry : old_entrySet) {
-            DepAssetLossDto dto = entry.getValue();
-            dto.setLossVal(old_lossValMap.get(dto.getAssetName()));
-            old_assetResultList.add(dto);
+        DepAssetLossResultDto old_resultDto = null;
+        DepAssetLossResultDto new_resultDto = null;
+        if (new_inv!=null){
+            new_resultDto = lossResult(new_inv);
         }
-        for (Map.Entry<String, DepAssetLossDto> entry : new_entrySet) {
-            DepAssetLossDto dto = entry.getValue();
-            dto.setLossVal(new_lossValMap.get(dto.getAssetName()));
-            new_assetResultList.add(dto);
-        }
-
-        //计算损耗总值
-        Set<Map.Entry<String, Double>> oldLossValSet = old_lossValMap.entrySet();
-        Set<Map.Entry<String, Double>> newLossValSet = new_lossValMap.entrySet();
-        double oldLossVal = 0.0;
-        double newLossVal = 0.0;
-        for (Map.Entry<String, Double> entry : oldLossValSet) {
-            oldLossVal+=entry.getValue();
-        }
-        for (Map.Entry<String, Double> entry : newLossValSet) {
-            newLossVal+=entry.getValue();
-        }
-
-
-
-        //封装结果
-        DepAssetLossResultDto old_resultDto = new DepAssetLossResultDto();
-        old_resultDto.setTotalLossVal(oldLossVal);
-        old_resultDto.setAssetResultList(old_assetResultList);
-
-        DepAssetLossResultDto new_resultDto = new DepAssetLossResultDto();
-        new_resultDto.setTotalLossVal(newLossVal);
-        new_resultDto.setAssetResultList(new_assetResultList);
+        if (!ObjectUtil.isNull(old_inv)) old_resultDto = lossResult(old_inv);
 
         List<DepAssetLossResultDto> results = new ArrayList<>();
         results.add(old_resultDto);
@@ -559,7 +506,12 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
         return results;
     }
 
-
+    /**
+     * 处理资产信息,统计每一样资产的损耗情况
+     * @param assetInfos
+     * @param assetMap
+     * @param lossValMap
+     */
     private void handleAssetInfo(List<TbAssetInformation> assetInfos,
                                  Map<String, DepAssetLossDto> assetMap,
                                  Map<String, Double> lossValMap){
@@ -586,13 +538,60 @@ public class TbAssetInventoryServiceImpl implements ITbAssetInventoryService
                     lossDto.setLossQuantity(lossDto.getLossQuantity()+asset.getQuantity());
                     lossDto.getLocations()
                             .add(asset.getAncestorLocationName()+asset.getParentLocationName()+asset.getLocationName());
-                    lossValMap.put(asset.getName(),lossValMap.get(asset.getName())
-                            +(asset.getOriginalValue()-asset.getNetValue())*asset.getQuantity());
+                    lossValMap.put(asset.getName(),
+                                   Double.sum(lossValMap.get(asset.getName()),
+                                           (asset.getOriginalValue()-asset.getNetValue())*asset.getQuantity()));
                 }
             }
 
         }
     }
 
+    /**
+     * 根据盘点计划的编号查询出资产元数据,并统计损耗
+     * @param invPlan
+     * @return
+     */
+    private DepAssetLossResultDto lossResult(AssetInvOrderDto invPlan){
+
+        List<String> asset_list = tbAssetInventoryMapper.getDepAssetByOrderNumber(invPlan.getOrderNumber());
+        //盘点资产详细信息-元数据
+        List<TbAssetInformation> assetInfos = new ArrayList<>();
+        //json数据 --> java对象
+        for (String asset : asset_list) {
+            System.out.println(asset);
+            assetInfos.add(JSONUtil.toBean(asset, TbAssetInformation.class));
+        }
+
+        Map<String, DepAssetLossDto> assetMap = new HashMap<>();
+        //各资产损耗值map
+        HashMap<String, Double> lossValMap = new HashMap<>();
+        //统计两次盘点计划每一样资产(同资产名)的相关信息
+        handleAssetInfo(assetInfos,assetMap,lossValMap);
+        //将map中统计好的资产信息转到list
+        ArrayList<DepAssetLossDto> assetResultList = new ArrayList<>();
+        Set<Map.Entry<String, DepAssetLossDto>> entrySet = assetMap.entrySet();
+        for (Map.Entry<String, DepAssetLossDto> entry : entrySet) {
+            DepAssetLossDto dto = entry.getValue();
+            if (lossValMap.containsKey(dto.getAssetName()))dto.setLossVal(lossValMap.get(dto.getAssetName()));
+            assetResultList.add(dto);
+        }
+        //计算损耗总值
+        Set<Map.Entry<String, Double>> lossValSet = lossValMap.entrySet();
+        double lossVal = 0.0;
+        for (Map.Entry<String, Double> entry : lossValSet) {
+            lossVal+=entry.getValue();
+        }
+
+//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        //封装结果
+        DepAssetLossResultDto resultDto = new DepAssetLossResultDto();
+        resultDto.setTotalLossVal(lossVal);
+        resultDto.setAssetResultList(assetResultList);
+        resultDto.setDate(invPlan.getInventDate());
+
+        return resultDto;
+    }
+
 
 }

+ 7 - 7
ruoyi-admin/src/main/resources/application-druid.yml

@@ -8,16 +8,16 @@ spring:
             master:
 #                url: jdbc:mysql://139.9.50.163:3306/rfid_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
 #                password: ydl@123456
-                url: jdbc:mysql://127.0.0.1:3306/rfid-hotel-manager?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
-                password: mysql@123456
+                url: jdbc:mysql://139.9.50.163:3306/rfid_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+                password: ydl@123456
                 username: root
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭
                 enabled: false
-                url: 
-                username: 
-                password: 
+                url:
+                username:
+                password:
             # 初始连接数
             initialSize: 5
             # 最小连接池数量
@@ -41,7 +41,7 @@ spring:
             testWhileIdle: true
             testOnBorrow: false
             testOnReturn: false
-            webStatFilter: 
+            webStatFilter:
                 enabled: true
             statViewServlet:
                 enabled: true
@@ -60,4 +60,4 @@ spring:
                     merge-sql: true
                 wall:
                     config:
-                        multi-statement-allow: true
+                        multi-statement-allow: true

+ 6 - 6
ruoyi-admin/src/main/resources/application.yml

@@ -60,7 +60,7 @@ spring:
   messages:
     # 国际化资源文件路径
     basename: i18n/messages
-  profiles: 
+  profiles:
     active: druid
   # 文件上传
   servlet:
@@ -79,7 +79,7 @@ spring:
     # 地址
     host: 127.0.0.1
     # 密码
-    password: redis@123456
+    password:
     # 端口,默认为6379
     port: 6379
     # 数据库索引
@@ -105,7 +105,7 @@ token:
     secret: abcdefghijklmnopqrstuvwxyz
     # 令牌有效期(默认30分钟)
     expireTime: 30
-  
+
 # MyBatis配置
 mybatis:
     # 搜索指定包别名
@@ -116,10 +116,10 @@ mybatis:
     configLocation: classpath:mybatis/mybatis-config.xml
 
 # PageHelper分页插件
-pagehelper: 
+pagehelper:
   helperDialect: mysql
   supportMethodsArguments: true
-  params: count=countSql 
+  params: count=countSql
 
 # Swagger配置
 swagger:
@@ -129,7 +129,7 @@ swagger:
   pathMapping: /dev-api
 
 # 防止XSS攻击
-xss: 
+xss:
   # 过滤开关
   enabled: true
   # 排除链接(多个用逗号分隔)

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

@@ -190,12 +190,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where order_number = #{orderNumber}
     </select>
 
-    <select id="getOrderNumberByDepId" parameterType="String" resultType="String">
-        select order_number
+    <select id="getOrderNumberByDepId" parameterType="String" resultType="com.ruoyi.inventory.domain.dto.AssetInvOrderDto">
+        select order_number orderNumber,inventory_date inventDate
         from tb_asset_inventory
         where inventory_status = 2 and inventory_department = #{depId}
         order by inventory_date desc
-        limit #{whichOne},1
     </select>
-
+    <!-- limit #{whichOne},1 -->
 </mapper>