无关风月
2 天以前 60afc1c228318d136a273cd0b389217f87583277
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.constants.AssetDeptConstant;
import com.ruoyi.system.query.AssetMainPageQuery;
import com.ruoyi.system.service.AssetMainService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.vo.asset.AssetMainPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * <p>
 * 资产主表 前端控制器
 * </p>
 *
 * 用于资产主数据的查询,新增:查询审批通过的资产分页列表接口
 */
@Api(tags = {"资产-资产主数据相关接口"})
@Validated
@RestController
@RequestMapping("/asset-main")
@RequiredArgsConstructor
public class AssetMainController {
 
    private final AssetMainService assetMainService;
    private final ISysUserService sysUserService;
 
    @ApiOperation("获取审批通过且可用的资产分页列表(排除已领用、已处置、未归还借用)")
    @PostMapping("/page-list")
    public R<IPage<AssetMainPageVO>> getApprovedAssetPageList(@RequestBody AssetMainPageQuery pageQuery) {
        // 数据权限:超级管理员/资产管理部查看所有数据,其他部门查看当前及下级部门的数据
        Long userId = SecurityUtils.getUserId();
        boolean isAdmin = SecurityUtils.isAdmin(userId);
 
        if (!isAdmin) {
            try {
                // 获取当前用户的部门名称
                String deptName = sysUserService.selectUserById(userId).getDept().getDeptName();
 
                // 非超级管理员且非资产管理部,设置部门权限
                if (!AssetDeptConstant.ASSET_DEPARTMENT_NAME.equals(deptName)) {
                    pageQuery.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId()));
                }
            } catch (Exception e) {
                // 如果获取部门信息失败,默认设置部门权限
                try {
                    pageQuery.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId()));
                } catch (Exception ex) {
                    // ignore parse, leave null if cannot parse
                }
            }
        }
        IPage<AssetMainPageVO> page = assetMainService.getApprovedPageList(pageQuery);
        return R.ok(page);
    }
 
    @ApiOperation("获取已入库的资产列表")
    @PostMapping("/page-list-all")
    public R<IPage<AssetMainPageVO>> getAssetPageList(@RequestBody AssetMainPageQuery pageQuery) {
        // 数据权限:超级管理员/资产管理部查看所有数据,其他部门查看当前及下级部门的数据
        Long userId = SecurityUtils.getUserId();
        boolean isAdmin = SecurityUtils.isAdmin(userId);
 
        if (!isAdmin) {
            try {
                // 获取当前用户的部门名称
                String deptName = sysUserService.selectUserById(userId).getDept().getDeptName();
 
                // 非超级管理员且非资产管理部,设置部门权限
                if (!AssetDeptConstant.ASSET_DEPARTMENT_NAME.equals(deptName)) {
                    pageQuery.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId()));
                }
            } catch (Exception e) {
                // 如果获取部门信息失败,默认设置部门权限
                try {
                    pageQuery.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId()));
                } catch (Exception ex) {
                    // ignore parse, leave null if cannot parse
                }
            }
        }
        IPage<AssetMainPageVO> page = assetMainService.getAssetPageList(pageQuery);
        return R.ok(page);
    }
}