From 84b7d5223a5f5229866a7d5686d198cca4251453 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 26 九月 2025 15:23:25 +0800
Subject: [PATCH] 代码提交,查询部门下级递归

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AssetTypeServiceImpl.java |  109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AssetTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AssetTypeServiceImpl.java
index 786edc5..a9fb969 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AssetTypeServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AssetTypeServiceImpl.java
@@ -5,20 +5,31 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.basic.PageInfo;
+import com.ruoyi.common.core.domain.entity.TDept;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.system.dto.asset.AssetTypeDTO;
 import com.ruoyi.system.mapper.AssetTypeMapper;
 import com.ruoyi.system.model.AssetMain;
 import com.ruoyi.system.model.AssetType;
+import com.ruoyi.system.query.AssetStatisticsListDetailQuery;
+import com.ruoyi.system.query.AssetStatisticsListQuery;
 import com.ruoyi.system.service.AssetMainService;
 import com.ruoyi.system.service.AssetTypeService;
+import com.ruoyi.system.vo.AssetStatisticsDetailVO;
+import com.ruoyi.system.vo.AssetStatisticsVO;
 import com.ruoyi.system.vo.asset.AssetTypeTreeVO;
+import com.ruoyi.system.vo.system.NotificationVO;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +50,7 @@
 public class AssetTypeServiceImpl extends ServiceImpl<AssetTypeMapper, AssetType> implements AssetTypeService {
 
     private final AssetMainService assetMainService;
+    private final AssetTypeService assetTypeService;
 
     @Override
     public List<AssetTypeTreeVO> getAssetTypeTree() {
@@ -287,4 +299,101 @@
         return parentTypeCode + subTypeCode;
     }
 
+    @Override
+    public PageInfo<AssetStatisticsVO> pageList(AssetStatisticsListQuery query) {
+        if (StringUtils.hasLength(query.getNameOrCode())){
+            // 查询出资产名称或者资产编号符合条件的code
+            List<Integer> assetTypeIds = assetMainService.lambdaQuery().like(AssetMain::getAssetName, query.getNameOrCode())
+                    .or()
+                    .like(AssetMain::getAssetCode, query.getNameOrCode())
+                    .list()
+                    .stream()
+                    .map(AssetMain::getAssetTypeId)
+                    .collect(Collectors.toList());
+            query.setAssetTypeIds(assetTypeIds);
+            if (assetTypeIds.isEmpty()){
+                return new PageInfo<>();
+            }
+        }
+        PageInfo<AssetStatisticsVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
+        List<AssetStatisticsVO> list = this.baseMapper.pageList(query,pageInfo);
+        List<AssetStatisticsVO> listNoLimit = this.baseMapper.pageListNoLimit(query);
+        List<Integer> assetTypeIds = listNoLimit.stream().map(AssetStatisticsVO::getAssetTypeIdSecond).collect(Collectors.toList());
+        if (assetTypeIds.isEmpty()){
+            return new PageInfo<>();
+        }
+        Map<Integer, List<AssetMain>> assetMainMap = assetMainService.lambdaQuery()
+                .eq(AssetMain::getOwnershipDeptId, query.getDeptId())
+                .in(AssetMain::getAssetTypeId, assetTypeIds).list()
+                .stream()
+                .collect(Collectors.groupingBy(AssetMain::getAssetTypeId));
+        for (AssetStatisticsVO asset : list) {
+            Integer totalCount= 0;
+            Integer idleCount= 0;
+            Integer useCount= 0;
+            Integer disposeCount= 0;
+            Integer otherCount= 0;
+            BigDecimal totalValue = new BigDecimal("0");
+            List<AssetMain> assetMains = assetMainMap.get(asset.getAssetTypeIdSecond());
+            if (!assetMains.isEmpty()){
+                for (AssetMain assetMain : assetMains) {
+                    if (assetMain.getAssetStatus().contains("闲置")){
+                        idleCount += assetMain.getQuantity();
+                    }else if (assetMain.getAssetStatus().contains("使用中")){
+                        useCount += assetMain.getQuantity();
+                    }else if (assetMain.getAssetStatus().contains("损坏") || assetMain.getAssetStatus().contains("报废")){
+                        disposeCount += assetMain.getQuantity();
+                    }else{
+                        otherCount += assetMain.getQuantity();
+                    }
+                    totalCount+= assetMain.getQuantity();
+                    totalValue = totalValue.add(new BigDecimal(assetMain.getQuantity())
+                            .multiply(assetMain.getUnitPrice()).setScale(2, RoundingMode.HALF_DOWN));
+                }
+            }
+            asset.setIdleCount(idleCount);
+            asset.setUseCount(useCount);
+            asset.setDisposeCount(disposeCount);
+            asset.setOtherCount(otherCount);
+            asset.setTotalCount(totalCount);
+            asset.setTotalValue(totalValue);
+        }
+        pageInfo.setRecords(list);
+        return pageInfo;
+    }
+
+    @Override
+    public PageInfo<AssetStatisticsDetailVO> pageListDetail(AssetStatisticsListDetailQuery query) {
+        String assetTypeName = null;
+        AssetType assetType = assetTypeService.getById(query.getAssetTypeIdSecond());
+        if (assetType!=null){
+            AssetType assetTypeParent = assetTypeService.getById(assetType.getParentId());
+            if (assetTypeParent!=null){
+                assetTypeName = assetTypeParent.getTypeName()+">"+assetType.getTypeName();
+            }
+        }
+
+        if (StringUtils.hasLength(query.getNameOrCode())){
+            // 查询出资产名称或者资产编号符合条件的code
+            List<Integer> assetTypeIds = assetMainService.lambdaQuery().like(AssetMain::getAssetName, query.getNameOrCode())
+                    .or()
+                    .like(AssetMain::getAssetCode, query.getNameOrCode())
+                    .list()
+                    .stream()
+                    .map(AssetMain::getAssetTypeId)
+                    .collect(Collectors.toList());
+            query.setAssetMainIds(assetTypeIds);
+            if (assetTypeIds.isEmpty()){
+                return new PageInfo<>();
+            }
+        }
+        PageInfo<AssetStatisticsDetailVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
+        List<AssetStatisticsDetailVO> list = this.baseMapper.pageListDetail(query,pageInfo);
+        for (AssetStatisticsDetailVO assetStatisticsDetailVO : list) {
+            assetStatisticsDetailVO.setAssetTypeName(assetTypeName);
+        }
+        pageInfo.setRecords(list);
+        return pageInfo;
+    }
+
 }

--
Gitblit v1.7.1