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 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; import javax.validation.Valid; /** *

* 资产入库申请 前端控制器 *

* * @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 submitGeneralAssetStorage(@Valid @RequestBody OaApprovalApplicationStorageGeneralDTO dto) { validateAddress(dto); oaApprovalApplicationStorageService.submitGeneralAssetStorage(dto); return R.ok(); } @ApiOperation("提交房产资产入库申请") @PostMapping("/submit-property") @Log(title = "房产资产入库申请-提交", businessType = BusinessType.INSERT) public R submitPropertyAssetStorage(@Valid @RequestBody OaApprovalApplicationStoragePropertyDTO dto) { validateAddress(dto); oaApprovalApplicationStorageService.submitPropertyAssetStorage(dto); return R.ok(); } @ApiOperation("提交车辆资产入库申请") @PostMapping("/submit-vehicle") @Log(title = "车辆资产入库申请-提交", businessType = BusinessType.INSERT) public R submitVehicleAssetStorage(@Valid @RequestBody OaApprovalApplicationStorageVehicleDTO dto) { validateAddress(dto); oaApprovalApplicationStorageService.submitVehicleAssetStorage(dto); return R.ok(); } @ApiOperation("获取资产入库申请分页列表") @PostMapping("/page-list") public R> getPageList(@RequestBody OaApprovalApplicationStoragePageQuery pageQuery) { IPage page = oaApprovalApplicationStorageService.getPageList(pageQuery); return R.ok(page); } /** * 校验位置类型与相关名称/地址 */ 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); } } }