Browse Source

/*增加taskInfoExport接口*/

master
htjcAdmin 8 months ago
parent
commit
b787e805c3
1 changed files with 212 additions and 1 deletions
  1. +212
    -1
      inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java

+ 212
- 1
inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java View File

@ -11,6 +11,7 @@ import com.inspect.base.core.constant.RedisConst;
import com.inspect.base.core.domain.DataMsg;
import com.inspect.base.core.enums.TaskStatus;
import com.inspect.base.core.service.SendService;
import com.inspect.base.core.sftp.SftpClient;
import com.inspect.base.core.utils.DateUtils;
import com.inspect.base.core.utils.HttpClientUtils;
import com.inspect.base.core.utils.SFTPUtil;
@ -48,16 +49,26 @@ import com.inspect.taskstatus.domain.PatrolTaskStatus;
import com.inspect.taskstatus.service.IPatrolTaskStatusService;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@ -77,6 +88,8 @@ public class PatrolTaskController extends BaseController {
public final RedisService redisService;
private final IPatrolTaskFtpService patrolTaskFtpService;
private final SendService sendService;
@Resource
private SftpClient sftpClient;
public PatrolTaskController(
IPatrolTaskService patrolTaskService,
@ -2325,13 +2338,211 @@ public class PatrolTaskController extends BaseController {
return jsonObject.get("data").toString();
}
@Log(
title = "导出任务详情数据",
businessType = BizType.EXPORT
)
@PostMapping({"/taskInfoExport"})
public ResponseEntity taskInfoExport(HttpServletResponse response, PatrolTaskStatus patrolTaskStatus) throws Exception {
long start = System.currentTimeMillis();
PatrolTaskStatus patro = this.patrolTaskStatusService.selectPatrolTaskStatusByLineId(patrolTaskStatus.getLineId());
ResultAnalysis resultAnalysis = new ResultAnalysis();
resultAnalysis.setTaskPatrolId(patro.getTaskPatrolledId());
resultAnalysis.setResult("0");
resultAnalysis.setAbnormal(patrolTaskStatus.getAbnormal());
resultAnalysis.setPosType(patrolTaskStatus.getPosType());
resultAnalysis.setResultType(patrolTaskStatus.getResultType());
resultAnalysis.setDeviceName(patrolTaskStatus.getDeviceName());
resultAnalysis.setPointName(patrolTaskStatus.getPointName());
resultAnalysis.setChannelName(patrolTaskStatus.getChannelName());
resultAnalysis.setDeviceSource(patrolTaskStatus.getDeviceSource());
resultAnalysis.setPointStatus(patrolTaskStatus.getPointStatus());
resultAnalysis.setAlgName(patrolTaskStatus.getAlgName());
resultAnalysis.setFilterDesc(patrolTaskStatus.getFilterDesc());
resultAnalysis.setDesc(patrolTaskStatus.getDesc());
List<PatrolData> filterList = patrolResultService.selectPatrolDataResultByTaskCodeV2(resultAnalysis);
List<AlgInfo> algInfos = patrolResultService.selectAlgInfo(new PatrolResult());
resultAnalysis.setResult("1");
List<PatrolData> newList = patrolResultService.selectPatrolDataResultByTaskCodeV2(resultAnalysis);
int maxNum = Integer.parseInt(patrolTaskService.selectConfigByKey("MAX_NUM"));
for (PatrolData item : newList) {
item.setAlgName(algInfos.stream().filter((alg) -> alg.getAlgSubtypeCode().equals(item.getAlgType())).findFirst().get().getAlgSubtypeName());
if ("0".equals(item.getFilter())) {
List<PatrolData> filterDatas = filterList.stream().filter((data) -> data.getObjectId().equals(item.getObjectId()) && data.getAlgType().equals(item.getAlgType())).collect(Collectors.toList());
if (!filterDatas.isEmpty()) {
item.setImg(filterDatas.get(0).getImgAnalyse());
item.setFilterDesc(filterDatas.get(0).getDesc());
} else {
item.setImg("--");
}
} else {
item.setImg(item.getImgAnalyse());
item.setImgAnalyse("--");
item.setFilterDesc(item.getDesc());
item.setDesc("--");
}
item.setWarnStatus(item.warnStatus(item.getWarnStatus()));
if (!"meter".equals(item.getAlgType())) {
item.setResValue("--");
}
}
if(StringUtils.isNotEmpty(resultAnalysis.getAlgName())) {
newList = newList.stream().filter((element) -> element.getAlgName().equals(resultAnalysis.getAlgName())).collect(Collectors.toList());
}
if(StringUtils.isNotEmpty(resultAnalysis.getFilterDesc())) {
newList = newList.stream().filter((element) -> element.getFilterDesc().equals(resultAnalysis.getFilterDesc())).collect(Collectors.toList());
}
if(newList.size() > maxNum) {
return ResponseEntity.ok("超过最大导出数量:" + maxNum + "条,请结合查询条件减少导出的数量!");
} else {
exportExcel(response, newList);
logger.info("任务详情导出耗时: {} ms", (System.currentTimeMillis() - start));
return ResponseEntity.ok("数据导出成功!");
}
}
private void exportExcel(HttpServletResponse response, List<PatrolData> newList) throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=\"example.xlsx\"");
HSSFWorkbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("任务详情_" + System.currentTimeMillis());
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("序号");
Cell cell1 = row.createCell(1);
cell1.setCellValue("设备");
Cell cell2 = row.createCell(2);
cell2.setCellValue("相机名");
Cell cell3 = row.createCell(3);
cell3.setCellValue("系统");
Cell cell4 = row.createCell(4);
cell4.setCellValue("点位名称");
Cell cell5 = row.createCell(5);
cell5.setCellValue("状态");
Cell cell6 = row.createCell(6);
cell6.setCellValue("算法名称");
Cell cell7 = row.createCell(7);
cell7.setCellValue("读数");
Cell cell8 = row.createCell(8);
cell8.setCellValue("筛选图片");
Cell cell9 = row.createCell(9);
cell9.setCellValue("筛选结果");
Cell cell10 = row.createCell(10);
cell10.setCellValue("分析图片");
Cell cell11 = row.createCell(11);
cell11.setCellValue("分析结果");
HSSFPatriarch patriarch = (HSSFPatriarch)sheet.createDrawingPatriarch();
for(int i = 0; i < newList.size(); ++i) {
Row row1 = sheet.createRow(i + 1);
Cell cell12 = row1.createCell(0);
cell12.setCellValue(i + 1);
Cell cell13 = row1.createCell(1);
cell13.setCellValue(newList.get(i).getDeviceName());
Cell cell14 = row1.createCell(2);
cell14.setCellValue(newList.get(i).getChannelName());
Cell cell15 = row1.createCell(3);
cell15.setCellValue(newList.get(i).getDeviceSource());
Cell cell16 = row1.createCell(4);
cell16.setCellValue(newList.get(i).getPointName());
Cell cell17 = row1.createCell(5);
cell17.setCellValue(newList.get(i).getPointStatus());
Cell cell18 = row1.createCell(6);
cell18.setCellValue(newList.get(i).getAlgName());
Cell cell19 = row1.createCell(7);
cell19.setCellValue(newList.get(i).getResValue());
try {
insertImage(workbook, patriarch, this.images(newList.get(i).getImg(), this.inputStreamMap(newList.get(i).getImg())), 8, i + 1, 8);
} catch (Exception e) {
e.printStackTrace();
}
Cell cell21 = row1.createCell(9);
cell21.setCellValue(newList.get(i).getFilterDesc());
try {
insertImage(workbook, patriarch, this.images(newList.get(i).getImg(), this.inputStreamMap(newList.get(i).getImg())), 10, i + 1, 10);
} catch (Exception e) {
e.printStackTrace();
}
Cell cell23 = row1.createCell(11);
cell23.setCellValue(newList.get(i).getDesc());
}
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
workbook.close();
outputStream.flush();
outputStream.close();
}
private static void insertImage(HSSFWorkbook wb, HSSFPatriarch pa, byte[] data, int cell, int row, int cell1) {
int x1 = 0;
int y1 = 0;
int x2 = 45;
int y2 = 0;
HSSFClientAnchor anchor = new HSSFClientAnchor(x1, y1, x2, y2, (short)cell, row, (short)cell1, row);
pa.createPicture(anchor, wb.addPicture(data, 5)).resize(1.0D);
}
public byte[] images(String imgSrc, Map<String, byte[]> inputStreamMap) {
return inputStreamMap.get(imgSrc);
}
public static byte[] getStringByInputStream(InputStream inputStream) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
byte[] b = new byte[10240];
int n;
while((n = inputStream.read(b)) != -1) {
outputStream.write(b, 0, n);
}
} catch (Exception e) {
e.printStackTrace();
try {
inputStream.close();
outputStream.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
return outputStream.toByteArray();
}
private Map<String, byte[]> inputStreamMap(String imgPath) throws IOException {
Map<String, byte[]> streamHashMap = new HashMap<>();
String[] images = imgPath.split(StringUtils.COMMA);
for (String image : images) {
try {
sftpClient.downLoad(image, (inputStream) -> {
byte[] shm = streamHashMap.get(image);
byte[] bytes = getStringByInputStream(inputStream);
if (shm == null) {
streamHashMap.put(image, bytes);
}
});
} catch (Exception e) {
e.printStackTrace();
logger.info("sss: {}", e.getMessage());
}
}
return streamHashMap;
}
protected TableDataInfo getDataTable(int flag, List<?> list2, List<?> list) {
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(200);
rspData.setRows(list2);
if (flag == 0) {
rspData.setMsg("查询成功");
rspData.setTotal((new PageInfo(list)).getTotal());
rspData.setTotal((new PageInfo<>(list)).getTotal());
} else if (flag == 1) {
rspData.setMsg("lineId为空");
} else if (flag == 2) {


Loading…
Cancel
Save