@@ -1,12 +1,10 @@
package com.njcn.harmonic.service.impl ;
package com.njcn.harmonic.service.report. impl ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.LocalDateTimeUtil ;
import cn.hutool.core.date.TimeInterval ;
import cn.hutool.core.io.IoUtil ;
import cn.hutool.core.text.StrBuilder ;
import cn.hutool.core.text.StrPool ;
import cn.hutool.core.util.CharsetUtil ;
import cn.hutool.core.util.StrUtil ;
@@ -14,20 +12,17 @@ import cn.hutool.json.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner ;
import com.njcn.common.pojo.enums.common.DataStateEnum ;
import com.njcn.common.pojo.enums.response.CommonResponseEnum ;
import com.njcn.common.pojo.exception.BusinessException ;
import com.njcn.common.utils.FileUtil ;
import com.njcn.csdevice.api.CsCommTerminalFeignClient ;
import com.njcn.csdevice.api.WlRecordFeignClient ;
import com.njcn.csdevice.pojo.po.WlRecord ;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient ;
import com.njcn.device.pq.api.DeptLineFeignClient ;
import com.njcn.device.pq.api.DeviceUnitClient ;
import com.njcn.device.pq.pojo.po.DeptLine ;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit ;
import com.njcn.harmonic.enums.HarmonicResponseEnum ;
import com.njcn.harmonic.mapper.DeptTempMapper ;
import com.njcn.harmonic.mapper.EleEpdMapper ;
import com.njcn.harmonic.mapper.ExcelRptMapper ;
import com.njcn.harmonic.mapper.ExcelRptTempMapper ;
import com.njcn.harmonic.pojo.dto.ReportTemplateDTO ;
import com.njcn.harmonic.pojo.param.ReportSearchParam ;
@@ -35,8 +30,6 @@ import com.njcn.harmonic.pojo.param.ReportTemplateParam;
import com.njcn.harmonic.utils.DataChangeUtil ;
import com.njcn.influx.constant.InfluxDbSqlConstant ;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant ;
import com.njcn.influx.pojo.dto.StatisticalDataDTO ;
import com.njcn.influx.service.CommonService ;
import com.njcn.influx.utils.InfluxDbUtils ;
import com.njcn.oss.enums.OssResponseEnum ;
import com.njcn.system.api.DicDataFeignClient ;
@@ -44,35 +37,28 @@ import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum ;
import com.njcn.system.pojo.po.DictData ;
import com.njcn.system.pojo.po.EleEpdPqd ;
import com.njcn.harmonic.pojo.po.ExcelRpt ;
import com.njcn.harmonic.pojo.po.ExcelRptTemp ;
import com.njcn.harmonic.pojo.po.SysDeptTemp ;
import com.njcn.harmonic.pojo.vo.ReportTemplateVO ;
import com.njcn.harmonic.pojo.vo.ReportTreeVO ;
import com.njcn.harmonic.pojo.vo.SysDeptTempVO ;
import com.njcn.harmonic.service.CustomReportService ;
import com.njcn.harmonic.service.report. CustomReportService ;
import com.njcn.oss.constant.OssPath ;
import com.njcn.oss.utils.FileStorageUtil ;
import com.njcn.user.api.DeptFeignClient ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang.StringUtils ;
import org.apache.ibatis.annotations.Param ;
import org.apache.ibatis.annotations.Select ;
import org.apache.tomcat.util.http.fileupload.IOUtils ;
import org.springframework.beans.BeanUtils ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.web.multipart.MultipartFile ;
import sun.reflect.generics.tree.Tree ;
import javax.servlet.http.HttpServletResponse ;
import java.io.* ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.text.DateFormat ;
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
@@ -122,6 +108,8 @@ public class CustomReportServiceImpl implements CustomReportService {
private final String STR_TWO = " $ " ;
private final String STR_THREE = " & " ;
private final String STR_FOUR = " % " ;
private final String UVOLTAGE_DEV = " UVOLTAGE_DEV " ;
private final String VOLTAGE_DEV = " VOLTAGE_DEV " ;
@Override
public void getCustomReport ( ReportSearchParam reportSearchParam , HttpServletResponse response ) {
@@ -691,7 +679,7 @@ public class CustomReportServiceImpl implements CustomReportService {
* @date 2023 / 10 / 20
* /
private void assSqlByMysql ( List < ReportTemplateDTO > data , StringBuilder sql , List < ReportTemplateDTO > endList , String method , ReportSearchParam reportSearchParam , Map < String , ReportTemplateDTO > limitMap , Map < String , Float > overLimitMap , Map < String , ReportTemplateDTO > assNoPassMap ) {
private void assSqlByMysql ( List < ReportTemplateDTO > data , StringBuilder sql , List < ReportTemplateDTO > endList , String method , ReportSearchParam reportSearchParam , Map < String , ReportTemplateDTO > limitMap , Map < String , Float > overLimitMap , Map < String , ReportTemplateDTO > assNoPassMap , List < String > noPhaseList ) {
/ / sql拼接示例 : select MAX ( IHA2 ) as IHA2 from power_quality_data where Phase = 'A' and LineId = ' 1324564568 ' and Stat_Method = ' max ' tz ( ' Asia / Shanghai ' )
if ( InfluxDbSqlConstant . CP95 . equals ( method ) ) {
for ( int i = 0 ; i < data . size ( ) ; i + + ) {
@@ -763,7 +751,10 @@ public class CustomReportServiceImpl implements CustomReportService {
/ / 频率和频率偏差仅统计T相
if ( data . get ( 0 ) . getTemplateName ( ) . equals ( " freq_dev " ) | | data . get ( 0 ) . getTemplateName ( ) . equals ( " freq " )) {
if ( noPhaseList . contains ( data . get ( 0 ) . getTemplateName ( ) ) ) {
if ( data . get ( 0 ) . getTemplateName ( ) . equalsIgnoreCase ( " v_unbalance " ) ) {
System . out . println ( 44 ) ;
}
sql . append ( InfluxDbSqlConstant . AND )
. append ( InfluxDBTableConstant . PHASIC_TYPE )
. append ( InfluxDbSqlConstant . EQ )
@@ -783,6 +774,7 @@ public class CustomReportServiceImpl implements CustomReportService {
if ( CollUtil . isEmpty ( mapList ) | | Objects . isNull ( mapList . get ( 0 ) ) ) {
data = data . stream ( ) . peek ( item - > item . setValue ( " / " ) ) . collect ( Collectors . toList ( ) ) ;
} else {
/ / 兼容达梦数据库方法
Map < String , Object > map = convertKeysToUpperCase ( mapList . get ( 0 ) ) ;
for ( ReportTemplateDTO item : data ) {
if ( map . containsKey ( item . getItemName ( ) ) ) {
@@ -790,10 +782,22 @@ public class CustomReportServiceImpl implements CustomReportService {
item . setValue ( String . format ( " %.3f " , v ) ) ;
if ( overLimitMap . containsKey ( item . getLimitName ( ) ) ) {
Float tagVal = overLimitMap . get ( item . getLimitName ( ) ) ;
if ( v > tagVal ) {
item . s etOver LimitFlag ( 1 ) ;
} else {
item . setOverLimitFlag ( 0 ) ;
if ( item . g etLimitName ( ) . equalsIgnoreCase ( UVOLTAGE_DEV ) ) {
/ / 对电压偏差特殊处理
Float tagVal_U = overLimitMap . get ( UVOLTAGE_DEV ) ;
if ( v > tagVal | | v < tagVal_U ) {
item . setOverLimitFlag ( 1 ) ;
} else {
item . setOverLimitFlag ( 0 ) ;
}
} else {
if ( v > tagVal ) {
item . setOverLimitFlag ( 1 ) ;
} else {
item . setOverLimitFlag ( 0 ) ;
}
}
}
@@ -803,12 +807,27 @@ public class CustomReportServiceImpl implements CustomReportService {
if ( limitMap . containsKey ( key ) ) {
ReportTemplateDTO tem = limitMap . get ( key ) ;
double limitVal = Double . parseDouble ( tem . getValue ( ) ) ;
if ( v > limitVal ) {
tem . s etOver LimitFlag ( 1 ) ;
assNoPassMap . put ( key , tem ) ;
} else if ( ! assNoPassMap . containsKey ( key ) ) {
tem . setOverLimitFlag ( 0 ) ;
assNoPassMap . put ( key , tem ) ;
if ( VOLTAGE_DEV . equalsIgnoreCase ( tem . g etLimitName ( ) ) ) {
/ / 针对电压偏差特殊处理
double limitLowVal = Double . parseDouble ( tem . getLowValue ( ) ) ;
if ( v > limitVal | | v < limitLowVal ) {
tem . setOverLimitFlag ( 1 ) ;
assNoPassMap . put ( key , tem ) ;
} else if ( ! assNoPassMap . containsKey ( key ) ) {
tem . setOverLimitFlag ( 0 ) ;
assNoPassMap . put ( key , tem ) ;
}
} else {
/ / 其他指标
if ( v > limitVal ) {
tem . setOverLimitFlag ( 1 ) ;
assNoPassMap . put ( key , tem ) ;
} else if ( ! assNoPassMap . containsKey ( key ) ) {
tem . setOverLimitFlag ( 0 ) ;
assNoPassMap . put ( key , tem ) ;
}
}
}
}
@@ -860,6 +879,14 @@ public class CustomReportServiceImpl implements CustomReportService {
throw new BusinessException ( HarmonicResponseEnum . CUSTOM_REPORT_JSON ) ;
}
}
/ / 查询不分相别的指标
DictData dictData = dicDataFeignClient . getDicDataByCodeAndType ( DicDataEnum . EPD . getCode ( ) , DicDataTypeEnum . CS_DATA_TYPE . getCode ( ) ) . getData ( ) ;
if ( Objects . isNull ( dictData ) ) {
throw new BusinessException ( CommonResponseEnum . FAIL , " 字典类型模板缺少! " ) ;
}
List < EleEpdPqd > temTargetList = eleEpdMapper . selectList ( new LambdaQueryWrapper < EleEpdPqd > ( ) . eq ( EleEpdPqd : : getDataType , dictData . getId ( ) ) . in ( EleEpdPqd : : getPhase , Arrays . asList ( " T " , " M " ) ) ) ;
List < String > noPhaseList = temTargetList . stream ( ) . filter ( it - > StrUtil . isNotBlank ( it . getOtherName ( ) ) ) . map ( it - > it . getOtherName ( ) . toUpperCase ( ) ) . collect ( Collectors . toList ( ) ) ;
/ / 处理指标是否合格
reportLimitList = new LinkedHashSet < > ( reportLimitList ) . stream ( ) . sorted ( Comparator . comparing ( ReportTemplateDTO : : getItemName ) ) . collect ( Collectors . toList ( ) ) ;
Map < String , Float > limitMap = overLimitDeal ( reportLimitList , reportSearchParam ) ;
@@ -884,13 +911,13 @@ public class CustomReportServiceImpl implements CustomReportService {
phaseMap . forEach ( ( phaseKey , phaseVal ) - > {
StringBuilder sql = new StringBuilder ( InfluxDbSqlConstant . SELECT ) ;
if ( InfluxDbSqlConstant . MAX . equalsIgnoreCase ( valueTypeKey ) ) {
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . MAX , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap ) ;
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . MAX , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap , noPhaseList );
} else if ( InfluxDbSqlConstant . MIN . equalsIgnoreCase ( valueTypeKey ) ) {
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . MIN , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap ) ;
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . MIN , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap , noPhaseList );
} else if ( InfluxDbSqlConstant . AVG_WEB . equalsIgnoreCase ( valueTypeKey ) ) {
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . AVG_WEB , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap ) ;
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . AVG_WEB , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap , noPhaseList );
} else if ( InfluxDbSqlConstant . CP95 . equalsIgnoreCase ( valueTypeKey ) ) {
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . CP95 , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap ) ;
assSqlByMysql ( phaseVal , sql , endList , InfluxDbSqlConstant . CP95 , reportSearchParam , limitTargetMapX , limitMap , assNoPassMap , noPhaseList );
}
} ) ;
@@ -1040,7 +1067,7 @@ public class CustomReportServiceImpl implements CustomReportService {
} else if ( vItem . length = = 4 ) {
/ / $HA [ _25 ] # max # classId$
reportTemplateDTO . setTemplateName ( vItem [ 0 ] . toUpperCase ( ) ) ;
reportTemplateDTO . setPhase ( " M " ) ;
reportTemplateDTO . setPhase ( " T " ) ;
reportTemplateDTO . setStatMethod ( vItem [ 1 ] . toUpperCase ( ) ) ;
reportTemplateDTO . setResourceId ( vItem [ 2 ] . toUpperCase ( ) ) ;
reportTemplateDTO . setLimitName ( vItem [ 3 ] . toUpperCase ( ) ) ;
@@ -1048,14 +1075,13 @@ public class CustomReportServiceImpl implements CustomReportService {
reportTemplateDTOList . add ( reportTemplateDTO ) ;
} else if ( v . charAt ( 0 ) = = '%' & & v . contains ( STR_ONE ) ) {
/ / 封装ReportTemplateDTO
/ / 封装指标结论 ReportTemplateDTO
ReportTemplateDTO reportTemplateDTO = new ReportTemplateDTO ( ) ;
v = v . replace ( STR_FOUR , " " ) ;
reportTemplateDTO . setItemName ( v . toUpperCase ( ) ) ;
/ / 根据 # 分割数据
String [ ] vItem = v . split ( STR_ONE ) ;
if ( vItem . length = = 3 ) {
/ / $HA [ _25 ] # B # max # classId$
reportTemplateDTO . setTemplateName ( vItem [ 0 ] . toUpperCase ( ) ) ;
reportTemplateDTO . setStatMethod ( vItem [ 1 ] . toUpperCase ( ) ) ;
reportTemplateDTO . setResourceId ( vItem [ 2 ] . toUpperCase ( ) ) ;
@@ -1092,11 +1118,13 @@ public class CustomReportServiceImpl implements CustomReportService {
StringBuilder sql = new StringBuilder ( InfluxDbSqlConstant . SELECT ) ;
for ( int i = 0 ; i < reportLimitList . size ( ) ; i + + ) {
if ( i = = reportLimitList . size ( ) - 1 ) {
sql . append ( UVOLTAGE_DEV ) . append ( StrUtil . COMMA ) ;
sql . append ( reportLimitList . get ( i ) . getTemplateName ( ) ) . append ( StrUtil . C_SPACE ) ;
} else {
sql . append ( reportLimitList . get ( i ) . getTemplateName ( ) ) . append ( StrUtil . COMMA ) ;
}
}
sql . append ( InfluxDbSqlConstant . FROM ) . append ( reportLimitList . get ( 0 ) . getResourceId ( ) ) . append ( InfluxDbSqlConstant . WHERE ) . append ( " id =' " ) . append ( reportSearchParam . getLineId ( ) ) . append ( " ' " ) ;
limitMap = excelRptTempMapper . dynamicSqlMap ( sql . toString ( ) ) ;
if ( Objects . isNull ( limitMap ) ) {
@@ -1105,6 +1133,10 @@ public class CustomReportServiceImpl implements CustomReportService {
for ( ReportTemplateDTO item : reportLimitList ) {
if ( limitMap . containsKey ( item . getTemplateName ( ) ) ) {
if ( item . getTemplateName ( ) . equalsIgnoreCase ( VOLTAGE_DEV ) ) {
item . setLowValue ( limitMap . get ( UVOLTAGE_DEV ) . toString ( ) ) ;
}
item . setValue ( limitMap . get ( item . getTemplateName ( ) ) . toString ( ) ) ;
}
}
@@ -1551,13 +1583,18 @@ public class CustomReportServiceImpl implements CustomReportService {
( Map < String , ReportTemplateDTO > assNoPassMap , Map < String , ReportTemplateDTO > limitTargetMapX , List < ReportTemplateDTO > endList ) {
assNoPassMap . forEach ( ( key , val ) - > {
limitTargetMapX . remove ( key ) ;
if ( " Voltage_Dev " . toUpperCase ( ) . equals ( val . getTemplateName ( ) ) | | " Freq_Dev" . toUpperCase ( ) . equals ( val . getTemplateName ( ) ) ) {
if ( " Freq_Dev " . toUpperCase ( ) . equals ( val . getTemplateName ( ) ) ) {
val . setValue ( " ± " + val . getValue ( ) ) ;
}
String expend = " " ;
if ( Objects . nonNull ( val . getLowValue ( ) ) ) {
expend = val . getLowValue ( ) + " , " ;
}
if ( val . getOverLimitFlag ( ) = = 1 ) {
val . setValue ( " 不合格 ( " + val . getValue ( ) + " ) " ) ;
val . setValue ( " 不合格 ( " + expend + val. getValue ( ) + " ) " ) ;
} else {
val . setValue ( " 合格 ( " + val . getValue ( ) + " ) " ) ;
val . setValue ( " 合格 ( " + expend + val. getValue ( ) + " ) " ) ;
}
endList . add ( val ) ;
} ) ;
@@ -1613,7 +1650,7 @@ public class CustomReportServiceImpl implements CustomReportService {
} else if ( vItem . length = = 4 ) {
/ / $HA [ _25 ] # max # classId$
reportTemplateDTO . setTemplateName ( vItem [ 0 ] ) ;
reportTemplateDTO . setPhase ( " M " ) ;
reportTemplateDTO . setPhase ( " T " ) ;
reportTemplateDTO . setStatMethod ( vItem [ 1 ] ) ;
reportTemplateDTO . setResourceId ( vItem [ 2 ] ) ;
reportTemplateDTO . setLimitName ( vItem [ 3 ] ) ;