Commit 287c13a9 authored by wdy's avatar wdy

Merge branch 'dev' into 'master'

dev - master 39

See merge request !403
parents e39158c6 e8e9a3db
...@@ -27,6 +27,14 @@ public interface ReviewEnterpriseArchiveMapper extends BaseMapper<ReviewEnterpri ...@@ -27,6 +27,14 @@ public interface ReviewEnterpriseArchiveMapper extends BaseMapper<ReviewEnterpri
Long findFileName(@Param("taskId") Long taskId,@Param("fileName") String fileName); 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); List<ReviewEnterpriseArchive> findEnterpriseArchive(ReviewEnterpriseArchiveFindRequest request);
ReviewEnterpriseArchive findByFileName(@Param("fileName") String fileName); ReviewEnterpriseArchive findByFileName(@Param("fileName") String fileName);
......
...@@ -9,6 +9,7 @@ import com.ruoyi.common.exception.ServiceException; ...@@ -9,6 +9,7 @@ import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.domain.ReviewEnterpriseArchive; import com.ruoyi.domain.ReviewEnterpriseArchive;
import com.ruoyi.domain.Task; import com.ruoyi.domain.Task;
import com.ruoyi.domain.vo.*; import com.ruoyi.domain.vo.*;
...@@ -253,20 +254,26 @@ public class ReviewEnterpriseArchiveServiceImpl extends ServiceImpl<ReviewEnterp ...@@ -253,20 +254,26 @@ public class ReviewEnterpriseArchiveServiceImpl extends ServiceImpl<ReviewEnterp
@Override @Override
public void importEnterprise(List<EnterpriseImportFileVO> list,Long taskId, HttpServletResponse response){ public void importEnterprise(List<EnterpriseImportFileVO> list,Long taskId, HttpServletResponse response){
List<EnterpriseImportFileVO> filteredList = new ArrayList<>();
for(EnterpriseImportFileVO vo: list){ for(EnterpriseImportFileVO vo: list){
vo.setCreateTime(getNowDate()); vo.setCreateTime(getNowDate());
vo.setCreateBy( SecurityUtils.getLoginUser().getUser().getNickName()); vo.setCreateBy( SecurityUtils.getLoginUser().getUser().getNickName());
vo.setTaskId(Long.valueOf(taskId)); vo.setTaskId(Long.valueOf(taskId));
vo.setId(IdUtil.getSnowflake().nextId()); vo.setId(IdUtil.getSnowflake().nextId());
Long sum = reviewEnterpriseArchiveMapper.findFileName(Long.valueOf(taskId), vo.getFileName()); ReviewEnterpriseArchive enterpriseArchive = reviewEnterpriseArchiveMapper.findByFileNameAndId(Long.valueOf(taskId), vo.getFileName());
if (sum >0 ) {
throw new ServiceException("新增文件名称重复,请检查", HttpStatus.ERROR);
}
if(vo.getFileName().isEmpty()){ if(vo.getFileName().isEmpty()){
throw new ServiceException("文件名称不能为空", HttpStatus.ERROR); 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 @Override
......
...@@ -82,6 +82,11 @@ ...@@ -82,6 +82,11 @@
</if> </if>
</where> </where>
</select> </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 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 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
......
package com.ruoyi;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.core.util.ZipUtil;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.File;
@SpringBootTest
public class TestDownload {
@Test
public void Test() {
try {
// 压缩包的名称和路径
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);
// 删除临时文件
FileUtil.del(tempFilePath);
} else {
System.err.println("无法从响应头中提取文件名");
}
} else {
System.err.println("下载失败,状态码:" + response.getStatus());
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 从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 "";
}
}
...@@ -28,7 +28,7 @@ public class TestRecordsTest { ...@@ -28,7 +28,7 @@ public class TestRecordsTest {
public void test() { public void test() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("id", "project_items;27"); map.put("id", "5wU7nij8QomtoGMVhoxQjryw8hncJ");
map.put("verbose", "ALL"); map.put("verbose", "ALL");
//以post形式请求接口 //以post形式请求接口
...@@ -43,7 +43,7 @@ public class TestRecordsTest { ...@@ -43,7 +43,7 @@ public class TestRecordsTest {
List<CaseResultVO> caseResultVOS = jsonObject.getList("case_result_list", CaseResultVO.class); List<CaseResultVO> caseResultVOS = jsonObject.getList("case_result_list", CaseResultVO.class);
// 获取本地存储的列表 // 获取本地存储的列表
List<TestRecords> recordsList = testRecordsService.findByTaskId("project_items;29"); List<TestRecords> recordsList = testRecordsService.findByTaskId("5wU7nij8QomtoGMVhoxQjryw8hncJ");
List<TestRecords> list = new ArrayList<>(); List<TestRecords> list = new ArrayList<>();
if (caseResultVOS.size() != 0 && caseResultVOS != null) { if (caseResultVOS.size() != 0 && caseResultVOS != null) {
......
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