From 7c3331d7be7c10059cc82586852d562f566a5087 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期五, 19 九月 2025 14:08:11 +0800 Subject: [PATCH] 资产管理-资产入库列表详情、撤销接口 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AssetTypeServiceImpl.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 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 e7e0f4d..f69ae9b 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 @@ -3,6 +3,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; 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.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; @@ -21,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; /** @@ -53,10 +55,31 @@ // 转换为VO对象 List<AssetTypeTreeVO> assetTypeVOs = BeanUtil.copyToList(allAssetTypes, AssetTypeTreeVO.class); + // 预查询:找出存在资产关联的资产类型ID集合(去重) + List<Integer> allTypeIds = allAssetTypes.stream().map(AssetType::getId).collect(Collectors.toList()); + QueryWrapper<AssetMain> usedTypeQuery = new QueryWrapper<>(); + usedTypeQuery.select("distinct asset_type_id").in("asset_type_id", allTypeIds); + List<AssetMain> usedTypeRows = assetMainService.list(usedTypeQuery); + Set<Integer> usedTypeIdSet = usedTypeRows.stream() + .map(AssetMain::getAssetTypeId) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + // 按父级ID分组 Map<Integer, List<AssetTypeTreeVO>> parentIdMap = assetTypeVOs.stream() .collect(Collectors.groupingBy(AssetTypeTreeVO::getParentId)); + // 计算可删除标记:一级仅判断是否有子分类;二级仅判断是否有关联资产 + for (AssetTypeTreeVO vo : assetTypeVOs) { + if (Objects.equals(vo.getLevel(), 1)) { + boolean hasChildren = parentIdMap.containsKey(vo.getId()) && CollUtil.isNotEmpty(parentIdMap.get(vo.getId())); + vo.setCanDelete(!hasChildren); + } else { + boolean hasAssets = usedTypeIdSet.contains(vo.getId()); + vo.setCanDelete(!hasAssets); + } + } + // 构建树形结构 List<AssetTypeTreeVO> rootNodes = parentIdMap.get(0); if (CollUtil.isEmpty(rootNodes)) { @@ -233,4 +256,34 @@ } } + @Override + public String getAssetCodePrefix(Integer assetTypeId) { + if (assetTypeId == null) { + throw new ServiceException("资产类型ID不能为空"); + } + + // 查询当前资产类型 + AssetType currentAssetType = this.getById(assetTypeId); + if (currentAssetType == null) { + throw new ServiceException("资产类型不存在"); + } + + String parentTypeCode = ""; + String subTypeCode = currentAssetType.getTypeCode(); + + // 如果是二级分类,需要获取父级分类的简写 + if (currentAssetType.getLevel() == 2 && currentAssetType.getParentId() != null && currentAssetType.getParentId() != 0) { + AssetType parentAssetType = this.getById(currentAssetType.getParentId()); + if (parentAssetType != null) { + parentTypeCode = parentAssetType.getTypeCode(); + } + } else if (currentAssetType.getLevel() == 1) { + // 如果是一级分类,父级简写为空,子类简写就是当前类型简写 + parentTypeCode = currentAssetType.getTypeCode(); + subTypeCode = ""; + } + + return parentTypeCode + subTypeCode; + } + } -- Gitblit v1.7.1