无关风月
2 天以前 6999d4114eb6d64d0775e2f9ff00572b0e60ee31
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AssetStatisticsController.java
@@ -4,12 +4,11 @@
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.AssetInventoryRecord;
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;
@@ -18,17 +17,14 @@
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.Api;
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;
@@ -95,9 +91,12 @@
        List<Integer> deptIds = deptService.getAllSubDeptIds(deptId);
        if (dept.getDeptName().contains("资产管理")){
            // 可以查询所有数据
            query.setDeptIds(new ArrayList<>());
        }else{
            if (deptIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }else{
                query.setDeptIds(deptIds);
            }
        }
        return R.ok(assetTypeService.pageList(query));
@@ -105,14 +104,38 @@
    @ApiOperation("资产明细")
    @PostMapping("/pageListDetail")
    public R<PageInfo<AssetStatisticsDetailVO>> pageListDetail(@RequestBody AssetStatisticsListDetailQuery query) {
        query.setDeptId(Integer.valueOf(tokenService.getLoginUser().getDeptId()));
        String deptId = tokenService.getLoginUser().getDeptId();
        TDept dept = deptService.getById(tokenService.getLoginUser().getDeptId());
        List<Integer> deptIds = deptService.getAllSubDeptIds(deptId);
        if (dept.getDeptName().contains("资产管理")){
            // 可以查询所有数据
            query.setDeptIds(new ArrayList<>());
        }else{
            if (deptIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }else{
                query.setDeptIds(deptIds);
            }
        }
        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 deptId = tokenService.getLoginUser().getDeptId();
        TDept dept = deptService.getById(tokenService.getLoginUser().getDeptId());
        List<Integer> deptIds = deptService.getAllSubDeptIds(deptId);
        if (dept.getDeptName().contains("资产管理")){
            // 可以查询所有数据
            query.setDeptIds(new ArrayList<>());
        }else{
            if (deptIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }else{
                query.setDeptIds(deptIds);
            }
        }
        String[] dateList = query.getDate().split(",");
        String month = dateList[1];
        int monthValue = Integer.parseInt(month);
@@ -122,26 +145,88 @@
                YearMonth.of(year, monthValue).lengthOfMonth(), 23, 59, 59);
        query.setDateStart(firstDay);
        query.setDateEnd(lastDay);
        List<Integer> assetMainIds = assetInventoryRecordService.lambdaQuery().between(AssetInventoryRecord::getCreateTime, query.getDateStart(), query.getDateEnd())
                .list().stream().map(AssetInventoryRecord::getAssetMainId).collect(Collectors.toList());
        if (assetMainIds.isEmpty()){
            return R.ok(new PageInfo<>());
        }
        if (StringUtils.hasLength(query.getNameOrCode())){
            // 查询出资产名称或者资产编号符合条件的code
            List<Integer> assetTypeIds = assetMainService.lambdaQuery().like(AssetMain::getAssetName, query.getNameOrCode())
                    .or()
                    .like(AssetMain::getAssetCode, query.getNameOrCode())
            List<Integer> assetTypeIds = assetMainService.lambdaQuery()
                    .in(AssetMain::getOwnershipDeptId, deptIds)
                    .and(wrapper -> wrapper.like(AssetMain::getAssetName, query.getNameOrCode())
                            .or()
                            .like(AssetMain::getAssetCode, query.getNameOrCode()))
                    .list()
                    .stream()
                    .map(AssetMain::getAssetTypeId)
                    .collect(Collectors.toList());
            query.setAssetTypeIds(assetTypeIds);
            query.setAssetMainIds(assetTypeIds);
            if (assetTypeIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }
            // 和assetMainIds取交集
            List<Integer> res = assetMainIds.stream().filter(assetTypeIds::contains).collect(Collectors.toList());
            if (res.isEmpty()){
                return R.ok(new PageInfo<>());
            }
            query.setAssetMainIds(res);
        }
        return R.ok(assetTypeService.pageListInventory(query));
    }
    @ApiOperation("资产出入库明细分页列表")
    @PostMapping("/pageListInventoryDetail")
    public R<PageInfo<AssetStatisticsDetailVO>> pageListInventoryDetail(@RequestBody AssetStatisticsListDetailQuery query) {
        PageInfo<AssetStatisticsDetailVO> res = assetTypeService.pageListDetail(query);
        String deptId = tokenService.getLoginUser().getDeptId();
        TDept dept = deptService.getById(tokenService.getLoginUser().getDeptId());
        List<Integer> deptIds = deptService.getAllSubDeptIds(deptId);
        if (dept.getDeptName().contains("资产管理")){
            // 可以查询所有数据
            query.setDeptIds(new ArrayList<>());
        }else{
            if (deptIds.isEmpty()){
                return R.ok(new PageInfo<>());
            }else{
                query.setDeptIds(deptIds);
            }
        }
        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);
        List<Integer> assetMainIds = assetInventoryRecordService.lambdaQuery().between(AssetInventoryRecord::getCreateTime, query.getDateStart(), query.getDateEnd())
                .list().stream().map(AssetInventoryRecord::getAssetMainId).collect(Collectors.toList());
        if (assetMainIds.isEmpty()){
            return R.ok(new PageInfo<>());
        }
        if (StringUtils.hasLength(query.getNameOrCode())){
            // 查询出资产名称或者资产编号符合条件的code
            List<Integer> assetTypeIds = assetMainService.lambdaQuery()
                    .in(AssetMain::getOwnershipDeptId, deptIds)
                    .and(wrapper -> wrapper.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 R.ok(new PageInfo<>());
            }
            // 和assetMainIds取交集
            List<Integer> res = assetMainIds.stream().filter(assetTypeIds::contains).collect(Collectors.toList());
            if (res.isEmpty()){
                return R.ok(new PageInfo<>());
            }
            query.setAssetMainIds(res);
        }
        PageInfo<AssetStatisticsDetailVO> res = assetTypeService.pageListInventoryDetail(query);
        return R.ok(res);
    }