mitao
1 天以前 236fb6ff1f6a955db5f78560204e042e977e2167
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaApprovalApplicationStorageController.java
@@ -3,11 +3,12 @@
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.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;
@@ -16,21 +17,22 @@
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.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 lombok.extern.slf4j.Slf4j;
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.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 org.springframework.web.bind.annotation.GetMapping;
import javax.validation.Valid;
@@ -42,6 +44,7 @@
 * @author CodeBuddy
 * @since 2025-09-17
 */
@Slf4j
@Api(tags = {"OA审批-资产入库申请相关接口"})
@Validated
@RestController
@@ -57,7 +60,21 @@
    @PostMapping("/submit-general")
    @Log(title = "通用资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitGeneralAssetStorage(@Valid @RequestBody OaApprovalApplicationStorageGeneralDTO dto) {
        validateAddress(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();
    }
@@ -66,7 +83,19 @@
    @PostMapping("/submit-property")
    @Log(title = "房产资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitPropertyAssetStorage(@Valid @RequestBody OaApprovalApplicationStoragePropertyDTO dto) {
        validateAddress(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();
    }
@@ -75,7 +104,19 @@
    @PostMapping("/submit-vehicle")
    @Log(title = "车辆资产入库申请-提交", businessType = BusinessType.INSERT)
    public R<Void> submitVehicleAssetStorage(@Valid @RequestBody OaApprovalApplicationStorageVehicleDTO dto) {
        validateAddress(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();
    }
@@ -83,7 +124,13 @@
    @ApiOperation("获取资产入库申请分页列表")
    @PostMapping("/page-list")
    public R<IPage<OaApprovalApplicationStoragePageVO>> getPageList(@RequestBody OaApprovalApplicationStoragePageQuery pageQuery) {
        IPage<OaApprovalApplicationStoragePageVO> page = oaApprovalApplicationStorageService.getPageList(pageQuery);
        IPage<OaApprovalApplicationStoragePageVO> page = null;
        try {
            page = oaApprovalApplicationStorageService.getPageList(pageQuery);
        } catch (Exception e) {
            log.error("获取资产入库申请分页列表失败", e);
            return R.fail("服务器开小差啦");
        }
        return R.ok(page);
    }
@@ -119,39 +166,38 @@
    /**
     * 校验位置类型与相关名称/地址
     */
    private void validateAddress(OaApprovalApplicationStorageDTO dto) {
        Integer addressType = dto.getAddressType();
    private void validateAddress(Integer addressType,String useDeptName,String wareHouseName,String address) {
        if (addressType == null) {
            throw new ServiceException("位置类型不能为空");
        }
        switch (addressType) {
            case 0:
                // 部门
                if (StringUtils.isEmpty(dto.getUseDeptName())) {
                if (StringUtils.isEmpty(useDeptName)) {
                    throw new ServiceException("使用部门名称不能为空");
                }
                TDept dept = deptService.lambdaQuery()
                        .eq(TDept::getDeptName, dto.getUseDeptName())
                        .eq(TDept::getDeptName, useDeptName)
                        .one();
                if (dept == null) {
                    throw new ServiceException("使用部门不存在: " + dto.getUseDeptName());
                    throw new ServiceException("使用部门不存在: " + useDeptName);
                }
                break;
            case 1:
                // 仓库
                if (StringUtils.isEmpty(dto.getWarehouseName())) {
                if (StringUtils.isEmpty(wareHouseName)) {
                    throw new ServiceException("仓库名称不能为空");
                }
                AssetWarehouse wh = assetWarehouseService.lambdaQuery()
                        .eq(AssetWarehouse::getWarehouseName, dto.getWarehouseName())
                        .eq(AssetWarehouse::getWarehouseName, wareHouseName)
                        .one();
                if (wh == null) {
                    throw new ServiceException("仓库不存在: " + dto.getWarehouseName());
                    throw new ServiceException("仓库不存在: " + wareHouseName);
                }
                break;
            case 2:
                // 地址
                if (StringUtils.isEmpty(dto.getAddress())) {
                if (StringUtils.isEmpty(address)) {
                    throw new ServiceException("所在位置不能为空");
                }
                break;