From dfe379f10f5d16a3b34b33f260d3a7ca97c7fdc6 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期五, 17 十月 2025 14:43:16 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaApprovalApplicationStorageController.java | 118 +++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 95 insertions(+), 23 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaApprovalApplicationStorageController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaApprovalApplicationStorageController.java
index 89ae307..a0c5174 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaApprovalApplicationStorageController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/OaApprovalApplicationStorageController.java
@@ -3,34 +3,39 @@
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.constants.AssetDeptConstant;
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.ISysUserService;
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 io.swagger.annotations.ApiParam;
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 +47,7 @@
* @author CodeBuddy
* @since 2025-09-17
*/
+@Slf4j
@Api(tags = {"OA审批-资产入库申请相关接口"})
@Validated
@RestController
@@ -52,12 +58,27 @@
private final OaApprovalApplicationStorageService oaApprovalApplicationStorageService;
private final TDeptService deptService;
private final AssetWarehouseService assetWarehouseService;
+ private final ISysUserService sysUserService;
@ApiOperation("提交通用资产入库申请")
@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 +87,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 +108,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,35 +128,63 @@
@ApiOperation("获取资产入库申请分页列表")
@PostMapping("/page-list")
public R<IPage<OaApprovalApplicationStoragePageVO>> getPageList(@RequestBody OaApprovalApplicationStoragePageQuery pageQuery) {
- IPage<OaApprovalApplicationStoragePageVO> page = oaApprovalApplicationStorageService.getPageList(pageQuery);
+ IPage<OaApprovalApplicationStoragePageVO> page = null;
+ // 数据权限:超级管理员/资产管理部查看所有数据,其他部门查看当前及下级部门的数据
+ 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
+ }
+ }
+ }
+ try {
+ page = oaApprovalApplicationStorageService.getPageList(pageQuery);
+ } catch (Exception e) {
+ log.error("获取资产入库申请分页列表失败", e);
+ return R.fail("服务器开小差啦");
+ }
return R.ok(page);
}
@ApiOperation("删除资产入库申请")
@DeleteMapping("/{id}")
@Log(title = "资产入库申请-删除", businessType = BusinessType.DELETE)
- public R<Void> delete(@PathVariable Integer id) {
- oaApprovalApplicationStorageService.removeById(id);
+ public R<Void> delete(@ApiParam(name = "id",value = "审批单ID",required = true) @PathVariable Integer id) {
+ oaApprovalApplicationStorageService.removeByApplicationId(id);
return R.ok();
}
@ApiOperation("获取通用资产入库申请详情")
@GetMapping("/detail/general/{id}")
- public R<OaApprovalApplicationStorageGeneralDetailVO> getGeneralDetail(@PathVariable Integer id) {
+ public R<OaApprovalApplicationStorageGeneralDetailVO> getGeneralDetail(@ApiParam(name = "id",value = "审批单ID",required = true) @PathVariable Integer id) {
OaApprovalApplicationStorageGeneralDetailVO detail = oaApprovalApplicationStorageService.getGeneralDetail(id);
return R.ok(detail);
}
@ApiOperation("获取房产资产入库申请详情")
@GetMapping("/detail/property/{id}")
- public R<OaApprovalApplicationStoragePropertyDetailVO> getPropertyDetail(@PathVariable Integer id) {
+ public R<OaApprovalApplicationStoragePropertyDetailVO> getPropertyDetail(@ApiParam(name = "id",value = "审批单ID",required = true) @PathVariable Integer id) {
OaApprovalApplicationStoragePropertyDetailVO detail = oaApprovalApplicationStorageService.getPropertyDetail(id);
return R.ok(detail);
}
@ApiOperation("获取车辆资产入库申请详情")
@GetMapping("/detail/vehicle/{id}")
- public R<OaApprovalApplicationStorageVehicleDetailVO> getVehicleDetail(@PathVariable Integer id) {
+ public R<OaApprovalApplicationStorageVehicleDetailVO> getVehicleDetail(@ApiParam(name = "id",value = "审批单ID",required = true) @PathVariable Integer id) {
OaApprovalApplicationStorageVehicleDetailVO detail = oaApprovalApplicationStorageService.getVehicleDetail(id);
return R.ok(detail);
}
@@ -119,39 +192,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;
--
Gitblit v1.7.1