1.浙江无线报表修改
This commit is contained in:
@@ -46,6 +46,9 @@ public class ReportTemplateDTO {
|
||||
*/
|
||||
private String resourceId;
|
||||
|
||||
/**
|
||||
* 标识指标是否越限 0.否 1.是
|
||||
*/
|
||||
private Integer overLimitFlag;
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.njcn.harmonic.mapper.ExcelRptTempMapper;
|
||||
import com.njcn.harmonic.pojo.dto.ReportTemplateDTO;
|
||||
import com.njcn.harmonic.pojo.param.ReportSearchParam;
|
||||
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;
|
||||
@@ -103,11 +104,8 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
private final CommonService commonService;
|
||||
|
||||
private final DeviceUnitClient deviceUnitClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final DeptFeignClient deptFeignClient;
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
@@ -819,11 +817,10 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
*/
|
||||
|
||||
private void analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp, HttpServletResponse response) {
|
||||
//定义一个线程集合
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
|
||||
long begin = System.currentTimeMillis();
|
||||
|
||||
//根据content,获取v值并进行处理
|
||||
//指标
|
||||
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
|
||||
//限值
|
||||
@@ -838,10 +835,8 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}
|
||||
|
||||
|
||||
long temEnd = System.currentTimeMillis();
|
||||
|
||||
|
||||
//处理指标是否合格
|
||||
reportLimitList = new LinkedHashSet<>(reportLimitList).stream().sorted(Comparator.comparing(ReportTemplateDTO::getItemName)).collect(Collectors.toList());
|
||||
Map<String, Float> limitMap = overLimitDeal(reportLimitList, reportSearchParam);
|
||||
@@ -860,6 +855,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
classMap.forEach((classKey, templateValue) -> {
|
||||
Map<String, List<ReportTemplateDTO>> valueTypeMap = templateValue.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getStatMethod));
|
||||
//每张表开启一个独立线程查询
|
||||
futures.add(executorService.submit(() -> {
|
||||
//avg.max,min,cp95
|
||||
valueTypeMap.forEach((valueTypeKey, valueTypeVal) -> {
|
||||
@@ -884,7 +880,6 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
});
|
||||
|
||||
|
||||
// 等待所有任务完成
|
||||
for (Future<?> future : futures) {
|
||||
try {
|
||||
@@ -894,7 +889,6 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//处理指标最终判定合格还是不合格
|
||||
dealTargetResult(assNoPassMap, limitTargetMapX, endList);
|
||||
|
||||
@@ -912,11 +906,12 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
//1、根据itemName分组
|
||||
Map<String, List<ReportTemplateDTO>> assMap = endList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getItemName));
|
||||
//处理台账信息
|
||||
Map<String, String> terminalMap = null;
|
||||
Map<String, String> finalTerminalMap;
|
||||
if (CollUtil.isNotEmpty(terminalList)) {
|
||||
terminalMap = commTerminalGeneralClient.getCustomDetailByLineId(reportSearchParam.getLineId()).getData();
|
||||
finalTerminalMap = commTerminalGeneralClient.getCustomDetailByLineId(reportSearchParam.getLineId()).getData();
|
||||
}else {
|
||||
finalTerminalMap = new HashMap<>();
|
||||
}
|
||||
Map<String, String> finalTerminalMap = terminalMap;
|
||||
|
||||
|
||||
//2、把itemName的value赋给v和m
|
||||
@@ -1168,6 +1163,11 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}
|
||||
|
||||
|
||||
DictData pqdDic = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.PQD.getCode(), DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
|
||||
List<EleEpdPqd> eleEpdPqdList = eleEpdMapper.selectList(new LambdaQueryWrapper<EleEpdPqd>().eq(EleEpdPqd::getDataType, pqdDic.getId()).isNotNull(EleEpdPqd::getPrimaryFormula));
|
||||
Map<String, List<EleEpdPqd>> pqdMap = eleEpdPqdList.stream().filter(item -> StrUtil.isNotBlank(item.getPrimaryFormula())).collect(Collectors.groupingBy(EleEpdPqd::getName));
|
||||
|
||||
//处理指标是否合格
|
||||
reportLimitList = new LinkedHashSet<>(reportLimitList)
|
||||
.stream()
|
||||
@@ -1178,15 +1178,16 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
//存放限值指标的map
|
||||
Map<String, ReportTemplateDTO> limitTargetMapX = reportLimitList.stream().collect(Collectors.toMap(ReportTemplateDTO::getItemName, Function.identity()));
|
||||
|
||||
List<ReportTemplateDTO> endList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(reportTemplateDTOList)) {
|
||||
|
||||
//组装最后监测点条件
|
||||
List<WlRecord> wlRecordList = wlRecordFeignClient.getWlAssByWlId(reportSearchParam.getLineId()).getData();
|
||||
List<WlRecord> temList = wlRecordFeignClient.getWlAssByWlId(reportSearchParam.getLineId()).getData();
|
||||
List<WlRecord> wlRecordList = temList.stream().filter(it -> it.getType() == 1).collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(wlRecordList)) {
|
||||
throw new BusinessException("当前测试项无测试数据");
|
||||
}
|
||||
|
||||
List<ReportTemplateDTO> endList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(reportTemplateDTOList)) {
|
||||
|
||||
//开始组织sql
|
||||
reportTemplateDTOList = new LinkedHashSet<>(reportTemplateDTOList)
|
||||
.stream()
|
||||
@@ -1208,13 +1209,13 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
phaseMap.forEach((phaseKey, phaseVal) -> {
|
||||
StringBuilder sql = new StringBuilder(InfluxDbSqlConstant.SELECT);
|
||||
if (InfluxDbSqlConstant.MAX.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList);
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList, pqdMap);
|
||||
} else if (InfluxDbSqlConstant.MIN.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList);
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList, pqdMap);
|
||||
} else if (InfluxDbSqlConstant.AVG_WEB.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.AVG, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList);
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.AVG, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList, pqdMap);
|
||||
} else if (InfluxDbSqlConstant.CP95.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.PERCENTILE, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList);
|
||||
assSqlZhejiang(phaseVal, sql, endList, InfluxDbSqlConstant.PERCENTILE, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap, wlRecordList, pqdMap);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1228,7 +1229,6 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
System.out.println("查询数据库花费时间" + (dealEnd - deal) / 1000 + "S");
|
||||
}
|
||||
|
||||
|
||||
if (CollUtil.isNotEmpty(endList)) {
|
||||
long jie = System.currentTimeMillis();
|
||||
//数据单位信息
|
||||
@@ -1237,33 +1237,46 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
//1、根据itemName分组
|
||||
Map<String, List<ReportTemplateDTO>> assMap = endList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getItemName));
|
||||
//处理台账信息
|
||||
/*Map<String, String> terminalMap = null;
|
||||
Map<String, String> finalTerminalMap;
|
||||
if (CollUtil.isNotEmpty(terminalList)) {
|
||||
terminalMap = commTerminalGeneralClient.getCustomDetailByLineId(reportSearchParam.getLineId()).getData();
|
||||
}
|
||||
Map<String, String> finalTerminalMap = terminalMap;*/
|
||||
if(Objects.nonNull(reportSearchParam.getCustomType()) && reportSearchParam.getCustomType() == 1){
|
||||
WlRecord wlRecordMain = temList.stream().filter(it -> it.getType() == 0).collect(Collectors.toList()).get(0);
|
||||
finalTerminalMap = new HashMap<>();
|
||||
finalTerminalMap.put("lineName",wlRecordMain.getItemName());
|
||||
//finalTerminalMap.put("statis_time",wlRecordMain.getStartTime()+"_"+wlRecordMain.getEndTime());
|
||||
finalTerminalMap.put("pt",wlRecordMain.getCt().toString());
|
||||
finalTerminalMap.put("ct",wlRecordMain.getPt().toString());
|
||||
|
||||
finalTerminalMap.put("Standard_Capacity",wlRecordMain.getCapacitySi().toString());
|
||||
finalTerminalMap.put("Short_Capacity",wlRecordMain.getCapacitySscmin().toString());
|
||||
finalTerminalMap.put("Deal_Capacity",wlRecordMain.getCapacitySi().toString());
|
||||
finalTerminalMap.put("Dev_Capacity",wlRecordMain.getCapacitySt().toString());
|
||||
}else {
|
||||
finalTerminalMap = commTerminalGeneralClient.getCustomDetailByLineId(reportSearchParam.getLineId()).getData();
|
||||
}
|
||||
}else {
|
||||
finalTerminalMap = new HashMap<>();
|
||||
}
|
||||
|
||||
//2、把itemName的value赋给v和m
|
||||
dealExcelResult(jsonArray, assMap, unit);
|
||||
dealExcelResult(jsonArray, assMap, unit,finalTerminalMap);
|
||||
long jieEnd = System.currentTimeMillis();
|
||||
|
||||
System.out.println("组装信息耗时 " + (jieEnd - jie) / 1000 + "S");
|
||||
}
|
||||
|
||||
|
||||
long daochu = System.currentTimeMillis();
|
||||
//导出自定义报表
|
||||
downReport(jsonArray, response);
|
||||
long daochuEnd = System.currentTimeMillis();
|
||||
System.out.println("导出耗时 " + (daochuEnd - daochu) / 1000 + "S");
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void assSqlZhejiang(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<WlRecord> wlRecordList) {
|
||||
sql, List<ReportTemplateDTO> endList, String method, ReportSearchParam reportSearchParam, Map<String, ReportTemplateDTO> limitMap, Map<String, Float> overLimitMap, Map<String,
|
||||
ReportTemplateDTO> assNoPassMap, List<WlRecord> wlRecordList, Map<String, List<EleEpdPqd>> pqdMap) {
|
||||
|
||||
//sql拼接示例:select MAX(IHA2) as IHA2 from power_quality_data where Phase = 'A' and LineId='1324564568' and Stat_Method='max' tz('Asia/Shanghai')
|
||||
//cp95函数特殊处理 PERCENTILE(field_key, N)
|
||||
if (InfluxDbSqlConstant.PERCENTILE.equals(method)) {
|
||||
@@ -1336,6 +1349,23 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
List<Map<String, Object>> temMapList = influxDbUtils.getMapResult(temSql.toString());
|
||||
if (CollUtil.isNotEmpty(temMapList)) {
|
||||
Map<String, Object> tem = temMapList.get(0);
|
||||
//需要吧测点为二次值的转换为一次值
|
||||
if (wlRecord.getDataLevel().equals("Secondary")) {
|
||||
for (Map.Entry<String, Object> entry : tem.entrySet()) {
|
||||
if (Objects.nonNull(entry.getValue()) && !entry.getKey().equals("time")) {
|
||||
String key = entry.getKey();
|
||||
double val = (double) entry.getValue();
|
||||
String zi = key.substring(0, key.indexOf("#"));
|
||||
if (pqdMap.containsKey(zi)) {
|
||||
EleEpdPqd eleEpdPqd = pqdMap.get(zi).get(0);
|
||||
double vRes = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), val / 1000, (double) wlRecord.getPt(), (double) wlRecord.getCt());
|
||||
entry.setValue(vRes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allList.add(temMapList.get(0));
|
||||
}
|
||||
}
|
||||
@@ -1344,12 +1374,12 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
if (resultMap.isEmpty()) {
|
||||
data = data.stream().peek(item -> item.setValue("/")).collect(Collectors.toList());
|
||||
} else {
|
||||
//遍历模板对查询出来的数据进行赋值
|
||||
for (ReportTemplateDTO item : data) {
|
||||
if (resultMap.containsKey(item.getItemName())) {
|
||||
double v = (Double) resultMap.get(item.getItemName());
|
||||
item.setValue(String.format("%.3f", v));
|
||||
|
||||
|
||||
if (overLimitMap.containsKey(item.getLimitName())) {
|
||||
Float tagVal = overLimitMap.get(item.getLimitName());
|
||||
if (v > tagVal) {
|
||||
@@ -1384,6 +1414,12 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对多测点数据进行计算求出一组数据
|
||||
* @param method
|
||||
* @param allList
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Object> dealResultMap(String method, List<Map<String, Object>> allList) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
// 遍历列表中的每个Map
|
||||
@@ -1450,7 +1486,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
|
||||
private void dealExcelResult(JSONArray
|
||||
jsonArray, Map<String, List<ReportTemplateDTO>> assMap, Map<String, String> unit) {
|
||||
jsonArray, Map<String, List<ReportTemplateDTO>> assMap, Map<String, String> unit,Map<String,String> finalTerminalMap) {
|
||||
jsonArray.forEach(item -> {
|
||||
JSONObject jsonObject = (JSONObject) item;
|
||||
JSONArray itemArr = (JSONArray) jsonObject.get("celldata");
|
||||
@@ -1491,18 +1527,18 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
son.set("fc", "#990000");
|
||||
}
|
||||
}
|
||||
} /*else if (v.charAt(0) == '&') {
|
||||
} else if (v.charAt(0) == '&') {
|
||||
//结论
|
||||
String tem = v.replace("&", "");
|
||||
if (Objects.nonNull(finalTerminalMap)) {
|
||||
if ("statis_time".equals(tem)) {
|
||||
son.set("v", reportSearchParam.getStartTime() + InfluxDbSqlConstant.START_TIME + "_" + reportSearchParam.getEndTime() + InfluxDbSqlConstant.END_TIME);
|
||||
// son.set("v", reportSearchParam.getStartTime() + InfluxDbSqlConstant.START_TIME + "_" + reportSearchParam.getEndTime() + InfluxDbSqlConstant.END_TIME);
|
||||
} else {
|
||||
//台账信息
|
||||
son.set("v", finalTerminalMap.getOrDefault(tem, "/"));
|
||||
}
|
||||
}
|
||||
}*/ else if (v.charAt(0) == '@' && v.contains("#")) {
|
||||
} else if (v.charAt(0) == '@' && v.contains("#")) {
|
||||
//解决数据单位问题 @指标#类型@
|
||||
String replace = v.replace("@", "");
|
||||
son.set("v", unit.getOrDefault(replace, "/"));
|
||||
|
||||
Reference in New Issue
Block a user