Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vehicle-quality-review
Project
Project
Details
Activity
Releases
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
王飞
vehicle-quality-review
Commits
4adf49fd
Commit
4adf49fd
authored
Jul 05, 2024
by
wdy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
车企文件导入
parent
b66dd431
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
27 deletions
+77
-27
ReviewEnterpriseArchiveMapper.java
.../java/com/ruoyi/mapper/ReviewEnterpriseArchiveMapper.java
+8
-0
ReviewEnterpriseArchiveServiceImpl.java
...uoyi/service/impl/ReviewEnterpriseArchiveServiceImpl.java
+12
-5
ReviewEnterpriseArchiveMapper.xml
...c/main/resources/mapper/ReviewEnterpriseArchiveMapper.xml
+5
-0
TestDownload.java
ruoyi-admin/src/test/java/com/ruoyi/TestDownload.java
+52
-22
No files found.
quality-review/src/main/java/com/ruoyi/mapper/ReviewEnterpriseArchiveMapper.java
View file @
4adf49fd
...
...
@@ -27,6 +27,14 @@ public interface ReviewEnterpriseArchiveMapper extends BaseMapper<ReviewEnterpri
Long
findFileName
(
@Param
(
"taskId"
)
Long
taskId
,
@Param
(
"fileName"
)
String
fileName
);
/**
* 根据文件名称和任务id查询
* @param taskId
* @param fileName
* @return
*/
ReviewEnterpriseArchive
findByFileNameAndId
(
@Param
(
"taskId"
)
Long
taskId
,
@Param
(
"fileName"
)
String
fileName
);
List
<
ReviewEnterpriseArchive
>
findEnterpriseArchive
(
ReviewEnterpriseArchiveFindRequest
request
);
ReviewEnterpriseArchive
findByFileName
(
@Param
(
"fileName"
)
String
fileName
);
...
...
quality-review/src/main/java/com/ruoyi/service/impl/ReviewEnterpriseArchiveServiceImpl.java
View file @
4adf49fd
...
...
@@ -9,6 +9,7 @@ import com.ruoyi.common.exception.ServiceException;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.SecurityUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.bean.BeanUtils
;
import
com.ruoyi.domain.ReviewEnterpriseArchive
;
import
com.ruoyi.domain.Task
;
import
com.ruoyi.domain.vo.*
;
...
...
@@ -253,20 +254,26 @@ public class ReviewEnterpriseArchiveServiceImpl extends ServiceImpl<ReviewEnterp
@Override
public
void
importEnterprise
(
List
<
EnterpriseImportFileVO
>
list
,
Long
taskId
,
HttpServletResponse
response
){
List
<
EnterpriseImportFileVO
>
filteredList
=
new
ArrayList
<>();
for
(
EnterpriseImportFileVO
vo:
list
){
vo
.
setCreateTime
(
getNowDate
());
vo
.
setCreateBy
(
SecurityUtils
.
getLoginUser
().
getUser
().
getNickName
());
vo
.
setTaskId
(
Long
.
valueOf
(
taskId
));
vo
.
setId
(
IdUtil
.
getSnowflake
().
nextId
());
Long
sum
=
reviewEnterpriseArchiveMapper
.
findFileName
(
Long
.
valueOf
(
taskId
),
vo
.
getFileName
());
if
(
sum
>
0
)
{
throw
new
ServiceException
(
"新增文件名称重复,请检查"
,
HttpStatus
.
ERROR
);
}
ReviewEnterpriseArchive
enterpriseArchive
=
reviewEnterpriseArchiveMapper
.
findByFileNameAndId
(
Long
.
valueOf
(
taskId
),
vo
.
getFileName
());
if
(
vo
.
getFileName
().
isEmpty
()){
throw
new
ServiceException
(
"文件名称不能为空"
,
HttpStatus
.
ERROR
);
}
if
(
enterpriseArchive
!=
null
)
{
BeanUtils
.
copyBeanProp
(
enterpriseArchive
,
vo
);
reviewEnterpriseArchiveService
.
updateById
(
enterpriseArchive
);
}
if
(
enterpriseArchive
==
null
)
{
// 只有当enterpriseArchive为空时,才将vo添加到新的列表中
filteredList
.
add
(
vo
);
}
}
reviewEnterpriseArchiveMapper
.
insertEnterprise
(
l
ist
);
reviewEnterpriseArchiveMapper
.
insertEnterprise
(
filteredL
ist
);
}
@Override
...
...
quality-review/src/main/resources/mapper/ReviewEnterpriseArchiveMapper.xml
View file @
4adf49fd
...
...
@@ -82,6 +82,11 @@
</if>
</where>
</select>
<select
id=
"findByFileNameAndId"
resultType=
"com.ruoyi.domain.ReviewEnterpriseArchive"
>
SELECT id, enterprise_name, file_name, version, publish_date, status, identify_number, storage, photo, task_id, create_by, create_time
FROM t_review_enterprise_archive
where file_name = #{fileName} and task_id = #{taskId}
</select>
<insert
id=
"insertEnterprise"
parameterType=
"java.util.List"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into t_review_enterprise_archive(id,enterprise_name,file_name,version,publish_date,status,identify_number,storage,task_id,create_by,create_time)values
...
...
ruoyi-admin/src/test/java/com/ruoyi/TestDownload.java
View file @
4adf49fd
...
...
@@ -2,46 +2,76 @@ package com.ruoyi;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.
http.HttpRequest
;
import
cn.hutool.
core.util.StrUtil
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpUtil
;
import
c
om.alibaba.fastjson2.JSONObject
;
import
c
n.hutool.core.util.ZipUtil
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.io.File
;
@SpringBootTest
public
class
TestDownload
{
@Test
public
void
t
est
()
{
public
void
T
est
()
{
try
{
//
直接使用URL作为POST请求的目标,假设所有需要的信息已包含在URL中
HttpResponse
response
=
HttpRequest
.
post
(
"https://10.12.48.78:8090/api/project/download"
+
"/fd40de37-9c57-4597-8f74-d0754dfa17b2"
)
// 如果需要添加特定的请求头,如认证信息,可以在这里添加
//.header("Authorization", "Bearer your_token_here
")
//
压缩包的名称和路径
String
zipFilePath
=
"downloaded_files.zip"
;
HttpResponse
response
=
HttpUtil
.
createPost
(
"https://10.12.48.78:8090/api/project/download/fd40de37-9c57-4597-8f74-d0754dfa17b2
"
)
.
execute
();
// 检查响应是否成功
if
(
response
.
isOk
())
{
// 从响应头中获取文件名,这里假设Content-Disposition头包含文件名
String
contentDisposition
=
response
.
header
(
"Content-Disposition"
);
String
fileName
=
extractFileNameFromContentDisposition
(
contentDisposition
);
if
(
StrUtil
.
isNotBlank
(
fileName
))
{
// 保存下载的文件到临时位置
String
tempFilePath
=
"temp_"
+
fileName
;
FileUtil
.
writeBytes
(
IoUtil
.
readBytes
(
response
.
bodyStream
()),
FileUtil
.
file
(
tempFilePath
));
System
.
out
.
println
(
"文件下载成功:"
+
fileName
);
// 将临时文件添加到压缩包中
// ZipUtil.addFile(zipFilePath, tempFilePath);
System
.
out
.
println
(
"文件已添加到压缩包:"
+
zipFilePath
);
System
.
out
.
println
(
"response = "
+
response
);
// 获取文件名,这里简化处理,实际情况可能需要从响应头中解析(如Content-Disposition)
// String fileName = "downloaded_file_from_post.zip";
//
// // 保存到本地
// FileUtil.writeBytes(IoUtil.readBytes(response.bodyStream()), FileUtil.file(fileName));
//
// System.out.println("文件下载成功:" + fileName);
// 删除临时文件
FileUtil
.
del
(
tempFilePath
);
}
else
{
System
.
err
.
println
(
"无法从响应头中提取文件名"
);
}
}
else
{
System
.
err
.
println
(
"下载失败,状态码:"
+
response
.
getStatus
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
//以post形式请求接口
// String result= HttpUtil.post("https://10.12.48.78:8090/api/project/download","/fd40de37-9c57-4597-8f74-d0754dfa17b2");
/**
* 从Content-Disposition头中提取文件名。
* 注意:这是一个简化的示例,真实场景可能需要更复杂的解析逻辑。
*
* @param contentDisposition Content-Disposition头的值
* @return 提取的文件名,如果未找到则返回空字符串
*/
private
static
String
extractFileNameFromContentDisposition
(
String
contentDisposition
)
{
if
(
StrUtil
.
isBlank
(
contentDisposition
))
{
return
""
;
}
String
[]
parts
=
contentDisposition
.
split
(
";"
);
for
(
String
part
:
parts
)
{
part
=
part
.
trim
();
if
(
part
.
startsWith
(
"filename="
))
{
return
part
.
substring
(
part
.
indexOf
(
'='
)
+
1
).
replace
(
"\""
,
""
);
}
}
return
""
;
}
}
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