From 03587b58b343956f910a653c37b9a7bcd84e4af9 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期五, 19 九月 2025 18:54:03 +0800 Subject: [PATCH] 资产管理-资产领用列表 阿里云OSS文件上传 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OaApprovalApplicationStorageServiceImpl.java | 117 ++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 64 insertions(+), 53 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OaApprovalApplicationStorageServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OaApprovalApplicationStorageServiceImpl.java index 8b336fd..a197e1c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OaApprovalApplicationStorageServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OaApprovalApplicationStorageServiceImpl.java @@ -20,6 +20,7 @@ import com.ruoyi.system.model.OaApprovalApplicationStorage; import com.ruoyi.system.model.OaApprovalApplications; import com.ruoyi.system.model.OaApprovalFlowNode; +import com.ruoyi.system.query.OaApprovalApplicationStoragePageQuery; import com.ruoyi.system.service.AssetGeneralExtService; import com.ruoyi.system.service.AssetMainService; import com.ruoyi.system.service.AssetPropertyExtService; @@ -33,8 +34,8 @@ import com.ruoyi.system.service.OaApprovalFlowNodeService; import com.ruoyi.system.service.OaApprovalTodoService; 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 lombok.RequiredArgsConstructor; @@ -146,8 +147,7 @@ */ private void saveGeneralAssets(List<OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO> assetItems, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStorageGeneralDTO baseDto) { List<AssetMain> allAssetMains = new ArrayList<>(); - List<AssetGeneralExt> allGeneralExts = new ArrayList<>(); - + for (OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item : assetItems) { // 根据数量创建对应数量的资产记录 int quantity = item.getQuantity().intValue(); @@ -162,19 +162,6 @@ // 批量保存资产主表数据 assetMainService.saveBatch(allAssetMains); - - // 为每个资产主表记录创建对应的扩展信息 - int assetMainIndex = 0; - for (OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item : assetItems) { - int quantity = item.getQuantity().intValue(); - for (int i = 0; i < quantity; i++) { - AssetGeneralExt generalExt = buildAssetGeneralExt(item, allAssetMains.get(assetMainIndex).getId()); - allGeneralExts.add(generalExt); - assetMainIndex++; - } - } - - assetGeneralExtService.saveBatch(allGeneralExts); } /** @@ -258,12 +245,21 @@ assetMain.setAssetOriginalCode(item.getAssetOriginalCode()); assetMain.setAssetCode(generateAssetCode(assetTypeId, storageDate)); // 系统生成资产编码 assetMain.setAssetName(item.getAssetName()); + assetMain.setCategory(item.getCategory()); assetMain.setSpecificationModel(item.getSpecificationModel()); assetMain.setAssetTypeId(assetTypeId); assetMain.setMeasurementUnit(item.getMeasurementUnit()); assetMain.setUnitPrice(item.getUnitPrice()); assetMain.setUsefulLife(item.getUsefulLife()); - assetMain.setOwnershipDeptId(item.getOwnershipDeptId()); + // 根据权属单位/部门名称填充ID + if (item.getOwnershipDeptName() != null && !item.getOwnershipDeptName().isEmpty()) { + TDept ownerDept = tDeptService.lambdaQuery() + .eq(TDept::getDeptName, item.getOwnershipDeptName()) + .one(); + if (ownerDept != null) { + assetMain.setOwnershipDeptId(ownerDept.getId()); + } + } assetMain.setUserName(item.getUserName()); // 根据整单 addressType 写入使用部门ID或仓库ID applyAddressToAssetMain(assetMain, baseDto.getAddressType(), baseDto.getUseDeptName(), baseDto.getWarehouseName(), baseDto.getAddress()); @@ -288,12 +284,20 @@ assetMain.setAssetOriginalCode(item.getAssetOriginalCode()); assetMain.setAssetCode(generateAssetCode(assetTypeId, storageDate)); assetMain.setAssetName(item.getAssetName()); + assetMain.setCategory(item.getCategory()); assetMain.setSpecificationModel(item.getSpecificationModel()); assetMain.setAssetTypeId(assetTypeId); assetMain.setMeasurementUnit(item.getMeasurementUnit()); assetMain.setUnitPrice(item.getUnitPrice()); assetMain.setUsefulLife(item.getUsefulLife()); - assetMain.setOwnershipDeptId(item.getOwnershipDeptId()); + if (item.getOwnershipDeptName() != null && !item.getOwnershipDeptName().isEmpty()) { + TDept ownerDept = tDeptService.lambdaQuery() + .eq(TDept::getDeptName, item.getOwnershipDeptName()) + .one(); + if (ownerDept != null) { + assetMain.setOwnershipDeptId(ownerDept.getId()); + } + } assetMain.setUserName(item.getUserName()); applyAddressToAssetMain(assetMain, baseDto.getAddressType(), baseDto.getUseDeptName(), baseDto.getWarehouseName(), baseDto.getAddress()); assetMain.setAssetMainType(baseDto.getAddressType()); @@ -317,12 +321,20 @@ assetMain.setAssetOriginalCode(item.getAssetOriginalCode()); assetMain.setAssetCode(generateAssetCode(assetTypeId, storageDate)); assetMain.setAssetName(item.getAssetName()); + assetMain.setCategory(item.getCategory()); assetMain.setSpecificationModel(item.getSpecificationModel()); assetMain.setAssetTypeId(assetTypeId); assetMain.setMeasurementUnit(item.getMeasurementUnit()); assetMain.setUnitPrice(item.getUnitPrice()); assetMain.setUsefulLife(item.getUsefulLife()); - assetMain.setOwnershipDeptId(item.getOwnershipDeptId()); + if (item.getOwnershipDeptName() != null && !item.getOwnershipDeptName().isEmpty()) { + TDept ownerDept = tDeptService.lambdaQuery() + .eq(TDept::getDeptName, item.getOwnershipDeptName()) + .one(); + if (ownerDept != null) { + assetMain.setOwnershipDeptId(ownerDept.getId()); + } + } assetMain.setUserName(item.getUserName()); applyAddressToAssetMain(assetMain, baseDto.getAddressType(), baseDto.getUseDeptName(), baseDto.getWarehouseName(), baseDto.getAddress()); assetMain.setAssetMainType(baseDto.getAddressType()); @@ -383,16 +395,6 @@ private AssetGeneralExt buildAssetGeneralExt(OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item, Integer assetMainId) { AssetGeneralExt generalExt = new AssetGeneralExt(); generalExt.setAssetMainId(assetMainId); - generalExt.setSupplierName(item.getSupplierName()); - generalExt.setPurchaseDate(item.getPurchaseDate()); - generalExt.setWarrantyPeriod(item.getWarrantyPeriod()); - generalExt.setWarrantyExpireDate(item.getWarrantyExpireDate()); - generalExt.setDepreciationMethod(item.getDepreciationMethod()); - generalExt.setDepreciationRate(item.getDepreciationRate()); - generalExt.setNetValue(item.getNetValue()); - generalExt.setMaintenanceCycle(item.getMaintenanceCycle()); - generalExt.setLastMaintenanceDate(item.getLastMaintenanceDate()); - generalExt.setNextMaintenanceDate(item.getNextMaintenanceDate()); generalExt.setDisabled(false); return generalExt; } @@ -414,7 +416,7 @@ propertyExt.setDetailedLocation(item.getDetailedLocation()); propertyExt.setProvincialPlatformValue(item.getProvincialPlatformValue()); propertyExt.setResettlementSituation(item.getResettlementSituation()); - propertyExt.setIsMortgaged(item.getIsMortgaged()); + propertyExt.setMortgaged(item.getMortgaged()); propertyExt.setTenantName(item.getTenantName()); propertyExt.setRentalAmount(item.getRentalAmount()); propertyExt.setLeaseStartDate(item.getLeaseStartDate()); @@ -472,7 +474,7 @@ applications.setApplicantName(generalDTO.getApplicantName()); applications.setDeptId(generalDTO.getDeptId()); applications.setDeptName(generalDTO.getDeptName()); - applications.setApplicationDate(generalDTO.getApplicationDate()); + applications.setApplicationDate(LocalDate.now()); applications.setApplicationReason(generalDTO.getApplicationReason()); applications.setAttachmentUrl(generalDTO.getAttachmentUrl()); } else if (dto instanceof OaApprovalApplicationStoragePropertyDTO) { @@ -481,7 +483,7 @@ applications.setApplicantName(propertyDTO.getApplicantName()); applications.setDeptId(propertyDTO.getDeptId()); applications.setDeptName(propertyDTO.getDeptName()); - applications.setApplicationDate(propertyDTO.getApplicationDate()); + applications.setApplicationDate(LocalDate.now()); applications.setApplicationReason(propertyDTO.getApplicationReason()); applications.setAttachmentUrl(propertyDTO.getAttachmentUrl()); } else if (dto instanceof OaApprovalApplicationStorageVehicleDTO) { @@ -490,7 +492,7 @@ applications.setApplicantName(vehicleDTO.getApplicantName()); applications.setDeptId(vehicleDTO.getDeptId()); applications.setDeptName(vehicleDTO.getDeptName()); - applications.setApplicationDate(vehicleDTO.getApplicationDate()); + applications.setApplicationDate(LocalDate.now()); applications.setApplicationReason(vehicleDTO.getApplicationReason()); applications.setAttachmentUrl(vehicleDTO.getAttachmentUrl()); } @@ -577,7 +579,7 @@ } @Override - public IPage<OaApprovalApplicationStoragePageVO> getPageList(com.ruoyi.system.query.OaApprovalApplicationStoragePageQuery pageQuery) { + public IPage<OaApprovalApplicationStoragePageVO> getPageList(OaApprovalApplicationStoragePageQuery pageQuery) { Page<OaApprovalApplicationStoragePageVO> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()); return this.baseMapper.selectApplicationStoragePage(page, pageQuery); } @@ -604,8 +606,11 @@ if (!CollectionUtils.isEmpty(mains)) { List<Integer> mainIds = mains.stream().map(AssetMain::getId).collect(Collectors.toList()); - List<AssetGeneralExt> exts = assetGeneralExtService.lambdaQuery().in(AssetGeneralExt::getAssetMainId, mainIds).list(); - Map<Integer, AssetGeneralExt> extMap = exts.stream().collect(Collectors.toMap(AssetGeneralExt::getAssetMainId, e -> e)); + // 批量查询权属部门,避免循环内查询 + List<Integer> ownerIds = mains.stream().map(AssetMain::getOwnershipDeptId) + .filter(id -> id != null).distinct().collect(Collectors.toList()); + Map<Integer, TDept> ownerDeptMap = ownerIds.isEmpty() ? java.util.Collections.emptyMap() + : tDeptService.listByIds(ownerIds).stream().collect(Collectors.toMap(TDept::getId, d -> d)); List<OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO> items = mains.stream().map(m -> { OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO item = new OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO(); @@ -616,7 +621,10 @@ item.setQuantity(m.getQuantity()); item.setUnitPrice(m.getUnitPrice()); item.setUsefulLife(m.getUsefulLife()); - item.setOwnershipDeptId(m.getOwnershipDeptId()); + if (m.getOwnershipDeptId() != null) { + TDept dept = ownerDeptMap.get(m.getOwnershipDeptId()); + item.setOwnerShipDeptName(dept != null ? dept.getDeptName() : null); + } item.setUserName(m.getUserName()); item.setAssetStatus(m.getAssetStatus()); item.setRemarks(m.getRemarks()); @@ -625,19 +633,6 @@ item.setAccountingVoucherNo(m.getAccountingVoucherNo()); item.setAccountingSubject(m.getAccountingSubject()); item.setAccountingAmount(m.getAccountingAmount()); - AssetGeneralExt ext = extMap.get(m.getId()); - if (ext != null) { - item.setSupplierName(ext.getSupplierName()); - item.setPurchaseDate(ext.getPurchaseDate()); - item.setWarrantyPeriod(ext.getWarrantyPeriod()); - item.setWarrantyExpireDate(ext.getWarrantyExpireDate()); - item.setDepreciationMethod(ext.getDepreciationMethod()); - item.setDepreciationRate(ext.getDepreciationRate()); - item.setNetValue(ext.getNetValue()); - item.setMaintenanceCycle(ext.getMaintenanceCycle()); - item.setLastMaintenanceDate(ext.getLastMaintenanceDate()); - item.setNextMaintenanceDate(ext.getNextMaintenanceDate()); - } return item; }).collect(Collectors.toList()); vo.setAssetItems(items); @@ -669,6 +664,11 @@ List<Integer> mainIds = mains.stream().map(AssetMain::getId).collect(Collectors.toList()); List<AssetPropertyExt> exts = assetPropertyExtService.lambdaQuery().in(AssetPropertyExt::getAssetMainId, mainIds).list(); Map<Integer, AssetPropertyExt> extMap = exts.stream().collect(Collectors.toMap(AssetPropertyExt::getAssetMainId, e -> e)); + // 批量查询权属部门 + List<Integer> ownerIds = mains.stream().map(AssetMain::getOwnershipDeptId) + .filter(id -> id != null).distinct().collect(Collectors.toList()); + Map<Integer, TDept> ownerDeptMap = ownerIds.isEmpty() ? java.util.Collections.emptyMap() + : tDeptService.listByIds(ownerIds).stream().collect(Collectors.toMap(TDept::getId, d -> d)); List<OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO> items = mains.stream().map(m -> { OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO item = new OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO(); @@ -679,7 +679,10 @@ item.setQuantity(m.getQuantity()); item.setUnitPrice(m.getUnitPrice()); item.setUsefulLife(m.getUsefulLife()); - item.setOwnershipDeptId(m.getOwnershipDeptId()); + if (m.getOwnershipDeptId() != null) { + TDept dept = ownerDeptMap.get(m.getOwnershipDeptId()); + item.setOwnerShipDeptName(dept != null ? dept.getDeptName() : null); + } item.setUserName(m.getUserName()); item.setAssetStatus(m.getAssetStatus()); item.setRemarks(m.getRemarks()); @@ -701,7 +704,7 @@ item.setDetailedLocation(ext.getDetailedLocation()); item.setProvincialPlatformValue(ext.getProvincialPlatformValue()); item.setResettlementSituation(ext.getResettlementSituation()); - item.setIsMortgaged(ext.getIsMortgaged()); + item.setMortgaged(ext.getMortgaged()); item.setTenantName(ext.getTenantName()); item.setRentalAmount(ext.getRentalAmount()); item.setLeaseStartDate(ext.getLeaseStartDate()); @@ -738,6 +741,11 @@ List<Integer> mainIds = mains.stream().map(AssetMain::getId).collect(Collectors.toList()); List<AssetVehicleExt> exts = assetVehicleExtService.lambdaQuery().in(AssetVehicleExt::getAssetMainId, mainIds).list(); Map<Integer, AssetVehicleExt> extMap = exts.stream().collect(Collectors.toMap(AssetVehicleExt::getAssetMainId, e -> e)); + // 批量查询权属部门 + List<Integer> ownerIds = mains.stream().map(AssetMain::getOwnershipDeptId) + .filter(id -> id != null).distinct().collect(Collectors.toList()); + Map<Integer, TDept> ownerDeptMap = ownerIds.isEmpty() ? java.util.Collections.emptyMap() + : tDeptService.listByIds(ownerIds).stream().collect(Collectors.toMap(TDept::getId, d -> d)); List<OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO> items = mains.stream().map(m -> { OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO item = new OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO(); @@ -748,7 +756,10 @@ item.setQuantity(m.getQuantity()); item.setUnitPrice(m.getUnitPrice()); item.setUsefulLife(m.getUsefulLife()); - item.setOwnershipDeptId(m.getOwnershipDeptId()); + if (m.getOwnershipDeptId() != null) { + TDept dept = ownerDeptMap.get(m.getOwnershipDeptId()); + item.setOwnerShipDeptName(dept != null ? dept.getDeptName() : null); + } item.setUserName(m.getUserName()); item.setAssetStatus(m.getAssetStatus()); item.setRemarks(m.getRemarks()); -- Gitblit v1.7.1