mitao
22 小时以前 0146a1483a3368f75daa6eb03aa42c714943e6b2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OaApprovalApplicationStorageServiceImpl.java
@@ -1,10 +1,33 @@
package com.ruoyi.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
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.emums.ApprovalStatusEnum;
import com.ruoyi.system.emums.ApprovalTypeEnum;
import com.ruoyi.system.emums.AssetTypeEnum;
import com.ruoyi.system.mapper.OaApprovalApplicationStorageMapper;
import com.ruoyi.system.model.OaApprovalApplicationStorage;
import com.ruoyi.system.service.OaApprovalApplicationStorageService;
import com.ruoyi.system.model.*;
import com.ruoyi.system.service.*;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
 * <p>
@@ -15,6 +38,596 @@
 * @since 2025-09-15
 */
@Service
@RequiredArgsConstructor
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 OaApprovalFlowNodeService oaApprovalFlowNodeService;
    private final OaApprovalTodoService oaApprovalTodoService;
    private final ISysUserService sysUserService;
    private final ISysDeptService sysDeptService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void submitGeneralAssetStorage(OaApprovalApplicationStorageGeneralDTO dto) {
        // 1. 保存审批申请主表数据
        OaApprovalApplications applications = buildOaApprovalApplications(dto);
        // 2. 获取流程节点并创建待办
        OaApprovalFlowNode firstFlowNode = getFirstFlowNode(ApprovalTypeEnum.IN_STOCK.getCode());
        applications.setCurrentFlowNodeId(firstFlowNode.getId());
        oaApprovalApplicationsService.save(applications);
        // 3. 创建待办事项记录
        createApprovalTodo(applications.getId(), applications.getApplicationCode(), firstFlowNode, dto.getDeptId());
        // 4. 保存资产入库申请明细数据
        OaApprovalApplicationStorage storage = buildOaApprovalApplicationStorage(dto, applications.getId());
        save(storage);
        // 5. 保存通用资产数据
        saveGeneralAssets(dto.getAssetItems(), applications.getId(), dto.getAssetTypeId(), dto.getStorageTime());
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void submitPropertyAssetStorage(OaApprovalApplicationStoragePropertyDTO dto) {
        // 1. 保存审批申请主表数据
        OaApprovalApplications applications = buildOaApprovalApplications(dto);
        // 2. 获取流程节点并创建待办
        OaApprovalFlowNode firstFlowNode = getFirstFlowNode(ApprovalTypeEnum.IN_STOCK.getCode());
        applications.setCurrentFlowNodeId(firstFlowNode.getId());
        oaApprovalApplicationsService.save(applications);
        // 3. 创建待办事项记录
        createApprovalTodo(applications.getId(), applications.getApplicationCode(), firstFlowNode, dto.getDeptId());
        // 4. 保存资产入库申请明细数据
        OaApprovalApplicationStorage storage = buildOaApprovalApplicationStorage(dto, applications.getId());
        save(storage);
        // 5. 保存房产资产数据
        savePropertyAssets(dto.getAssetItems(), applications.getId(), dto.getAssetTypeId(), dto.getStorageTime());
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void submitVehicleAssetStorage(OaApprovalApplicationStorageVehicleDTO dto) {
        // 1. 保存审批申请主表数据
        OaApprovalApplications applications = buildOaApprovalApplications(dto);
        // 2. 获取流程节点并创建待办
        OaApprovalFlowNode firstFlowNode = getFirstFlowNode(ApprovalTypeEnum.IN_STOCK.getCode());
        applications.setCurrentFlowNodeId(firstFlowNode.getId());
        oaApprovalApplicationsService.save(applications);
        // 3. 创建待办事项记录
        createApprovalTodo(applications.getId(), applications.getApplicationCode(), firstFlowNode, dto.getDeptId());
        // 4. 保存资产入库申请明细数据
        OaApprovalApplicationStorage storage = buildOaApprovalApplicationStorage(dto, applications.getId());
        save(storage);
        // 5. 保存车辆资产数据
        saveVehicleAssets(dto.getAssetItems(), applications.getId(), dto.getAssetTypeId(), dto.getStorageTime());
    }
    /**
     * 保存通用资产数据
     */
    private void saveGeneralAssets(List<OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO> assetItems, Integer applicationId, Integer assetTypeId, LocalDate storageDate) {
        List<AssetMain> allAssetMains = new ArrayList<>();
        List<AssetGeneralExt> allGeneralExts = 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);
                assetMain.setAssetMainType(AssetTypeEnum.GENERAL.getCode());
                assetMain.setQuantity(BigDecimal.ONE); // 每个资产记录数量为1
                assetMain.setTotalValue(item.getUnitPrice()); // 总价值等于单价
                allAssetMains.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);
    }
    /**
     * 保存房产资产数据
     */
    private void savePropertyAssets(List<OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO> assetItems, Integer applicationId, Integer assetTypeId, LocalDate storageDate) {
        List<AssetMain> allAssetMains = new ArrayList<>();
        List<AssetPropertyExt> 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);
                assetMain.setAssetMainType(AssetTypeEnum.HOUSE.getCode());
                assetMain.setQuantity(BigDecimal.ONE); // 每个资产记录数量为1
                assetMain.setTotalValue(item.getUnitPrice()); // 总价值等于单价
                allAssetMains.add(assetMain);
            }
        }
        // 批量保存资产主表数据
        assetMainService.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());
                allPropertyExts.add(propertyExt);
                assetMainIndex++;
            }
        }
        assetPropertyExtService.saveBatch(allPropertyExts);
    }
    /**
     * 保存车辆资产数据
     */
    private void saveVehicleAssets(List<OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO> assetItems, Integer applicationId, Integer assetTypeId, LocalDate storageDate) {
        List<AssetMain> allAssetMains = new ArrayList<>();
        List<AssetVehicleExt> 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);
                assetMain.setAssetMainType(AssetTypeEnum.VEHICLE.getCode());
                assetMain.setQuantity(BigDecimal.ONE); // 每个资产记录数量为1
                assetMain.setTotalValue(item.getUnitPrice()); // 总价值等于单价
                allAssetMains.add(assetMain);
            }
        }
        // 批量保存资产主表数据
        assetMainService.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());
                allVehicleExts.add(vehicleExt);
                assetMainIndex++;
            }
        }
        assetVehicleExtService.saveBatch(allVehicleExts);
    }
    /**
     * 构建通用资产主表数据
     */
    private AssetMain buildAssetMain(OaApprovalApplicationStorageGeneralDTO.GeneralAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate) {
        AssetMain assetMain = new AssetMain();
        assetMain.setApprovalApplicationId(applicationId.intValue());
        assetMain.setAssetOriginalCode(item.getAssetOriginalCode());
        assetMain.setAssetCode(generateAssetCode(assetTypeId, storageDate)); // 系统生成资产编码
        assetMain.setAssetName(item.getAssetName());
        assetMain.setSpecificationModel(item.getSpecificationModel());
        assetMain.setAssetTypeId(assetTypeId);
        assetMain.setMeasurementUnit(item.getMeasurementUnit());
        assetMain.setUnitPrice(item.getUnitPrice());
        assetMain.setUsefulLife(item.getUsefulLife());
        assetMain.setOwnershipDeptId(item.getOwnershipDeptId());
        assetMain.setUserName(item.getUserName());
        assetMain.setUseDeptId(item.getUseDeptId());
        assetMain.setWarehouseId(item.getWarehouseId());
        assetMain.setWarehouseName(item.getWarehouseName());
        assetMain.setAddress(item.getAddress());
        assetMain.setAssetStatus(item.getAssetStatus());
        assetMain.setRemarks(item.getRemarks());
        assetMain.setAccountingStatus(item.getAccountingStatus());
        assetMain.setAccountingDate(item.getAccountingDate());
        assetMain.setAccountingVoucherNo(item.getAccountingVoucherNo());
        assetMain.setAccountingSubject(item.getAccountingSubject());
        assetMain.setAccountingAmount(item.getAccountingAmount());
        assetMain.setDisabled(false);
        return assetMain;
    }
    /**
     * 构建房产资产主表数据
     */
    private AssetMain buildAssetMainFromProperty(OaApprovalApplicationStoragePropertyDTO.PropertyAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate) {
        AssetMain assetMain = new AssetMain();
        assetMain.setApprovalApplicationId(applicationId.intValue());
        assetMain.setAssetOriginalCode(item.getAssetOriginalCode());
        assetMain.setAssetCode(generateAssetCode(assetTypeId, storageDate));
        assetMain.setAssetName(item.getAssetName());
        assetMain.setSpecificationModel(item.getSpecificationModel());
        assetMain.setAssetTypeId(assetTypeId);
        assetMain.setMeasurementUnit(item.getMeasurementUnit());
        assetMain.setUnitPrice(item.getUnitPrice());
        assetMain.setUsefulLife(item.getUsefulLife());
        assetMain.setOwnershipDeptId(item.getOwnershipDeptId());
        assetMain.setUserName(item.getUserName());
        assetMain.setUseDeptId(item.getUseDeptId());
        assetMain.setWarehouseId(item.getWarehouseId());
        assetMain.setWarehouseName(item.getWarehouseName());
        assetMain.setAddress(item.getAddress());
        assetMain.setAssetStatus(item.getAssetStatus());
        assetMain.setRemarks(item.getRemarks());
        assetMain.setAccountingStatus(item.getAccountingStatus());
        assetMain.setAccountingDate(item.getAccountingDate());
        assetMain.setAccountingVoucherNo(item.getAccountingVoucherNo());
        assetMain.setAccountingSubject(item.getAccountingSubject());
        assetMain.setAccountingAmount(item.getAccountingAmount());
        assetMain.setDisabled(false);
        return assetMain;
    }
    /**
     * 构建车辆资产主表数据
     */
    private AssetMain buildAssetMainFromVehicle(OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item, Integer applicationId, Integer assetTypeId, LocalDate storageDate) {
        AssetMain assetMain = new AssetMain();
        assetMain.setApprovalApplicationId(applicationId.intValue());
        assetMain.setAssetOriginalCode(item.getAssetOriginalCode());
        assetMain.setAssetCode(generateAssetCode(assetTypeId, storageDate));
        assetMain.setAssetName(item.getAssetName());
        assetMain.setSpecificationModel(item.getSpecificationModel());
        assetMain.setAssetTypeId(assetTypeId);
        assetMain.setMeasurementUnit(item.getMeasurementUnit());
        assetMain.setUnitPrice(item.getUnitPrice());
        assetMain.setUsefulLife(item.getUsefulLife());
        assetMain.setOwnershipDeptId(item.getOwnershipDeptId());
        assetMain.setUserName(item.getUserName());
        assetMain.setUseDeptId(item.getUseDeptId());
        assetMain.setWarehouseId(item.getWarehouseId());
        assetMain.setWarehouseName(item.getWarehouseName());
        assetMain.setAddress(item.getAddress());
        assetMain.setAssetStatus(item.getAssetStatus());
        assetMain.setRemarks(item.getRemarks());
        assetMain.setAccountingStatus(item.getAccountingStatus());
        assetMain.setAccountingDate(item.getAccountingDate());
        assetMain.setAccountingVoucherNo(item.getAccountingVoucherNo());
        assetMain.setAccountingSubject(item.getAccountingSubject());
        assetMain.setAccountingAmount(item.getAccountingAmount());
        assetMain.setDisabled(false);
        return assetMain;
    }
    /**
     * 构建通用资产扩展数据
     */
    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);
        propertyExt.setRegion(item.getRegion());
        propertyExt.setDesignPurpose(item.getDesignPurpose());
        propertyExt.setBuilding(item.getBuilding());
        propertyExt.setRoomNumber(item.getRoomNumber());
        propertyExt.setConstructionArea(item.getConstructionArea());
        propertyExt.setStructureType(item.getStructureType());
        propertyExt.setCertificateNumber(item.getCertificateNumber());
        propertyExt.setCompletionDate(item.getCompletionDate());
        propertyExt.setDetailedLocation(item.getDetailedLocation());
        propertyExt.setProvincialPlatformValue(item.getProvincialPlatformValue());
        propertyExt.setResettlementSituation(item.getResettlementSituation());
        propertyExt.setIsMortgaged(item.getIsMortgaged());
        propertyExt.setTenantName(item.getTenantName());
        propertyExt.setRentalAmount(item.getRentalAmount());
        propertyExt.setLeaseStartDate(item.getLeaseStartDate());
        propertyExt.setLeaseEndDate(item.getLeaseEndDate());
        propertyExt.setDisabled(false);
        return propertyExt;
    }
    /**
     * 构建车辆资产扩展数据
     */
    private AssetVehicleExt buildAssetVehicleExt(OaApprovalApplicationStorageVehicleDTO.VehicleAssetItemDTO item, Integer assetMainId) {
        AssetVehicleExt vehicleExt = new AssetVehicleExt();
        vehicleExt.setAssetMainId(assetMainId);
        vehicleExt.setLicensePlate(item.getLicensePlate());
        vehicleExt.setVinCode(item.getVinCode());
        vehicleExt.setEngineNumber(item.getEngineNumber());
        vehicleExt.setDisplacement(item.getDisplacement());
        vehicleExt.setStaffingSituation(item.getStaffingSituation());
        vehicleExt.setOrigin(item.getOrigin());
        vehicleExt.setAcquisitionDate(item.getAcquisitionDate());
        vehicleExt.setPropertyRightForm(item.getPropertyRightForm());
        vehicleExt.setDisabled(false);
        return vehicleExt;
    }
    /**
     * 获取第一个流程节点
     */
    private OaApprovalFlowNode getFirstFlowNode(Integer approvalId) {
        List<OaApprovalFlowNode> flowNodes = oaApprovalFlowNodeService.lambdaQuery()
                .eq(OaApprovalFlowNode::getApprovalId, approvalId)
                .eq(OaApprovalFlowNode::getStatus, 1)
                .orderByAsc(OaApprovalFlowNode::getSortOrder)
                .list();
        if (CollectionUtils.isEmpty(flowNodes)) {
            throw new ServiceException("未找到有效的审批流程配置");
        }
        return flowNodes.get(0);
    }
    /**
     * 创建待办数据
     */
    private void createApprovalTodo(Integer applicationId, String applicationCode, OaApprovalFlowNode flowNode, Integer deptId) {
        Integer approvalType = flowNode.getApprovalType();
        if (approvalType == null) {
            throw new ServiceException("审批类型不能为空");
        }
        switch (approvalType) {
            case 0:
                createUpperDeptTodo(applicationId, applicationCode, flowNode, deptId);
                break;
            case 1:
                createSpecifiedDeptTodo(applicationId, applicationCode, flowNode);
                break;
            case 2:
                createSpecifiedUserTodo(applicationId, applicationCode, flowNode);
                break;
            default:
                throw new ServiceException("不支持的审批类型: " + approvalType);
        }
    }
    /**
     * 创建上级部门审批待办
     */
    private void createUpperDeptTodo(Integer applicationId, String applicationCode, OaApprovalFlowNode flowNode, Integer deptId) {
        if (deptId == null) {
            throw new ServiceException("未填写申请部门信息");
        }
        SysDept currentDept = sysDeptService.selectDeptById(Long.valueOf(deptId));
        if (currentDept == null) {
            throw new ServiceException("申请部门信息不存在");
        }
        if (currentDept.getParentId() == null || currentDept.getParentId() == 0) {
            throw new ServiceException("当前部门没有上级部门");
        }
        SysDept parentDept = sysDeptService.selectDeptById(currentDept.getParentId());
        if (parentDept == null) {
            throw new ServiceException("上级部门信息不存在");
        }
        List<SysUser> users = sysUserService.selectListByDeptId(parentDept.getDeptId().toString());
        if (CollUtil.isEmpty(users)) {
            throw new ServiceException("上级部门下没有找到用户");
        }
        createTodoItem(applicationId, applicationCode, flowNode, users);
    }
    /**
     * 创建指定部门审批待办
     */
    private void createSpecifiedDeptTodo(Integer applicationId, String applicationCode, OaApprovalFlowNode flowNode) {
        if (StringUtils.isBlank(flowNode.getApprovalIds())) {
            throw new ServiceException("操作失败,审批流程配置异常");
        }
        List<String> deptIdList = Arrays.stream(flowNode.getApprovalIds().split(",")).collect(Collectors.toList());
        List<SysUser> users = sysUserService.selectListByDeptIds(deptIdList);
        if (CollUtil.isEmpty(users)) {
            throw new ServiceException("指定部门下没有找到用户");
        }
        createTodoItem(applicationId, applicationCode, flowNode, users);
    }
    /**
     * 创建指定人员审批待办
     */
    private void createSpecifiedUserTodo(Integer applicationId, String applicationCode, OaApprovalFlowNode flowNode) {
        if (StringUtils.isBlank(flowNode.getApprovalIds())) {
            throw new ServiceException("操作失败,审批流程配置异常");
        }
        List<Integer> userIds = Arrays.stream(flowNode.getApprovalIds().split(","))
                .map(Integer::valueOf).collect(Collectors.toList());
        List<SysUser> users = sysUserService.selectListByUserIds(userIds);
        if (CollUtil.isEmpty(users)) {
            throw new ServiceException("没有找到指定审批用户");
        }
        createTodoItem(applicationId, applicationCode, flowNode, users);
    }
    /**
     * 创建待办数据项
     */
    private void createTodoItem(Integer applicationId, String applicationCode, OaApprovalFlowNode flowNode, List<SysUser> userList) {
        List<OaApprovalTodo> approvalTodoList = userList.stream().map(item -> {
            OaApprovalTodo todo = new OaApprovalTodo();
            todo.setApplicationId(applicationId);
            todo.setApplicationCode(applicationCode);
            todo.setFlowNodeId(flowNode.getId());
            todo.setUserId(item.getUserId().intValue());
            todo.setUserName(item.getNickName());
            if (item.getDeptId() != null) {
                todo.setDeptId(Integer.valueOf(item.getDeptId()));
            }
            todo.setSortOrder(flowNode.getSortOrder());
            todo.setStatus(0);
            todo.setCreateTime(LocalDateTime.now());
            return todo;
        }).collect(Collectors.toList());
        oaApprovalTodoService.saveBatch(approvalTodoList);
    }
    /**
     * 构建审批申请主表数据
     */
    private OaApprovalApplications buildOaApprovalApplications(Object dto) {
        OaApprovalApplications applications = new OaApprovalApplications();
        applications.setApprovalId(ApprovalTypeEnum.IN_STOCK.getCode());
        if (dto instanceof OaApprovalApplicationStorageGeneralDTO) {
            OaApprovalApplicationStorageGeneralDTO generalDTO = (OaApprovalApplicationStorageGeneralDTO) dto;
            applications.setApplicantUserId(generalDTO.getApplicantUserId());
            applications.setApplicantName(generalDTO.getApplicantName());
            applications.setDeptId(generalDTO.getDeptId());
            applications.setDeptName(generalDTO.getDeptName());
            applications.setApplicationDate(generalDTO.getApplicationDate());
            applications.setApplicationReason(generalDTO.getApplicationReason());
            applications.setAttachmentUrl(generalDTO.getAttachmentUrl());
        } else if (dto instanceof OaApprovalApplicationStoragePropertyDTO) {
            OaApprovalApplicationStoragePropertyDTO propertyDTO = (OaApprovalApplicationStoragePropertyDTO) dto;
            applications.setApplicantUserId(propertyDTO.getApplicantUserId());
            applications.setApplicantName(propertyDTO.getApplicantName());
            applications.setDeptId(propertyDTO.getDeptId());
            applications.setDeptName(propertyDTO.getDeptName());
            applications.setApplicationDate(propertyDTO.getApplicationDate());
            applications.setApplicationReason(propertyDTO.getApplicationReason());
            applications.setAttachmentUrl(propertyDTO.getAttachmentUrl());
        } else if (dto instanceof OaApprovalApplicationStorageVehicleDTO) {
            OaApprovalApplicationStorageVehicleDTO vehicleDTO = (OaApprovalApplicationStorageVehicleDTO) dto;
            applications.setApplicantUserId(vehicleDTO.getApplicantUserId());
            applications.setApplicantName(vehicleDTO.getApplicantName());
            applications.setDeptId(vehicleDTO.getDeptId());
            applications.setDeptName(vehicleDTO.getDeptName());
            applications.setApplicationDate(vehicleDTO.getApplicationDate());
            applications.setApplicationReason(vehicleDTO.getApplicationReason());
            applications.setAttachmentUrl(vehicleDTO.getAttachmentUrl());
        }
        applications.setApplicationCode(generateApplicationCode());
        applications.setDisabled(0);
        applications.setApprovalStatus(ApprovalStatusEnum.PENDING.getCode());
        return applications;
    }
    /**
     * 构建资产入库申请明细数据
     */
    private OaApprovalApplicationStorage buildOaApprovalApplicationStorage(Object dto, Integer applicationId) {
        OaApprovalApplicationStorage storage = new OaApprovalApplicationStorage();
        storage.setApprovalApplicationId(applicationId.intValue());
        if (dto instanceof OaApprovalApplicationStorageGeneralDTO) {
            OaApprovalApplicationStorageGeneralDTO generalDTO = (OaApprovalApplicationStorageGeneralDTO) dto;
            storage.setTitle(generalDTO.getTitle());
            storage.setAssetTypeId(generalDTO.getAssetTypeId());
            storage.setStorageType(generalDTO.getStorageType());
            storage.setStorageTime(generalDTO.getStorageTime());
        } else if (dto instanceof OaApprovalApplicationStoragePropertyDTO) {
            OaApprovalApplicationStoragePropertyDTO propertyDTO = (OaApprovalApplicationStoragePropertyDTO) dto;
            storage.setTitle(propertyDTO.getTitle());
            storage.setAssetTypeId(propertyDTO.getAssetTypeId());
            storage.setStorageType(propertyDTO.getStorageType());
            storage.setStorageTime(propertyDTO.getStorageTime());
        } else if (dto instanceof OaApprovalApplicationStorageVehicleDTO) {
            OaApprovalApplicationStorageVehicleDTO vehicleDTO = (OaApprovalApplicationStorageVehicleDTO) dto;
            storage.setTitle(vehicleDTO.getTitle());
            storage.setAssetTypeId(vehicleDTO.getAssetTypeId());
            storage.setStorageType(vehicleDTO.getStorageType());
            storage.setStorageTime(vehicleDTO.getStorageTime());
        }
        return storage;
    }
    /**
     * 生成申请单号
     * 格式:RK + 年月日 + 3位序号
     */
    private String generateApplicationCode() {
        String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String prefix = "RK" + dateStr;
        Long count = oaApprovalApplicationsService.lambdaQuery()
                .like(OaApprovalApplications::getApplicationCode, prefix)
                .ge(OaApprovalApplications::getCreateTime, LocalDate.now().atStartOfDay())
                .lt(OaApprovalApplications::getCreateTime, LocalDate.now().plusDays(1).atStartOfDay())
                .count();
        int sequence = (count != null ? count.intValue() : 0) + 1;
        String sequenceStr = String.format("%03d", sequence);
        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;
    }
}