Commit d6cea61b authored by huyuchen's avatar huyuchen

huych-电子档案批量导入第五次提交

parent d75d7647
......@@ -34,9 +34,11 @@ public interface ElectronicArchiveImportService {
/**
* 第三步:异步处理上传
*
* @param taskId 任务ID
* @param taskId 任务ID
* @param userId 用户ID
* @param userName 用户名
*/
void asyncProcessUpload(String taskId);
void asyncProcessUpload(String taskId, String userId, String userName);
/**
* 生成任务编号
......
......@@ -22,6 +22,21 @@ public interface FileUploadService {
R<TAttaInfo> uploadFileReturnAtta(MultipartFile file, String filePath, String type, String domainId, String taskId) throws IOException;
/**
* 上传文件并返回附件信息(支持传递用户ID,用于异步场景)
*
* @param file 文件
* @param filePath 文件路径
* @param type 类型
* @param domainId 域ID
* @param taskId 任务ID
* @param userId 用户ID
* @param userName 用户名
* @return 附件信息
* @throws IOException IO异常
*/
R<TAttaInfo> uploadFileReturnAtta(MultipartFile file, String filePath, String type, String domainId, String taskId, String userId, String userName) throws IOException;
R<T> uploadAsso(MultipartFile file, String filePath, String type, String domain, String uploadType);
R<T> uploadAsso(MultipartFile file, String filePath, String type, String domain, String uploadType, String taskId);
......
......@@ -462,7 +462,8 @@ public class ElectronicArchiveImportServiceImpl implements ElectronicArchiveImpo
attaInfoService.save(zipAtta);
// 调用异步处理(通过self代理对象调用,使@Async生效)
self.asyncProcessUpload(taskId);
// 传递用户ID和用户名,因为异步线程无法获取用户上下文
self.asyncProcessUpload(taskId, user.getId(), user.getNickname());
return R.ok("ZIP文件提交成功,正在处理中");
......@@ -482,10 +483,14 @@ public class ElectronicArchiveImportServiceImpl implements ElectronicArchiveImpo
/**
* 第三步:异步处理上传
*
* @param taskId 任务ID
* @param userId 用户ID(用于上传反馈文件)
* @param userName 用户名(用于上传反馈文件)
*/
@Override
@Async
public void asyncProcessUpload(String taskId) {
public void asyncProcessUpload(String taskId, String userId, String userName) {
List<ArchiveFeedbackVO> feedbackList = new ArrayList<>();
File tempDir = null;
......@@ -668,13 +673,13 @@ public class ElectronicArchiveImportServiceImpl implements ElectronicArchiveImpo
feedbackList.add(feedback);
}
// 处理完成,更新任务状态
task.setStatus(ArchiveConstants.TASK_STATUS_GENERATED);
taskService.updateById(task);
// 处理完成,更新任务状态
task.setStatus(ArchiveConstants.TASK_STATUS_GENERATED);
taskService.updateById(task);
// 生成反馈表
generateFeedbackExcel(task, feedbackList);
log.info("异步任务处理完成,任务ID:{}", taskId);
// 生成反馈表(传递用户信息)
generateFeedbackExcel(task, feedbackList, userId, userName);
log.info("异步任务处理完成,任务ID:{}", taskId);
} catch (Exception e) {
log.error("异步处理任务失败,任务ID:{}", taskId, e);
......@@ -1201,9 +1206,16 @@ public class ElectronicArchiveImportServiceImpl implements ElectronicArchiveImpo
/**
* 生成反馈表Excel
*
* @param task 任务信息
* @param feedbackList 反馈列表
* @param userId 用户ID
* @param userName 用户名
*/
private void generateFeedbackExcel(TElectronicArchiveTask task, List<ArchiveFeedbackVO> feedbackList) {
private void generateFeedbackExcel(TElectronicArchiveTask task, List<ArchiveFeedbackVO> feedbackList,
String userId, String userName) {
if (CollUtil.isEmpty(feedbackList)) {
log.warn("反馈列表为空,跳过生成反馈表,任务ID:{}", task.getId());
return;
}
......@@ -1217,29 +1229,36 @@ public class ElectronicArchiveImportServiceImpl implements ElectronicArchiveImpo
EasyExcel.write(feedbackFile, ArchiveFeedbackVO.class)
.sheet("处理结果反馈")
.doWrite(feedbackList);
log.info("反馈表Excel文件生成成功,文件路径:{},记录数:{}", tempFilePath, feedbackList.size());
// 上传反馈表到OSS
YifuUser user = SecurityUtils.getUser();
if (user != null) {
// 上传反馈表到OSS(传递用户信息)
if (StrUtil.isNotBlank(userId)) {
R<TAttaInfo> uploadResult = fileUploadService.uploadFileReturnAtta(
fileToMultipartFile(feedbackFile),
"archive/feedback",
ArchiveConstants.ATTA_RELATION_TYPE_FEEDBACK,
task.getId()
task.getId(),
null, // taskId为null
userId,
userName
);
if (R.isSuccess(uploadResult)) {
log.info("反馈表生成成功");
log.info("反馈表上传成功,任务ID:{},附件ID:{}", task.getId(), uploadResult.getData().getId());
} else {
log.error("反馈表上传失败");
log.error("反馈表上传失败,任务ID:{},失败原因:{}", task.getId(), uploadResult.getMsg());
}
} else {
log.error("用户ID为空,无法上传反馈表,任务ID:{}", task.getId());
}
// 删除临时文件
FileUtil.del(feedbackFile);
log.info("临时反馈表文件已删除:{}", tempFilePath);
} catch (Exception e) {
log.error("生成反馈表失败:", e);
log.error("生成反馈表失败,任务ID:{},异常信息:", task.getId(), e);
}
}
......
......@@ -14,17 +14,12 @@ import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@Service
......@@ -49,6 +44,18 @@ public class FileUploadServiceImpl implements FileUploadService {
@Override
public R<TAttaInfo> uploadFileReturnAtta(MultipartFile file, String filePath, String type, String domainId, String taskId) throws IOException {
// 从当前上下文获取用户信息
YifuUser user = SecurityUtils.getUser();
if (user != null) {
return uploadFileReturnAtta(file, filePath, type, domainId, taskId, user.getId(), user.getNickname());
} else {
return uploadFileReturnAtta(file, filePath, type, domainId, taskId, null, null);
}
}
@Override
public R<TAttaInfo> uploadFileReturnAtta(MultipartFile file, String filePath, String type, String domainId,
String taskId, String userId, String userName) throws IOException {
if (null == file) {
return R.failed("文件删除异常,请重新上传!");
}
......@@ -98,12 +105,23 @@ public class FileUploadServiceImpl implements FileUploadService {
attaInfo.setDomainId(domainId);
attaInfo.setTaskId(taskId);
Set<String> dbAuthsSet = new HashSet<>();
Collection<? extends GrantedAuthority> authorities = AuthorityUtils
.createAuthorityList(dbAuthsSet.toArray(new String[0]));
YifuUser user = SecurityUtils.getUser();
attaInfo.setCreateBy(user.getId());
attaInfo.setCreateName(user.getNickname());
// 优先使用传入的用户信息(支持异步场景)
if (Common.isNotNull(userId)) {
attaInfo.setCreateBy(userId);
attaInfo.setCreateName(userName);
} else {
// 从上下文获取(同步场景)
try {
YifuUser user = SecurityUtils.getUser();
if (user != null) {
attaInfo.setCreateBy(user.getId());
attaInfo.setCreateName(user.getNickname());
}
} catch (Exception e) {
log.warn("获取用户上下文失败,使用默认值", e);
}
}
attaInfo = tAttaInfoService.add(attaInfo);
} catch (Exception e) {
log.error("OSS文件上传异常:" + e.getMessage());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment