包头bug修复

This commit is contained in:
guoshengxiong 2025-02-17 18:27:58 +08:00
parent f4948136a0
commit 737edb1393
5 changed files with 138 additions and 2 deletions

View File

@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.zhgd.jeecg.common.execption.OpenAlertException; import com.zhgd.jeecg.common.execption.OpenAlertException;
import com.zhgd.jeecg.common.system.query.QueryGenerator; import com.zhgd.jeecg.common.system.query.QueryGenerator;
import com.zhgd.xmgl.constant.Cts;
import com.zhgd.xmgl.modules.baotou.plan.entity.*; import com.zhgd.xmgl.modules.baotou.plan.entity.*;
import com.zhgd.xmgl.modules.baotou.plan.mapper.PlanRecordMapper; import com.zhgd.xmgl.modules.baotou.plan.mapper.PlanRecordMapper;
import com.zhgd.xmgl.modules.baotou.plan.service.*; import com.zhgd.xmgl.modules.baotou.plan.service.*;
@ -96,7 +97,7 @@ public class PlanRecordServiceImpl extends ServiceImpl<PlanRecordMapper, PlanRec
private List<PlanRecord> dealList(List<PlanRecord> list, HashMap<String, Object> param) { private List<PlanRecord> dealList(List<PlanRecord> list, HashMap<String, Object> param) {
if (CollUtil.isNotEmpty(list)) { if (CollUtil.isNotEmpty(list)) {
List<PlanRecord> alls = planRecordMapper.selectList(new LambdaQueryWrapper<PlanRecord>() List<PlanRecord> alls = planRecordMapper.selectList(new LambdaQueryWrapper<PlanRecord>()
.eq(PlanRecord::getProjectSn, MapUtils.getString(param, "projectSn"))); .eq(PlanRecord::getProjectSn, MapUtils.getString(param, "projectSn")).last(Cts.IGNORE_DATA_SCOPE_CONDITION));
Map<Long, Pair<BigDecimal, BigDecimal>> ridRateMap = this.getManyActualCompleteRates(alls); Map<Long, Pair<BigDecimal, BigDecimal>> ridRateMap = this.getManyActualCompleteRates(alls);
String approvalId = MapUtils.getString(param, "approvalId"); String approvalId = MapUtils.getString(param, "approvalId");
Map<Long, PlanFeedbackApprovalWork> ridMap = planFeedbackApprovalWorkService.list(new LambdaQueryWrapper<PlanFeedbackApprovalWork>() Map<Long, PlanFeedbackApprovalWork> ridMap = planFeedbackApprovalWorkService.list(new LambdaQueryWrapper<PlanFeedbackApprovalWork>()

View File

@ -1,5 +1,6 @@
package com.zhgd.xmgl.modules.exam.controller; package com.zhgd.xmgl.modules.exam.controller;
import cn.afterturn.easypoi.word.WordExportUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
@ -36,6 +37,7 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -45,6 +47,8 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -419,7 +423,7 @@ public class ExamWorkerController {
// String dest = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + "." + StrUtil.subAfter(url, ".", true); // String dest = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + "." + StrUtil.subAfter(url, ".", true);
// HttpUtil.downloadFile(url, dest); // HttpUtil.downloadFile(url, dest);
// imageMap.put(imageKey, EasyPoiUtil.imgFormatting(dest, 18, 18)); // imageMap.put(imageKey, EasyPoiUtil.imgFormatting(dest, 18, 18));
// content.append("{{" + imageKey + "}}"); // content.append("##" + imageKey + "##");
// params.put(imageKey, imageMap.get(imageKey)); // params.put(imageKey, imageMap.get(imageKey));
// } catch (Exception e) { // } catch (Exception e) {
// log.error("导出word添加题目和选项错误", e); // log.error("导出word添加题目和选项错误", e);

View File

@ -3,6 +3,7 @@ package com.zhgd.xmgl.util;
import cn.afterturn.easypoi.entity.ImageEntity; import cn.afterturn.easypoi.entity.ImageEntity;
import cn.afterturn.easypoi.word.WordExportUtil; import cn.afterturn.easypoi.word.WordExportUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.documents4j.api.DocumentType; import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter; import com.documents4j.api.IConverter;
@ -11,15 +12,113 @@ import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument; 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 javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
@Slf4j @Slf4j
public class EasyPoiUtil { public class EasyPoiUtil {
// /**
// * 导出word和图片
// *
// * @param response
// * @param params
// * @param file
// * @throws Exception
// */
// public static void exportNewLineWordAndPic(HttpServletResponse response, Map<String, Object> params, File file) {
// XWPFDocument doc = null;
// FileOutputStream tempFos = null;
// try {
// //导出临时文件
// doc = WordExportUtil.exportWord07(URLDecoder.decode(file.getPath(), "UTF-8"), params);
// WordUtils.addBreakInCellForExam(doc.getParagraphs());
//
// //######改成占位符{{}}
// List<XWPFParagraph> paragraphs = doc.getParagraphs();
// Iterator<XWPFParagraph> itPara = paragraphs.iterator();
// while (itPara.hasNext()) {
// XWPFParagraph paragraph = (XWPFParagraph) itPara.next();
// List<XWPFRun> run = paragraph.getRuns();
// for (int i = 0; i < run.size(); i++) {
// XWPFRun xwpfRun = run.get(i);
// String text = xwpfRun.getText(xwpfRun.getTextPosition());
// if (text.contains("##")) {
// String replacedText = text.replaceAll("##(.*?)##", "{{}}{{$1}}{{}}");
//// xwpfRun.setText(replacedText,0);
//// // 为剩余行创建新的 XWPFRun
//// for (int j = 1; j < lines.length; j++) {
//// XWPFRun newRun = paragraph.insertNewRun(i + j); // 插入新的 XWPFRun
//// newRun.setText("{{}}"); // 设置新行的文本
//// // 复制原始 XWPFRun 的样式到新的 XWPFRun
//// newRun.setBold(run.isBold());
//// newRun.setItalic(run.isItalic());
//// newRun.setFontSize(run.getFontSize());
//// newRun.setFontFamily(run.getFontFamily());
//// }
// // 清空当前 run 的文本
// xwpfRun.setText("", 0);
//
// // 将替换后的文本拆分为多个部分并设置蓝色字体
// String[] parts = replacedText.split("(?=\\{\\{)|(?<=\\}\\})");
// for (String part : parts) {
// XWPFRun newRun = paragraph.insertNewRun(i++); // 插入新的 run
// newRun.setText(part);
// if (part.equals("{{}}")) {
// newRun.setColor("0000FF"); // 设置蓝色字体
// }
// }
// }
// }
// }
// String tempName = IdUtil.randomUUID() + ".docx";
// String tempPath = PathUtil.getBasePath() + "/temp/" + tempName;
// tempFos = new FileOutputStream(tempPath);
// doc.write(tempFos);
// tempFos.close();
// doc.close();
//
// //导出response
// doc = WordExportUtil.exportWord07(URLDecoder.decode(tempPath, "UTF-8"), params);
// //设置响应体内容类型
// 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();
//// FileUtil.del(tempPath);
// } catch (Exception e) {
// log.error("exportNewLineWord", e);
// } finally {
// if (doc != null) {
// try {
// doc.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// if (tempFos != null) {
// try {
// tempFos.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
// }
/** /**
* 导出word * 导出word
* *

View File

@ -82,4 +82,36 @@ public class WordUtils {
} }
} }
} }
/**
* 文本换行
*/
public static void addBreakInCellForExam(List<XWPFParagraph> paragraphs) {
for (XWPFParagraph p : paragraphs) {
List<XWPFRun> runs = p.getRuns();
for (int i = 0; i < runs.size(); i++) {
XWPFRun run = runs.get(i);
String text = run.getText(0); // 获取完整文本
if (text != null && text.contains("\n")) {
String[] lines = text.split("\n");
if (lines.length > 0) {
// 设置第一行文本
run.setText(lines[0], 0);
// 为剩余行创建新的 XWPFRun
for (int j = 1; j < lines.length; j++) {
run.addBreak(); // 添加换行符
XWPFRun newRun = p.insertNewRun(i + j); // 插入新的 XWPFRun
newRun.setText(lines[j]); // 设置新行的文本
// 复制原始 XWPFRun 的样式到新的 XWPFRun
newRun.setBold(run.isBold());
newRun.setItalic(run.isItalic());
newRun.setFontSize(10);
newRun.setFontFamily("宋体");
}
}
}
}
}
}
} }