Commit e8e9a3db authored by wdy's avatar wdy

Merge branch 'wangdingyi' into 'dev'

车企文件导入

See merge request !402
parents b66dd431 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);
......
......@@ -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(list);
reviewEnterpriseArchiveMapper.insertEnterprise(filteredList);
}
@Override
......
......@@ -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
......
......@@ -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 com.alibaba.fastjson2.JSONObject;
import cn.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 test() {
public void Test() {
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("response = " + response);
// 获取文件名,这里简化处理,实际情况可能需要从响应头中解析(如Content-Disposition)
// String fileName = "downloaded_file_from_post.zip";
//
// // 保存到本地
// FileUtil.writeBytes(IoUtil.readBytes(response.bodyStream()), FileUtil.file(fileName));
//
// System.out.println("文件下载成功:" + fileName);
System.out.println("文件下载成功:" + fileName);
// 将临时文件添加到压缩包中
// ZipUtil.addFile(zipFilePath, tempFilePath);
System.out.println("文件已添加到压缩包:" + zipFilePath);
// 删除临时文件
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 "";
}
}
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