UPDATE: 导入和导出计划检测数据测试报告同步
This commit is contained in:
@@ -384,11 +384,14 @@ public class AdPlanController extends BaseController {
|
|||||||
@OperateInfo(operateType = OperateType.DOWNLOAD)
|
@OperateInfo(operateType = OperateType.DOWNLOAD)
|
||||||
@PostMapping("/exportPlanCheckData")
|
@PostMapping("/exportPlanCheckData")
|
||||||
@ApiOperation("导出计划检测结果数据")
|
@ApiOperation("导出计划检测结果数据")
|
||||||
@ApiImplicitParam(name = "planId", value = "计划id", required = true)
|
@ApiImplicitParams({
|
||||||
public void exportPlanCheckData(@RequestParam("planId") String planId, HttpServletResponse response) {
|
@ApiImplicitParam(name = "planId", value = "计划id", required = true),
|
||||||
|
@ApiImplicitParam(name = "report", value = "是否导出报告, 0 否,1 是", required = true)
|
||||||
|
})
|
||||||
|
public void exportPlanCheckData(@RequestParam("planId") String planId,@RequestParam("report") Integer report, HttpServletResponse response) {
|
||||||
String methodDescribe = getMethodDescribe("exportPlanCheckData");
|
String methodDescribe = getMethodDescribe("exportPlanCheckData");
|
||||||
LogUtil.njcnDebug(log, "{},导出ID数据为:{}", methodDescribe, planId);
|
LogUtil.njcnDebug(log, "{},导出ID数据为:{}", methodDescribe, planId);
|
||||||
adPlanService.exportPlanCheckDataZip(planId, response);
|
adPlanService.exportPlanCheckDataZip(planId,report, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -191,9 +191,10 @@ public interface IAdPlanService extends IService<AdPlan> {
|
|||||||
* 导出计划检测结果数据
|
* 导出计划检测结果数据
|
||||||
*
|
*
|
||||||
* @param planId
|
* @param planId
|
||||||
|
* @param report
|
||||||
* @param response
|
* @param response
|
||||||
*/
|
*/
|
||||||
void exportPlanCheckDataZip(String planId, HttpServletResponse response);
|
void exportPlanCheckDataZip(String planId,Integer report, HttpServletResponse response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入计划检测结果数据
|
* 导入计划检测结果数据
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ import com.njcn.gather.plan.service.IAdPlanSourceService;
|
|||||||
import com.njcn.gather.plan.service.IAdPlanStandardDevService;
|
import com.njcn.gather.plan.service.IAdPlanStandardDevService;
|
||||||
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
|
import com.njcn.gather.report.pojo.constant.ReportConstant;
|
||||||
import com.njcn.gather.report.pojo.po.PqReport;
|
import com.njcn.gather.report.pojo.po.PqReport;
|
||||||
import com.njcn.gather.report.service.IPqReportService;
|
import com.njcn.gather.report.service.IPqReportService;
|
||||||
import com.njcn.gather.script.pojo.po.PqScript;
|
import com.njcn.gather.script.pojo.po.PqScript;
|
||||||
@@ -95,6 +96,7 @@ import org.apache.poi.xddf.usermodel.chart.*;
|
|||||||
import org.apache.poi.xssf.usermodel.*;
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -143,6 +145,8 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
private final IAdPlanTestConfigService adPlanTestConfigService;
|
private final IAdPlanTestConfigService adPlanTestConfigService;
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
@Value("${report.reportDir}")
|
||||||
|
private String reportPath;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
|
public List<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
|
||||||
@@ -409,7 +413,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
param.getDevIds().removeAll(devIds);
|
param.getDevIds().removeAll(devIds);
|
||||||
// 更新检测配置
|
// 更新检测配置
|
||||||
AdPlanTestConfig testConfig = param.getTestConfig();
|
AdPlanTestConfig testConfig = param.getTestConfig();
|
||||||
adPlanTestConfigService.update(testConfig,new LambdaUpdateWrapper<AdPlanTestConfig>().eq(AdPlanTestConfig::getPlanId, testConfig.getPlanId()));
|
adPlanTestConfigService.update(testConfig, new LambdaUpdateWrapper<AdPlanTestConfig>().eq(AdPlanTestConfig::getPlanId, testConfig.getPlanId()));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 修改检测计划、检测源关联
|
// 修改检测计划、检测源关联
|
||||||
@@ -422,7 +426,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
.set(AdPlan::getOrigin, param.getName()).update();
|
.set(AdPlan::getOrigin, param.getName()).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.updateById(plan2);
|
return this.updateById(plan2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1821,7 +1825,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportPlanCheckDataZip(String planId, HttpServletResponse response) {
|
public void exportPlanCheckDataZip(String planId, Integer report, HttpServletResponse response) {
|
||||||
AdPlanCheckDataVO planCheckDataVO = new AdPlanCheckDataVO();
|
AdPlanCheckDataVO planCheckDataVO = new AdPlanCheckDataVO();
|
||||||
// 获取检测计划基本数据
|
// 获取检测计划基本数据
|
||||||
AdPlan plan = this.getById(planId);
|
AdPlan plan = this.getById(planId);
|
||||||
@@ -1861,9 +1865,29 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
String zipFileName = URLEncoder.encode(plan.getName() + "_检测数据.zip", "UTF-8");
|
String zipFileName = URLEncoder.encode(plan.getName() + "_检测数据.zip", "UTF-8");
|
||||||
File zipFile = FileUtil.file(tempDir, zipFileName);
|
File zipFile = FileUtil.file(tempDir, zipFileName);
|
||||||
|
|
||||||
// 先将json文件添加到zip中
|
// 创建一个临时目录存放文件
|
||||||
ZipUtil.zip(jsonFile.getAbsolutePath(), zipFile.getAbsolutePath());
|
File tempZipDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "temp_plan_check_data_" + System.currentTimeMillis() + "/");
|
||||||
|
// 复制json文件到临时目录
|
||||||
|
FileUtil.copy(jsonFile, tempZipDir, true);
|
||||||
|
// 添加检测报告文件
|
||||||
|
if (ObjectUtil.isNotNull(report) && report.equals(1)) {
|
||||||
|
for (PqDev dev : devList) {
|
||||||
|
DevType devType = devTypeService.getById(dev.getDevType());
|
||||||
|
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
||||||
|
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
|
||||||
|
// 如果reportFile存在,则将reportFile中的文件添加到已有的zip文件中
|
||||||
|
if (FileUtil.exist(reportFile)) {
|
||||||
|
// 复制reportFile到临时目录
|
||||||
|
FileUtil.copy(reportFile, tempZipDir, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 重新创建zip文件,包含所有文件
|
||||||
|
ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath());
|
||||||
|
|
||||||
|
// 删除临时目录
|
||||||
|
FileUtil.del(tempZipDir);
|
||||||
// 设置响应头
|
// 设置响应头
|
||||||
response.reset();
|
response.reset();
|
||||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||||
@@ -1964,13 +1988,11 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
for (Map<String, Object> row : dataList) {
|
for (Map<String, Object> row : dataList) {
|
||||||
// 构造批量插入SQL - 收集所有可能的列名
|
// 构造批量插入SQL - 收集所有可能的列名
|
||||||
List<String> columnNames = new ArrayList<>(row.keySet());
|
List<String> columnNames = new ArrayList<>(row.keySet());
|
||||||
StringBuilder sqlBuilder = new StringBuilder();
|
|
||||||
sqlBuilder.append("INSERT INTO ").append(tableName).append(" (");
|
|
||||||
sqlBuilder.append(columnNames.stream().map(column -> "`" + column + "`").collect(Collectors.joining(",")));
|
|
||||||
sqlBuilder.append(") VALUES ");
|
|
||||||
|
|
||||||
sqlBuilder.append("(" + columnNames.stream().map(column -> "?").collect(Collectors.joining(",")) + ")");
|
String sql = "INSERT INTO " + tableName + " (" +
|
||||||
String sql = sqlBuilder.toString();
|
columnNames.stream().map(column -> "`" + column + "`").collect(Collectors.joining(",")) +
|
||||||
|
") VALUES " +
|
||||||
|
"(" + columnNames.stream().map(column -> "?").collect(Collectors.joining(",")) + ")";
|
||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
for (String column : columnNames) {
|
for (String column : columnNames) {
|
||||||
Object value = row.getOrDefault(column, null);
|
Object value = row.getOrDefault(column, null);
|
||||||
@@ -1986,6 +2008,25 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 报告文件复制到指定位置
|
||||||
|
for (File f : files) {
|
||||||
|
if (f.isFile() && f.getName().endsWith(ReportConstant.DOCX)) {
|
||||||
|
for (PqDev dev : devList) {
|
||||||
|
DevType devType = devTypeService.getById(dev.getDevType());
|
||||||
|
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
||||||
|
File reportFile = new File(dirPath.concat(File.separator).concat(dev.getCreateId()).concat(ReportConstant.DOCX));
|
||||||
|
// 文件名匹配,复制到对应目录下
|
||||||
|
if (f.getName().equals(reportFile.getName())) {
|
||||||
|
File parentDir = reportFile.getParentFile();
|
||||||
|
if (!parentDir.exists()) {
|
||||||
|
parentDir.mkdirs();
|
||||||
|
}
|
||||||
|
FileUtil.copy(f, parentDir, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// 删除临时目录
|
// 删除临时目录
|
||||||
FileUtil.del(tempDir);
|
FileUtil.del(tempDir);
|
||||||
return true;
|
return true;
|
||||||
@@ -2008,7 +2049,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
if (CollUtil.isEmpty(subPlanList)) {
|
if (CollUtil.isEmpty(subPlanList)) {
|
||||||
throw new BusinessException(CommonResponseEnum.FAIL, "该计划未找到子计划");
|
throw new BusinessException(CommonResponseEnum.FAIL, "该计划未找到子计划");
|
||||||
}
|
}
|
||||||
// 获取所有子计划检测数据
|
// 获取所有子计划检测数据
|
||||||
List<Integer> subPlanCodeList = subPlanList.stream().map(AdPlan::getCode).collect(Collectors.toList());
|
List<Integer> subPlanCodeList = subPlanList.stream().map(AdPlan::getCode).collect(Collectors.toList());
|
||||||
for (Integer code : subPlanCodeList) {
|
for (Integer code : subPlanCodeList) {
|
||||||
List<String> dataTableNames = CollUtil.newArrayList("ad_harmonic_" + code, "ad_non_harmonic_" + code, "ad_harmonic_result_" + code, "ad_non_harmonic_result_" + code);
|
List<String> dataTableNames = CollUtil.newArrayList("ad_harmonic_" + code, "ad_non_harmonic_" + code, "ad_harmonic_result_" + code, "ad_non_harmonic_result_" + code);
|
||||||
|
|||||||
Reference in New Issue
Block a user