From 84b7d5223a5f5229866a7d5686d198cca4251453 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期五, 26 九月 2025 15:23:25 +0800 Subject: [PATCH] 代码提交,查询部门下级递归 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetStatisticsController.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 96 insertions(+), 4 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetStatisticsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetStatisticsController.java index a36fb7f..c88eb73 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetStatisticsController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetStatisticsController.java @@ -2,10 +2,20 @@ import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.domain.entity.TDept; +import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.dto.asset.AssetTypeDTO; +import com.ruoyi.system.model.AssetMain; +import com.ruoyi.system.query.AssetInventoryListQuery; +import com.ruoyi.system.query.AssetStatisticsListDetailQuery; import com.ruoyi.system.query.AssetStatisticsListQuery; import com.ruoyi.system.query.NotificationListQuery; +import com.ruoyi.system.service.AssetInventoryRecordService; +import com.ruoyi.system.service.AssetMainService; import com.ruoyi.system.service.AssetTypeService; +import com.ruoyi.system.service.TDeptService; +import com.ruoyi.system.vo.AssetInventoryVO; +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; @@ -13,11 +23,17 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * <p> @@ -27,14 +43,23 @@ * @author WuGuanFengYue * @since 2025-09-15 */ -@Api(tags = {"资产-资产汇总"}) +@Api(tags = {"资产-资产汇总-资产出入库-闲置房产"}) @Validated @RestController @RequestMapping("/asset-statistics") @RequiredArgsConstructor public class AssetStatisticsController { - private final AssetTypeService assetTypeService; + @Autowired + private AssetTypeService assetTypeService; + @Autowired + private AssetInventoryRecordService assetInventoryRecordService; + @Autowired + private AssetMainService assetMainService; + @Autowired + private TokenService tokenService; + @Autowired + private TDeptService deptService; @ApiOperation("获取资产类型树形数据") @GetMapping("/tree") @@ -42,15 +67,82 @@ List<AssetTypeTreeVO> treeData = assetTypeService.getAssetTypeTree(); return R.ok(treeData); } + + + + public List<Integer> getAllSubDeptIds(Integer parentId) { + List<Integer> allSubIds = new ArrayList<>(); + allSubIds.add(parentId); + getSubDeptIdsRecursive(parentId, allSubIds); + return allSubIds.stream().distinct().collect(Collectors.toList()); + } + private void getSubDeptIdsRecursive(Integer parentId, List<Integer> allSubIds) { + // 查询直接下级 + List<Integer> directSubIds = deptService.lambdaQuery().eq(TDept::getParentId, parentId).list() + .stream().map(TDept::getId).collect(Collectors.toList()); + + for (Integer subId : directSubIds) { + allSubIds.add(subId); + // 递归查询下级的下级 + getSubDeptIdsRecursive(subId, allSubIds); + } + } @ApiOperation("资产汇总分页列表") @PostMapping("/pageList") public R<PageInfo<AssetStatisticsVO>> pageList(@RequestBody AssetStatisticsListQuery query) { + String deptId = tokenService.getLoginUser().getDeptId(); + TDept dept = deptService.getById(tokenService.getLoginUser().getDeptId()); + List<Integer> deptIds = deptService.getAllSubDeptIds(deptId); + if (dept.getDeptName().contains("资产管理")){ + // 可以查询所有数据 + }else{ + if (deptIds.isEmpty()){ + + } + } return R.ok(assetTypeService.pageList(query)); } @ApiOperation("资产明细") @PostMapping("/pageListDetail") - public R<PageInfo<AssetStatisticsVO>> pageListDetail(@RequestBody AssetStatisticsListQuery query) { - return R.ok(assetTypeService.pageList(query)); + public R<PageInfo<AssetStatisticsDetailVO>> pageListDetail(@RequestBody AssetStatisticsListDetailQuery query) { + query.setDeptId(Integer.valueOf(tokenService.getLoginUser().getDeptId())); + PageInfo<AssetStatisticsDetailVO> res = assetTypeService.pageListDetail(query); + return R.ok(res); + } + @ApiOperation("资产出入库分页列表") + @PostMapping("/pageListInventory") + public R<PageInfo<AssetInventoryVO>> pageListInventory(@RequestBody AssetInventoryListQuery query) { + query.setDeptId(Integer.valueOf(tokenService.getLoginUser().getDeptId())); + String[] dateList = query.getDate().split(","); + String month = dateList[1]; + int monthValue = Integer.parseInt(month); + int year = LocalDateTime.now().getYear(); + LocalDateTime firstDay = LocalDateTime.of(year, monthValue, 1, 0, 0, 0); + LocalDateTime lastDay = LocalDateTime.of(year, monthValue, + YearMonth.of(year, monthValue).lengthOfMonth(), 23, 59, 59); + query.setDateStart(firstDay); + query.setDateEnd(lastDay); + 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 R.ok(new PageInfo<>()); + } + } + return R.ok(assetTypeService.pageListInventory(query)); + } + @ApiOperation("资产出入库明细分页列表") + @PostMapping("/pageListInventoryDetail") + public R<PageInfo<AssetStatisticsDetailVO>> pageListInventoryDetail(@RequestBody AssetStatisticsListDetailQuery query) { + PageInfo<AssetStatisticsDetailVO> res = assetTypeService.pageListDetail(query); + return R.ok(res); } -- Gitblit v1.7.1