Compare commits
2 Commits
6b7e38fef6
...
89667367ea
| Author | SHA1 | Date | |
|---|---|---|---|
| 89667367ea | |||
| 92b95dd86d |
@@ -118,4 +118,11 @@ public interface IPqMonitorService extends IService<PqMonitor> {
|
||||
* @return
|
||||
*/
|
||||
boolean removeByDevId(String devId);
|
||||
|
||||
/**
|
||||
* 根据被检设备id和监测点编号获取监测点信息
|
||||
* @param id 被检设备id
|
||||
* @param monitorNum 监测点编号
|
||||
*/
|
||||
PqMonitor getByDevAndNum(String id, int monitorNum);
|
||||
}
|
||||
|
||||
@@ -432,4 +432,16 @@ public class PqMonitorServiceImpl extends ServiceImpl<PqMonitorMapper, PqMonitor
|
||||
wrapper.eq("pq_monitor.Dev_Id", devId);
|
||||
return this.remove(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqMonitor getByDevAndNum(String devId, int monitorNum) {
|
||||
QueryWrapper<PqMonitor> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("pq_monitor.Dev_Id", devId)
|
||||
.eq("pq_monitor.Num", monitorNum);
|
||||
List<PqMonitor> pqMonitors = this.list(wrapper);
|
||||
if(CollUtil.isNotEmpty(pqMonitors)){
|
||||
return pqMonitors.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ import com.njcn.gather.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.service.IPqDevSubService;
|
||||
import com.njcn.gather.err.pojo.po.PqErrSys;
|
||||
import com.njcn.gather.err.service.IPqErrSysService;
|
||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
@@ -179,6 +181,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
private final ISysUserService sysUserService;
|
||||
private final IPqErrSysService pqErrSysService;
|
||||
private final IAdPlanTestConfigService adPlanTestConfigService;
|
||||
private final IPqMonitorService pqMonitorService;
|
||||
|
||||
@Resource
|
||||
private RestTemplateUtil restTemplateUtil;
|
||||
@@ -820,6 +823,14 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
|
||||
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
|
||||
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
|
||||
// 判断是否需要在报告上输出水印
|
||||
String leader = baseModelDataMap.get(BaseReportKeyEnum.AUDIT_BY.getKey());
|
||||
String loginName = RequestUtil.getLoginNameByToken();
|
||||
SysUser user = sysUserService.getUserByLoginName(loginName);
|
||||
if (!leader.equals(user.getName())) {
|
||||
log.info("当前用户不是审核人,添加非正式水印");
|
||||
Docx4jUtil.addWatermarkToDocument(baseModelDocument, "非正式");
|
||||
}
|
||||
Docx4jUtil.cleanBlankPagesAndRedundantPageBreaks(baseModelDocument);
|
||||
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(fileName)));
|
||||
this.updateDevAndPlanState(devId, devReportParam.getPlanId());
|
||||
@@ -1157,7 +1168,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
// 插入回路号前,先换个页
|
||||
todoInsertList.add(Docx4jUtil.createPageBreakParagraph());
|
||||
// 回路标题
|
||||
todoInsertList.add(getContrastLineTitle(contentMap, monitorNum, stepIndex, factory));
|
||||
todoInsertList.add(getContrastLineTitle(contentMap, monitorNum, stepIndex, factory, pqDevVO));
|
||||
int scriptIndex = 1;
|
||||
for (ContrastTestResult contrastTestResult : contrastTestResults) {
|
||||
// 比如电压 V
|
||||
@@ -2016,7 +2027,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
// 委托方
|
||||
String delegate = pqDevVO.getDelegate();
|
||||
if (StrUtil.isNotBlank(delegate)) {
|
||||
DictData delegateDictData = dictDataService.getDictDataById(pqDevVO.getManufacturer());
|
||||
DictData delegateDictData = dictDataService.getDictDataById(pqDevVO.getDelegate());
|
||||
if (ObjectUtil.isNotNull(delegateDictData)) {
|
||||
baseModelMap.put(BaseReportKeyEnum.DELEGATE.getKey(), delegateDictData.getName());
|
||||
} else {
|
||||
@@ -2392,16 +2403,21 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
/**
|
||||
* 创建回路标题到报告中
|
||||
*/
|
||||
private P getContrastLineTitle(Map<String, List<Docx4jUtil.HeadingContent>> contentMap, int monitorNum, int index, ObjectFactory factory) {
|
||||
private P getContrastLineTitle(Map<String, List<Docx4jUtil.HeadingContent>> contentMap, int monitorNum, int index, ObjectFactory factory, PqDevVO pqDevVO) {
|
||||
PqMonitor pqMonitor = pqMonitorService.getByDevAndNum(pqDevVO.getId(), monitorNum);
|
||||
String monitorInfoName = "";
|
||||
if (StrUtil.isNotBlank(pqDevVO.getSubName()) && Objects.nonNull(pqMonitor)) {
|
||||
monitorInfoName = "(" + pqDevVO.getSubName() + "-" + pqMonitor.getName() + ")";
|
||||
}
|
||||
List<Docx4jUtil.HeadingContent> headingContents = contentMap.get(PowerIndexEnum.LINE_TITLE.getKey());
|
||||
// 如果contentMap中有指定内容,创建大纲级别为2的标题
|
||||
if (CollUtil.isNotEmpty(headingContents)) {
|
||||
return Docx4jUtil.createTitle(factory, 2, index + ".测量回路" + monitorNum,
|
||||
return Docx4jUtil.createTitle(factory, 2, index + ".测量回路" + monitorNum + monitorInfoName,
|
||||
"SimSun", 30, true);
|
||||
}
|
||||
// 没有模板配置时,创建默认样式段落
|
||||
P titleParagraph = factory.createP();
|
||||
Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + monitorNum,
|
||||
Docx4jUtil.createTitle(factory, titleParagraph, "测量回路" + monitorNum + monitorInfoName,
|
||||
28, true);
|
||||
return titleParagraph;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.docx4j.XmlUtils;
|
||||
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
|
||||
@@ -27,6 +28,7 @@ import java.util.Map;
|
||||
* @version 1.0
|
||||
* @data 2025/3/26 13:47
|
||||
*/
|
||||
@Slf4j
|
||||
public class Docx4jUtil {
|
||||
|
||||
/**
|
||||
@@ -2139,5 +2141,83 @@ public class Docx4jUtil {
|
||||
return specialCaseP;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为Word文档添加水印
|
||||
* 使用页眉方式,但设置页眉高度为0,确保不影响文档结构
|
||||
*
|
||||
* @param wordPackage Word文档包
|
||||
* @param watermarkText 水印文字(如:"非正式")
|
||||
* @throws Exception 添加水印失败时抛出异常
|
||||
*/
|
||||
public static void addWatermarkToDocument(WordprocessingMLPackage wordPackage, String watermarkText) throws Exception {
|
||||
try {
|
||||
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
|
||||
ObjectFactory factory = new ObjectFactory();
|
||||
|
||||
// 创建页眉部分
|
||||
org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart headerPart =
|
||||
new org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart();
|
||||
|
||||
// 将页眉部分添加到文档并获取关系ID
|
||||
org.docx4j.relationships.Relationship relationship = mainDocumentPart.addTargetPart(headerPart);
|
||||
|
||||
// 创建页眉对象
|
||||
org.docx4j.wml.Hdr hdr = factory.createHdr();
|
||||
|
||||
// 创建段落
|
||||
P paragraph = factory.createP();
|
||||
|
||||
// 创建Run
|
||||
R run = factory.createR();
|
||||
|
||||
// 使用VML textbox方式创建水印文本(绝对定位,显示在页面中部)
|
||||
String vmlString = String.format(
|
||||
"<w:pict xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" " +
|
||||
"xmlns:v=\"urn:schemas-microsoft-com:vml\">" +
|
||||
"<v:shape style=\"position:absolute;left:0;text-align:center;margin-left:0;margin-top:0;" +
|
||||
"width:500pt;height:200pt;z-index:-251658240;" +
|
||||
"mso-position-horizontal:center;mso-position-horizontal-relative:page;" +
|
||||
"mso-position-vertical:center;mso-position-vertical-relative:page\" " +
|
||||
"fillcolor=\"none\" stroked=\"f\">" +
|
||||
"<v:textbox style=\"mso-fit-shape-to-text:t\">" +
|
||||
"<w:txbxContent>" +
|
||||
"<w:p><w:pPr><w:jc w:val=\"center\"/></w:pPr>" +
|
||||
"<w:r><w:rPr>" +
|
||||
"<w:color w:val=\"D8D8D8\"/>" +
|
||||
"<w:sz w:val=\"240\"/>" +
|
||||
"<w:szCs w:val=\"240\"/>" +
|
||||
"<w:rFonts w:ascii=\"微软雅黑\" w:eastAsia=\"微软雅黑\" w:hAnsi=\"微软雅黑\"/>" +
|
||||
"</w:rPr><w:t>%s</w:t></w:r></w:p>" +
|
||||
"</w:txbxContent></v:textbox>" +
|
||||
"</v:shape></w:pict>", watermarkText);
|
||||
|
||||
// 解析VML并添加到Run
|
||||
Object vmlObject = XmlUtils.unmarshalString(vmlString);
|
||||
run.getContent().add(vmlObject);
|
||||
|
||||
paragraph.getContent().add(run);
|
||||
hdr.getContent().add(paragraph);
|
||||
headerPart.setJaxbElement(hdr);
|
||||
|
||||
// 获取或创建节属性(SectPr)
|
||||
SectPr sectPr = mainDocumentPart.getJaxbElement().getBody().getSectPr();
|
||||
if (sectPr == null) {
|
||||
sectPr = factory.createSectPr();
|
||||
mainDocumentPart.getJaxbElement().getBody().setSectPr(sectPr);
|
||||
}
|
||||
|
||||
// 创建页眉引用并关联到节属性
|
||||
org.docx4j.wml.HeaderReference headerReference = factory.createHeaderReference();
|
||||
headerReference.setId(relationship.getId());
|
||||
headerReference.setType(org.docx4j.wml.HdrFtrRef.DEFAULT);
|
||||
sectPr.getEGHdrFtrReferences().add(headerReference);
|
||||
|
||||
log.info("成功添加水印:{}", watermarkText);
|
||||
} catch (Exception e) {
|
||||
log.error("添加水印失败:{}", e.getMessage(), e);
|
||||
throw new Exception("添加水印失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user