mitao
1 天以前 206c1338ae6f5100cb408fb02a2095e211c0521f
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
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.core.domain.entity.TDept;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.dto.asset.OaApprovalApplicationStorageGeneralDTO;
import com.ruoyi.system.dto.asset.OaApprovalApplicationStoragePropertyDTO;
import com.ruoyi.system.dto.asset.OaApprovalApplicationStorageVehicleDTO;
import com.ruoyi.system.model.AssetWarehouse;
import com.ruoyi.system.query.OaApprovalApplicationStoragePageQuery;
import com.ruoyi.system.service.AssetWarehouseService;
import com.ruoyi.system.service.OaApprovalApplicationStorageService;
import com.ruoyi.system.service.TDeptService;
import com.ruoyi.system.vo.asset.OaApprovalApplicationStorageGeneralDetailVO;
import com.ruoyi.system.vo.asset.OaApprovalApplicationStoragePageVO;
import com.ruoyi.system.vo.asset.OaApprovalApplicationStoragePropertyDetailVO;
import com.ruoyi.system.vo.asset.OaApprovalApplicationStorageVehicleDetailVO;
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.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;
 
/**
 * <p>
 * 资产入库申请 前端控制器
 * </p>
 *
 * @author CodeBuddy
 * @since 2025-09-17
 */
@Api(tags = {"OA审批-资产入库申请相关接口"})
@Validated
@RestController
@RequestMapping("/oa-approval-application-storage")
@RequiredArgsConstructor
public class OaApprovalApplicationStorageController {
 
    private final OaApprovalApplicationStorageService oaApprovalApplicationStorageService;
    private final TDeptService deptService;
    private final AssetWarehouseService assetWarehouseService;
 
    @ApiOperation("提交通用资产入库申请")
    @PostMapping("/submit-general")
    @Log(title = "通用资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitGeneralAssetStorage(@Valid @RequestBody OaApprovalApplicationStorageGeneralDTO dto) {
 
        // 校验每条明细的权属单位/部门名称是否存在
        for (OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item : dto.getAssetItems()) {
            if (StringUtils.isEmpty(item.getOwnershipDeptName())) {
                throw new ServiceException("权属单位/部门名称不能为空");
            }
            TDept owner = deptService.lambdaQuery().eq(TDept::getDeptName, item.getOwnershipDeptName()).one();
            if (owner == null) {
                throw new ServiceException("权属单位/部门不存在: " + item.getOwnershipDeptName());
            }
            validateAddress(item.getAddressType(), item.getUseDeptName(), item.getWarehouseName(), item.getAddress());
        }
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dto.setApplicantUserId(loginUser.getUserId().intValue());
        dto.setApplicantName(loginUser.getUser().getNickName());
        oaApprovalApplicationStorageService.submitGeneralAssetStorage(dto);
        return R.ok();
    }
 
    @ApiOperation("提交房产资产入库申请")
    @PostMapping("/submit-property")
    @Log(title = "房产资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitPropertyAssetStorage(@Valid @RequestBody OaApprovalApplicationStoragePropertyDTO dto) {
        for (OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item : dto.getAssetItems()) {
            if (StringUtils.isEmpty(item.getOwnershipDeptName())) {
                throw new ServiceException("权属单位/部门名称不能为空");
            }
            TDept owner = deptService.lambdaQuery().eq(TDept::getDeptName, item.getOwnershipDeptName()).one();
            if (owner == null) {
                throw new ServiceException("权属单位/部门不存在: " + item.getOwnershipDeptName());
            }
            validateAddress(item.getAddressType(), item.getUseDeptName(), item.getWarehouseName(), item.getAddress());
        }
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dto.setApplicantUserId(loginUser.getUserId().intValue());
        dto.setApplicantName(loginUser.getUser().getNickName());
        oaApprovalApplicationStorageService.submitPropertyAssetStorage(dto);
        return R.ok();
    }
 
