|
|
|
|
@@ -3,14 +3,18 @@ package com.zt.plat.module.infra.service.businessfile;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import com.zt.plat.framework.common.pojo.PageResult;
|
|
|
|
|
import com.zt.plat.framework.common.util.object.BeanUtils;
|
|
|
|
|
import com.zt.plat.framework.common.util.user.UserNameEnrichUtils;
|
|
|
|
|
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
|
|
import com.zt.plat.module.infra.controller.admin.businessfile.vo.BusinessFilePageReqVO;
|
|
|
|
|
import com.zt.plat.module.infra.controller.admin.businessfile.vo.BusinessFileRespVO;
|
|
|
|
|
import com.zt.plat.module.infra.controller.admin.businessfile.vo.BusinessFileSaveReqVO;
|
|
|
|
|
import com.zt.plat.module.infra.controller.admin.businessfile.vo.BusinessFileWithUrlRespVO;
|
|
|
|
|
import com.zt.plat.module.infra.dal.dataobject.businessfile.BusinessFileDO;
|
|
|
|
|
import com.zt.plat.module.infra.dal.dataobject.file.FileDO;
|
|
|
|
|
import com.zt.plat.module.infra.dal.mysql.businessfile.BusinessFileMapper;
|
|
|
|
|
import com.zt.plat.module.infra.service.file.FileService;
|
|
|
|
|
import com.zt.plat.module.system.api.user.AdminUserApi;
|
|
|
|
|
import com.zt.plat.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
@@ -35,6 +39,9 @@ public class BusinessFileServiceImpl implements BusinessFileService {
|
|
|
|
|
@Resource
|
|
|
|
|
private FileService fileService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Long createBusinessFile(BusinessFileSaveReqVO createReqVO) {
|
|
|
|
|
// 插入
|
|
|
|
|
@@ -97,13 +104,40 @@ public class BusinessFileServiceImpl implements BusinessFileService {
|
|
|
|
|
PageResult<BusinessFileDO> pageResult = getBusinessFilePage(pageReqVO);
|
|
|
|
|
PageResult<BusinessFileWithUrlRespVO> result = BeanUtils.toBean(pageResult, BusinessFileWithUrlRespVO.class);
|
|
|
|
|
|
|
|
|
|
// 批量获取文件信息并设置URL
|
|
|
|
|
List<Long> fileIds = result.getList().stream()
|
|
|
|
|
if (CollUtil.isEmpty(result.getList())) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量设置文件信息
|
|
|
|
|
setFileInfo(result.getList());
|
|
|
|
|
|
|
|
|
|
// 批量设置创建人名称
|
|
|
|
|
UserNameEnrichUtils.setCreatorNames(result.getList(),
|
|
|
|
|
BusinessFileRespVO::getCreator,
|
|
|
|
|
BusinessFileWithUrlRespVO::setCreatorName,
|
|
|
|
|
UserNameEnrichUtils.createUserNicknameProvider(
|
|
|
|
|
userIds -> adminUserApi.getUserMap(userIds),
|
|
|
|
|
AdminUserRespDTO::getNickname
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量设置文件信息
|
|
|
|
|
*/
|
|
|
|
|
private void setFileInfo(List<BusinessFileWithUrlRespVO> voList) {
|
|
|
|
|
// 批量获取文件信息
|
|
|
|
|
List<Long> fileIds = voList.stream()
|
|
|
|
|
.map(BusinessFileWithUrlRespVO::getFileId)
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.distinct()
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
if (fileIds.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量查询文件信息
|
|
|
|
|
Map<Long, FileDO> fileMap = new HashMap<>();
|
|
|
|
|
for (Long fileId : fileIds) {
|
|
|
|
|
@@ -114,7 +148,7 @@ public class BusinessFileServiceImpl implements BusinessFileService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置文件相关信息
|
|
|
|
|
for (BusinessFileWithUrlRespVO vo : result.getList()) {
|
|
|
|
|
voList.forEach(vo -> {
|
|
|
|
|
if (vo.getFileId() != null) {
|
|
|
|
|
FileDO fileDO = fileMap.get(vo.getFileId());
|
|
|
|
|
if (fileDO != null) {
|
|
|
|
|
@@ -125,8 +159,7 @@ public class BusinessFileServiceImpl implements BusinessFileService {
|
|
|
|
|
vo.setFileSize(fileDO.getSize());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|