Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangxinjiang
yifu-mvp
Commits
d6cea61b
Commit
d6cea61b
authored
Jan 14, 2026
by
huyuchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
huych-电子档案批量导入第五次提交
parent
d75d7647
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
29 deletions
+83
-29
ElectronicArchiveImportService.java
...plus/v1/batch/service/ElectronicArchiveImportService.java
+4
-2
FileUploadService.java
...m/yifu/cloud/plus/v1/batch/service/FileUploadService.java
+15
-0
ElectronicArchiveImportServiceImpl.java
...atch/service/impl/ElectronicArchiveImportServiceImpl.java
+35
-16
FileUploadServiceImpl.java
...oud/plus/v1/batch/service/impl/FileUploadServiceImpl.java
+29
-11
No files found.
yifu-batch/yifu-batch-biz/src/main/java/com/yifu/cloud/plus/v1/batch/service/ElectronicArchiveImportService.java
View file @
d6cea61b
...
...
@@ -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
);
/**
* 生成任务编号
...
...
yifu-batch/yifu-batch-biz/src/main/java/com/yifu/cloud/plus/v1/batch/service/FileUploadService.java
View file @
d6cea61b
...
...
@@ -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
);
...
...
yifu-batch/yifu-batch-biz/src/main/java/com/yifu/cloud/plus/v1/batch/service/impl/ElectronicArchiveImportServiceImpl.java
View file @
d6cea61b
...
...
@@ -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
);
}
}
...
...
yifu-batch/yifu-batch-biz/src/main/java/com/yifu/cloud/plus/v1/batch/service/impl/FileUploadServiceImpl.java
View file @
d6cea61b
...
...
@@ -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
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment