mitao
1 天以前 7c3331d7be7c10059cc82586852d562f566a5087
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
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.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.entity.TDept;
import com.ruoyi.system.dto.asset.OaApprovalApplicationStorageDTO;
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.OaApprovalApplicationStoragePageVO;
import com.ruoyi.system.vo.asset.OaApprovalApplicationStorageGeneralDetailVO;
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.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
 
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) {
        validateAddress(dto);
        oaApprovalApplicationStorageService.submitGeneralAssetStorage(dto);
        return R.ok();
    }
 
    @ApiOperation("提交房产资产入库申请")
    @PostMapping("/submit-property")
    @Log(title = "房产资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitPropertyAssetStorage(@Valid @RequestBody OaApprovalApplicationStoragePropertyDTO dto) {
        validateAddress(dto);
        oaApprovalApplicationStorageService.submitPropertyAssetStorage(dto);
        return R.ok();
    }
 
    @ApiOperation("提交车辆资产入库申请")
    @PostMapping("/submit-vehicle")
    @Log(title = "车辆资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitVehicleAssetStorage(@Valid @RequestBody OaApprovalApplicationStorageVehicleDTO dto) {
        validateAddress(dto);
        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(OaApprovalApplicationStorageDTO dto) {
        Integer addressType = dto.getAddressType();
        if (addressType == null) {
            throw new ServiceException("位置类型不能为空");
        }
        switch (addressType) {
            case 0:
                // 部门
                if (StringUtils.isEmpty(dto.getUseDeptName())) {
                    throw new ServiceException("使用部门名称不能为空");
                }
                TDept dept = deptService.lambdaQuery()
                        .eq(TDept::getDeptName, dto.getUseDeptName())
                        .one();
                if (dept == null) {
                    throw new ServiceException("使用部门不存在: " + dto.getUseDeptName());
                }
                break;
            case 1:
                // 仓库
                if (StringUtils.isEmpty(dto.getWarehouseName())) {
                    throw new ServiceException("仓库名称不能为空");
                }
                AssetWarehouse wh = assetWarehouseService.lambdaQuery()
                        .eq(AssetWarehouse::getWarehouseName, dto.getWarehouseName())
                        .one();
                if (wh == null) {
                    throw new ServiceException("仓库不存在: " + dto.getWarehouseName());
                }
                break;
            case 2:
                // 地址
                if (StringUtils.isEmpty(dto.getAddress())) {
                    throw new ServiceException("所在位置不能为空");
                }
                break;
            default:
                throw new ServiceException("位置类型不支持: " + addressType);
        }
    }
}