    @ApiOperation("提交车辆资产入库申请")
    @PostMapping("/submit-vehicle")
    @Log(title = "车辆资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitVehicleAssetStorage(@Valid @RequestBody OaApprovalApplicationStorageVehicleDTO dto) {
        for (OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item : dto.getAssetItems()) {
            if (StringUtils.isEmpty(item.getOwnershipDeptName())) {
                throw new ServiceException("权属单位/部门名称不能为空");
            }
            TDept owner = deptService.lambdaQuery().eq(TDept::getDeptName, item.getOwnershipDeptName()).one();
            if (owner == null) {
                throw new ServiceException("权属单位/部门不存在: " + item.getOwnershipDeptName());
            }
            validateAddress(item.getAddressType(), item.getUseDeptName(), item.getWarehouseName(), item.getAddress());
        }
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dto.setApplicantUserId(loginUser.getUserId().intValue());
        dto.setApplicantName(loginUser.getUser().getNickName());
        oaApprovalApplicationStorageService.submitVehicleAssetStorage(dto);
        return R.ok();
    }
 
    @ApiOperation("获取资产入库申请分页列表")
    @PostMapping("/page-list")
    public R<IPage<OaApprovalApplicationStoragePageVO>> getPageList(@RequestBody OaApprovalApplicationStoragePageQuery pageQuery) {
        IPage<OaApprovalApplicationStoragePageVO> page = oaApprovalApplicationStorageService.getPageList(pageQuery);
        return R.ok(page);
    }
 
    @ApiOperation("删除资产入库申请")
    @DeleteMapping("/{id}")
    @Log(title = "资产入库申请-删除", businessType = BusinessType.DELETE)
    public R<Void> delete(@PathVariable Integer id) {
        oaApprovalApplicationStorageService.removeById(id);
        return R.ok();
    }
 
    @ApiOperation("获取通用资产入库申请详情")
    @GetMapping("/detail/general/{id}")
    public R<OaApprovalApplicationStorageGeneralDetailVO> getGeneralDetail(@PathVariable Integer id) {
        OaApprovalApplicationStorageGeneralDetailVO detail = oaApprovalApplicationStorageService.getGeneralDetail(id);
        return R.ok(detail);
    }
 
    @ApiOperation("获取房产资产入库申请详情")
    @GetMapping("/detail/property/{id}")
    public R<OaApprovalApplicationStoragePropertyDetailVO> getPropertyDetail(@PathVariable Integer id) {
        OaApprovalApplicationStoragePropertyDetailVO detail = oaApprovalApplicationStorageService.getPropertyDetail(id);
        return R.ok(detail);
    }
 
    @ApiOperation("获取车辆资产入库申请详情")
    @GetMapping("/detail/vehicle/{id}")
    public R<OaApprovalApplicationStorageVehicleDetailVO> getVehicleDetail(@PathVariable Integer id) {
        OaApprovalApplicationStorageVehicleDetailVO detail = oaApprovalApplicationStorageService.getVehicleDetail(id);
        return R.ok(detail);
    }
 
    /**
     * 校验位置类型与相关名称/地址
     */
    private void validateAddress(Integer addressType,String useDeptName,String wareHouseName,String address) {
        if (addressType == null) {
            throw new ServiceException("位置类型不能为空");
        }
        switch (addressType) {
            case 0:
                // 部门
                if (StringUtils.isEmpty(useDeptName)) {
                    throw new ServiceException("使用部门名称不能为空");
                }
                TDept dept = deptService.lambdaQuery()
                        .eq(TDept::getDeptName, useDeptName)
                        .one();
                if (dept == null) {
                    throw new ServiceException("使用部门不存在: " + useDeptName);
                }
                break;
            case 1:
                // 仓库
                if (StringUtils.isEmpty(wareHouseName)) {
                    throw new ServiceException("仓库名称不能为空");
                }
                AssetWarehouse wh = assetWarehouseService.lambdaQuery()
                        .eq(AssetWarehouse::getWarehouseName, wareHouseName)
                        .one();
                if (wh == null) {
                    throw new ServiceException("仓库不存在: " + wareHouseName);
                }
                break;
            case 2:
                // 地址
                if (StringUtils.isEmpty(address)) {
                    throw new ServiceException("所在位置不能为空");
                }
                break;
            default:
                throw new ServiceException("位置类型不支持: " + addressType);
        }
    }
}