From 236fb6ff1f6a955db5f78560204e042e977e2167 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期一, 22 九月 2025 20:47:52 +0800 Subject: [PATCH] 资产入库审批通过保存资产数据 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OaApprovalApplicationStorageServiceImpl.java | 497 ++++++++++++++++++++++-------------------------------- 1 files changed, 205 insertions(+), 292 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..5c9f687 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 @@ -1,8 +1,10 @@ package com.ruoyi.system.service.impl; +import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.entity.TDept; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.system.dto.asset.OaApprovalApplicationStorageGeneralDTO; @@ -12,29 +14,27 @@ import com.ruoyi.system.emums.ApprovalTypeEnum; import com.ruoyi.system.emums.AssetTypeEnum; import com.ruoyi.system.mapper.OaApprovalApplicationStorageMapper; -import com.ruoyi.system.model.AssetGeneralExt; -import com.ruoyi.system.model.AssetMain; -import com.ruoyi.system.model.AssetPropertyExt; -import com.ruoyi.system.model.AssetVehicleExt; import com.ruoyi.system.model.AssetWarehouse; import com.ruoyi.system.model.OaApprovalApplicationStorage; +import com.ruoyi.system.model.OaApprovalApplicationStorageAsset; +import com.ruoyi.system.model.OaApprovalApplicationStorageAssetPropertyExt; +import com.ruoyi.system.model.OaApprovalApplicationStorageAssetVehicleExt; import com.ruoyi.system.model.OaApprovalApplications; import com.ruoyi.system.model.OaApprovalFlowNode; -import com.ruoyi.system.service.AssetGeneralExtService; -import com.ruoyi.system.service.AssetMainService; -import com.ruoyi.system.service.AssetPropertyExtService; -import com.ruoyi.system.service.AssetTypeService; -import com.ruoyi.system.service.AssetVehicleExtService; +import com.ruoyi.system.query.ApprovalDetailQuery; +import com.ruoyi.system.query.OaApprovalApplicationStoragePageQuery; import com.ruoyi.system.service.AssetWarehouseService; -import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysUserService; +import com.ruoyi.system.service.OaApprovalApplicationStorageAssetPropertyExtService; +import com.ruoyi.system.service.OaApprovalApplicationStorageAssetService; +import com.ruoyi.system.service.OaApprovalApplicationStorageAssetVehicleExtService; import com.ruoyi.system.service.OaApprovalApplicationStorageService; import com.ruoyi.system.service.OaApprovalApplicationsService; 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.StorageListVO; 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; @@ -42,12 +42,13 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import java.math.BigDecimal; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -63,15 +64,11 @@ public class OaApprovalApplicationStorageServiceImpl extends ServiceImpl<OaApprovalApplicationStorageMapper, OaApprovalApplicationStorage> implements OaApprovalApplicationStorageService { private final OaApprovalApplicationsService oaApprovalApplicationsService; - private final AssetMainService assetMainService; - private final AssetGeneralExtService assetGeneralExtService; - private final AssetPropertyExtService assetPropertyExtService; - private final AssetVehicleExtService assetVehicleExtService; - private final AssetTypeService assetTypeService; + private final OaApprovalApplicationStorageAssetService oaApprovalApplicationStorageAssetService; + private final OaApprovalApplicationStorageAssetPropertyExtService oaApprovalApplicationStorageAssetPropertyExtService; + private final OaApprovalApplicationStorageAssetVehicleExtService oaApprovalApplicationStorageAssetVehicleExtService; private final OaApprovalFlowNodeService oaApprovalFlowNodeService; private final OaApprovalTodoService oaApprovalTodoService; - private final ISysUserService sysUserService; - private final ISysDeptService sysDeptService; private final TDeptService tDeptService; private final AssetWarehouseService assetWarehouseService; @@ -145,129 +142,99 @@ * 保存通用资产数据 */ 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<>(); - + List<OaApprovalApplicationStorageAsset> storageAssets = new ArrayList<>(); + for (OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item : assetItems) { // 根据数量创建对应数量的资产记录 - int quantity = item.getQuantity().intValue(); - for (int i = 0; i < quantity; i++) { - AssetMain assetMain = buildAssetMain(item, applicationId, assetTypeId, storageDate, baseDto); - assetMain.setAssetMainType(AssetTypeEnum.GENERAL.getCode()); - assetMain.setQuantity(BigDecimal.ONE); // 每个资产记录数量为1 - assetMain.setTotalValue(item.getUnitPrice()); // 总价值等于单价 - allAssetMains.add(assetMain); - } + OaApprovalApplicationStorageAsset assetMain = buildAssetMain(item, applicationId, assetTypeId, storageDate, baseDto); + assetMain.setAssetMainType(AssetTypeEnum.GENERAL.getCode()); + storageAssets.add(assetMain); } - // 批量保存资产主表数据 - 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); + oaApprovalApplicationStorageAssetService.saveBatch(storageAssets); } /** * 保存房产资产数据 */ private void savePropertyAssets(List<OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO> assetItems, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStoragePropertyDTO baseDto) { - List<AssetMain> allAssetMains = new ArrayList<>(); - List<AssetPropertyExt> allPropertyExts = new ArrayList<>(); + List<OaApprovalApplicationStorageAsset> allAssetMains = new ArrayList<>(); + List<OaApprovalApplicationStorageAssetPropertyExt> allPropertyExts = new ArrayList<>(); for (OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item : assetItems) { - // 根据数量创建对应数量的资产记录 - int quantity = item.getQuantity().intValue(); - for (int i = 0; i < quantity; i++) { - AssetMain assetMain = buildAssetMainFromProperty(item, applicationId, assetTypeId, storageDate, baseDto); - assetMain.setAssetMainType(AssetTypeEnum.HOUSE.getCode()); - assetMain.setQuantity(BigDecimal.ONE); // 每个资产记录数量为1 - assetMain.setTotalValue(item.getUnitPrice()); // 总价值等于单价 - allAssetMains.add(assetMain); - } + OaApprovalApplicationStorageAsset assetMain = buildAssetMainFromProperty(item, applicationId, assetTypeId, storageDate, baseDto); + assetMain.setAssetMainType(AssetTypeEnum.HOUSE.getCode()); + allAssetMains.add(assetMain); } // 批量保存资产主表数据 - assetMainService.saveBatch(allAssetMains); + oaApprovalApplicationStorageAssetService.saveBatch(allAssetMains); // 为每个资产主表记录创建对应的扩展信息 - int assetMainIndex = 0; - for (OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item : assetItems) { - int quantity = item.getQuantity().intValue(); - for (int i = 0; i < quantity; i++) { - AssetPropertyExt propertyExt = buildAssetPropertyExt(item, allAssetMains.get(assetMainIndex).getId()); + for (OaApprovalApplicationStorageAsset allAssetMain : allAssetMains) { + for (OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item : assetItems) { + OaApprovalApplicationStorageAssetPropertyExt propertyExt = buildAssetPropertyExt(item, allAssetMain.getId()); allPropertyExts.add(propertyExt); - assetMainIndex++; } } - - assetPropertyExtService.saveBatch(allPropertyExts); + oaApprovalApplicationStorageAssetPropertyExtService.saveBatch(allPropertyExts); } /** * 保存车辆资产数据 */ private void saveVehicleAssets(List<OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO> assetItems, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStorageVehicleDTO baseDto) { - List<AssetMain> allAssetMains = new ArrayList<>(); - List<AssetVehicleExt> allVehicleExts = new ArrayList<>(); - + List<OaApprovalApplicationStorageAsset> allAssetMains = new ArrayList<>(); + List<OaApprovalApplicationStorageAssetVehicleExt> allVehicleExts = new ArrayList<>(); + for (OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item : assetItems) { - // 根据数量创建对应数量的资产记录 - int quantity = item.getQuantity().intValue(); - for (int i = 0; i < quantity; i++) { - AssetMain assetMain = buildAssetMainFromVehicle(item, applicationId, assetTypeId, storageDate, baseDto); - assetMain.setAssetMainType(AssetTypeEnum.VEHICLE.getCode()); - assetMain.setQuantity(BigDecimal.ONE); // 每个资产记录数量为1 - assetMain.setTotalValue(item.getUnitPrice()); // 总价值等于单价 - allAssetMains.add(assetMain); - } + OaApprovalApplicationStorageAsset assetMain = buildAssetMainFromVehicle(item, applicationId, assetTypeId, storageDate, baseDto); + assetMain.setAssetMainType(AssetTypeEnum.VEHICLE.getCode()); + allAssetMains.add(assetMain); } // 批量保存资产主表数据 - assetMainService.saveBatch(allAssetMains); + oaApprovalApplicationStorageAssetService.saveBatch(allAssetMains); // 为每个资产主表记录创建对应的扩展信息 - int assetMainIndex = 0; - for (OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item : assetItems) { - int quantity = item.getQuantity().intValue(); - for (int i = 0; i < quantity; i++) { - AssetVehicleExt vehicleExt = buildAssetVehicleExt(item, allAssetMains.get(assetMainIndex).getId()); + for (OaApprovalApplicationStorageAsset allAssetMain : allAssetMains) { + for (OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item : assetItems) { + OaApprovalApplicationStorageAssetVehicleExt vehicleExt = buildAssetVehicleExt(item, allAssetMain.getId()); allVehicleExts.add(vehicleExt); - assetMainIndex++; } + } - - assetVehicleExtService.saveBatch(allVehicleExts); + oaApprovalApplicationStorageAssetVehicleExtService.saveBatch(allVehicleExts); } /** * 构建通用资产主表数据 */ - private AssetMain buildAssetMain(OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStorageGeneralDTO baseDto) { - AssetMain assetMain = new AssetMain(); + private OaApprovalApplicationStorageAsset buildAssetMain(OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStorageGeneralDTO baseDto) { + OaApprovalApplicationStorageAsset assetMain = new OaApprovalApplicationStorageAsset(); assetMain.setApprovalApplicationId(applicationId.intValue()); 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()); - assetMain.setAssetMainType(baseDto.getAddressType()); + applyAddressToAssetMain(assetMain, item.getAddressType(), item.getUseDeptName(), item.getWarehouseName(), item.getAddress()); + assetMain.setAddressType(item.getAddressType()); + assetMain.setAssetMainType(AssetTypeEnum.GENERAL.getCode()); assetMain.setAssetStatus(item.getAssetStatus()); assetMain.setRemarks(item.getRemarks()); assetMain.setAccountingStatus(item.getAccountingStatus()); @@ -282,21 +249,29 @@ /** * 构建房产资产主表数据 */ - private AssetMain buildAssetMainFromProperty(OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStoragePropertyDTO baseDto) { - AssetMain assetMain = new AssetMain(); + private OaApprovalApplicationStorageAsset buildAssetMainFromProperty(OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStoragePropertyDTO baseDto) { + OaApprovalApplicationStorageAsset assetMain = new OaApprovalApplicationStorageAsset(); assetMain.setApprovalApplicationId(applicationId.intValue()); 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()); + applyAddressToAssetMain(assetMain, item.getAddressType(), item.getUseDeptName(), item.getWarehouseName(), item.getAddress()); + assetMain.setAddressType(item.getAddressType()); + assetMain.setAssetMainType(AssetTypeEnum.HOUSE.getCode()); assetMain.setAssetStatus(item.getAssetStatus()); assetMain.setRemarks(item.getRemarks()); assetMain.setAccountingStatus(item.getAccountingStatus()); @@ -311,21 +286,29 @@ /** * 构建车辆资产主表数据 */ - private AssetMain buildAssetMainFromVehicle(OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStorageVehicleDTO baseDto) { - AssetMain assetMain = new AssetMain(); + private OaApprovalApplicationStorageAsset buildAssetMainFromVehicle(OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate, OaApprovalApplicationStorageVehicleDTO baseDto) { + OaApprovalApplicationStorageAsset assetMain = new OaApprovalApplicationStorageAsset(); assetMain.setApprovalApplicationId(applicationId.intValue()); 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()); + applyAddressToAssetMain(assetMain, item.getAddressType(), item.getUseDeptName(), item.getWarehouseName(), item.getAddress()); + assetMain.setAddressType(item.getAddressType()); + assetMain.setAssetMainType(AssetTypeEnum.VEHICLE.getCode()); assetMain.setAssetStatus(item.getAssetStatus()); assetMain.setRemarks(item.getRemarks()); assetMain.setAccountingStatus(item.getAccountingStatus()); @@ -340,7 +323,7 @@ /** * 按整单地址类型设置资产主表位置信息(使用部门ID或仓库ID或地址) */ - private void applyAddressToAssetMain(AssetMain assetMain, Integer addressType, String useDeptName, String warehouseName, String address) { + private void applyAddressToAssetMain(OaApprovalApplicationStorageAsset assetMain, Integer addressType, String useDeptName, String warehouseName, String address) { if (addressType == null) { return; } @@ -377,32 +360,14 @@ } } - /** - * 构建通用资产扩展数据 - */ - 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; - } + /** * 构建房产资产扩展数据 */ - private AssetPropertyExt buildAssetPropertyExt(OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item, Integer assetMainId) { - AssetPropertyExt propertyExt = new AssetPropertyExt(); - propertyExt.setAssetMainId(assetMainId); + private OaApprovalApplicationStorageAssetPropertyExt buildAssetPropertyExt(OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item, Integer assetMainId) { + OaApprovalApplicationStorageAssetPropertyExt propertyExt = new OaApprovalApplicationStorageAssetPropertyExt(); + propertyExt.setStorageAssetId(assetMainId); propertyExt.setRegion(item.getRegion()); propertyExt.setDesignPurpose(item.getDesignPurpose()); propertyExt.setBuilding(item.getBuilding()); @@ -414,7 +379,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()); @@ -426,9 +391,9 @@ /** * 构建车辆资产扩展数据 */ - private AssetVehicleExt buildAssetVehicleExt(OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item, Integer assetMainId) { - AssetVehicleExt vehicleExt = new AssetVehicleExt(); - vehicleExt.setAssetMainId(assetMainId); + private OaApprovalApplicationStorageAssetVehicleExt buildAssetVehicleExt(OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item, Integer assetMainId) { + OaApprovalApplicationStorageAssetVehicleExt vehicleExt = new OaApprovalApplicationStorageAssetVehicleExt(); + vehicleExt.setStorageAssetId(assetMainId); vehicleExt.setLicensePlate(item.getLicensePlate()); vehicleExt.setVinCode(item.getVinCode()); vehicleExt.setEngineNumber(item.getEngineNumber()); @@ -472,7 +437,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 +446,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 +455,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()); } @@ -551,33 +516,8 @@ return prefix + sequenceStr; } - /** - * 生成资产编码 - * 格式:资产类型一级分类简写+资产类型子类简写+入库日期+【-】+数量顺序编号(4位) - * 例如:GDFC20250917-0001 - */ - private String generateAssetCode(Integer assetTypeId, LocalDate storageDate) { - // 根据资产类型ID获取资产编码前缀 - String typeCodePrefix = assetTypeService.getAssetCodePrefix(assetTypeId); - - String dateStr = storageDate.format(DateTimeFormatter.ofPattern("yyyyMMdd")); - String prefix = typeCodePrefix + dateStr + "-"; - - // 查询当天该类型资产的数量 - Long count = assetMainService.lambdaQuery() - .like(AssetMain::getAssetCode, prefix) - .ge(AssetMain::getCreateTime, storageDate.atStartOfDay()) - .lt(AssetMain::getCreateTime, storageDate.plusDays(1).atStartOfDay()) - .count(); - - int sequence = (count != null ? count.intValue() : 0) + 1; - String sequenceStr = String.format("%04d", sequence); - - return prefix + sequenceStr; - } - @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); } @@ -596,47 +536,38 @@ OaApprovalApplicationStorageGeneralDetailVO vo = new OaApprovalApplicationStorageGeneralDetailVO(); fillBaseFields(vo, app, storage); - List<AssetMain> mains = assetMainService.lambdaQuery() - .eq(AssetMain::getApprovalApplicationId, app.getId()) - .eq(AssetMain::getAssetTypeId, storage.getAssetTypeId()) + List<OaApprovalApplicationStorageAsset> mains = oaApprovalApplicationStorageAssetService.lambdaQuery() + .eq(OaApprovalApplicationStorageAsset::getApprovalApplicationId, app.getId()) + .eq(OaApprovalApplicationStorageAsset::getAssetTypeId, storage.getAssetTypeId()) .list(); - setAddressInfo(vo, mains); - 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(OaApprovalApplicationStorageAsset::getOwnershipDeptId) + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + Map<Integer, TDept> ownerDeptMap = ownerIds.isEmpty() ? Collections.emptyMap() + : tDeptService.listByIds(ownerIds).stream().collect(Collectors.toMap(TDept::getId, d -> d)); + // 批量查询使用部门 + List<Integer> useDeptIds = mains.stream().map(OaApprovalApplicationStorageAsset::getUseDeptId) + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + Map<Integer, TDept> useDeptMap = ownerIds.isEmpty() ? Collections.emptyMap() + : tDeptService.listByIds(useDeptIds).stream().collect(Collectors.toMap(TDept::getId, d -> d)); + // 批量查询仓库 + List<Integer> warehouseIds = mains.stream().map(OaApprovalApplicationStorageAsset::getWarehouseId) + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + Map<Integer, AssetWarehouse> warehouseMap = warehouseIds.isEmpty() ? Collections.emptyMap() + : assetWarehouseService.listByIds(useDeptIds).stream().collect(Collectors.toMap(AssetWarehouse::getId, d -> d)); List<OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO> items = mains.stream().map(m -> { - OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO item = new OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO(); - item.setAssetOriginalCode(m.getAssetOriginalCode()); - item.setAssetName(m.getAssetName()); - item.setSpecificationModel(m.getSpecificationModel()); - item.setMeasurementUnit(m.getMeasurementUnit()); - item.setQuantity(m.getQuantity()); - item.setUnitPrice(m.getUnitPrice()); - item.setUsefulLife(m.getUsefulLife()); - item.setOwnershipDeptId(m.getOwnershipDeptId()); - item.setUserName(m.getUserName()); - item.setAssetStatus(m.getAssetStatus()); - item.setRemarks(m.getRemarks()); - item.setAccountingStatus(m.getAccountingStatus()); - item.setAccountingDate(m.getAccountingDate()); - 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()); + OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO item = BeanUtil.copyProperties(m, OaApprovalApplicationStorageGeneralDetailVO.GeneralAssetItemVO.class); + if (m.getOwnershipDeptId() != null) { + TDept dept = ownerDeptMap.get(m.getOwnershipDeptId()); + item.setOwnerShipDeptName(dept != null ? dept.getDeptName() : null); + } + if (m.getAddressType().equals(0) && m.getUseDeptId() != null) { + TDept dept = useDeptMap.get(m.getUseDeptId()); + item.setUseDeptName(dept != null ? dept.getDeptName() : null); + } else if (m.getAddressType().equals(1) && m.getWarehouseId() != null){ + AssetWarehouse assetWarehouse = warehouseMap.get(m.getWarehouseId()); + item.setWarehouseName(assetWarehouse != null ? assetWarehouse.getWarehouseName() : null); } return item; }).collect(Collectors.toList()); @@ -659,36 +590,45 @@ OaApprovalApplicationStoragePropertyDetailVO vo = new OaApprovalApplicationStoragePropertyDetailVO(); fillBaseFields(vo, app, storage); - List<AssetMain> mains = assetMainService.lambdaQuery() - .eq(AssetMain::getApprovalApplicationId, app.getId()) - .eq(AssetMain::getAssetTypeId, storage.getAssetTypeId()) + List<OaApprovalApplicationStorageAsset> mains = oaApprovalApplicationStorageAssetService.lambdaQuery() + .eq(OaApprovalApplicationStorageAsset::getApprovalApplicationId, app.getId()) + .eq(OaApprovalApplicationStorageAsset::getAssetTypeId, storage.getAssetTypeId()) .list(); - setAddressInfo(vo, mains); if (!CollectionUtils.isEmpty(mains)) { - 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> mainIds = mains.stream().map(OaApprovalApplicationStorageAsset::getId).collect(Collectors.toList()); + List<OaApprovalApplicationStorageAssetPropertyExt> exts = oaApprovalApplicationStorageAssetPropertyExtService.lambdaQuery().in(OaApprovalApplicationStorageAssetPropertyExt::getStorageAssetId, mainIds).list(); + Map<Integer, OaApprovalApplicationStorageAssetPropertyExt> extMap = exts.stream().collect(Collectors.toMap(OaApprovalApplicationStorageAssetPropertyExt::getStorageAssetId, e -> e)); + // 批量查询权属部门 + List<Integer> ownerIds = mains.stream().map(OaApprovalApplicationStorageAsset::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<Integer> useDeptIds = mains.stream().map(OaApprovalApplicationStorageAsset::getUseDeptId) + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + Map<Integer, TDept> useDeptMap = ownerIds.isEmpty() ? Collections.emptyMap() + : tDeptService.listByIds(useDeptIds).stream().collect(Collectors.toMap(TDept::getId, d -> d)); + // 批量查询仓库 + List<Integer> warehouseIds = mains.stream().map(OaApprovalApplicationStorageAsset::getWarehouseId) + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + Map<Integer, AssetWarehouse> warehouseMap = warehouseIds.isEmpty() ? Collections.emptyMap() + : assetWarehouseService.listByIds(useDeptIds).stream().collect(Collectors.toMap(AssetWarehouse::getId, d -> d)); List<OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO> items = mains.stream().map(m -> { - OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO item = new OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO(); - item.setAssetOriginalCode(m.getAssetOriginalCode()); - item.setAssetName(m.getAssetName()); - item.setSpecificationModel(m.getSpecificationModel()); - item.setMeasurementUnit(m.getMeasurementUnit()); - item.setQuantity(m.getQuantity()); - item.setUnitPrice(m.getUnitPrice()); - item.setUsefulLife(m.getUsefulLife()); - item.setOwnershipDeptId(m.getOwnershipDeptId()); - item.setUserName(m.getUserName()); - item.setAssetStatus(m.getAssetStatus()); - item.setRemarks(m.getRemarks()); - item.setAccountingStatus(m.getAccountingStatus()); - item.setAccountingDate(m.getAccountingDate()); - item.setAccountingVoucherNo(m.getAccountingVoucherNo()); - item.setAccountingSubject(m.getAccountingSubject()); - item.setAccountingAmount(m.getAccountingAmount()); - AssetPropertyExt ext = extMap.get(m.getId()); + OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO item = BeanUtil.copyProperties(m, OaApprovalApplicationStoragePropertyDetailVO.PropertyAssetItemVO.class); + if (m.getOwnershipDeptId() != null) { + TDept dept = ownerDeptMap.get(m.getOwnershipDeptId()); + item.setOwnerShipDeptName(dept != null ? dept.getDeptName() : null); + } + if (m.getAddressType().equals(0) && m.getUseDeptId() != null) { + TDept dept = useDeptMap.get(m.getUseDeptId()); + item.setUseDeptName(dept != null ? dept.getDeptName() : null); + } else if (m.getAddressType().equals(1) && m.getWarehouseId() != null){ + AssetWarehouse assetWarehouse = warehouseMap.get(m.getWarehouseId()); + item.setWarehouseName(assetWarehouse != null ? assetWarehouse.getWarehouseName() : null); + } + OaApprovalApplicationStorageAssetPropertyExt ext = extMap.get(m.getId()); if (ext != null) { item.setRegion(ext.getRegion()); item.setDesignPurpose(ext.getDesignPurpose()); @@ -701,7 +641,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()); @@ -728,36 +668,44 @@ OaApprovalApplicationStorageVehicleDetailVO vo = new OaApprovalApplicationStorageVehicleDetailVO(); fillBaseFields(vo, app, storage); - List<AssetMain> mains = assetMainService.lambdaQuery() - .eq(AssetMain::getApprovalApplicationId, app.getId()) - .eq(AssetMain::getAssetTypeId, storage.getAssetTypeId()) + List<OaApprovalApplicationStorageAsset> mains = oaApprovalApplicationStorageAssetService.lambdaQuery() + .eq(OaApprovalApplicationStorageAsset::getApprovalApplicationId, app.getId()) + .eq(OaApprovalApplicationStorageAsset::getAssetTypeId, storage.getAssetTypeId()) .list(); - setAddressInfo(vo, mains); if (!CollectionUtils.isEmpty(mains)) { - 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> mainIds = mains.stream().map(OaApprovalApplicationStorageAsset::getId).collect(Collectors.toList()); + List<OaApprovalApplicationStorageAssetVehicleExt> exts = oaApprovalApplicationStorageAssetVehicleExtService.lambdaQuery().in(OaApprovalApplicationStorageAssetVehicleExt::getStorageAssetId, mainIds).list(); + Map<Integer, OaApprovalApplicationStorageAssetVehicleExt> extMap = exts.stream().collect(Collectors.toMap(OaApprovalApplicationStorageAssetVehicleExt::getStorageAssetId, e -> e)); + // 批量查询权属部门 + List<Integer> ownerIds = mains.stream().map(OaApprovalApplicationStorageAsset::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<Integer> useDeptIds = mains.stream().map(OaApprovalApplicationStorageAsset::getUseDeptId) + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + Map<Integer, TDept> useDeptMap = ownerIds.isEmpty() ? Collections.emptyMap() + : tDeptService.listByIds(useDeptIds).stream().collect(Collectors.toMap(TDept::getId, d -> d)); + // 批量查询仓库 + List<Integer> warehouseIds = mains.stream().map(OaApprovalApplicationStorageAsset::getWarehouseId) + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + Map<Integer, AssetWarehouse> warehouseMap = warehouseIds.isEmpty() ? Collections.emptyMap() + : assetWarehouseService.listByIds(useDeptIds).stream().collect(Collectors.toMap(AssetWarehouse::getId, d -> d)); List<OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO> items = mains.stream().map(m -> { - OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO item = new OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO(); - item.setAssetOriginalCode(m.getAssetOriginalCode()); - item.setAssetName(m.getAssetName()); - item.setSpecificationModel(m.getSpecificationModel()); - item.setMeasurementUnit(m.getMeasurementUnit()); - item.setQuantity(m.getQuantity()); - item.setUnitPrice(m.getUnitPrice()); - item.setUsefulLife(m.getUsefulLife()); - item.setOwnershipDeptId(m.getOwnershipDeptId()); - item.setUserName(m.getUserName()); - item.setAssetStatus(m.getAssetStatus()); - item.setRemarks(m.getRemarks()); - item.setAccountingStatus(m.getAccountingStatus()); - item.setAccountingDate(m.getAccountingDate()); - item.setAccountingVoucherNo(m.getAccountingVoucherNo()); - item.setAccountingSubject(m.getAccountingSubject()); - item.setAccountingAmount(m.getAccountingAmount()); - AssetVehicleExt ext = extMap.get(m.getId()); + OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO item = BeanUtil.copyProperties(m, OaApprovalApplicationStorageVehicleDetailVO.VehicleAssetItemVO.class); + if (m.getOwnershipDeptId() != null) { + TDept dept = ownerDeptMap.get(m.getOwnershipDeptId()); + item.setOwnerShipDeptName(dept != null ? dept.getDeptName() : null); + } + if (m.getAddressType().equals(0) && m.getUseDeptId() != null) { + TDept dept = useDeptMap.get(m.getUseDeptId()); + item.setUseDeptName(dept != null ? dept.getDeptName() : null); + } else if (m.getAddressType().equals(1) && m.getWarehouseId() != null){ + AssetWarehouse assetWarehouse = warehouseMap.get(m.getWarehouseId()); + item.setWarehouseName(assetWarehouse != null ? assetWarehouse.getWarehouseName() : null); + } + OaApprovalApplicationStorageAssetVehicleExt ext = extMap.get(m.getId()); if (ext != null) { item.setLicensePlate(ext.getLicensePlate()); item.setVinCode(ext.getVinCode()); @@ -818,46 +766,11 @@ } } - private void setAddressInfo(Object vo, List<AssetMain> mains) { - if (CollectionUtils.isEmpty(mains)) { - return; - } - AssetMain sample = mains.get(0); - Integer addressType = null; - String useDeptName = null; - String warehouseName = null; - String address = null; - if (sample.getUseDeptId() != null) { - addressType = 0; - TDept dept = tDeptService.getById(sample.getUseDeptId()); - useDeptName = dept != null ? dept.getDeptName() : null; - } else if (sample.getWarehouseId() != null) { - addressType = 1; - AssetWarehouse wh = assetWarehouseService.getById(sample.getWarehouseId()); - warehouseName = wh != null ? wh.getWarehouseName() : null; - } else if (sample.getAddress() != null && !sample.getAddress().isEmpty()) { - addressType = 2; - address = sample.getAddress(); - } - - if (vo instanceof OaApprovalApplicationStorageGeneralDetailVO) { - OaApprovalApplicationStorageGeneralDetailVO v = (OaApprovalApplicationStorageGeneralDetailVO) vo; - v.setAddressType(addressType); - v.setUseDeptName(useDeptName); - v.setWarehouseName(warehouseName); - v.setAddress(address); - } else if (vo instanceof OaApprovalApplicationStoragePropertyDetailVO) { - OaApprovalApplicationStoragePropertyDetailVO v = (OaApprovalApplicationStoragePropertyDetailVO) vo; - v.setAddressType(addressType); - v.setUseDeptName(useDeptName); - v.setWarehouseName(warehouseName); - v.setAddress(address); - } else if (vo instanceof OaApprovalApplicationStorageVehicleDetailVO) { - OaApprovalApplicationStorageVehicleDetailVO v = (OaApprovalApplicationStorageVehicleDetailVO) vo; - v.setAddressType(addressType); - v.setUseDeptName(useDeptName); - v.setWarehouseName(warehouseName); - v.setAddress(address); - } + @Override + public PageInfo<StorageListVO> pageList(ApprovalDetailQuery query) { + PageInfo<StorageListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); + List<StorageListVO> list = this.baseMapper.pageList(query,pageInfo); + pageInfo.setRecords(list); + return pageInfo; } } -- Gitblit v1.7.1