소스 검색

Merge branch 'develop' of http://192.168.11.14:51037/gitadmin/tuoheng_freeway into feature_v1.0

tags/v1.0.0^2
chengwang 1 년 전
부모
커밋
2217c61ba9
11개의 변경된 파일785개의 추가작업 그리고 633개의 파일을 삭제
  1. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/ReportController.java
  2. +50
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/report/ExportInspectionHandleReportCodeEnum.java
  3. +50
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/report/ExportInspectionReportReportCodeEnum.java
  4. +0
    -15
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/inspection/QueryInspectionPageListRequest.java
  5. +7
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspectionfile/query/QueryInspectionFilePageListService.java
  6. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/IReportService.java
  7. +8
    -3
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/IReportServiceImpl.java
  8. +143
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/export/ExportInspectionHandleReportService.java
  9. +45
    -609
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/export/ExportInspectionReportService.java
  10. +414
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/export/GenerateReportWordService.java
  11. +64
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/DownloadUtil.java

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/ReportController.java 파일 보기

@@ -61,7 +61,7 @@ public class ReportController {
@GetMapping("/export/inspection/{id}")
public void exportInspectionReport(@PathVariable("id")String id, HttpServletRequest request, HttpServletResponse response) {
log.info("进入导出巡检报告接口");
reportService.exportInspectionReport(id, request, response);
reportService.exportInspectionReport(request, response, id);
}

/**
@@ -79,7 +79,7 @@ public class ReportController {
@GetMapping("/export/inspection/handle/{id}")
public void exportHandleReport(@PathVariable("id")String id, HttpServletRequest request, HttpServletResponse response) {
log.info("进入导出处理报告接口");
reportService.exportInspectionHandleReport(id, request, response);
reportService.exportInspectionHandleReport(request, response, id);
}

}

+ 50
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/report/ExportInspectionHandleReportCodeEnum.java 파일 보기

@@ -0,0 +1,50 @@
package com.tuoheng.admin.enums.code.report;

/**
* 导出巡检处理报告返回码
* 模块代码:27(报告管理)
* 接口代码:05 (导出处理巡检)
*
* @author wanjing
* @team tuoheng
* @date 2022-12-14
*/
public enum ExportInspectionHandleReportCodeEnum {

EXPORT_IS_FAILED(1270500, "导出巡检处理报告失败"),
REPORT_ID_IS_NULL(1270501, "报告id为空"),
REPORT_IS_NOT_EXIST(1270502, "报告不存在");

/**
* 编号
*/
private int code;

/**
* 类型名称
*/
private String msg;

ExportInspectionHandleReportCodeEnum(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}


}

+ 50
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/report/ExportInspectionReportReportCodeEnum.java 파일 보기

@@ -0,0 +1,50 @@
package com.tuoheng.admin.enums.code.report;

/**
* 导出巡检报告返回码
* 模块代码:27(报告管理)
* 接口代码:04 (导出巡检)
*
* @author wanjing
* @team tuoheng
* @date 2022-12-14
*/
public enum ExportInspectionReportReportCodeEnum {

EXPORT_IS_FAILED(1270400, "导出巡检报告失败"),
REPORT_ID_IS_NULL(1270401, "报告id为空"),
REPORT_IS_NOT_EXIST(1270402, "报告不存在");

/**
* 编号
*/
private int code;

/**
* 类型名称
*/
private String msg;

ExportInspectionReportReportCodeEnum(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}


}

+ 0
- 15
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/inspection/QueryInspectionPageListRequest.java 파일 보기

@@ -15,21 +15,6 @@ import java.util.List;
@Data
public class QueryInspectionPageListRequest extends BaseQuery {

/**
* 用户ID
*/
private Integer userId;

/**
* 租户id
*/
private Integer tenantId;

/**
* 关键字,匹配任务编号和任务名称
*/
// private String key;

/**
* 任务编号
*/

+ 7
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/inspectionfile/query/QueryInspectionFilePageListService.java 파일 보기

@@ -1,5 +1,6 @@
package com.tuoheng.admin.service.inspectionfile.query;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -154,8 +155,12 @@ public class QueryInspectionFilePageListService {
}
road = roadMap.get(inspectionFilePageListVo.getRoadId());
dept = deptMap.get(inspectionFilePageListVo.getDeptId());
inspectionFilePageListVo.setRoadName(road.getName());
inspectionFilePageListVo.setDeptName(dept.getName());
if (ObjectUtil.isNotNull(road)) {
inspectionFilePageListVo.setRoadName(road.getName());
}
if (ObjectUtil.isNotNull(dept)) {
inspectionFilePageListVo.setDeptName(dept.getName());
}
inspectionFilePageListVo.setFileThumbnail(CommonConfig.imageURL + inspectionFilePageListVo.getFileThumbnail());
}
return inspectionFilePageListVoList;

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/IReportService.java 파일 보기

@@ -55,7 +55,7 @@ public interface IReportService {
*
* @return
*/
void exportInspectionReport(String id, HttpServletRequest request, HttpServletResponse response);
void exportInspectionReport(HttpServletRequest request, HttpServletResponse response, String id);
/**
*
@@ -63,5 +63,5 @@ public interface IReportService {
*
* @return
*/
void exportInspectionHandleReport(String id, HttpServletRequest request, HttpServletResponse response);
void exportInspectionHandleReport(HttpServletRequest request, HttpServletResponse response, String id);
}

+ 8
- 3
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/IReportServiceImpl.java 파일 보기

@@ -1,6 +1,7 @@
package com.tuoheng.admin.service.report;

import com.tuoheng.admin.request.report.QueryReportPageListRequest;
import com.tuoheng.admin.service.report.export.ExportInspectionHandleReportService;
import com.tuoheng.admin.service.report.export.ExportInspectionReportService;
import com.tuoheng.admin.service.report.generate.GenerateReportService;
import com.tuoheng.admin.service.report.query.QueryInspectionHandleReportService;
@@ -33,6 +34,9 @@ public class IReportServiceImpl implements IReportService{
@Autowired
private ExportInspectionReportService exportInspectionReportService;

@Autowired
private ExportInspectionHandleReportService exportInspectionHandleReportService;

/**
*
* 生成报告
@@ -85,8 +89,8 @@ public class IReportServiceImpl implements IReportService{
* @return
*/
@Override
public void exportInspectionReport(String id, HttpServletRequest request, HttpServletResponse response) {
exportInspectionReportService.exportReport(id, response);
public void exportInspectionReport(HttpServletRequest request, HttpServletResponse response, String id) {
exportInspectionReportService.exportReport(response, id);
}

/**
@@ -96,6 +100,7 @@ public class IReportServiceImpl implements IReportService{
* @return
*/
@Override
public void exportInspectionHandleReport(String id, HttpServletRequest request, HttpServletResponse response) {
public void exportInspectionHandleReport(HttpServletRequest request, HttpServletResponse response, String id) {
exportInspectionHandleReportService.exportReport(response, id);
}
}

+ 143
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/export/ExportInspectionHandleReportService.java 파일 보기

@@ -0,0 +1,143 @@
package com.tuoheng.admin.service.report.export;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.InspectionFile;
import com.tuoheng.admin.entity.InspectionFileHandle;
import com.tuoheng.admin.entity.Report;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.enums.code.report.ExportInspectionHandleReportCodeEnum;
import com.tuoheng.admin.mapper.InspectionFileHandleMapper;
import com.tuoheng.admin.mapper.InspectionFileMapper;
import com.tuoheng.admin.mapper.ReportMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.utils.DownloadUtil;
import com.tuoheng.admin.utils.ShiroUtils;
import com.tuoheng.common.core.config.UploadFileConfig;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;

/**
* 导出巡检处理报告业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2022-12-14
*/
@Slf4j
@Service
public class ExportInspectionHandleReportService {

@Autowired
private ReportMapper reportMapper;

@Autowired
private TenantMapper tenantMapper;

@Autowired
private InspectionFileMapper inspectionFileMapper;

@Autowired
private InspectionFileHandleMapper inspectionFileHandleMapper;

@Autowired
private GenerateReportWordService generateReportWordService;

public JsonResult exportReport(HttpServletResponse response, String reportId) {
String tenantId = ShiroUtils.getTenantId();

JsonResult result = this.check(reportId);
if (0 != result.getCode()) {
log.info("导出巡检处理报告业务:校验失败:{}", result.getMsg());
return result;
}

//查询报告
Report report = (Report) result.getData();

// 查询问题清单
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(new LambdaQueryWrapper<InspectionFile>()
.eq(InspectionFile::getTenantId, tenantId)
.eq(InspectionFile::getInspectionId, report.getInspectionId()));

// 查询问题处理结果
List<String> inspectionFileIdList = inspectionFileList.stream().map(o -> o.getId()).collect(Collectors.toList());
List<InspectionFileHandle> inspectionFileHandleList = inspectionFileHandleMapper.selectList(new LambdaQueryWrapper<InspectionFileHandle>()
.in(InspectionFileHandle::getInspectionFileId, inspectionFileIdList));

String filename = report.getReportCode() + "CL.doc";
String filePath = UploadFileConfig.uploadFolder + "/doc/" + filename;
File fd = new File(UploadFileConfig.uploadFolder + "/doc");
if (!fd.exists()) {
fd.mkdirs();
}

// 生成word
String areaName = this.getAreaName();
String titleName = areaName + "高速巡检处理报告";
File f = new File(filePath);
if (!f.exists() || f.length() < 1000) {
result = generateReportWordService.buildWord(filePath, titleName, report, inspectionFileList, inspectionFileHandleList);
if (0 != result.getCode()) {
log.info("导出巡检处理报告业务:生成word失败:{}", result.getMsg());
return result;
}
}

// 下载
String fileName = this.getAreaName() + "高速巡检处理报告【" + report.getReportCode() + "】.doc";
DownloadUtil.download(response, filePath, fileName);

return JsonResult.success();
}

/**
* 检查
*
* @param id
* @return
*/
private JsonResult check(String id) {
if (StringUtils.isEmpty(id)) {
return JsonResult.error(ExportInspectionHandleReportCodeEnum.REPORT_ID_IS_NULL.getCode(), ExportInspectionHandleReportCodeEnum.REPORT_ID_IS_NULL.getMsg());
}
Report report = reportMapper.selectOne(Wrappers.<Report>lambdaQuery()
.eq(Report::getId, id)
.eq(Report::getMark, 1));
if (null == report) {
return JsonResult.error(ExportInspectionHandleReportCodeEnum.REPORT_IS_NOT_EXIST.getCode(), ExportInspectionHandleReportCodeEnum.REPORT_IS_NOT_EXIST.getMsg());
}
return JsonResult.success(report);
}

/**
* 获取区域名称
*
* @return
*/
private String getAreaName() {
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId());
String areaName = "";
if (ObjectUtil.isNotNull(tenant)) {
if (!StringUtils.isEmpty(tenant.getProvinceName())) {
areaName += tenant.getProvinceName();
}
if (!StringUtils.isEmpty(tenant.getCityName())) {
areaName += tenant.getCityName();
}
if (!StringUtils.isEmpty(tenant.getDistrictName())) {
areaName += tenant.getDistrictName();
}
}
return areaName;
}
}

+ 45
- 609
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/export/ExportInspectionReportService.java 파일 보기

@@ -3,33 +3,27 @@ package com.tuoheng.admin.service.report.export;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lowagie.text.*;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.enums.code.questiontype.QuestionTypeEnum;
import com.tuoheng.admin.enums.code.report.GenerateReportCodeEnum;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.entity.InspectionFile;
import com.tuoheng.admin.entity.InspectionFileHandle;
import com.tuoheng.admin.entity.Report;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.enums.code.report.ExportInspectionReportReportCodeEnum;
import com.tuoheng.admin.mapper.InspectionFileHandleMapper;
import com.tuoheng.admin.mapper.InspectionFileMapper;
import com.tuoheng.admin.mapper.ReportMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.utils.DownloadUtil;
import com.tuoheng.admin.utils.ShiroUtils;
import com.tuoheng.admin.utils.WordUtils;
import com.tuoheng.common.core.config.UploadFileConfig;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
@@ -46,9 +40,6 @@ public class ExportInspectionReportService {
@Autowired
private ReportMapper reportMapper;

@Autowired
private UserMapper userMapper;

@Autowired
private TenantMapper tenantMapper;

@@ -58,7 +49,10 @@ public class ExportInspectionReportService {
@Autowired
private InspectionFileHandleMapper inspectionFileHandleMapper;

public JsonResult exportReport(String reportId, HttpServletResponse response) {
@Autowired
private GenerateReportWordService generateReportWordService;

public JsonResult exportReport(HttpServletResponse response, String reportId) {
String tenantId = ShiroUtils.getTenantId();

JsonResult result = this.check(reportId);
@@ -70,128 +64,34 @@ public class ExportInspectionReportService {
//查询报告
Report report = (Report) result.getData();

// BeanUtils.copyProperties(report, reportInfoVo);

// 查询问题清单
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectList(new LambdaQueryWrapper<InspectionFile>()
.eq(InspectionFile::getTenantId, tenantId)
.eq(InspectionFile::getInspectionId, report.getInspectionId()));

// 查询问题处理结果
List<String> inspectionFileIdList = inspectionFileList.stream().map(o -> o.getId()).collect(Collectors.toList());
List<InspectionFileHandle> inspectionFileHandleList = inspectionFileHandleMapper.selectList(new LambdaQueryWrapper<InspectionFileHandle>()
.in(InspectionFileHandle::getInspectionFileId, inspectionFileIdList));
.eq(InspectionFile::getTenantId, tenantId)
.eq(InspectionFile::getInspectionId, report.getInspectionId()));

//创建word
String filename = report.getReportCode() + ".doc";
String filepath = UploadFileConfig.uploadFolder + "/doc/" + filename;
String filePath = UploadFileConfig.uploadFolder + "/doc/" + filename;
File fd = new File(UploadFileConfig.uploadFolder + "/doc");
File f = new File(filepath);
if (!fd.exists()) {
fd.mkdirs();
}

WordUtils wordUtils = new WordUtils();
try {
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId());
String areaName = "";
if(ObjectUtil.isNotNull(tenant)){
// areaName = tenant.getProvinceName() + tenant.getCityName() + tenant.getDistrictName();
if (!StringUtils.isEmpty(tenant.getProvinceName())) {
areaName += tenant.getProvinceName();
}
if (!StringUtils.isEmpty(tenant.getCityName())) {
areaName += tenant.getCityName();
}
if (!StringUtils.isEmpty(tenant.getDistrictName())) {
areaName += tenant.getDistrictName();
}
}
if (!f.exists() || f.length() < 1000) {
f.delete();
f.createNewFile();
wordUtils.openDocument(filepath);
wordUtils.getDocument().setPageSize(PageSize.A4);
wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f);

//标题
wordUtils.insertTitlePattern(areaName + "高速巡检报告", wordUtils.rtfGsBt1);
wordUtils.insertContext("报告编号:" + report.getReportCode(), 10, Font.NORMAL, Element.ALIGN_RIGHT, 20, 0, 0);

// wordUtils.insertTitlePatternThird("一:高速信息", wordUtils.rtfGsBt3);
// //wordUtils.getDocument().add(new Paragraph(""));
// Table inspectionTable = this.buildInspectionTable();
// wordUtils.getDocument().add(inspectionTable);

wordUtils.insertTitlePatternThird("巡检信息", wordUtils.rtfGsBt3);
Table table2 = this.buildInspectionTable(report);
wordUtils.getDocument().add(table2);

wordUtils.insertTitlePatternThird("巡检结果", wordUtils.rtfGsBt3);
Table table3 = this.buildTable3();
wordUtils.getDocument().add(table3);

wordUtils.insertTitlePatternThird("问题清单", wordUtils.rtfGsBt3);
Table inspectionFileTable = this.buildInspectionFileTable(inspectionFileList);
wordUtils.getDocument().add(inspectionFileTable);

// if (reportInfoVo.getImageList().size() > 0) {
// wordUtils.insertTitlePatternThird("四:问题清单", wordUtils.rtfGsBt3);
// for (int i = 0; i < reportInfoVo.getImageList().size(); i++) {
// InspectionFileInfoVo inspectionFileInfoVo = reportInfoVo.getImageList().get(i);
//
// InspectionQuestionItem item = inspectionQuestionItemMapper.selectOne(new LambdaQueryWrapper<InspectionQuestionItem>()
// .eq(inspectionFileInfoVo.getId() != null, InspectionQuestionItem::getInspectionFileId, inspectionFileInfoVo.getId())
// .eq(InspectionQuestionItem::getTenantId, tenantId));
// if (item != null) {
// inspectionFileInfoVo.setHandImg(item.getHandlerImage());
// inspectionFileInfoVo.setHandContent(item.getHandlerResult());
// inspectionFileInfoVo.setHandTime(DateUtils.dateTime(item.getHandlerTime()));
// User user = userMapper.selectById(item.getHandlerUser());
// inspectionFileInfoVo.setHanderName(user.getRealname());
// }
//
// Table table4 = this.buildTable4();
// wordUtils.getDocument().add(table4);
// }
// }
wordUtils.closeDocument();
// 生成word
String areaName = this.getAreaName();
String titleName = areaName + "高速巡检报告";
File f = new File(filePath);
if (!f.exists() || f.length() < 1000) {
result = generateReportWordService.buildWord(filePath, titleName, report, inspectionFileList, null);
if (0 != result.getCode()) {
log.info("导出巡检报告业务:生成word失败:{}", result.getMsg());
return result;
}
}

//清空缓存
response.reset();
// 定义浏览器响应表头,并定义下载名
String fileName = URLEncoder.encode(areaName + "高速巡检报告【" + report.getReportCode() + "】.doc", "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName,"UTF-8"));
response.setCharacterEncoding("utf-8");
//定义下载的类型
response.setContentType("application/msword;charset=UTF-8");
OutputStream out;
File files = new File(UploadFileConfig.uploadFolder + "doc/", filename);
// 下载
String fileName = this.getAreaName() + "高速巡检报告【" + report.getReportCode() + "】.doc";
DownloadUtil.download(response, filePath, fileName);

FileInputStream inputStream = new FileInputStream(files);
//3.通过response获取ServletOutputStream对象(out)
out = response.getOutputStream();
int b = 0;
byte[] buffer = new byte[512];
while (b != -1) {
b = inputStream.read(buffer);
//4.写到输出流(out)中
out.write(buffer, 0, b);
}
inputStream.close();
out.close();
out.flush();
System.out.println("结束。。。。。。");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
wordUtils.closeDocument();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
}
return JsonResult.success();
}

@@ -203,500 +103,36 @@ public class ExportInspectionReportService {
*/
private JsonResult check(String id) {
if (StringUtils.isEmpty(id)) {
return JsonResult.error(GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getCode(), GenerateReportCodeEnum.INSPECTION_ID_IS_NULL.getMsg());
return JsonResult.error(ExportInspectionReportReportCodeEnum.REPORT_ID_IS_NULL.getCode(), ExportInspectionReportReportCodeEnum.REPORT_ID_IS_NULL.getMsg());
}
Report report = reportMapper.selectOne(Wrappers.<Report>lambdaQuery()
.eq(Report::getId, id)
.eq(Report::getMark, 1));
if (null == report) {
return JsonResult.error(GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getCode(), GenerateReportCodeEnum.INSPECTION_IS_NOT_EXIST.getMsg());
return JsonResult.error(ExportInspectionReportReportCodeEnum.REPORT_IS_NOT_EXIST.getCode(), ExportInspectionReportReportCodeEnum.REPORT_IS_NOT_EXIST.getMsg());
}
return JsonResult.success(report);
}

/**
* 获取区域名称
*
* 构建巡检信息
*
*/
private Table buildInspectionTable1() throws DocumentException {
Table table = new Table(6); //生成一表格
table.setOffset(1f);
int width[] = {1, 1, 1, 1, 1, 1};
table.setWidths(width);//设置系列所占比例
table.setWidth(100);
table.setAutoFillEmptyCells(true);
table.setAlignment(Element.ALIGN_LEFT);//居中显示
for (int i = 0; i < 11; i++) {
Cell cell = new Cell();
String str = null;
cell.setVerticalAlignment(Element.ALIGN_RIGHT);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
Font font = new Font();
font.setSize(10.5f);
font.setStyle(Font.BOLD);
if (i == 0) {
str = "河道基本信息";
cell.setColspan(6);
} else if (i == 1) {
str = "责任单位";
} else if (i == 2) {
// str = reportInfoVo.getStreamArea();
font.setStyle(Font.NORMAL);
} else if (i == 3) {
str = "河流名称";
} else if (i == 4) {
// str = reportInfoVo.getStreamName();
font.setStyle(Font.NORMAL);
} else if (i == 5) {
str = "河段长度";
} else if (i == 6) {
// str = reportInfoVo.getStreamLength();
font.setStyle(Font.NORMAL);
} else if (i == 7) {
str = "起讫位置";
} else if (i == 8) {
// str = reportInfoVo.getStreamLocation();
font.setStyle(Font.NORMAL);
cell.setColspan(3);
} else if (i == 9) {
str = "巡查里程";
} else if (i == 10) {
// str = reportInfoVo.getStreamLength();
font.setStyle(Font.NORMAL);
}
Paragraph p = new Paragraph(str, font);
cell.add(p);
table.addCell(cell);
}
return table;
}

/**
*
* 构建巡检信息
*
* @return
*/
private Table buildInspectionTable(Report report) throws DocumentException {
Table table = new Table(2);//生成一表格
table.setOffset(1f);
int width2[] = {1, 1};
table.setWidths(width2);//设置系列所占比例
table.setWidth(100);
table.setAutoFillEmptyCells(true);
table.setAlignment(Element.ALIGN_CENTER); //居中显示
table.setAlignment(Element.ALIGN_MIDDLE); //垂直居中显示
for (int i = 0; i < 14; i++) {
Cell cell = new Cell();
String str = null;
cell.setVerticalAlignment(Element.ALIGN_LEFT);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
Font font = new Font();
font.setSize(10.5f);
font.setStyle(Font.BOLD);
if (i == 0) {
str = "气象信息";
} else if (i == 1) {
str = report.getWeather();
font.setStyle(Font.NORMAL);
} else if (i == 2) {
str = "巡检部门";
} else if (i == 3) {
str = "";
font.setStyle(Font.NORMAL);
} else if (i == 4) {
str = "巡检方式";
} else if (i == 5) {
if (report.getInspectionType() == 1) {
str = "无人机";
} else if (report.getInspectionType() == 2) {
str = "机场巡逻";
} else if (report.getInspectionType() == 3) {
str = "飞手值飞";
}
font.setStyle(Font.NORMAL);
} else if (i == 6) {
str = "巡查设备";
} else if (i == 7) {
str = report.getEquipmentName();
font.setStyle(Font.NORMAL);
} else if (i == 8) {
str = "巡查开始时间";
} else if (i == 9) {
str = report.getExecutionStartTime() == null ? "" : DateUtils.dateTime(report.getExecutionStartTime());
font.setStyle(Font.NORMAL);
} else if (i == 10) {
str = "巡查结束时间";
} else if (i == 11) {
str = report.getExecutionEndTime() == null ? "" : DateUtils.dateTime(report.getExecutionEndTime());
font.setStyle(Font.NORMAL);
} else if (i == 12) {
str = "巡检高速";
} else if (i == 13) {
str = "G2";
font.setStyle(Font.NORMAL);
private String getAreaName() {
Tenant tenant = tenantMapper.selectById(ShiroUtils.getTenantId());
String areaName = "";
if (ObjectUtil.isNotNull(tenant)) {
if (!StringUtils.isEmpty(tenant.getProvinceName())) {
areaName += tenant.getProvinceName();
}
Paragraph p = new Paragraph(str, font);
cell.add(p);
table.addCell(cell);
}
return table;
}

/**
*
* 构建巡检信息
*
*/
private Table buildTable3() throws DocumentException {
Table table = new Table(5);//生成一表格
// Map<String, Object> params = getInsCount(reportInfoVo);
// table.setOffset(1f);
// int width[] = {1, 2, 3, 14, 3};
// table.setWidths(width);//设置系列所占比例
// table.setWidth(100);
// table.setAutoFillEmptyCells(true);
// // table3.setAlignment(Element.ALIGN_CENTER);//居中显示
// // table3.setAlignment(Element.ALIGN_MIDDLE);//垂直居中显示
// for (int i = 0; i < 44; i++) {
// Cell cell = new Cell();
// String str = null;
// cell.setVerticalAlignment(Element.ALIGN_CENTER);
// cell.setHorizontalAlignment(Element.ALIGN_CENTER);
// Font font = new Font();
// font.setSize(10.5f);
// font.setStyle(Font.BOLD);
// if (i == 0) {
// str = "序号";
// } else if (i == 1) {
// str = "项目";
// cell.setColspan(2);
// } else if (i == 2) {
// str = "巡检内容";
// } else if (i == 3) {
// str = "巡检监测结果";
// } else if (i == 4) {
// str = "一";
// cell.setRowspan(6);
// } else if (i == 5) {
// str = QuestionNameEnum.WATER_SURFACE.getName();
// cell.setRowspan(6);
// } else if (i == 6) {
// str = QuestionTypeEnum.DAILY_MONITORING.getName();
// cell.setRowspan(3);
// } else if (i == 7) {
// str = "水面有漂浮物";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 8) {
// str = params.get("${totalCount1}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 9) {
// str = "水面有明显鱼类翻肚现象";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 10) {
// str = params.get("${totalCount2}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 11) {
// str = "河道内存在水生植被";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 12) {
// str = params.get("${totalCount3}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 13) {
// str = QuestionTypeEnum.KEY_VERIFICATION.getName();
// cell.setRowspan(3);
// } else if (i == 14) {
// str = "河道内有蓝藻爆发";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 15) {
// str = params.get("${totalCount4}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 16) {
// str = "水生动、植物死亡";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 17) {
// str = params.get("${totalCount5}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 18) {
// str = "河道有违规阻水物";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 19) {
// str = params.get("${totalCount6}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 20) {
// str = "二";
// cell.setRowspan(4);
// } else if (i == 21) {
// str = QuestionNameEnum.WATER_FRONT.getName();
// cell.setRowspan(4);
// } else if (i == 22) {
// str = QuestionTypeEnum.DAILY_MONITORING.getName();
// cell.setRowspan(3);
// } else if (i == 23) {
// str = "河道养护范围内种菜";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 24) {
// str = params.get("${totalCount7}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 25) {
// str = "河堤、栏杆等设施有损坏";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 26) {
// str = params.get("${totalCount8}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 27) {
// str = "岸坡有垃圾";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 28) {
// str = params.get("${totalCount9}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 29) {
// str = QuestionTypeEnum.KEY_VERIFICATION.getName();
// } else if (i == 30) {
// str = "河道蓝线内(岸上)新增违法建筑或构造物";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 31) {
// str = params.get("${totalCount10}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 32) {
// str = "三";
// } else if (i == 33) {
// str = QuestionNameEnum.WATER_QUALITY.getName();
// } else if (i == 34) {
// str = QuestionTypeEnum.DAILY_MONITORING.getName();
// } else if (i == 35) {
// str = "水体出现水质明显突变(感官、颜色)";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 36) {
// str = params.get("${totalCount11}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 37) {
// str = "四";
// cell.setRowspan(2);
// } else if (i == 38) {
// str = QuestionNameEnum.OUTFALL.getName();
// cell.setRowspan(2);
// } else if (i == 39) {
// str = QuestionTypeEnum.DAILY_MONITORING.getName();
// cell.setRowspan(2);
// } else if (i == 40) {
// str = "入河、湖支流、泵站、入河排口晴天排放异常水体";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 41) {
// str = params.get("${totalCount12}").toString();
// font.setStyle(Font.NORMAL);
// } else if (i == 42) {
// str = "存在排口";
// cell.setHorizontalAlignment(Element.ALIGN_LEFT);
// font.setStyle(Font.NORMAL);
// } else if (i == 43) {
// str = params.get("${totalCount13}").toString();
// font.setStyle(Font.NORMAL);
// }
// Paragraph p = new Paragraph(str, font);
// cell.add(p);
// table.addCell(cell);
// }
return table;
}

/**
*
* 构建巡检问题信息
*
*/
private Table buildInspectionFileTable(List<InspectionFile> inspectionFileList) throws DocumentException, IOException {
Table table = new Table(2); //生成一表格
table.setOffset(1f);
int width2[] = {1, 1};
table.setWidths(width2); //设置系列所占比例
table.setWidth(100);
table.setAutoFillEmptyCells(true);

InspectionFile inspectionFile;
Font font = new Font();
font.setSize(10.5f);
for (int i = 0; i < inspectionFileList.size(); i++) {
inspectionFile = inspectionFileList.get(i);
for (int j = 0; j < 7; j++) {
Cell cell = new Cell();
cell.setVerticalAlignment(Element.ALIGN_CENTER); // 设置单元格的垂直对齐方式 : 居中
cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 设置单元格的水平对齐方式 :居中对齐
String str = "";
if (j == 0) {
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
font.setSize(12);
str = " 问题" + (i + 1);
cell.add(new Paragraph(str, font));
cell.setColspan(2);
font.setStyle(Font.BOLD);
} else if (j == 1) {
str = " 坐标";
cell.add(new Paragraph(str, font));
} else if (j == 2) {
str = inspectionFile.getLongitude() + "," + inspectionFile.getLatitude();
cell.add(new Paragraph(str, font));
} else if (j == 3) {
str = " 问题描述";
cell.add(new Paragraph(str, font));
} else if (j == 4) {
str = inspectionFile.getQuestionDesc();
cell.add(new Paragraph(str, font));
} else if (j == 5) {
str = " 问题图片";
cell.add(new Paragraph(str, font));
} else if (j == 6) {
Image image = null;
String url = CommonConfig.imageURL + inspectionFile.getFileThumbnail();
url = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Ff%2F57a42b9002e19.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1673509195&t=57d6710dc11bdd1ff75f5121a7d6c73f";

if (new UrlResource(url).exists()) {
image = Image.getInstance(url);
image.setAlignment(Image.ALIGN_CENTER);
image.scalePercent(100); //依照比例缩放
image.setAbsolutePosition(400, 600);
image.scaleToFit(300, 300);//自定义大
} else {
log.error("图片不存在!" + url);
}
if (new UrlResource(url).exists()) {
cell.add(image);
} else {
cell.add(new Paragraph(""));
}
}
table.addCell(cell);
if (!StringUtils.isEmpty(tenant.getCityName())) {
areaName += tenant.getCityName();
}
}
return table;
}

/**
*
* 构建巡检问题信息
*
*/
private Table buildInspectionFileTable2() throws DocumentException, IOException {
Table table = new Table(2); //生成一表格
table.setOffset(1f);
int width4[] = {1, 2};
table.setWidths(width4);//设置系列所占比例
table.setWidth(100);
table.setAutoFillEmptyCells(true);
for (int i = 0; i < 8; i++) {
Cell cell = new Cell();
String str = "";
Font font = new Font();
font.setSize(10.5f);
cell.setVerticalAlignment(Element.ALIGN_CENTER);
// if (i == 0) {
// font.setSize(12);
// str = " 问题" + (i + 1);
// cell.add(new Paragraph(str, font));
// cell.setColspan(2);
// font.setStyle(Font.BOLD);
// } else if (i == 1) {
// str = " 坐标";
// cell.add(new Paragraph(str, font));
// } else if (i == 2) {
// str = report.getImageList().get(i).getLongitude() + "," + reportInfoVo.getImageList().get(i).getLatitude();
// cell.add(new Paragraph(str, font));
// } else if (i == 3) {
// str = " 问题描述";
// cell.add(new Paragraph(str, font));
// } else if (i == 4) {
// str = reportInfoVo.getImageList().get(i).getContent();
// cell.add(new Paragraph(str, font));
// } else if (i == 5) {
// str = " 问题图片";
// cell.add(new Paragraph(str, font));
// } else if (i == 6) {
// Image image = null;
// String url = CommonConfig.imageURL + reportInfoVo.getImageList().get(i).getFileImage();
// if (new UrlResource(url).exists()) {
// image = Image.getInstance(url);
// image.setAlignment(Image.ALIGN_CENTER);
// image.scalePercent(100); //依照比例缩放
// image.setAbsolutePosition(400, 600);
// image.scaleToFit(300, 300);//自定义大
// } else {
// log.error("图片不存在!" + url);
// }
// if (new UrlResource(url).exists()) {
// cell.add(image);
// } else {
// cell.add(new Paragraph(""));
// }
// } else if (i == 7) {
// str = " 处理结果";
// cell.add(new Paragraph(str, font));
// cell.setColspan(2);
// font.setStyle(Font.BOLD);
// } else if (i == 8) {
// str = " 处理人";
// cell.add(new Paragraph(str, font));
// } else if (i == 9) {
// str = inspectionFileInfoVo.getHanderName();
// cell.add(new Paragraph(str, font));
// } else if (j == 10) {
// str = " 处理时间";
// cell.add(new Paragraph(str, font));
// } else if (j == 11) {
// str = inspectionFileInfoVo.getHandTime();
// cell.add(new Paragraph(str, font));
// } else if (j == 12) {
// str = " 备注";
// cell.add(new Paragraph(str, font));
// } else if (j == 13) {
// str = inspectionFileInfoVo.getHandContent();
// cell.add(new Paragraph(str, font));
// } else if (j == 14) {
// String[] handUrls = inspectionFileInfoVo.getHandImg().split(",");
// for (int k = 0; k < handUrls.length; k++) {
// cell = new Cell();
// cell.setVerticalAlignment(Element.ALIGN_CENTER);
// if (handUrls.length == 1) {
// cell.add(new Paragraph(" 结果图片", font));
// } else {
// cell.add(new Paragraph(" 结果图片" + (k + 1), font));
// }
// table.addCell(cell);
// cell = new Cell();
// Image image = null;
// String url = CommonConfig.imageURL + handUrls[k];
// if (new UrlResource(url).exists()) {
// image = Image.getInstance(url);
// image.setAlignment(Image.ALIGN_CENTER);
// image.scalePercent(100); //依照比例缩放
// image.setAbsolutePosition(400, 600);
// image.scaleToFit(300, 300);//自定义大
// } else {
// System.out.println("图片不存在!" + url);
// }
// if (new UrlResource(url).exists()) {
// cell.add(image);
// } else {
// cell.add(new Paragraph(""));
// }
// table.addCell(cell);
// }
// }
if (i != 14) {
table.addCell(cell);
if (!StringUtils.isEmpty(tenant.getDistrictName())) {
areaName += tenant.getDistrictName();
}
}
return table;
return areaName;
}
}

+ 414
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/report/export/GenerateReportWordService.java 파일 보기

@@ -0,0 +1,414 @@
package com.tuoheng.admin.service.report.export;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lowagie.text.*;
import com.tuoheng.admin.entity.*;
import com.tuoheng.admin.mapper.*;
import com.tuoheng.admin.utils.WordUtils;
import com.tuoheng.common.core.config.common.CommonConfig;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
public class GenerateReportWordService {

@Autowired
private UserMapper userMapper;

@Autowired
private DeptMapper deptMapper;

@Autowired
private RoadInformationMapper roadInformationMapper;

@Autowired
private QuestionTypeMapper questionTypeMapper;

@Autowired
private InspectionFileMapper inspectionFileMapper;

/**
* 创建word
*
* @param filepath
* @param report
* @param inspectionFileList
* @return
*/
public JsonResult buildWord(String filepath, String titleName, Report report, List<InspectionFile> inspectionFileList, List<InspectionFileHandle> inspectionFileHandleList) {
WordUtils wordUtils = new WordUtils();
wordUtils.getDocument().setPageSize(PageSize.A4);
wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f);
try {
wordUtils.openDocument(filepath);

// 标题
wordUtils.insertTitlePattern(titleName, wordUtils.rtfGsBt1);
wordUtils.insertContext("报告编号:" + report.getReportCode(), 10, Font.NORMAL, Element.ALIGN_RIGHT, 20, 0, 0);

wordUtils.insertTitlePatternThird("巡检信息", wordUtils.rtfGsBt3);
Table inspectionTableTable = this.buildInspectionTable(report);
wordUtils.getDocument().add(inspectionTableTable);

wordUtils.insertTitlePatternThird("巡检结果", wordUtils.rtfGsBt3);
Table inspectionResultTable = this.buildInspectionResultTable(report);
wordUtils.getDocument().add(inspectionResultTable);

wordUtils.insertTitlePatternThird("问题清单", wordUtils.rtfGsBt3);
Table inspectionFileTable = this.buildInspectionFileTable(inspectionFileList, inspectionFileHandleList);
wordUtils.getDocument().add(inspectionFileTable);
} catch (DocumentException e) {
log.info("生成报告word异常");
throw new RuntimeException(e);
} catch (IOException e) {
log.info("生成报告word异常");
throw new RuntimeException(e);
} finally {
try {
wordUtils.closeDocument();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
}
return JsonResult.success();
}

/**
* 构建巡检信息
*/
private Table buildInspectionTable(Report report) throws DocumentException {
Table table = new Table(2);//生成一表格
table.setOffset(1f);
int width2[] = {1, 1};
table.setWidths(width2);//设置系列所占比例
table.setWidth(100);
table.setAutoFillEmptyCells(true);
table.setAlignment(Element.ALIGN_CENTER); //居中显示
table.setAlignment(Element.ALIGN_MIDDLE); //垂直居中显示

Font font = new Font();
font.setSize(10.5f);
font.setStyle(Font.NORMAL);
for (int i = 0; i < 14; i++) {
Cell cell = new Cell();
String str = null;
cell.setVerticalAlignment(Element.ALIGN_LEFT);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
if (i == 0) {
str = "气象信息";
} else if (i == 1) {
str = report.getWeather();
} else if (i == 2) {
str = "巡检部门";
} else if (i == 3) {
str = this.getDeptName(report.getDeptId());
} else if (i == 4) {
str = "巡检方式";
} else if (i == 5) {
if (report.getInspectionType() == 1) {
str = "无人机";
} else if (report.getInspectionType() == 2) {
str = "机场巡逻";
} else if (report.getInspectionType() == 3) {
str = "飞手值飞";
}
} else if (i == 6) {
str = "巡查设备";
} else if (i == 7) {
str = report.getEquipmentName();
} else if (i == 8) {
str = "巡查开始时间";
} else if (i == 9) {
str = report.getExecutionStartTime() == null ? "" : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, report.getExecutionStartTime());
} else if (i == 10) {
str = "巡查结束时间";
} else if (i == 11) {
str = report.getExecutionEndTime() == null ? "" : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, report.getExecutionEndTime());
} else if (i == 12) {
str = "巡检高速";
} else if (i == 13) {
str = this.getRoadName(report.getRoadId());
}
Paragraph p = new Paragraph(str, font);
cell.add(p);
table.addCell(cell);
}
return table;
}

/**
* 获取部门路名称
*/
private String getDeptName(String deptId) {
if (StringUtils.isEmpty(deptId)) {
return "";
}
Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>()
.eq(Dept::getId, deptId)
.eq(Dept::getMark, 1));
if (null != dept) {
return dept.getName();
}
return "";
}


/**
* 获取公路名称
*/
private String getRoadName(String roadId) {
if (StringUtils.isEmpty(roadId)) {
return "";
}
RoadInformation roadInformation = roadInformationMapper.selectOne(new LambdaQueryWrapper<RoadInformation>()
.eq(RoadInformation::getId, roadId)
.eq(RoadInformation::getMark, 1));
if (null != roadInformation) {
return roadInformation.getName();
}
return "";
}

/**
* 构建巡检信息
*/
private Table buildInspectionResultTable(Report report) throws DocumentException {
List<QuestionType> questionTypeList = questionTypeMapper.selectList(new LambdaQueryWrapper<QuestionType>()
.eq(QuestionType::getMark, 1));

Table table = new Table(2); //生成一表格
table.setOffset(1f);
int width[] = {1, 1};
table.setWidths(width); //设置系列所占比例
table.setWidth(100);
table.setAutoFillEmptyCells(true);
table.setAlignment(Element.ALIGN_CENTER); //居中显示
table.setAlignment(Element.ALIGN_MIDDLE); //垂直居中显示

Font font = new Font();
font.setSize(10.5f);
font.setStyle(Font.NORMAL);

Cell cell1 = this.getCell(font, "巡检内容");
Cell cell2 = this.getCell(font, "巡检监测结果");

table.addCell(cell1);
table.addCell(cell2);

QuestionType questionType;
Cell questionTypeContentCell;
Cell questionTypeCell;
for (int i = 0; i < questionTypeList.size(); i++) {
questionType = questionTypeList.get(i);
String count = this.getCount(report.getInspectionId(), questionType.getId());
questionTypeContentCell = this.getCell(font, questionType.getContent());
questionTypeCell = this.getCell(font, count);
table.addCell(questionTypeContentCell);
table.addCell(questionTypeCell);
}
return table;
}

private Cell getCell(Font font, String str) {
Cell cell = new Cell();
cell.setVerticalAlignment(Element.ALIGN_CENTER); // 设置单元格的垂直对齐方式 : 居中
cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 设置单元格的水平对齐方式 :居中对齐
cell.add(new Paragraph(str, font));
return cell;
}

private String getCount(String inspectionId, String questionTypeId) {
Integer count = inspectionFileMapper.selectCount(new LambdaQueryWrapper<InspectionFile>()
.eq(InspectionFile::getInspectionId, inspectionId)
.eq(InspectionFile::getQuestionId, questionTypeId)
.eq(InspectionFile::getMark, 1));
return Integer.toString(count);
}

/**
* 构建巡检问题信息
*/
private Table buildInspectionFileTable(List<InspectionFile> inspectionFileList, List<InspectionFileHandle> inspectionFileHandleList) throws DocumentException, IOException {
Table table = new Table(2); //生成一表格
table.setOffset(1f);
int width2[] = {1, 1};
table.setWidths(width2); //设置系列所占比例
table.setWidth(100);
table.setAutoFillEmptyCells(true);

InspectionFile inspectionFile;
Font font = new Font();
font.setSize(10.5f);
for (int i = 0; i < inspectionFileList.size(); i++) {
inspectionFile = inspectionFileList.get(i);
for (int j = 0; j < 7; j++) {
font.setStyle(Font.NORMAL);
Cell cell = new Cell();
cell.setVerticalAlignment(Element.ALIGN_CENTER); // 设置单元格的垂直对齐方式 : 居中
cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 设置单元格的水平对齐方式 :居中对齐
String str = "";
if (j == 0) {
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
font.setSize(12);
str = "问题" + (i + 1);
cell.add(new Paragraph(str, font));
cell.setColspan(2);
font.setStyle(Font.BOLD);
} else if (j == 1) {
str = "坐标";
cell.add(new Paragraph(str, font));
} else if (j == 2) {
if (!StringUtils.isEmpty(inspectionFile.getLongitude())) {
str += inspectionFile.getLongitude();
}
if (StringUtils.isEmpty(str)) {
if (!StringUtils.isEmpty(inspectionFile.getLatitude())) {
str += inspectionFile.getLatitude();
}
} else {
if (!StringUtils.isEmpty(inspectionFile.getLatitude())) {
str += "," + inspectionFile.getLatitude();
}
}
cell.add(new Paragraph(str, font));
} else if (j == 3) {
str = "问题描述";
cell.add(new Paragraph(str, font));
} else if (j == 4) {
str = inspectionFile.getQuestionDesc();
cell.add(new Paragraph(str, font));
} else if (j == 5) {
str = "问题图片";
cell.add(new Paragraph(str, font));
} else if (j == 6) {
cell = this.getImageCell(inspectionFile.getFileThumbnail());;
}
table.addCell(cell);
}

if (CollectionUtil.isEmpty(inspectionFileHandleList)) {
continue;
}

this.buildInspectionFileHandleTable(table, font, inspectionFile.getId(), inspectionFileHandleList);
}
return table;
}

private void buildInspectionFileHandleTable(Table table, Font font, String inspectionFileId, List<InspectionFileHandle> inspectionFileHandleList) throws MalformedURLException {
Map<String, User> handleUserMap = this.getInspectionFileHandleUserMap(inspectionFileHandleList);
Map<String, InspectionFileHandle> inspectionFileHandleMap = inspectionFileHandleList.stream().collect(Collectors.toMap(InspectionFileHandle::getInspectionFileId, Function.identity()));
InspectionFileHandle inspectionFileHandle = inspectionFileHandleMap.get(inspectionFileId);
if (null != inspectionFileHandle) {
Cell handlerUserTitleCell = this.getCell(font, "处理人");
User user = handleUserMap.get(inspectionFileHandle.getHandlerUser());
Cell handlerUserDataCell;
if (null != user) {
handlerUserDataCell = this.getCell(font, user.getRealname());
} else {
handlerUserDataCell = this.getCell(font, "");
}

Cell handlerResultCell = this.getCell(font, "处理结果");
Cell handlerResultDataCell = this.getCell(font, inspectionFileHandle.getHandlerResult());

Cell handlerTimeCell = this.getCell(font, "处理时间");
Cell handlerTimeDataCell = this.getCell(font, inspectionFileHandle.getHandlerTime() == null ? "" : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, inspectionFileHandle.getHandlerTime()));

table.addCell(handlerUserTitleCell);
table.addCell(handlerUserDataCell);

table.addCell(handlerResultCell);
table.addCell(handlerResultDataCell);

table.addCell(handlerTimeCell);
table.addCell(handlerTimeDataCell);

if (!StringUtils.isEmpty(inspectionFileHandle.getHandlerImage())) {
String[] arr = inspectionFileHandle.getHandlerImage().split(",");
List<String> list = Arrays.stream(arr).map(String::toString).collect(Collectors.toList());
String imageUrl;
for (int i = 0; i < list.size(); i++) {
Cell imageTileCell;
if (1 == list.size()) {
imageTileCell = this.getCell(font, "处理图片");
} else {
imageTileCell = this.getCell(font, "处理图片" + (i+1));
}
imageUrl = list.get(i);
Cell imageCell = this.getImageCell(imageUrl);
table.addCell(imageTileCell);
table.addCell(imageCell);
}
}
}
}

/**
*
* 生成报告word表格处理图片
*
* @param imageUrl
* @return
* @throws MalformedURLException
*/
private Cell getImageCell(String imageUrl) throws MalformedURLException {
Cell imageCell = new Cell();
imageCell.setVerticalAlignment(Element.ALIGN_CENTER); // 设置单元格的垂直对齐方式 : 居中
imageCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 设置单元格的水平对齐方式 :居中对齐

String url = CommonConfig.imageURL + imageUrl;
if (new UrlResource(url).exists()) {
try {
Image image = Image.getInstance(url);
image.setAlignment(Image.ALIGN_CENTER);
image.scalePercent(100); //依照比例缩放
image.setAbsolutePosition(200, 300);
image.scaleToFit(300, 300);//自定义大
imageCell.add(image);
} catch (BadElementException e) {
log.info("生成报告word表格处理图片异常");
throw new RuntimeException(e);
} catch (IOException e) {
log.info("生成报告word表格处理图片异常");
throw new RuntimeException(e);
}
} else {
log.error("图片不存在!" + url);
imageCell.add(new Paragraph(""));
}
return imageCell;
}

/**
*
* 获取问题处理人map
*
* @param inspectionFileHandleList
* @return
*/
private Map<String, User> getInspectionFileHandleUserMap(List<InspectionFileHandle> inspectionFileHandleList) {
List<String> userIdList = inspectionFileHandleList.stream().map(o -> o.getHandlerUser()).collect(Collectors.toList());
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>()
.in(User::getId, userIdList)
.eq(User::getMark, 1));

Map<String, User> userMap = userList.stream().collect(Collectors.toMap(User::getId, Function.identity()));
return userMap;
}
}

+ 64
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/utils/DownloadUtil.java 파일 보기

@@ -0,0 +1,64 @@
package com.tuoheng.admin.utils;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;

@Slf4j
public final class DownloadUtil {

/**
*
* 下载
*
* @param response
* @param filePath
* @param fileName
*/
public static void download(HttpServletResponse response, String filePath, String fileName) {
//清空缓存
response.reset();
// 定义浏览器响应表头,并定义下载名

try {
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
response.setCharacterEncoding("utf-8");
//定义下载的类型
response.setContentType("application/msword;charset=UTF-8");

File files = new File(filePath);
OutputStream out = null;
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(files);
//3.通过response获取ServletOutputStream对象(out)
out = response.getOutputStream();
int b = 0;
byte[] buffer = new byte[512];
while (b != -1) {
b = inputStream.read(buffer);
//4.写到输出流(out)中
out.write(buffer, 0, b);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
inputStream.close();
out.close();
out.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
log.info("下载结束......");
}

}

Loading…
취소
저장