Browse Source

测试数据/测试app上传,结果下载

master
zhouyl 11 months ago
parent
commit
cc4e7c785a
  1. 108
      tp-admin/src/main/java/com/inscloudtech/web/controller/system/TestReportController.java
  2. 5
      tp-common/src/main/java/com/inscloudtech/common/utils/file/FileUtils.java
  3. 57
      tp-functional/src/main/java/com/inscloudtech/functional/domain/TestReport.java
  4. 10
      tp-functional/src/main/java/com/inscloudtech/functional/service/impl/TestReportServiceImpl.java
  5. 2
      tp-system/src/main/java/com/inscloudtech/system/service/impl/SysOssServiceImpl.java

108
tp-admin/src/main/java/com/inscloudtech/web/controller/system/TestReportController.java

@ -6,6 +6,7 @@ package com.inscloudtech.web.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inscloudtech.common.annotation.Log; import com.inscloudtech.common.annotation.Log;
@ -32,7 +33,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** /**
* 测试报告管理
* 测试任务管理
* *
* @author zfcf * @author zfcf
* @date 2024-08-28 * @date 2024-08-28
@ -50,27 +51,48 @@ public class TestReportController {
/** /**
* 测试数据-分页查询
* 测试内容/测试模型-分页查询
* @param * @param
* @param * @param
* @return * @return
*/ */
@GetMapping("/page" )
public TableDataInfo<TestReport> page(PageQuery pageQuery, TestReport testReport) {
Page page = new Page();
page.setSize(pageQuery.getPageSize());
page.setCurrent(pageQuery.getPageNum());
@GetMapping("/testDataPage" )
public TableDataInfo<TestReport> testDataPage(PageQuery pageQuery, TestReport testReport) {
if (!StpUtil.hasRole("admin")) { if (!StpUtil.hasRole("admin")) {
testReport.setCreateBy(LoginHelper.getUsername()); testReport.setCreateBy(LoginHelper.getUsername());
} }
QueryWrapper<TestReport> query = Wrappers.query(testReport);
query.isNotNull("data_atlas");
return getCommonPage(pageQuery,query);
}
Page result = testReportService.page(page, Wrappers.query(testReport));
TableDataInfo getCommonPage(PageQuery pageQuery,QueryWrapper<TestReport> query){
Page page = new Page();
page.setSize(pageQuery.getPageSize());
page.setCurrent(pageQuery.getPageNum());
Page result = testReportService.page(page, query);
TableDataInfo dataInfo = new TableDataInfo(); TableDataInfo dataInfo = new TableDataInfo();
dataInfo.setTotal(result.getTotal()); dataInfo.setTotal(result.getTotal());
dataInfo.setRows(result.getRecords()); dataInfo.setRows(result.getRecords());
return dataInfo; return dataInfo;
} }
/**
* 测试App-分页查询
* @param
* @param
* @return
*/
@GetMapping("/testAppPage" )
public TableDataInfo<TestReport> testAppPage(PageQuery pageQuery, TestReport testReport) {
if (!StpUtil.hasRole("admin")) {
testReport.setCreateBy(LoginHelper.getUsername());
}
QueryWrapper<TestReport> query = Wrappers.query(testReport);
query.isNotNull("app_name");
return getCommonPage(pageQuery,query);
}
/** /**
* 通过id查询测试报告 * 通过id查询测试报告
@ -88,7 +110,7 @@ public class TestReportController {
* 提交测试报告 * 提交测试报告
* *
*/ */
@Log(title = "测试报告管理", businessType = BusinessType.INSERT)
@Log(title = "测试任务管理", businessType = BusinessType.INSERT)
@PostMapping(value = "/add") @PostMapping(value = "/add")
public R add(@RequestBody TestReportSubmit vo) { public R add(@RequestBody TestReportSubmit vo) {
return R.ok(testReportService.add(vo)); return R.ok(testReportService.add(vo));
@ -117,53 +139,89 @@ public class TestReportController {
} }
/** /**
* 后台管理-上传测试报告文件
* 后台管理-上传测试结果
* *
*/ */
@Log(title = "测试报告管理", businessType = BusinessType.INSERT)
@PostMapping(value = "/uploadReport", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Log(title = "测试任务管理", businessType = BusinessType.INSERT)
@PostMapping(value = "/uploadResult", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R upload( @RequestPart("file") MultipartFile file, public R upload( @RequestPart("file") MultipartFile file,
@RequestPart("id") Long id) {
@RequestPart("id") String id) {
if (id == null) { if (id == null) {
return R.fail("测试报告id不能为空!");
return R.fail("测试任务id不能为空!");
} }
TestReport testReport = new TestReport(); TestReport testReport = new TestReport();
testReport.setId(id);
testReport.setId(Long.parseLong(id));
if(file != null ){ if(file != null ){
SysOssVo toolVo = iSysOssService.upload(file,true); SysOssVo toolVo = iSysOssService.upload(file,true);
testReport.setReportPath(toolVo.getOriginalName());
testReport.setReportOssId(toolVo.getOssId());
testReport.setResultPath(toolVo.getOriginalName());
testReport.setResultOssId(toolVo.getOssId());
} }
testReportService.save(testReport);
testReport.setTestStatus("测试完成");
testReportService.updateById(testReport);
return R.ok("操作成功!"); return R.ok("操作成功!");
} }
/** /**
* 前端用户-上传测试数据
* 前端用户-上传测试内容/测试模型
* *
*/ */
@SneakyThrows @SneakyThrows
@Log(title = "测试数据管理", businessType = BusinessType.INSERT) @Log(title = "测试数据管理", businessType = BusinessType.INSERT)
@PostMapping(value = "/uploadTestData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/uploadTestData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R uploadTestData( @RequestPart("file") MultipartFile file, public R uploadTestData( @RequestPart("file") MultipartFile file,
@RequestPart("reportName") String reportName) {
@RequestPart("taskName") String taskName,@RequestPart("companyName") String companyName,
@RequestPart("dataAtlas") String dataAtlas,String taskDesc) {
if (StrUtil.isEmpty(reportName)) {
return R.fail("数据名称不能为空!");
if (StrUtil.isEmpty(taskName)) {
return R.fail("测试任务名称不能为空!");
} }
// testReportService.check(reportName); // testReportService.check(reportName);
TestReport testReport = new TestReport(); TestReport testReport = new TestReport();
testReport.setReportName(reportName);
if(file != null ){ if(file != null ){
SysOssVo toolVo = iSysOssService.upload(file,true); SysOssVo toolVo = iSysOssService.upload(file,true);
testReport.setReportPath(toolVo.getOriginalName());
testReport.setReportOssId(toolVo.getOssId());
testReport.setTestDataPath(toolVo.getOriginalName());
testReport.setTestDataOssId(toolVo.getOssId());
}else {
return R.fail("测试数据不能为空!");
}
testReport.setTestStatus("测试中");
testReport.setTaskName(taskName);
testReport.setCompanyName(companyName);
testReport.setDataAtlas(dataAtlas);
testReport.setTaskDesc(taskDesc);
testReportService.save(testReport);
return R.ok("操作成功!");
}
/**
* 前端用户-上传测试App
*
*/
@SneakyThrows
@Log(title = "测试数据管理", businessType = BusinessType.INSERT)
@PostMapping(value = "/uploadTestApp", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R uploadTestApp( @RequestPart("file") MultipartFile file,
@RequestPart("taskName") String taskName,String appVersion) {
if (StrUtil.isEmpty(taskName)) {
return R.fail("测试任务名称不能为空!");
}
TestReport testReport = new TestReport();
testReport.setTaskName(taskName);
if(file != null ){
SysOssVo toolVo = iSysOssService.upload(file,true);
testReport.setTestDataPath(toolVo.getOriginalName());
testReport.setTestDataOssId(toolVo.getOssId());
testReport.setAppName(toolVo.getFileName());
} }
testReport.setTestStatus("测试中");
testReport.setAppVersion(appVersion);
testReportService.save(testReport); testReportService.save(testReport);
return R.ok("操作成功!"); return R.ok("操作成功!");
} }

5
tp-common/src/main/java/com/inscloudtech/common/utils/file/FileUtils.java

@ -65,13 +65,14 @@ public class FileUtils extends FileUtil {
return false; return false;
} }
// 检查允许下载的文件规则
/* // 检查允许下载的文件规则
if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) { if (ArrayUtils.contains(MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, FileTypeUtils.getFileType(resource))) {
return true; return true;
} }
// 不在允许下载的文件规则 // 不在允许下载的文件规则
return false;
return false;*/
return true;
} }
/** /**

57
tp-functional/src/main/java/com/inscloudtech/functional/domain/TestReport.java

@ -6,12 +6,14 @@ import com.inscloudtech.common.core.domain.BaseEntity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Date;
/** /**
* 测试报告管理对象 test_report
* 用户数据上传/测试报告回传对象 test_report
* *
* @author inscloudtech * @author inscloudtech
* @date 2024-09-02
* @date 2024-10-08
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ -26,27 +28,60 @@ public class TestReport extends BaseEntity {
@TableId(value = "id") @TableId(value = "id")
private Long id; private Long id;
/** /**
* 报告名称/测试数据名称
* 任务名称
*/ */
@TableField(condition = SqlCondition.LIKE)
private String reportName;
private String taskName;
/** /**
* 测试数据文件
* 测试内容/测试模型
*/ */
private String reportPath;
private String testDataPath;
/** /**
* 分析结果文件
* 测试结果文件
*/ */
private String resultPath; private String resultPath;
/** /**
* 报告文件下载id
*测试内容/测试模型存储id
*/ */
private Long reportOssId;
private Long testDataOssId;
/** /**
* 分析结果文件下载id
*测试结果存储id
*/ */
private Long resultOssId; private Long resultOssId;
/**
* 任务描述
*/
private String taskDesc;
/**
* 数据图集
*/
private String dataAtlas;
/**
*app名称
*/
private String appName;
/**
*公司名称
*/
private String companyName;
/**
*app版本/终端类型
*/
private String appVersion;
/**
* 测试时间
*/
private Date createTime;
/**
* 上传时间
*/
private Date updateTime;
/**
*测试状态
*/
private String testStatus;
} }

