diff --git a/pom.xml b/pom.xml
index fb239b500..27a6615a6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -416,6 +416,23 @@
easypoi-web
4.4.0
+
+
+ com.documents4j
+ documents4j-local
+ 1.1.12
+
+
+ com.documents4j
+ documents4j-transformer-msoffice-word
+ 1.1.12
+
+
+
+ com.documents4j
+ documents4j-transformer-msoffice-excel
+ 1.1.12
+
org.apache.poi
diff --git a/src/main/java/com/zhgd/xmgl/modules/ocr/controller/OcrBuildLogController.java b/src/main/java/com/zhgd/xmgl/modules/ocr/controller/OcrBuildLogController.java
index 147c73871..85b8e5142 100644
--- a/src/main/java/com/zhgd/xmgl/modules/ocr/controller/OcrBuildLogController.java
+++ b/src/main/java/com/zhgd/xmgl/modules/ocr/controller/OcrBuildLogController.java
@@ -3,28 +3,41 @@ package com.zhgd.xmgl.modules.ocr.controller;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.util.ZipUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.gexin.fastjson.JSON;
+import com.gexin.fastjson.JSONObject;
import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
+import com.zhgd.jeecg.common.execption.OpenAlertException;
import com.zhgd.xmgl.modules.ocr.entity.OcrBuildLog;
import com.zhgd.xmgl.modules.ocr.entity.dto.OcrBuildLogDto;
import com.zhgd.xmgl.modules.ocr.entity.vo.OcrBuildLogForMonthVo;
import com.zhgd.xmgl.modules.ocr.entity.vo.OcrBuildLogVo;
import com.zhgd.xmgl.modules.ocr.service.IOcrBuildLogService;
import com.zhgd.xmgl.security.util.SecurityUtils;
+import com.zhgd.xmgl.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.io.IOUtils;
import org.simpleframework.xml.core.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
@@ -159,5 +172,88 @@ public class OcrBuildLogController {
return Result.success(vos);
}
+ @ApiOperation(value = "OCR施工日志模板下载", notes = "OCR施工日志模板下载")
+ @GetMapping("/downloadTemplate")
+ public void downloadTemplate(HttpServletResponse response) {
+ try (OutputStream out = response.getOutputStream();
+ InputStream fis = new ClassPathResource("word/ocr施工日志模版.docx").getInputStream()) {
+
+ // 设置正确的 Content-Type
+ response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+ response.setCharacterEncoding("UTF-8");
+
+ // 设置文件名(URL编码)
+ String fileName = URLEncoder.encode("施工日志模版.docx", "UTF-8").replace("+", "%20");
+ response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
+
+ IOUtils.copy(fis, out);
+ } catch (Exception e) {
+ log.error("下载模板失败:", e);
+ }
+ }
+
+ @ApiOperation(value = "导出zip文件", notes = "导出zip文件", httpMethod = "POST")
+ @ApiImplicitParam(name = "idList", value = "idList", paramType = "body", required = true, dataType = "String")
+ @PostMapping("exportZip")
+ public void exportZip(HttpServletResponse response, @ApiIgnore @RequestBody HashMap param) throws IOException {
+ try (OutputStream out = response.getOutputStream();) {
+ String wordDir = PathUtil.getBasePath() + "/temp/" + DateUtil.today() + "/" + IdUtil.randomUUID() + "/导出OCR施工日志ZIP/word";
+ FileUtil.mkdir(wordDir);
+ List idList = MapUtil.getList(param, "idList", String.class);
+ List logVos = ocrBuildLogService.queryList(new MapBuilder()
+ .put("idList", idList)
+ .build());
+ String dir = new File(wordDir).getParent();
+ for (OcrBuildLogVo logVo : logVos) {
+ Map map = new HashMap<>();
+ if (StrUtil.isNotBlank(logVo.getWeatherJson())) {
+ JSONObject jsonObject = JSON.parseObject(logVo.getWeatherJson());
+ map.put("win_speed", jsonObject.getString("win_speed"));
+ map.put("wea", jsonObject.getString("wea"));
+ map.put("tem_day", jsonObject.getString("tem_day"));
+ }
+ map.put("constructionUnitIds", logVo.getConstructionUnitIds());
+ map.put("constructionAreaNames", logVo.getConstructionAreaNames());
+ map.put("constructionUnitNames", logVo.getConstructionUnitNames());
+ map.put("constructionWorkerNames", logVo.getConstructionWorkerNames());
+ map.put("supervisionUnitNames", logVo.getSupervisionUnitNames());
+ map.put("supervisionPersonnelNames", logVo.getSupervisionPersonnelNames());
+ map.put("type", logVo.getType());
+ map.put("uploaderName", logVo.getUploaderName());
+ map.put("id", logVo.getId());
+ map.put("date", DateUtil.formatDate(logVo.getDate()));
+ map.put("weatherJson", logVo.getWeatherJson());
+ map.put("constructionAreaIds", logVo.getConstructionAreaIds());
+ map.put("constructionWorkerIds", logVo.getConstructionWorkerIds());
+ map.put("supervisionUnitIds", logVo.getSupervisionUnitIds());
+ map.put("supervisionPersonnelIds", logVo.getSupervisionPersonnelIds());
+ map.put("constructionTask", logVo.getConstructionTask());
+ map.put("constructionMachinery", logVo.getConstructionMachinery());
+ map.put("attendance", logVo.getAttendance());
+ map.put("designChangeMaterial", logVo.getDesignChangeMaterial());
+ map.put("safetyBriefingMaterial", logVo.getSafetyBriefingMaterial());
+ map.put("technicalBriefingMaterial", logVo.getTechnicalBriefingMaterial());
+ map.put("createTime", logVo.getCreateTime());
+ map.put("updateTime", logVo.getUpdateTime());
+ map.put("projectSn", logVo.getProjectSn());
+ map.put("uploaderId", logVo.getUploaderId());
+ String url = Fileutils.getExportTemplateFile("word/ocr施工日志导出模版.docx").getAbsolutePath();
+ File wordFile = new File(wordDir, logVo.getConstructionAreaNames() + DateUtil.formatDate(logVo.getDate()) + ".docx");
+ EasyPoiUtil.exportNewLineWord(map, url, wordFile);
+ EasyPoiUtil.wordToPdfExport(wordFile, new File(dir, logVo.getConstructionAreaNames() + DateUtil.formatDate(logVo.getDate()) + ".pdf").getAbsolutePath());
+ }
+ FileUtil.del(wordDir);
+ ZipUtil.zip(dir);
+ response.setContentType("application/json");
+ response.setHeader("Content-disposition", "attachment; filename=" +
+ URLEncoder.encode(new File(dir + ".zip").getName(), "UTF-8"));
+ InputStream fis = new FileInputStream(dir + ".zip");
+ org.apache.poi.util.IOUtils.copy(fis, out);
+ out.flush();
+ } catch (Exception e) {
+ log.error("", e);
+ throw new OpenAlertException(e.getMessage());
+ }
+ }
}
diff --git a/src/main/java/com/zhgd/xmgl/modules/ocr/mapper/xml/OcrBuildLogMapper.xml b/src/main/java/com/zhgd/xmgl/modules/ocr/mapper/xml/OcrBuildLogMapper.xml
index 0cd2567ee..ff57c82d8 100644
--- a/src/main/java/com/zhgd/xmgl/modules/ocr/mapper/xml/OcrBuildLogMapper.xml
+++ b/src/main/java/com/zhgd/xmgl/modules/ocr/mapper/xml/OcrBuildLogMapper.xml
@@ -7,6 +7,14 @@
,su.real_name as uploader_name
from ocr_build_log t
left join system_user su on su.user_id=t.uploader_id
+ where 1=1
+
+ and t.id in
+
+ #{item}
+
+
)t
${ew.customSqlSegment}
diff --git a/src/main/java/com/zhgd/xmgl/modules/risk/controller/RiskListSourceController.java b/src/main/java/com/zhgd/xmgl/modules/risk/controller/RiskListSourceController.java
index 660f17324..da680ca76 100644
--- a/src/main/java/com/zhgd/xmgl/modules/risk/controller/RiskListSourceController.java
+++ b/src/main/java/com/zhgd/xmgl/modules/risk/controller/RiskListSourceController.java
@@ -270,6 +270,7 @@ public class RiskListSourceController {
@ApiImplicitParams({
@ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = false, dataType = "Integer"),
@ApiImplicitParam(name = "regionIds", value = "区域ids(多个,分割)", paramType = "body", required = false, dataType = "Integer"),
+ @ApiImplicitParam(name = "httpPrefix", value = "http的前缀", paramType = "body", required = false, dataType = "String"),
})
@PostMapping(value = "/downloadRegionQrCode")
public void downloadRegionQrCode(HttpServletResponse response, @RequestBody HashMap param) {
@@ -306,6 +307,7 @@ public class RiskListSourceController {
* @param dir
*/
private void generateRegionQrCode(HashMap param, String dir) {
+ String httpPrefix = MapUtils.getString(param, "httpPrefix");
String projectSn = MapUtils.getString(param, "projectSn");
List regionIds = StrUtil.split(MapUtils.getString(param, "regionIds"), ",");
List regionV2Vos = qualityRegionService.queryList(new MapBuilder()
@@ -382,7 +384,7 @@ public class RiskListSourceController {
QrConfig config = new QrConfig(qrSize, qrSize);
config.setMargin(1); // 设置边距
BufferedImage qrImage = QrCodeUtil.generate(
- regionV2Vo.getId() + "",
+ httpPrefix + regionV2Vo.getId(),
config
);
diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java b/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java
index 4372616cf..b6f38c65f 100644
--- a/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java
+++ b/src/main/java/com/zhgd/xmgl/modules/worker/controller/WorkerDailyAttendanceStatisticsV2Controller.java
@@ -446,4 +446,41 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
}
}
+ @OperLog(operModul = "员工每日的考勤统计记录v2管理", operType = "", operDesc = "考勤总览")
+ @ApiOperation(value = "考勤总览", notes = "考勤总览", httpMethod = "POST")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "enterpriseTypeId", value = "企业类型id", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "enterpriseId", value = "所属企业id", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "teamId", value = "班组ID", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "startMonth", value = "开始时间,格式2020-08(startMonth和endMonth或startDate和endDate至少传其中一组)", dataType = "String", paramType = "body", required = true),
+ @ApiImplicitParam(name = "endMonth", value = "结束时间,格式2020-08", dataType = "String", paramType = "body", required = true),
+ @ApiImplicitParam(name = "startDate", value = "开始时间,yyyy-MM-dd", paramType = "body", dataType = "String", required = true),
+ @ApiImplicitParam(name = "endDate", value = "结束时间,yyyy-MM-dd", paramType = "body", dataType = "String", required = true),
+ })
+ @PostMapping(value = "/countWorkerDailyAttendanceStatisticsV2")
+ public Result countWorkerDailyAttendanceStatisticsV2(@RequestBody Map param) {
+ return Result.success(workerDailyAttendanceStatisticsV2Service.countWorkerDailyAttendanceStatisticsV2(param));
+ }
+
+ @OperLog(operModul = "员工每日的考勤统计记录v2管理", operType = "", operDesc = "每月/日出勤/在职人数统计")
+ @ApiOperation(value = "每月/日出勤/在职人数统计", notes = "每月/日出勤/在职人数统计", httpMethod = "POST")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "enterpriseTypeId", value = "企业类型id", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "enterpriseId", value = "所属企业id", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "teamId", value = "班组ID", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "body", required = false, dataType = "String"),
+ @ApiImplicitParam(name = "startMonth", value = "开始时间,格式2020-08(startMonth和endMonth或startDate和endDate至少传其中一组)", dataType = "String", paramType = "body", required = true),
+ @ApiImplicitParam(name = "endMonth", value = "结束时间,格式2020-08", dataType = "String", paramType = "body", required = true),
+ @ApiImplicitParam(name = "startDate", value = "开始时间,yyyy-MM-dd", paramType = "body", dataType = "String", required = true),
+ @ApiImplicitParam(name = "endDate", value = "结束时间,yyyy-MM-dd", paramType = "body", dataType = "String", required = true),
+ })
+ @PostMapping(value = "/countWorkerDailyAttendanceStatisticsV2ByDate")
+ public Result countWorkerDailyAttendanceStatisticsV2ByDate(@RequestBody Map param) {
+ return Result.success(workerDailyAttendanceStatisticsV2Service.countWorkerDailyAttendanceStatisticsV2ByDate(param));
+ }
+
+
}
diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/xml/WorkerDailyAttendanceStatisticsV2Mapper.xml b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/xml/WorkerDailyAttendanceStatisticsV2Mapper.xml
index 1af831cc6..73a2f3d47 100644
--- a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/xml/WorkerDailyAttendanceStatisticsV2Mapper.xml
+++ b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/xml/WorkerDailyAttendanceStatisticsV2Mapper.xml
@@ -39,4 +39,99 @@
)t
where t.id = #{id}
+
+
+
+
diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/controller/XzSecurityDangerFieldController.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/controller/XzSecurityDangerFieldController.java
index b68f3fcd4..1da77dbd6 100644
--- a/src/main/java/com/zhgd/xmgl/modules/xz/security/controller/XzSecurityDangerFieldController.java
+++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/controller/XzSecurityDangerFieldController.java
@@ -171,7 +171,7 @@ public class XzSecurityDangerFieldController {
String sn = MapUtils.getString(param, "sn");
List configVos = xzSecurityDangerFieldConfigService.queryList(param);
List list = xzSecurityDangerFieldService.queryList(param);
- if (Objects.equals(companyProjectType, 2) && (CollUtil.isEmpty(list) || Objects.equals(CollUtil.getFirst(configVos).getEnableProject(), 0))) {
+ if (Objects.equals(companyProjectType, 2) && CollUtil.isEmpty(list)) {
//项目不存在,查询企业配置
list = getCompanyConfig(param, sn);
for (XzSecurityDangerFieldVo fieldVo : list) {
diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/entity/XzSecurityDangerReviewVerify.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/entity/XzSecurityDangerReviewVerify.java
index 4bcc5cad3..dc3016417 100644
--- a/src/main/java/com/zhgd/xmgl/modules/xz/security/entity/XzSecurityDangerReviewVerify.java
+++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/entity/XzSecurityDangerReviewVerify.java
@@ -63,16 +63,6 @@ public class XzSecurityDangerReviewVerify implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间")
private java.util.Date updateTime;
- /**
- * 复查配置项目端是否开启,1开启,0不开启
- */
- @ApiModelProperty(value = "复查配置项目端是否开启,1开启,0不开启")
- private java.lang.Integer enableProjectForReview;
- /**
- * 核验配置项目端是否开启,1开启,0不开启
- */
- @ApiModelProperty(value = "核验配置项目端是否开启,1开启,0不开启")
- private java.lang.Integer enableProjectForVerify;
@ApiModelProperty("1开启复查0不开启复查")
private Integer enableReview;
@ApiModelProperty("1开启核验0不开启核验")
diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerFieldServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerFieldServiceImpl.java
index 2a2c2d4e0..4b8d62e54 100644
--- a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerFieldServiceImpl.java
+++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerFieldServiceImpl.java
@@ -1,10 +1,14 @@
package com.zhgd.xmgl.modules.xz.security.service.impl;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.resource.ResourceUtil;
+import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.base.Objects;
import com.zhgd.jeecg.common.execption.OpenAlertException;
import com.zhgd.jeecg.common.system.query.QueryGenerator;
import com.zhgd.xmgl.modules.xz.security.entity.XzSecurityDangerField;
@@ -14,11 +18,13 @@ import com.zhgd.xmgl.modules.xz.security.mapper.XzSecurityDangerFieldMapper;
import com.zhgd.xmgl.modules.xz.security.service.IXzSecurityDangerFieldService;
import com.zhgd.xmgl.util.PageUtil;
import com.zhgd.xmgl.util.RefUtil;
+import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
+import java.util.stream.Collectors;
/**
* @Description: 安全隐患检查字段设置
@@ -36,14 +42,14 @@ public class XzSecurityDangerFieldServiceImpl extends ServiceImpl queryWrapper = this.getQueryWrapper(param);
Page page = PageUtil.getPage(param);
IPage pageList = baseMapper.queryList(page, queryWrapper, param);
- pageList.setRecords(this.dealList(pageList.getRecords()));
+ pageList.setRecords(this.dealList(pageList.getRecords(), param));
return pageList;
}
@Override
public List queryList(HashMap param) {
QueryWrapper queryWrapper = getQueryWrapper(param);
- return dealList(baseMapper.queryList(queryWrapper, param));
+ return dealList(baseMapper.queryList(queryWrapper, param), param);
}
private QueryWrapper getQueryWrapper(HashMap param) {
@@ -52,7 +58,19 @@ public class XzSecurityDangerFieldServiceImpl extends ServiceImpl dealList(List list) {
+ private List dealList(List list, HashMap param) {
+ Integer recordType = MapUtils.getInteger(param, "recordType");
+ Integer companyProjectType = MapUtils.getInteger(param, "companyProjectType");
+ String sn = MapUtils.getString(param, "sn");
+ if (CollUtil.isEmpty(list)) {
+ //空就初始化值
+ List fieldVos = JSON.parseArray(ResourceUtil.readUtf8Str("init/data/xzSecurityDangerField.json"), XzSecurityDangerFieldVo.class);
+ list = fieldVos.stream().filter(vo -> Objects.equal(vo.getRecordType(), recordType)).collect(Collectors.toList());
+ for (XzSecurityDangerFieldVo vo : list) {
+ vo.setSn(sn);
+ vo.setCompanyProjectType(companyProjectType);
+ }
+ }
return list;
}
diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerReviewVerifyServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerReviewVerifyServiceImpl.java
index 91266a0d8..7521fc38b 100644
--- a/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerReviewVerifyServiceImpl.java
+++ b/src/main/java/com/zhgd/xmgl/modules/xz/security/service/impl/XzSecurityDangerReviewVerifyServiceImpl.java
@@ -130,27 +130,9 @@ public class XzSecurityDangerReviewVerifyServiceImpl extends ServiceImpl list = this.queryList(param);
- if (Objects.equals(companyProjectType, 2)) {
- if (CollUtil.isEmpty(list)) {
- //项目没数据
- list = getCompanyConfig(param, sn);
- } else {
- XzSecurityDangerReviewVerifyVo vo = CollUtil.getFirst(list);
- if (Objects.equals(vo.getEnableProjectForReview(), 0) || Objects.equals(vo.getEnableProjectForVerify(), 0)) {
- List companyConfigs = getCompanyConfig(param, sn);
- if (CollUtil.isNotEmpty(companyConfigs)) {
- XzSecurityDangerReviewVerifyVo verifyVo = companyConfigs.get(0);
- if (Objects.equals(vo.getEnableProjectForReview(), 0)) {
- vo.setReviewRoleName(verifyVo.getReviewRoleName());
- vo.setEnableReview(verifyVo.getEnableReview());
- }
- if (Objects.equals(vo.getEnableProjectForReview(), 0)) {
- vo.setVerifyRoleName(verifyVo.getVerifyRoleName());
- vo.setEnableVerify(verifyVo.getEnableVerify());
- }
- }
- }
- }
+ if (Objects.equals(companyProjectType, 2) && CollUtil.isEmpty(list)) {
+ //项目没数据
+ list = getCompanyConfig(param, sn);
}
XzSecurityDangerReviewVerifyVo vo = CollUtil.getFirst(list);
if (Objects.isNull(vo)) {
@@ -158,8 +140,6 @@ public class XzSecurityDangerReviewVerifyServiceImpl extends ServiceImpl params, File file) {
+ try {
+ XWPFDocument doc = WordExportUtil.exportWord07(URLDecoder.decode(file.getPath(), "UTF-8"), params);
+ WordUtils.addBreakInCell(doc.getParagraphs());
+ //设置响应体内容类型
+ response.setContentType("application/octet-stream");
+ //添加响应头
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("下载试卷.docx", "UTF-8"));
+ //暴露新添加的响应头
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
+ //将word文档流输出到输出流中
+ doc.write(response.getOutputStream());
+ //关闭流
+ doc.close();
+ } catch (Exception e) {
+ log.error("exportNewLineWord:", e);
+ }
+ }
+
+ /**
+ * 根据模板导出word
+ *
+ * @param map 数据
+ * @param tempUrl 模板地址
+ * @param outputFile 临时模板文件
+ */
+ public static void exportWord(Map map, String tempUrl, File outputFile) {
+ try {
+ XWPFDocument doc = WordExportUtil.exportWord07(tempUrl, map);
+ FileOutputStream fos = new FileOutputStream(outputFile);
+ doc.write(fos);
+ fos.close();
+ } catch (Exception e) {
+ log.error("exportWord:", e);
+ }
+ }
+
+ /**
+ * 根据模板导出word会换行的
+ *
+ * @param map 参数map
+ * @param tempUrl 模板url
+ * @param outputFile 导出位置
+ */
+ public static void exportNewLineWord(Map map, String tempUrl, File outputFile) {
+ try {
+ XWPFDocument doc = WordExportUtil.exportWord07(tempUrl, map);
+ //文本换行
+ WordUtils.addBreakInCell(doc.getParagraphs());
+ FileOutputStream fos = new FileOutputStream(outputFile);
+ doc.write(fos);
+ fos.close();
+ } catch (Exception e) {
+ log.error("exportNewLineWord:", e);
+ }
+ }
+
+ /**
+ * word转pdf导出
+ *
+ * @param response
+ * @param wordFile word文档文件
+ */
+ public static void wordToPdfExport(HttpServletResponse response, File wordFile) {
+ response.setContentType("application/pdf");
+ response.setHeader("Content-Disposition", "attachment; filename=name.pdf");
+ // 获取当前系统名称
+ String osName = System.getProperty("os.name").toLowerCase();
+ // 根据系统选择执行方法
+ if (osName.contains("win")) {
+ try (InputStream docxInputStream = new FileInputStream(wordFile);
+ OutputStream pdfOutputStream = response.getOutputStream()
+// OutputStream pdfOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\管道焊接记录.pdf")
+ ) {
+
+ IConverter converter = LocalConverter.builder().build();
+ converter
+ .convert(docxInputStream)
+ .as(DocumentType.DOCX)
+ .to(pdfOutputStream)
+ .as(DocumentType.PDF)
+ .execute();
+
+ // 通常不需要在这里调用 flush(),因为 execute()方法可能已经完成了它,但如果遇到特定问题,可以尝试调用它
+ // pdfOutputStream.flush();
+
+ } catch (Exception e) {
+ // 设置适当的 HTTP 状态码和错误消息
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ // 可以在这里记录错误或向客户端发送错误消息(但注意,响应流可能已关闭)
+ log.error("", e);
+ } finally {
+ // 清理临时文件
+ if (!wordFile.delete()) {
+ wordFile.deleteOnExit();
+ }
+ }
+ } else if (osName.contains("nux") || osName.contains("nix")) {
+ File pdfFile = new File(wordFile.getParent(), StringUtils.substringBeforeLast(wordFile.getName(), ".") + ".pdf");
+ log.info("linux环境开始导出pdf,源文件:{},目标文件:{}", wordFile.getAbsolutePath(), pdfFile.getAbsolutePath());
+ linuxWordToPdf(pdfFile, wordFile);
+ try {
+ FileUtil.writeToStream(pdfFile, response.getOutputStream());
+ } catch (IOException e) {
+ log.error("word导出pdf出错");
+ }
+ }
+ }
+
+ /**
+ * word转pdf导出
+ *
+ * @param wordFile word文档文件
+ */
+ public static void wordToPdfExport(File wordFile) {
+ wordToPdfExport(wordFile, StrUtil.subBefore(wordFile.getAbsolutePath(), ".", true) + ".pdf");
+ }
+
+ /**
+ * word转pdf导出
+ *
+ * @param wordFile word文档文件
+ * @param outputFilePath
+ */
+ public static void wordToPdfExport(File wordFile, String outputFilePath) {
+ // 获取当前系统名称
+ String osName = System.getProperty("os.name").toLowerCase();
+ // 根据系统选择执行方法
+ if (osName.contains("win")) {
+ try (InputStream docxInputStream = new FileInputStream(wordFile);
+ OutputStream pdfOutputStream = new FileOutputStream(outputFilePath)
+// OutputStream pdfOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\管道焊接记录.pdf")
+ ) {
+
+ IConverter converter = LocalConverter.builder().build();
+ converter
+ .convert(docxInputStream)
+ .as(DocumentType.DOCX)
+ .to(pdfOutputStream)
+ .as(DocumentType.PDF)
+ .execute();
+
+ // 通常不需要在这里调用 flush(),因为 execute()方法可能已经完成了它,但如果遇到特定问题,可以尝试调用它
+ // pdfOutputStream.flush();
+
+ } catch (Exception e) {
+ // 可以在这里记录错误或向客户端发送错误消息(但注意,响应流可能已关闭)
+ log.error("", e);
+ } finally {
+ // 清理临时文件
+ if (!wordFile.delete()) {
+ wordFile.deleteOnExit();
+ }
+ }
+ } else if (osName.contains("nux") || osName.contains("nix")) {
+ try {
+ File pdfFile = new File(wordFile.getParent(), StringUtils.substringBeforeLast(wordFile.getName(), ".") + ".pdf");
+ log.info("linux环境开始导出pdf,源文件:{},目标文件:{}", wordFile.getAbsolutePath(), pdfFile.getAbsolutePath());
+ linuxWordToPdf(pdfFile, wordFile);
+ } catch (Exception e) {
+ log.error("word导出pdf出错");
+ } finally {
+ // 清理临时文件
+ if (!wordFile.delete()) {
+ wordFile.deleteOnExit();
+ }
+ }
+ }
+ }
+
+ /**
+ * linux系统word转pdf
+ * * 使用LibreOffice转换。系统需安装LibreOffice
+ * * 转换命令 libreoffice --invisible --convert-to pdf --outdir output_dir source_path
+ * * 转换后的pdf文件名使用的是源文件的名称,所以如果要指定输出文件名称,就需把源文件名称改成想要输出的名称
+ *
+ * @param pdfFile 转换后的pdf文件
+ * @param wordFile word源文件
+ */
+ private static void linuxWordToPdf(File pdfFile, File wordFile) {
+ // 获取word文件的绝对路径
+ String sourcePath = wordFile.getAbsolutePath();
+ // 获取pdf文件存放文件夹的绝对路径
+ String outDir = pdfFile.getAbsolutePath().substring(0, pdfFile.getAbsolutePath().lastIndexOf(File.separator));
+
+ // 构建LibreOffice的命令行工具命令
+ List cmd = new ArrayList<>();
+ cmd.add("libreoffice");
+ cmd.add("--invisible");
+ cmd.add("--convert-to");
+ cmd.add("pdf");
+ cmd.add("--outdir");
+ cmd.add(outDir);
+ cmd.add(sourcePath);
+ log.info(cmd.toString());
+ // 执行转换命令
+ try {
+ executeLinuxCmd(cmd);
+ } catch (Exception e) {
+ log.error("linuxWordToPdf linux环境word转换为pdf时出现异常:", e);
+ }
+ }
+
+ /**
+ * 执行命令行
+ *
+ * @param cmd 命令行
+ * @return
+ */
+// private static boolean executeLinuxCmd(List cmd) {
+// try {
+// Process process = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]));
+// process.waitFor();
+// InputStream in = process.getInputStream();
+// BufferedReader read = new BufferedReader(new InputStreamReader(in));
+// String result = read.readLine();
+// log.info("executeLinuxCmd 执行Linux命令INFO:" + result);
+// } catch (InterruptedException e) {
+// log.error("executeLinuxCmd 执行Linux命令异常:", e);
+// Thread.currentThread().interrupt();
+// return false;
+// } catch (IOException e) {
+// log.error("获取系统命令执行环境异常", e);
+// }
+// return true;
+// }
+ private static boolean executeLinuxCmd(List cmd) {
+ try {
+ ProcessBuilder processBuilder = new ProcessBuilder(cmd);
+ // 合并标准输出和错误输出
+ processBuilder.redirectErrorStream(true);
+ Process process = processBuilder.start();
+
+ // 读取命令输出
+ InputStream in = process.getInputStream();
+ BufferedReader read = new BufferedReader(new InputStreamReader(in));
+ String line;
+ while ((line = read.readLine()) != null) {
+ log.info("executeLinuxCmd 执行Linux命令INFO: " + line);
+ }
+
+ int exitCode = process.waitFor();
+ if (exitCode != 0) {
+ log.error("executeLinuxCmd 命令执行失败,退出码: " + exitCode);
+ return false;
+ }
+ } catch (InterruptedException e) {
+ log.error("executeLinuxCmd 执行Linux命令异常:", e);
+ Thread.currentThread().interrupt();
+ return false;
+ } catch (IOException e) {
+ log.error("获取系统命令执行环境异常", e);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * 图片格式化,Word导出图片格式
+ *
+ * @param imgPath 图片路径
+ */
+ public static ImageEntity imgFormatting(String imgPath, int width, int height) {
+ //设置图片
+ ImageEntity image = new ImageEntity(imgPath, width, height);
+ //表格外添加简单图片
+ image.setType(ImageEntity.URL);
+ image.setRowspan(ImageEntity.EMBED);
+ return image;
+ }
+
+ /**
+ * excel转pdf
+ *
+ * @param excelPath
+ * @return
+ */
+ public static void excelToPdf(String excelPath) {
+ File inputWord = new File(excelPath);
+ try (InputStream docxInputStream = new FileInputStream(inputWord);
+ OutputStream outputStream = new FileOutputStream(StrUtil.subBefore(excelPath, ".", true) + ".pdf")) {
+ IConverter converter = LocalConverter.builder().build();
+ String fileTyle = excelPath.substring(excelPath.lastIndexOf("."), excelPath.length());//获取文件类型
+ if (".xls".equals(fileTyle)) {
+ converter.convert(docxInputStream).as(DocumentType.XLS).to(outputStream).as(DocumentType.PDF).execute();
+ } else if (".xlsx".equals(fileTyle)) {
+ converter.convert(docxInputStream).as(DocumentType.XLSX).to(outputStream).as(DocumentType.PDF).execute();
+ }
+ docxInputStream.close();
+ outputStream.close();
+ inputWord.delete();
+ System.out.println("pdf转换成功");
+ } catch (Exception e) {
+ log.error("", e);
+ }
+ }
+
+}
diff --git a/src/main/java/com/zhgd/xmgl/util/WordUtils.java b/src/main/java/com/zhgd/xmgl/util/WordUtils.java
new file mode 100644
index 000000000..b766882b8
--- /dev/null
+++ b/src/main/java/com/zhgd/xmgl/util/WordUtils.java
@@ -0,0 +1,157 @@
+package com.zhgd.xmgl.util;
+
+import cn.afterturn.easypoi.word.WordExportUtil;
+import cn.afterturn.easypoi.word.parse.ParseWord07;
+import org.apache.poi.poifs.filesystem.DirectoryEntry;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.List;
+import java.util.Map;
+
+public class WordUtils {
+
+ /**
+ * word下载
+ *
+ * @param fileName 下载时的文件名称
+ * @param response
+ * @param doc
+ */
+ private static void downLoadWord(String fileName, HttpServletResponse response, XWPFDocument doc) throws IOException {
+ try {
+ response.setCharacterEncoding("UTF-8");
+ response.setHeader("content-Type", "application/msword");
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".docx", "UTF-8"));
+ doc.write(response.getOutputStream());
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ /**
+ * word下载
+ *
+ * @param fileName 下载时的文件名称
+ * @param response
+ */
+ private static void downLoadWord(String fileName, HttpServletResponse response, POIFSFileSystem poifsFileSystem) throws IOException {
+ try {
+ response.setCharacterEncoding("UTF-8");
+ response.setHeader("content-Type", "application/octet-stream");
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".docx", "UTF-8"));
+ poifsFileSystem.writeFilesystem(response.getOutputStream());
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ /**
+ * html转word
+ *
+ * @param response
+ * @param html
+ * @throws IOException
+ */
+ public static void html2Word(HttpServletResponse response, String html) throws IOException {
+ // String html = FileUtil.readString("C:\\Users\\Administrator\\Desktop\\t\\文档.html", StandardCharsets.UTF_8 );
+ byte by[] = html.getBytes("UTF-8");
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(by);
+ POIFSFileSystem poifsFileSystem = new POIFSFileSystem();
+ DirectoryEntry directoryEntry = poifsFileSystem.getRoot();
+ directoryEntry.createDocument("WordDocument", byteArrayInputStream);
+ WordUtils.downLoadWord("导出word", response, poifsFileSystem);
+ }
+
+ /**
+ * word模板导出
+ *
+ * @param map
+ * @param templatePath
+ * @param fileName
+ * @param response
+ * @throws Exception
+ */
+ public static void WordTemplateExport(Map map, String templatePath, String fileName, HttpServletResponse response) throws Exception {
+ XWPFDocument doc = WordExportUtil.exportWord07(templatePath, map);
+ downLoadWord(fileName, response, doc);
+ }
+
+
+ /**
+ * word模板导出多页
+ *
+ * @param list
+ * @param templatePath
+ * @param fileName
+ * @param response
+ * @throws Exception
+ */
+ public static void WordTemplateExportMorePage(List