|
|
@ -2,7 +2,6 @@ package com.inspect.resultmain.controller; |
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
import cn.hutool.core.date.DateUtil; |
|
|
import com.inspect.analysis.domain.ResultAnalysis; |
|
|
import com.inspect.analysis.domain.ResultAnalysis; |
|
|
import com.inspect.analysis.domain.resultList; |
|
|
|
|
|
import com.inspect.analysis.service.IResultAnalysisService; |
|
|
import com.inspect.analysis.service.IResultAnalysisService; |
|
|
import com.inspect.base.core.sftp.SftpClient; |
|
|
import com.inspect.base.core.sftp.SftpClient; |
|
|
import com.inspect.base.core.sftp.SftpUploadEntity; |
|
|
import com.inspect.base.core.sftp.SftpUploadEntity; |
|
|
@ -24,38 +23,16 @@ import com.inspect.message.MessageUtils; |
|
|
import com.inspect.partrolresult.domain.PatrolResult; |
|
|
import com.inspect.partrolresult.domain.PatrolResult; |
|
|
import com.inspect.partrolresult.service.IPatrolResultService; |
|
|
import com.inspect.partrolresult.service.IPatrolResultService; |
|
|
import com.inspect.partrolresult.util.PrintUtil; |
|
|
import com.inspect.partrolresult.util.PrintUtil; |
|
|
import com.inspect.partrolresultAux.domain.PatrolResultAux; |
|
|
|
|
|
import com.inspect.partrolresultAux.service.IPatrolResultAuxService; |
|
|
import com.inspect.partrolresultAux.service.IPatrolResultAuxService; |
|
|
import com.inspect.resultmain.domain.PatrolTaskResultMain; |
|
|
import com.inspect.resultmain.domain.PatrolTaskResultMain; |
|
|
import com.inspect.resultmain.service.IPatrolTaskResultMainService; |
|
|
import com.inspect.resultmain.service.IPatrolTaskResultMainService; |
|
|
import com.inspect.task.service.IPatrolTaskService; |
|
|
import com.inspect.task.service.IPatrolTaskService; |
|
|
import com.inspect.taskinfo.service.IPatrolTaskInfoService; |
|
|
import com.inspect.taskinfo.service.IPatrolTaskInfoService; |
|
|
|
|
|
import com.inspect.taskstatus.domain.PatrolTaskStatus; |
|
|
import com.inspect.taskstatus.service.IPatrolTaskStatusService; |
|
|
import com.inspect.taskstatus.service.IPatrolTaskStatusService; |
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
|
|
import java.math.BigInteger; |
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
|
|
import java.util.zip.ZipOutputStream; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
import net.coobird.thumbnailator.Thumbnails; |
|
|
import net.coobird.thumbnailator.Thumbnails; |
|
|
import org.apache.commons.io.function.IOConsumer; |
|
|
import org.apache.commons.io.function.IOConsumer; |
|
|
import org.apache.poi.hssf.usermodel.HSSFCell; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFFont; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFPatriarch; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.*; |
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
import org.apache.poi.ss.util.CellRangeAddress; |
|
|
import org.apache.poi.ss.util.CellRangeAddress; |
|
|
import org.apache.poi.util.Units; |
|
|
import org.apache.poi.util.Units; |
|
|
@ -68,8 +45,23 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.io.*; |
|
|
|
|
|
import java.math.BigInteger; |
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
|
|
import java.util.zip.ZipOutputStream; |
|
|
|
|
|
|
|
|
@RestController |
|
|
@RestController |
|
|
@RefreshScope |
|
|
@RefreshScope |
|
|
@RequestMapping({"/resultmain"}) |
|
|
@RequestMapping({"/resultmain"}) |
|
|
@ -269,6 +261,88 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping({"/updateInfo_shaoxing"}) |
|
|
|
|
|
public AjaxResult updateInfo_shaoxing( |
|
|
|
|
|
@RequestBody PatrolTaskResultMain resultMain) { |
|
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
|
|
logger.info("[ARCHIVE] Starting, resultMain: {}", resultMain); |
|
|
|
|
|
logger.info("-----------resultMain getTaskPatrolledId: {}", resultMain.getTaskPatrolledId()); |
|
|
|
|
|
PatrolTaskResultMain patrolTaskResultMain = patrolTaskResultMainService.selectPatrolTaskResultMainByTaskPatrolledId(resultMain.getTaskPatrolledId()); |
|
|
|
|
|
logger.info("-----------patrolTaskResultMain: {}", patrolTaskResultMain); |
|
|
|
|
|
if (patrolTaskResultMain == null) { |
|
|
|
|
|
logger.error("[归档]失败, 数据采集中..."); |
|
|
|
|
|
return AjaxResult.error("数据采集中请稍后...."); |
|
|
|
|
|
} |
|
|
|
|
|
Long lineId = patrolTaskResultMain.getLineId(); |
|
|
|
|
|
List<Long> lineIds = new ArrayList<>(); |
|
|
|
|
|
lineIds.add(lineId); |
|
|
|
|
|
List<Long> longs = patrolTaskResultMainService.selectLineIdsByList(lineIds); |
|
|
|
|
|
if (longs != null && longs.size() > 0) { |
|
|
|
|
|
lineIds.addAll(longs); |
|
|
|
|
|
} |
|
|
|
|
|
lineIds = lineIds.stream().distinct().collect(Collectors.toList()); |
|
|
|
|
|
PrintUtil.useTime("收集需归档的lineIds", startTime); |
|
|
|
|
|
logger.info("---归档--lineIds size: {},lineIds:{}", lineIds.size(), lineIds); |
|
|
|
|
|
List<PatrolResult> resultList = patrolResultService.selectPatrolResultListByMainIds(lineIds); |
|
|
|
|
|
if (resultList.isEmpty()) { |
|
|
|
|
|
logger.error("[归档]失败, 数据采集中..."); |
|
|
|
|
|
return AjaxResult.error("数据采集中请稍后...."); |
|
|
|
|
|
} |
|
|
|
|
|
startTime = System.currentTimeMillis(); |
|
|
|
|
|
ResultAnalysis resultAnalysis = new ResultAnalysis(); |
|
|
|
|
|
int csQxNum = 0, aiQxNum = 0; |
|
|
|
|
|
List<String> taskPatrolledIds = resultList.stream().map(PatrolResult::getTaskPatrolledId).distinct().collect(Collectors.toList()); |
|
|
|
|
|
for (String taskPatrolledId : taskPatrolledIds) { |
|
|
|
|
|
resultAnalysis.setTaskPatrolledId(taskPatrolledId); |
|
|
|
|
|
ResultAnalysis ras = patrolResultService.selectTaskAbnormalData(resultAnalysis); |
|
|
|
|
|
csQxNum += ras.getCsQxNum(); |
|
|
|
|
|
aiQxNum += ras.getAiQxNum(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if("0".equals(exportReportFlag) && 0 == aiQxNum && 0 == csQxNum) { |
|
|
|
|
|
logger.error("[归档]没有缺陷数据, 无需归档!"); |
|
|
|
|
|
return AjaxResult.error("没有缺陷数据, 无需归档!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PrintUtil.useTime("查询统计缺陷数据", startTime); |
|
|
|
|
|
startTime = System.currentTimeMillis(); |
|
|
|
|
|
// 使用CompletableFuture异步执行saveReport |
|
|
|
|
|
int finalAiQxNum = aiQxNum; |
|
|
|
|
|
int finalCsQxNum = csQxNum; |
|
|
|
|
|
List<Long> finalLineIds = lineIds; |
|
|
|
|
|
CompletableFuture<List<Long>> saveReportFuture = CompletableFuture.supplyAsync(() -> { |
|
|
|
|
|
logger.info("[ARCHIVE] Start saving reports"); |
|
|
|
|
|
return patrolResultService.saveReportShaoxing(resultMain, finalLineIds, lineId, resultList, finalAiQxNum, finalCsQxNum); |
|
|
|
|
|
}, executor).exceptionally(ex -> { |
|
|
|
|
|
logger.error("Report saving failed", ex); |
|
|
|
|
|
return Collections.emptyList(); |
|
|
|
|
|
}); |
|
|
|
|
|
PrintUtil.useTime("保存报告数据", startTime); |
|
|
|
|
|
startTime = System.currentTimeMillis(); |
|
|
|
|
|
// 当saveReport完成后,再异步处理所有导出任务 |
|
|
|
|
|
saveReportFuture.thenAcceptAsync(reportIds -> { |
|
|
|
|
|
logger.info("-----------[ARCHIVE] Saved export reportIds: {}", reportIds); |
|
|
|
|
|
if (reportIds.isEmpty()) { |
|
|
|
|
|
logger.warn("No reports to export"); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
// 为每个reportId创建异步导出任务 |
|
|
|
|
|
CompletableFuture<?>[] exportFutures = reportIds.stream() |
|
|
|
|
|
.map(reportId -> CompletableFuture.runAsync(() -> { |
|
|
|
|
|
logger.info("[EXPORT] Start export for reportId: {}", reportId); |
|
|
|
|
|
exportExcelWordAndZipLingzhou(String.valueOf(reportId)); |
|
|
|
|
|
}, executor)) |
|
|
|
|
|
.toArray(CompletableFuture[]::new); |
|
|
|
|
|
|
|
|
|
|
|
}, executor).exceptionally(ex -> { |
|
|
|
|
|
logger.error("Error occurred during saveReport: ", ex); |
|
|
|
|
|
return null; |
|
|
|
|
|
}); |
|
|
|
|
|
PrintUtil.useTime("导出报告数据", startTime); |
|
|
|
|
|
return toAjax(1); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping({"/updateInfo"}) |
|
|
@PostMapping({"/updateInfo"}) |
|
|
public AjaxResult updateInfo_lingzhou( |
|
|
public AjaxResult updateInfo_lingzhou( |
|
|
@ -382,6 +456,27 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Log( |
|
|
|
|
|
title = "导出报告", |
|
|
|
|
|
businessType = BizType.EXPORT |
|
|
|
|
|
) |
|
|
|
|
|
@PostMapping({"/reportExport"}) |
|
|
|
|
|
public ResponseEntity taskInfoExport(HttpServletResponse response, PatrolTaskResultMain patrolTaskResultMain) throws Exception { |
|
|
|
|
|
logger.info("开始导出报告,patrolTaskResultMain:{}", patrolTaskResultMain.toString()); |
|
|
|
|
|
|
|
|
|
|
|
// response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
|
|
// response.setHeader("Content-Disposition", "attachment; filename=\"task_export_" + System.currentTimeMillis() + ".xlsx\""); |
|
|
|
|
|
// InspectionReport inspectionReport = new InspectionReport(); |
|
|
|
|
|
// |
|
|
|
|
|
// try (SXSSFWorkbook sxssfWorkbook = getSXSSFWorkbookLingzhou(inspectionReport, streamHashMap); |
|
|
|
|
|
// ServletOutputStream outputStream = response.getOutputStream()) { |
|
|
|
|
|
// sxssfWorkbook.write(outputStream); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok("报告导出成功!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public String ToStationIn(String areaId) { |
|
|
public String ToStationIn(String areaId) { |
|
|
String areaName = ""; |
|
|
String areaName = ""; |
|
|
Map<String, Object> map = this.patrolResultService.selectAreaInfo(areaId); |
|
|
Map<String, Object> map = this.patrolResultService.selectAreaInfo(areaId); |
|
|
|