10
tp-functional/src/main/java/com/inscloudtech/functional/service/impl/TestReportServiceImpl.java

@ -37,11 +37,11 @@ public class TestReportServiceImpl extends ServiceImpl<TestReportMapper, TestRep
@Override @Override
public void check(String reportName) { public void check(String reportName) {
TestReport dbObj = baseMapper.selectOne(new LambdaQueryWrapper<TestReport>().eq(TestReport::getReportName, reportName)
.eq(TestReport::getCreateBy, LoginHelper.getUsername()));
if (ObjectUtil.isNotNull(dbObj)) {
throw new ServiceException("测试报告名称【"+reportName+"】已存在!");
}
// TestReport dbObj = baseMapper.selectOne(new LambdaQueryWrapper<TestReport>().eq(TestReport::getReportName, reportName)
// .eq(TestReport::getCreateBy, LoginHelper.getUsername()));
// if (ObjectUtil.isNotNull(dbObj)) {
// throw new ServiceException("测试报告名称【"+reportName+"】已存在!");
// }
} }

2
tp-system/src/main/java/com/inscloudtech/system/service/impl/SysOssServiceImpl.java

@ -159,7 +159,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
@SneakyThrows @SneakyThrows
public void downloadLocal(String fileName, String originalName, HttpServletResponse response,boolean isDecrypt){ public void downloadLocal(String fileName, String originalName, HttpServletResponse response,boolean isDecrypt){
if (!FileUtils.checkAllowDownload(fileName)) { if (!FileUtils.checkAllowDownload(fileName)) {
throw new RuntimeException(StrUtil.format("文件名称({})非法,不允许下载。 ", fileName));
throw new RuntimeException(StrUtil.format("文件名称【{}】非法,不允许下载。 ", fileName));
} }
String filePath = ProjectConfig.getUploadPath() + fileName; String filePath = ProjectConfig.getUploadPath() + fileName;
FileUtils.setAttachmentResponseHeader(response, originalName); FileUtils.setAttachmentResponseHeader(response, originalName);

Loading…
Cancel
Save