@@ -19,6 +19,7 @@ import com.njcn.gather.detection.pojo.vo.DetectionData;
import com.njcn.gather.device.pojo.enums.DevReportStateEnum ;
import com.njcn.gather.device.pojo.vo.PqDevVO ;
import com.njcn.gather.device.service.IPqDevService ;
import com.njcn.gather.err.service.IPqErrSysDtlsService ;
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum ;
import com.njcn.gather.plan.pojo.po.AdPlan ;
import com.njcn.gather.plan.service.IAdPlanService ;
@@ -26,28 +27,37 @@ import com.njcn.gather.report.mapper.PqReportMapper;
import com.njcn.gather.report.pojo.DevReportParam ;
import com.njcn.gather.report.pojo.enums.ReportResponseEnum ;
import com.njcn.gather.report.pojo.param.ReportParam ;
import com.njcn.gather.report.pojo.po.CellEntity ;
import com.njcn.gather.report.pojo.po.PqReport ;
import com.njcn.gather.report.pojo.vo.PqReportVO ;
import com.njcn.gather.report.service.IPqReportService ;
import com.njcn.gather.report.utils.WordUtil ;
import com.njcn.gather.result.pojo.param.ResultParam ;
import com.njcn.gather.result.pojo.vo.ResultVO ;
import com.njcn.gather.result.service.IResultService ;
import com.njcn.gather.script.pojo.po.PqScriptCheckData ;
import com.njcn.gather.script.pojo.po.PqScriptDtls ;
import com.njcn.gather.script.service.IPqScriptCheckDataService ;
import com.njcn.gather.script.service.IPqScriptDtlsService ;
import com.njcn.gather.storage.pojo.param.SingleNonHarmParam ;
import com.njcn.gather.storage.pojo.po.AdBaseResult ;
import com.njcn.gather.storage.pojo.po.AdHarmonicResult ;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult ;
import com.njcn.gather.storage.pojo.vo.RawResultDataVO ;
import com.njcn.gather.storage.service.AdHarmonicService ;
import com.njcn.gather.storage.service.AdNonHarmonicService ;
import com.njcn.gather.system.dictionary.pojo.po.DictData ;
import com.njcn.gather.system.dictionary.pojo.po.DictTree ;
import com.njcn.gather.system.dictionary.service.IDictDataService ;
import com.njcn.gather.system.dictionary.service.IDictTreeService ;
import com.njcn.gather.system.pojo.enums.DicDataEnum ;
import com.njcn.gather.type.pojo.po.DevType ;
import com.njcn.gather.type.service.IDevTypeService ;
import com.njcn.web.factory.PageFactory ;
import com.njcn.web.utils.RequestUtil ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.poi.xwpf.usermodel.XWPFDocument ;
import org.apache.poi.xwpf.usermodel.* ;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.* ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.core.io.ClassPathResource ;
@@ -65,6 +75,7 @@ import java.nio.file.Path;
import java.nio.file.Paths ;
import java.util.* ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
/**
* @author makejava
@@ -75,6 +86,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class PqReportServiceImpl extends ServiceImpl < PqReportMapper , PqReport > implements IPqReportService {
private static final int TWIPS_PER_INCH = 1440 ;
@Value ( " ${report.template:D: \\ template} " )
private String templatePath ;
@@ -98,6 +110,12 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
private final IDevTypeService devTypeService ;
private final IDictTreeService dictTreeService ;
private final IPqErrSysDtlsService pqErrSysDtlsService ;
private final IResultService resultService ;
@Override
public Page < PqReportVO > list ( ReportParam . QueryParam queryParam ) {
QueryWrapper < PqReport > wrapper = new QueryWrapper < > ( ) ;
@@ -111,12 +129,12 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
BeanUtils . copyProperties ( pqReport , pqReportVO ) ;
PqReportVO . FileVO baseFileVo = new PqReportVO . FileVO ( ) ;
baseFileVo . setFile Name ( pqReport . getBasePath ( ) . substring ( pqReport . getBasePath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
baseFileVo . setName ( pqReport . getBasePath ( ) . substring ( pqReport . getBasePath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
baseFileVo . setUrl ( pqReport . getBasePath ( ) ) ;
pqReportVO . setBaseFileVO ( baseFileVo ) ;
PqReportVO . FileVO detailFileVo = new PqReportVO . FileVO ( ) ;
detailFileVo . setFile Name ( pqReport . getBasePath ( ) . substring ( pqReport . getBasePath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
detailFileVo . setName ( pqReport . getBasePath ( ) . substring ( pqReport . getBasePath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
detailFileVo . setUrl ( pqReport . getBasePath ( ) ) ;
pqReportVO . setDetailFileVO ( detailFileVo ) ;
@@ -138,12 +156,12 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
BeanUtils . copyProperties ( pqReport , pqReportVO ) ;
PqReportVO . FileVO baseFileVo = new PqReportVO . FileVO ( ) ;
baseFileVo . setFile Name ( pqReport . getBasePath ( ) . substring ( pqReport . getBasePath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
baseFileVo . setName ( pqReport . getBasePath ( ) . substring ( pqReport . getBasePath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
baseFileVo . setUrl ( pqReport . getBasePath ( ) ) ;
pqReportVO . setBaseFileVO ( baseFileVo ) ;
PqReportVO . FileVO detailFileVo = new PqReportVO . FileVO ( ) ;
detailFileVo . setFile Name ( pqReport . getDetailPath ( ) . substring ( pqReport . getDetailPath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
detailFileVo . setName ( pqReport . getDetailPath ( ) . substring ( pqReport . getDetailPath ( ) . lastIndexOf ( File . separator ) + 1 ) ) ;
detailFileVo . setUrl ( pqReport . getDetailPath ( ) ) ;
pqReportVO . setDetailFileVO ( detailFileVo ) ;
@@ -159,7 +177,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
pqReport . setState ( DataStateEnum . ENABLE . getCode ( ) ) ;
// 上传文件
this . uploadFile ( reportParam , pqReport ) ;
this . uploadFile ( reportParam , pqReport , true );
return this . save ( pqReport ) ;
}
@@ -171,7 +189,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
BeanUtils . copyProperties ( reportParam , pqReport ) ;
// 上传文件
this . uploadFile ( reportParam , pqReport ) ;
this . uploadFile ( reportParam , pqReport , false );
return this . updateById ( pqReport ) ;
}
@@ -193,7 +211,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
@Override
public List < String > listAllName ( ) {
List < String > result = this . lambdaQuery ( )
. eq ( PqReport : : getState , DataStateEnum . ENABLE . getCode ( ) ) . list ( ) . stream ( ) . map ( PqReport : : getName ) . collect ( Collectors . toList ( ) ) ;
. eq ( PqReport : : getState , DataStateEnum . ENABLE . getCode ( ) ) . list ( ) . stream ( ) . map ( PqReport : : getName ) . distinct ( ) . collect( Collectors . toList ( ) ) ;
return result ;
}
@@ -210,8 +228,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
*
* @param reportParam
* @param pqReport
* @param isAdd
*/
private void uploadFile ( ReportParam reportParam , PqReport pqReport ) {
private void uploadFile ( ReportParam reportParam , PqReport pqReport , Boolean isAdd ) {
String uploadDir = templatePath + File . separator + reportParam . getName ( ) + File . separator + reportParam . getVersion ( ) + File . separator ;
//校验文件后缀
@@ -268,7 +287,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
throw new BusinessException ( ReportResponseEnum . FILE_UPLOAD_FAILED ) ;
}
} else {
throw new BusinessException ( ReportResponseEnum . FILE_NOT_NULL ) ;
if ( isAdd ) {
throw new BusinessException ( ReportResponseEnum . FILE_NOT_NULL ) ;
}
}
}
@@ -306,7 +327,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
@Override
public void generateReport ( DevReportParam devReportParam ) {
AdPlan plan = adPlanService . getById ( devReportParam . getPlanId ( ) ) ;
if ( Object Util. isNotNull ( plan . getReportTemplateId ( ) ) ) {
if ( Str Util. isNotBlank ( plan . getReportTemplateId ( ) ) ) {
this . generateReportByPlan ( plan , devReportParam ) ;
} else {
// 根据设备类型找到报告模板
@@ -364,16 +385,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 根据设备类型找到报告模板
PqDevVO pqDevVO = iPqDevService . getPqDevById ( devReportParam . getDevId ( ) ) ;
if ( Objects . isNull ( pqDevVO ) ) {
throw new BusinessException ( " 请检查装置是否存在! " ) ;
throw new BusinessException ( ReportResponseEnum . DEVICE_NOT_EXIST ) ;
}
// 获取设备型号
DevType devType = devTypeService . getById ( pqDevVO . getDevType ( ) ) ;
if ( Objects . isNull ( devType ) ) {
throw new BusinessException ( " 设备类型缺失,请联系管理员! " ) ;
throw new BusinessException ( ReportResponseEnum . DEVICE_TYPE_NOT_EXIST ) ;
}
PqReport report = this . lambdaQuery ( ) . eq ( PqReport : : getId , plan . getAssociateReport ( ) ) . eq ( PqReport : : getState , DataStateEnum . ENABLE . getCode ( ) ) . one ( ) ;
PqReport report = this . lambdaQuery ( ) . eq ( PqReport : : getId , plan . getReportTemplateId ( ) ) . eq ( PqReport : : getState , DataStateEnum . ENABLE . getCode ( ) ) . one ( ) ;
if ( Objects . isNull ( report ) ) {
throw new BusinessException ( " 报告模板缺失,请联系管理员! " ) ;
throw new BusinessException ( ReportResponseEnum . REPORT_TEMPLATE_NOT_EXIST ) ;
}
FileSystemResource resource = new FileSystemResource ( report . getBasePath ( ) ) ;
@@ -383,7 +404,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
// 处理基础模版中的信息
dealBaseModel ( baseModelDocument , pqDevVO , devType ) ;
// 处理数据页中的信息
dealDataModel ( baseModelDocument , devReportParam , pqDevVO ) ;
dealDataModelZJ ( baseModelDocument , devReportParam , pqDevVO ) ;
// 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx
// 最终文件输出的路径
String dirPath = reportPath . concat ( File . separator ) . concat ( devType . getName ( ) ) ;
@@ -422,7 +443,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
adPlanService . update ( updateWrapper ) ;
}
@Override
public void downloadReport ( DevReportParam devReportParam , HttpServletResponse response ) {
PqDevVO pqDevVO = iPqDevService . getPqDevById ( devReportParam . getDevId ( ) ) ;
@@ -476,9 +496,10 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
Map < String , String > baseModelMap = new HashMap < > ( 16 ) ;
// 获取设备型号
baseModelMap . put ( " ${devType} " , devType . getName ( ) ) ;
baseModelMap . put ( " ${device_type} " , devType . getName ( ) ) ;
// 调试人员, todo... 待咨询曹泽辉如何获取当前用户信息,目前先写死
String userName = RequestUtil. getUserName( ) ;
baseModelMap . put ( " ${userName} " , userName ) ;
// String userName = RequestUtil. getUserName() ;
baseModelMap . put ( " ${userName} " , pqDevVO . getCheckBy ( ) ) ;
// 调试日期
if ( pqDevVO . getCheckTime ( ) ! = null ) {
baseModelMap . put ( " ${testDate} " , DateUtil . format ( pqDevVO . getCheckTime ( ) , DatePattern . CHINESE_DATE_PATTERN ) ) ;
@@ -503,6 +524,17 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
baseModelMap . put ( " ${count} " , pqDevVO . getDevChns ( ) . toString ( ) ) ;
DictData dictData = dictDataService . getDictDataById ( pqDevVO . getManufacturer ( ) ) ;
if ( ObjectUtil . isNotNull ( dictData ) ) {
baseModelMap . put ( " ${manufacturer} " , dictData . getName ( ) ) ;
} else {
baseModelMap . put ( " ${manufacturer} " , " 未知 " ) ;
}
baseModelMap . put ( " ${sample_id} " , pqDevVO . getSampleId ( ) ) ;
baseModelMap . put ( " ${arrived_date} " , String . valueOf ( pqDevVO . getArrivedDate ( ) ) ) ;
baseModelMap . put ( " ${check_date} " , String . valueOf ( pqDevVO . getCheckTime ( ) ) . substring ( 0 , 10 ) ) ;
baseModelMap . put ( " ${tested_by} " , pqDevVO . getCheckBy ( ) ) ;
// 替换模板中的信息,避免信息丢失,段落和表格均参与替换
WordUtil . replacePlaceholdersInParagraphs ( baseModelDocument , baseModelMap ) ;
WordUtil . replacePlaceholdersInTables ( baseModelDocument , baseModelMap ) ;
@@ -516,15 +548,15 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* @param devReportParam 查询参数
*/
private void dealDataModel ( XWPFDocument baseModelDocument , DevReportParam devReportParam , PqDevVO pqDevVO ) throws IOException {
AdPlan adPlan = adPlanService. getById( devReportParam. getPlanId( ) ) ;
String scriptId = adPlan. getScriptId( ) ;
// AdPlan adPlan = adPlanService. getById( devReportParam. getPlanId()) ;
// String scriptId = adPlan. getScriptId() ;
Integer devChns = pqDevVO . getDevChns ( ) ;
for ( int i = 1 ; i < = devChns ; i + + ) {
ClassPathResource resource = new ClassPathResource ( " /model/report_table.docx " ) ;
XWPFDocument dataModelDocumentTemp = new XWPFDocument ( resource . getInputStream ( ) ) ;
SingleNonHarmParam singleNonHarmParam = new SingleNonHarmParam ( ) ;
singleNonHarmParam . setPlanCode ( adPlan . getCode ( ) ) ;
singleNonHarmParam . setPlanCode ( Integer . valueOf ( devReportParam . getPlan Code ( ) ) ) ;
singleNonHarmParam . setDevId ( pqDevVO . getId ( ) ) ;
singleNonHarmParam . setChannelNo ( i ) ;
@@ -678,6 +710,490 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
}
}
private void dealDataModelZJ ( XWPFDocument baseModelDocument , DevReportParam devReportParam , PqDevVO pqDevVO ) {
List < AdBaseResult > nonHarmonicResultList = adNonHarmonicService . get ( devReportParam . getScriptId ( ) , null , devReportParam . getDevId ( ) , " -1 " , devReportParam . getPlanCode ( ) ) ;
List < AdBaseResult > harmonicResultList = adHarmonicService . get ( devReportParam . getScriptId ( ) , null , devReportParam . getDevId ( ) , " -1 " , devReportParam . getPlanCode ( ) ) ;
if ( CollectionUtil . isEmpty ( nonHarmonicResultList ) & & CollectionUtil . isEmpty ( harmonicResultList ) ) {
throw new BusinessException ( ReportResponseEnum . NO_CHECK_DATA ) ;
}
List < AdBaseResult > allBaseResultList = Stream . concat ( nonHarmonicResultList . stream ( ) , harmonicResultList . stream ( ) )
. sorted ( Comparator . comparing ( AdBaseResult : : getSort ) ) . collect ( Collectors . toList ( ) ) ;
LinkedHashMap < String , List < AdBaseResult > > chnResultMap = allBaseResultList . stream ( ) . sorted ( Comparator . comparing ( AdBaseResult : : getSort ) )
. collect ( Collectors . groupingBy (
( obj ) - > obj . getMonitorId ( ) . substring ( obj . getMonitorId ( ) . lastIndexOf ( " _ " ) + 1 ) ,
LinkedHashMap : : new ,
Collectors . toList ( ) ) ) ;
for ( int i = 1 ; i < = pqDevVO . getDevChns ( ) ; i + + ) {
XWPFParagraph paragraph = baseModelDocument . createParagraph ( ) ;
paragraph . setAlignment ( ParagraphAlignment . LEFT ) ;
XWPFRun run = paragraph . createRun ( ) ;
run . setFontFamily ( " 宋体 " ) ;
run . setBold ( true ) ;
run . setFontSize ( 14 ) ;
run . setText ( " 测量回路 " + i ) ;
List < AdBaseResult > chnResultList = chnResultMap . get ( String . valueOf ( i ) ) ;
// // 排除电压相角、电压偏差、电流相角
// list1 = list1.stream().filter(obj -> !"e8bbfaad7a3fa343d3c46d345fb45fa3".equals(obj.getAdType()))
// .filter(obj -> !"148faabd2630aaac0b70be8609075f69".equals(obj.getAdType()))
// .filter(obj -> !"fdffc6b5dfdc8751b9fde9b599b8ea51".equals(obj.getAdType())).collect(Collectors.toList());
Map < String , Set < Integer > > checkMap = this . getCheckMap ( chnResultList ) ;
for ( String key : checkMap . keySet ( ) ) {
Set < Integer > indexSet = checkMap . get ( key ) ;
generateTitleAndTableZJ ( baseModelDocument , String . valueOf ( i ) , key , devReportParam , indexSet ) ;
}
}
//generateNonHarmABCTableHeaderZJ(baseModelDocument);
XWPFTable table = baseModelDocument . getTables ( ) . get ( 2 ) ;
for ( int i = 1 ; i < = 3 ; i + + ) {
XWPFTableRow row = table . createRow ( ) ;
for ( int j = 0 ; j < 8 ; j + + ) {
row . getCell ( j ) . setText ( " 1.00 " ) ;
row . getCell ( j ) . setWidth ( " 12.5% " ) ;
row . getCell ( j ) . setVerticalAlignment ( XWPFTableCell . XWPFVertAlign . CENTER ) ;
row . getCell ( j ) . getParagraphs ( ) . get ( 0 ) . setAlignment ( ParagraphAlignment . CENTER ) ;
if ( j = = 0 ) {
row . getCell ( j ) . setWidth ( " 15.0% " ) ;
}
if ( j = = 7 ) {
row . getCell ( j ) . setWidth ( " 10.0% " ) ;
}
}
}
}
/**
* 获取map。 key为 检测大项code_大项ID , value为大检测项下的所有index。
*
* @param list
*/
private Map < String , Set < Integer > > getCheckMap ( List < AdBaseResult > list ) {
Map < String , Set < Integer > > checkMap = new LinkedHashMap < > ( ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
AdBaseResult adBaseResult = list . get ( i ) ;
DictTree dictTree = dictTreeService . getById ( adBaseResult . getAdType ( ) ) ;
DictTree parentDictTree = dictTreeService . getById ( dictTree . getPid ( ) ) ;
if ( ObjectUtil . isNotNull ( parentDictTree ) ) {
String key = parentDictTree . getCode ( ) ;
checkMap . putIfAbsent ( key + " _ " + parentDictTree . getId ( ) , new TreeSet < > ( ) ) ;
checkMap . get ( key + " _ " + parentDictTree . getId ( ) ) . add ( adBaseResult . getSort ( ) ) ;
}
}
return checkMap ;
}
/**
* 浙江电科院版-动态生成标题和表格
*
* @param baseModelDocument
* @param devNum
* @param key
* @param devReportParam
* @param indexSet
*/
private void generateTitleAndTableZJ ( XWPFDocument baseModelDocument , String devNum , String key , DevReportParam devReportParam , Set < Integer > indexSet ) {
boolean isHarm = key . contains ( DicDataEnum . HV . getCode ( ) ) | | key . contains ( DicDataEnum . HI . getCode ( ) ) | | key . contains ( DicDataEnum . HSV . getCode ( ) ) | | key . contains ( DicDataEnum . HSV . getCode ( ) ) ;
Map < String , List < RawResultDataVO > > radiusMap = getRadiusMap ( devNum , key , devReportParam , indexSet , isHarm ) ;
for ( String radius : radiusMap . keySet ( ) ) {
XWPFParagraph paragraph = baseModelDocument . createParagraph ( ) ;
paragraph . setAlignment ( ParagraphAlignment . LEFT ) ;
XWPFRun run = paragraph . createRun ( ) ;
run . setFontFamily ( " 宋体 " ) ;
run . setBold ( true ) ;
run . setFontSize ( 12 ) ;
if ( isHarm ) {
run . setText ( key . split ( " _ " ) [ 0 ] + " 测量准确度(最大允许误差:± " + radius . split ( " _ " ) [ 1 ] + " ) " ) ;
} else {
run . setText ( key . split ( " _ " ) [ 0 ] + " 测量准确度(最大允许误差:± " + radius + " ) " ) ;
}
XWPFTable table = generateTableHeaderZJ ( baseModelDocument , DicDataEnum . getEnumByCode ( key . split ( " _ " ) [ 0 ] ) ) ;
// 填写数据
// for (RawResultDataVO rawResultDataVO : radiusMap.get(radius)) {
//
// }
}
}
/**
* 获取同一个检测大项下不同的误差范围,及其检测结果
*
* @param devNum
* @param key
* @param devReportParam
* @param indexSet
* @return
*/
private Map < String , List < RawResultDataVO > > getRadiusMap ( String devNum , String key , DevReportParam devReportParam , Set < Integer > indexSet , boolean isHarm ) {
Map < String , List < RawResultDataVO > > raiusMap = new LinkedHashMap < > ( ) ;
ResultParam param = new ResultParam ( ) ;
param . setScriptId ( devReportParam . getScriptId ( ) ) ;
param . setDevId ( devReportParam . getDevId ( ) ) ;
param . setDevNum ( devNum ) ;
param . setCode ( devReportParam . getPlanCode ( ) ) ;
String [ ] split = key . split ( " _ " ) ;
param . setScriptType ( split [ 1 ] ) ;
for ( Integer index : indexSet ) {
param . setIndex ( index ) ;
ResultVO resultVO = resultService . resultDataForReport ( param ) ;
Map < String , RawResultDataVO > resultData = resultVO . getResultData ( ) ;
if ( CollectionUtil . isNotEmpty ( resultData ) ) {
if ( DicDataEnum . V . getCode ( ) . equals ( split [ 0 ] ) | | DicDataEnum . I . getCode ( ) . equals ( split [ 0 ] ) ) {
// 排除电压相角、电压偏差、电流相角
resultData . remove ( " 电压相角 " ) ;
resultData . remove ( " 电压偏差 " ) ;
resultData . remove ( " 电流相角 " ) ;
}
resultData . values ( ) . stream ( ) . findFirst ( ) . ifPresent ( obj - > {
String radius = obj . getRadius ( ) ;
String unit = obj . getUnit ( ) ;
if ( StrUtil . isNotBlank ( radius ) ) {
if ( isHarm ) {
raiusMap . put ( index + " _ " + radius . split ( " ~ " ) [ 1 ] + unit , resultData . values ( ) . stream ( ) . collect ( Collectors . toList ( ) ) ) ;
} else {
raiusMap . put ( radius . split ( " ~ " ) [ 1 ] + unit , resultData . values ( ) . stream ( ) . collect ( Collectors . toList ( ) ) ) ;
}
}
} ) ;
}
}
return raiusMap ;
}
/**
* 浙江电科院版-生成表格头部
*
* @param doc
* @param checkItem 区分不同的表头
* @return 生成的表格
*/
private XWPFTable generateTableHeaderZJ ( XWPFDocument doc , DicDataEnum checkItem ) {
List < List < CellEntity > > rows = new ArrayList < > ( ) ;
List < CellEntity > row = null ;
switch ( checkItem ) {
case FREQ : // 用于 频率
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 给定值( HZ) " , " 25.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值( HZ) " , " 25.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差( HZ) " , " 25.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 25.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case V : // 用于 电压
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 给定值( V) " , " 15.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值( V) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 10.0% " , 2 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " " , " 15.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 10.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case I : // 用于 电流
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 给定值( A) " , " 15.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值( A) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 10.0% " , 2 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " " , " 15.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 10.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case IMBV : // 用于 负序电压不平衡度、负序电流不平衡度
case IMBA :
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 给定值(%) " , " 25.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值(%) " , " 25.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 25.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 25.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case F : // 用于 短时闪变
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 给定值 " , " 15.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值 " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 10.0% " , 2 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " " , " 15.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 10.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case HV : // 用于 谐波电压
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 谐波次数 " , " 7.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 谐波电压给定值(%) " , " 10.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 8.0% " , 2 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " " , " 7.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 10.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 8.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case HI : // 用于 谐波电流
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 谐波次数 " , " 8.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 谐波电流给定值( A) " , " 10.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值( A) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 7.0% " , 2 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " " , " 8.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 10.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 7.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case HSV : // 用于 间谐波电压
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 间谐波次数 " , " 8.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 间谐波电压给定值(%) " , " 10.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 7.0% " , 2 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " " , " 8.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 10.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 7.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case HSI : // 用于 间谐波电流
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 间谐波次数 " , " 8.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 间谐波电流给定值( A) " , " 10.0% " , 2 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值( A) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差(%) " , " 12.5% " , 1 , 3 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 结论 " , " 7.0% " , 2 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " " , " 8.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 10.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L1 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L2 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " L3 " , " 12.5% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " " , " 7.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
case VOLTAGE : // 用于 电压暂降、暂升及短时中断
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 给定值 " , " 16.0% " , 1 , 2 ) ) ;
row . add ( new CellEntity ( " " , " 16.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 测试值 " , " 16.0% " , 1 , 2 ) ) ;
row . add ( new CellEntity ( " " , " 16.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 误差 " , " 16.0% " , 1 , 2 ) ) ;
row . add ( new CellEntity ( " " , " 16.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
row = new ArrayList < > ( ) ;
row . add ( new CellEntity ( " 特征幅值(%) " , " 16.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 持续时间( ms) " , " 16.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 特征幅值(%) " , " 16.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 持续时间( ms) " , " 16.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 特征幅值(%) " , " 16.0% " , 1 , 1 ) ) ;
row . add ( new CellEntity ( " 持续时间( ms) " , " 16.0% " , 1 , 1 ) ) ;
rows . add ( row ) ;
break ;
default :
break ;
}
return generateTableHeader ( doc , rows ) ;
}
/**
* 动态生成表格头部
*
* @param doc
* @param rows 表头数据
* @return 生成的表格
*/
private XWPFTable generateTableHeader ( XWPFDocument doc , List < List < CellEntity > > rows ) {
XWPFTable table = doc . createTable ( rows . size ( ) , rows . get ( 0 ) . size ( ) ) ;
table . setTableAlignment ( TableRowAlign . CENTER ) ;
table . setWidth ( " 100% " ) ;
CTTblGrid grid = table . getCTTbl ( ) . addNewTblGrid ( ) ;
for ( int i = 0 ; i < rows . get ( 0 ) . size ( ) ; i + + ) {
grid . addNewGridCol ( ) ;
}
for ( int i = 0 ; i < rows . size ( ) ; i + + ) {
XWPFTableRow row = table . getRow ( i ) ;
row . setHeight ( ( int ) ( 1 / 2 . 54 * TWIPS_PER_INCH ) ) ;
for ( int j = 0 ; j < rows . get ( i ) . size ( ) ; j + + ) {
CellEntity cellEntity = rows . get ( i ) . get ( j ) ;
row . getCell ( j ) . setText ( cellEntity . getCellValue ( ) ) ;
row . getCell ( j ) . setWidth ( cellEntity . getWidth ( ) ) ;
setHeaderCellStyle ( row . getCell ( j ) ) ;
if ( cellEntity . getColSpan ( ) > 1 ) {
mergeCellsHorizontal ( table , i , j , j + cellEntity . getColSpan ( ) - 1 ) ;
}
if ( cellEntity . getRowSpan ( ) > 1 ) {
mergeCellsVertically ( table , j , i , i + cellEntity . getRowSpan ( ) - 1 ) ;
}
}
}
return table ;
}
public CTTcPr getTcPr ( XWPFTableCell cell ) {
return cell . getCTTc ( ) . isSetTcPr ( ) ? cell . getCTTc ( ) . getTcPr ( ) : cell . getCTTc ( ) . addNewTcPr ( ) ;
}
/**
* word单元格列合并( 合并列)
*
* @param table
* @param row
* @param fromCol
* @param toCol
*/
public void mergeCellsHorizontal ( XWPFTable table , int row , int fromCol , int toCol ) {
for ( int colIndex = fromCol ; colIndex < = toCol ; colIndex + + ) {
XWPFTableCell cell = table . getRow ( row ) . getCell ( colIndex ) ;
CTTcPr tcPr = getTcPr ( cell ) ;
CTHMerge hMerge = tcPr . addNewHMerge ( ) ;
if ( colIndex = = fromCol ) {
hMerge . setVal ( STMerge . RESTART ) ;
} else {
hMerge . setVal ( STMerge . CONTINUE ) ;
}
}
}
/**
* word单元格行合并( 合并行)
*
* @param table
* @param col
* @param fromRow
* @param toRow
*/
public void mergeCellsVertically ( XWPFTable table , int col , int fromRow , int toRow ) {
for ( int rowIndex = fromRow ; rowIndex < = toRow ; rowIndex + + ) {
XWPFTableCell cell = table . getRow ( rowIndex ) . getCell ( col ) ;
CTTcPr tcPr = getTcPr ( cell ) ;
CTVMerge vMerge = tcPr . addNewVMerge ( ) ;
if ( rowIndex = = fromRow ) {
vMerge . setVal ( STMerge . RESTART ) ;
} else {
vMerge . setVal ( STMerge . CONTINUE ) ;
}
}
}
public void setHeaderCellStyle ( XWPFTableCell cell ) {
cell . setVerticalAlignment ( XWPFTableCell . XWPFVertAlign . CENTER ) ;
XWPFParagraph xwpfParagraph = cell . getParagraphs ( ) . get ( 0 ) ;
xwpfParagraph . setAlignment ( ParagraphAlignment . CENTER ) ;
// System.out.println("Paragraph text: " + xwpfParagraph.getText());
// List<XWPFRun> runs = xwpfParagraph.getRuns();
// runs.get(0).setBold(true);
// runs.get(0).setFontSize(10);
// String text = runs.get(0).getText(0);
// if (StrUtil.isNotBlank(text) && Pattern.matches("^[A-Za-z0-9]+$", text)) {
// runs.get(0).setFontFamily("Arial");
// } else {
// runs.get(0).setFontFamily("宋体");
// }
}
private void specialDealVoltage ( Map < String , String > dataModelMap , String symbol ) {
String value = dataModelMap . get ( symbol ) ;
if ( Objects . nonNull ( value ) & & ! value . equals ( " / " ) ) {