mitao
2 天以前 bb5ce8ef60a63815f222716c40111bd045464689
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.constants.AssetDeptConstant;
import com.ruoyi.system.dto.asset.OaApprovalApplicationAssetReceiveDTO;
import com.ruoyi.system.dto.asset.OaApprovalApplicationAssetReturnDTO;
import com.ruoyi.system.query.OaApprovalApplicationAssetPageQuery;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.OaApprovalApplicationAssetService;
import com.ruoyi.system.vo.asset.AssetMainVO;
import com.ruoyi.system.vo.asset.OaApprovalApplicationAssetDetailVO;
import com.ruoyi.system.vo.asset.OaApprovalApplicationAssetPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;
 
import javax.validation.Valid;
import java.util.List;
 
/**
 * <p>
 * 资产领用单明细表 前端控制器
 * </p>
 */
@Api(tags = {"OA审批-资产领用相关接口"})
@Validated
@RestController
@RequestMapping("/oa-approval-application-asset")
@RequiredArgsConstructor
public class OaApprovalApplicationAssetController {
 
    private final OaApprovalApplicationAssetService oaApprovalApplicationAssetService;
    private final ISysUserService sysUserService;
 
    @ApiOperation("提交资产领用申请")
    @PostMapping("/submit-receive")
    @Log(title = "资产领用申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitReceive(@Valid @RequestBody OaApprovalApplicationAssetReceiveDTO dto) {
        oaApprovalApplicationAssetService.submitReceiveBorrow(dto);
        return R.ok();
    }
 
    @ApiOperation("获取资产领用申请分页列表")
    @PostMapping("/page-list")
    public R<IPage<OaApprovalApplicationAssetPageVO>> getReceivePageList(@RequestBody OaApprovalApplicationAssetPageQuery 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<OaApprovalApplicationAssetPageVO> page = oaApprovalApplicationAssetService.getReceivePageList(pageQuery);
        return R.ok(page);
    }
 
    @ApiOperation("获取资产领用详情")
    @GetMapping("/detail/receive/{id}")
    public R<OaApprovalApplicationAssetDetailVO> getReceiveDetail(@ApiParam(name = "id", value = "审批单ID", required = true) @PathVariable Integer id) {
        OaApprovalApplicationAssetDetailVO detail = oaApprovalApplicationAssetService.getDetail(id);
        return R.ok(detail);
    }
 
    @ApiOperation("提交资产借用申请")
    @PostMapping("/submit-borrow")
    @Log(title = "资产借用申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitBorrow(@Valid @RequestBody OaApprovalApplicationAssetReceiveDTO dto) {
        oaApprovalApplicationAssetService.submitReceiveBorrow(dto);
        return R.ok();
    }
 
    @ApiOperation("获取资产借用申请分页列表")
    @PostMapping("/page-borrow-list")
    public R<IPage<OaApprovalApplicationAssetPageVO>> getBorrowPageList(@RequestBody OaApprovalApplicationAssetPageQuery pageQuery) {
        // 数据权限:非管理员仅能查看本部门
        Long userId = SecurityUtils.getUserId();
        boolean isAdmin = SecurityUtils.isAdmin(userId);
        if (!isAdmin) {
            try {
                pageQuery.setDeptId(Integer.valueOf(SecurityUtils.getDeptId()));
            } catch (Exception e) {
                // ignore parse, leave null if cannot parse
            }
        }
        IPage<OaApprovalApplicationAssetPageVO> page = oaApprovalApplicationAssetService.getBorrowPageList(pageQuery);
        return R.ok(page);
    }
 
    @ApiOperation("获取资产借用详情")
    @GetMapping("/detail/borrow/{id}")
    public R<OaApprovalApplicationAssetDetailVO> getBorrowDetail(@ApiParam(name = "id", value = "审批单ID", required = true) @PathVariable Integer id) {
        OaApprovalApplicationAssetDetailVO detail = oaApprovalApplicationAssetService.getBorrowDetail(id);
        return R.ok(detail);
    }
 
    @ApiOperation("查询当前登录用户提交的借用申请记录列表")
    @GetMapping("/borrow-list")
    public R<List<OaApprovalApplicationAssetDetailVO>> getBorrowDetailByApplicationCode() {
        List<OaApprovalApplicationAssetDetailVO> detail = oaApprovalApplicationAssetService.getBorrowDetailByApplicationCode();
        return R.ok(detail);
    }
 
    @ApiOperation(("根据借用单ID获取借用资产列表"))
    @GetMapping("/borrow-detail-list/{id}")
    public R<List<AssetMainVO>> getBorrowDetailList(@ApiParam(name = "id", value = "审批单ID", required = true) @PathVariable Integer id) {
        List<AssetMainVO> list = oaApprovalApplicationAssetService.getBorrowDetailList(id);
        return R.ok(list);
    }
 
    @ApiOperation("提交资产归还申请")
    @PostMapping("/submit-return")
    @Log(title = "资产归还申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitReturn(@Valid @RequestBody OaApprovalApplicationAssetReturnDTO dto) {
        oaApprovalApplicationAssetService.submitReturn(dto);
        return R.ok();
    }
 
    @ApiOperation("获取资产归还申请分页列表")
    @PostMapping("/page-return-list")
    public R<IPage<OaApprovalApplicationAssetPageVO>> getReturnPageList(@RequestBody OaApprovalApplicationAssetPageQuery 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<OaApprovalApplicationAssetPageVO> page = oaApprovalApplicationAssetService.getReturnPageList(pageQuery);
        return R.ok(page);
    }
 
    @ApiOperation("获取资产归还提醒分页列表")
    @PostMapping("/page-return-notify-list")
    public R<IPage<OaApprovalApplicationAssetPageVO>> getReturnNotifyPageList(@RequestBody OaApprovalApplicationAssetPageQuery 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<OaApprovalApplicationAssetPageVO> page = oaApprovalApplicationAssetService.getReturnNotifyPageList(pageQuery);
        return R.ok(page);
    }
 
    @ApiOperation("获取资产归还详情")
    @GetMapping("/detail/return/{id}")
    public R<OaApprovalApplicationAssetDetailVO> getReturnDetail(@ApiParam(name = "id", value = "审批单ID", required = true) @PathVariable Integer id) {
        OaApprovalApplicationAssetDetailVO detail = oaApprovalApplicationAssetService.getReturnDetail(id);
        return R.ok(detail);
    }
    @ApiOperation("删除/领用/借用/归还申请")
    @DeleteMapping("/{id}")
    public R<?> delete(@ApiParam(name = "id",value = "审批记录ID",required = true) @PathVariable Integer id){
        oaApprovalApplicationAssetService.deleteByApplicationId(id);
        return R.ok();
    }
}