自定义报表初步处理
This commit is contained in:
@@ -11,7 +11,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ReportTemplateDTO {
|
||||
/**
|
||||
* $HA[_25]#B#max#classId$
|
||||
* $HA[_25]#B#max#classId#resourceId$
|
||||
*/
|
||||
private String itemName;
|
||||
|
||||
@@ -21,6 +21,11 @@ public class ReportTemplateDTO {
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 对应限值字段
|
||||
*/
|
||||
private String limitName;
|
||||
|
||||
/**
|
||||
* 相别
|
||||
*/
|
||||
@@ -36,6 +41,13 @@ public class ReportTemplateDTO {
|
||||
*/
|
||||
private String classId;
|
||||
|
||||
/**
|
||||
* 对应mysql数据库的表名
|
||||
*/
|
||||
private String resourceId;
|
||||
|
||||
private Integer overLimitFlag;
|
||||
|
||||
/**
|
||||
* 填入的value值
|
||||
*/
|
||||
|
||||
@@ -33,4 +33,6 @@ public class ReportSearchParam {
|
||||
@ApiModelProperty(name = "deptId",value = "部门ID")
|
||||
private String deptId;
|
||||
|
||||
private Integer resourceType = 1;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
|
||||
import lombok.Data;
|
||||
import org.influxdb.annotation.Measurement;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.harmonic.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,12 +13,17 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
public class ReportTreeVO {
|
||||
|
||||
@ApiModelProperty(name = "id",value = "模板索引")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(name = "name",value = "模板字段名")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "showName",value = "模板中文展示名")
|
||||
private String showName;
|
||||
|
||||
@ApiModelProperty(name = "flag",value = "用于标识最底层对象 1.表示已经没有子级")
|
||||
private Integer flag;
|
||||
|
||||
private List<ReportTreeVO> children;
|
||||
|
||||
@@ -235,9 +235,22 @@ public class CustomReportController extends BaseController {
|
||||
public void getCustomReport(@RequestBody ReportSearchParam reportSearchParam, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("getCustomReport");
|
||||
customReportService.getCustomReport(reportSearchParam,response);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取报表指标是否合格模板树
|
||||
* @author cdf
|
||||
* @date 2023/10/11
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/targetLimitChooseTree")
|
||||
@ApiOperation("获取报表指标是否合格模板树")
|
||||
public HttpResult<List<ReportTreeVO>> targetLimitChooseTree(){
|
||||
String methodDescribe = getMethodDescribe("targetLimitChooseTree");
|
||||
List<ReportTreeVO> res = customReportService.targetLimitChooseTree();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,11 +5,16 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.harmonic.pojo.param.ReportSearchParam;
|
||||
import com.njcn.harmonic.pojo.po.ExcelRptTemp;
|
||||
import com.njcn.harmonic.pojo.vo.ReportTemplateVO;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.user.pojo.dto.DeptDTO;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
@@ -24,4 +29,11 @@ public interface ExcelRptTempMapper extends BaseMapper<ExcelRptTemp> {
|
||||
List<ReportTemplateVO> getReportTemplateList(@Param("reportSearchParam")ReportSearchParam reportSearchParam);
|
||||
|
||||
List<ReportTemplateVO> getReportTemplateByDept(@Param("ids") List<String> ids);
|
||||
|
||||
|
||||
@Select("${sqlStr}")
|
||||
StatisticalDataDTO dynamicSql(@Param("sqlStr")String sql);
|
||||
|
||||
@Select("${sqlStr}")
|
||||
Map<String, Float> dynamicSqlMap(@Param("sqlStr")String sql);
|
||||
}
|
||||
|
||||
@@ -47,4 +47,6 @@ public interface RStatOrgMMapper extends BaseMapper<RStatOrgM> {
|
||||
*/
|
||||
List<PwRStatOrgVO> getPwMonthRStatOrgIndex(@Param("param") StatSubstationBizBaseParam param,
|
||||
@Param("dataType") String dataType);
|
||||
|
||||
List<RStatOrgM> getRStatOrgMList();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.njcn.harmonic.pojo.po.ExcelRptTemp;
|
||||
import com.njcn.harmonic.pojo.vo.ReportTemplateVO;
|
||||
import com.njcn.harmonic.pojo.vo.ReportTreeVO;
|
||||
import com.njcn.harmonic.pojo.vo.SysDeptTempVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
@@ -77,6 +79,7 @@ public interface CustomReportService {
|
||||
void getCustomReport(ReportSearchParam reportSearchParam, HttpServletResponse response);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询报告模板树节点
|
||||
* @author cdf
|
||||
@@ -84,6 +87,8 @@ public interface CustomReportService {
|
||||
*/
|
||||
List<ReportTreeVO> reportChooseTree();
|
||||
|
||||
List<ReportTreeVO> targetLimitChooseTree();
|
||||
|
||||
/**
|
||||
* 绑定/解绑模板数据
|
||||
* @author qijian
|
||||
|
||||
@@ -26,6 +26,8 @@ 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;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
@@ -43,15 +45,24 @@ import com.njcn.oss.utils.FileStorageUtil;
|
||||
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.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -82,6 +93,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final DeptLineFeignClient deptLineFeignClient;
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
@Override
|
||||
public boolean addCustomReportTemplate(ReportTemplateParam reportTemplateParam) {
|
||||
checkName(reportTemplateParam, false);
|
||||
@@ -221,22 +235,24 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_ACTIVE);
|
||||
}
|
||||
//先查询库里是否存在已解析的报表数据,存在直接返回/不存在解析数据
|
||||
LambdaQueryWrapper<ExcelRpt> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
/* LambdaQueryWrapper<ExcelRpt> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery
|
||||
.eq(ExcelRpt::getLineId, reportSearchParam.getLineId())
|
||||
.eq(ExcelRpt::getTempId, reportSearchParam.getTempId())
|
||||
//年季月周日
|
||||
.eq(ExcelRpt::getType, reportSearchParam.getType())
|
||||
//报表日期
|
||||
.eq(ExcelRpt::getDataDate, reportSearchParam.getStartTime());
|
||||
.eq(ExcelRpt::getDataDate, reportSearchParam.getStartTime());*/
|
||||
try {
|
||||
List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
|
||||
/* List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
|
||||
if (CollUtil.isNotEmpty(excelRpts)) {
|
||||
fileStorageUtil.downloadStream(response, excelRpts.get(0).getContent());
|
||||
} else {
|
||||
fileStorageUtil.downloadStream(response, analyzeReport(reportSearchParam, excelRptTemp));
|
||||
}
|
||||
} else {*/
|
||||
analyzeReport(reportSearchParam, excelRptTemp, response);
|
||||
/*}*/
|
||||
} catch (Exception exception) {
|
||||
log.error(exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
throw new BusinessException(HarmonicResponseEnum.REPORT_DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
@@ -245,11 +261,11 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
@Override
|
||||
public List<ReportTreeVO> reportChooseTree() {
|
||||
DictData dic = dicDataFeignClient.getDicDataByNameAndTypeName(DicDataTypeEnum.CS_DATA_TYPE.getName(), DicDataEnum.EPD.getName()).getData();
|
||||
LambdaQueryWrapper<EleEpdPqd> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.isNotNull(EleEpdPqd::getOtherName);
|
||||
lambdaQueryWrapper.orderByAsc(EleEpdPqd::getSort);
|
||||
lambdaQueryWrapper.eq(EleEpdPqd::getDataType, dic.getId()).orderByAsc(EleEpdPqd::getSort);
|
||||
List<EleEpdPqd> list = eleEpdMapper.selectList(lambdaQueryWrapper);
|
||||
Map<String, List<EleEpdPqd>> map = list.stream().collect(Collectors.groupingBy(EleEpdPqd::getName));
|
||||
Map<String, List<EleEpdPqd>> map = list.stream().collect(Collectors.groupingBy(EleEpdPqd::getName, LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
List<ReportTreeVO> tree = new ArrayList<>();
|
||||
map.forEach((key, value) -> {
|
||||
@@ -278,6 +294,55 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
return tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportTreeVO> targetLimitChooseTree() {
|
||||
List<ReportTreeVO> result = new ArrayList<>();
|
||||
DictData dic = dicDataFeignClient.getDicDataByCode(DicDataEnum.EPD.getCode()).getData();
|
||||
LambdaQueryWrapper<EleEpdPqd> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(EleEpdPqd::getDataType, dic.getId()).eq(EleEpdPqd::getLimitTable, "pq_overlimit").orderByAsc(EleEpdPqd::getSort);
|
||||
List<EleEpdPqd> list = eleEpdMapper.selectList(lambdaQueryWrapper);
|
||||
Map<String, List<EleEpdPqd>> map = list.stream().collect(Collectors.groupingBy(EleEpdPqd::getLimitName));
|
||||
map.forEach((key, val) -> {
|
||||
ReportTreeVO reportTreeVO = new ReportTreeVO();
|
||||
reportTreeVO.setShowName(val.get(0).getShowName());
|
||||
|
||||
if (Objects.nonNull(val.get(0).getHarmStart()) && Objects.nonNull(val.get(0).getHarmEnd())) {
|
||||
String[] str = val.get(0).getLimitName().split("#");
|
||||
List<ReportTreeVO> temList = new ArrayList<>();
|
||||
for (int i = val.get(0).getHarmStart(); i <= val.get(0).getHarmEnd(); i++) {
|
||||
double count;
|
||||
ReportTreeVO reportTreeItem = new ReportTreeVO();
|
||||
|
||||
if (val.get(0).getHarmStart() == 1) {
|
||||
count = i + 0.5;
|
||||
reportTreeItem.setShowName(count + "次" + val.get(0).getShowName());
|
||||
reportTreeItem.setName(str[0] + count + "#" + str[1] + count + "#" + val.get(0).getLimitTable());
|
||||
} else {
|
||||
reportTreeItem.setShowName(i + "次" + val.get(0).getShowName());
|
||||
reportTreeItem.setName(str[0] + i + "#" + str[1] + i + "#" + val.get(0).getLimitTable());
|
||||
}
|
||||
|
||||
reportTreeItem.setFlag(1);
|
||||
temList.add(reportTreeItem);
|
||||
}
|
||||
reportTreeVO.setChildren(temList);
|
||||
} else {
|
||||
reportTreeVO.setName(val.get(0).getLimitName() + "#" + val.get(0).getFormula());
|
||||
reportTreeVO.setFlag(1);
|
||||
}
|
||||
|
||||
result.add(reportTreeVO);
|
||||
});
|
||||
/*list.forEach(item->{
|
||||
ReportTreeVO reportTreeVO = new ReportTreeVO();
|
||||
reportTreeVO.setId(item.getId());
|
||||
reportTreeVO.setName(item.getName());
|
||||
reportTreeVO.setShowName(item.getShowName());
|
||||
result.add(reportTreeVO);
|
||||
});*/
|
||||
return result;
|
||||
}
|
||||
|
||||
/*组装相别*/
|
||||
private void assPhase(List<EleEpdPqd> value, ReportTreeVO reportTreeItem, String key) {
|
||||
List<ReportTreeVO> phaseTree = new ArrayList<>();
|
||||
@@ -311,10 +376,16 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
if (CollUtil.isNotEmpty(stat)) {
|
||||
stat.forEach(statItem -> {
|
||||
ReportTreeVO reportTreeStat = new ReportTreeVO();
|
||||
if (StrUtil.isNotBlank(twoKey)) {
|
||||
reportTreeStat.setName("$" + oneKey + "#" + twoKey + "#" + statItem + "#" + item.getClassId().trim() + "$");
|
||||
String tem = "";
|
||||
if (Objects.nonNull(item.getLimitName())) {
|
||||
tem = "#" + item.getLimitName();
|
||||
} else {
|
||||
reportTreeStat.setName("$" + oneKey + "#" + statItem + "#" + item.getClassId().trim() + "$");
|
||||
tem = "#NO";
|
||||
}
|
||||
if (StrUtil.isNotBlank(twoKey)) {
|
||||
reportTreeStat.setName("$" + oneKey + "#" + twoKey + "#" + statItem + "#" + item.getClassId().trim() + tem.trim() + "$");
|
||||
} else {
|
||||
reportTreeStat.setName("$" + oneKey + "#" + statItem + "#" + item.getClassId().trim() + tem.trim() + "$");
|
||||
}
|
||||
|
||||
reportTreeStat.setShowName(statItem);
|
||||
@@ -355,7 +426,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
/**
|
||||
* 解析报表模板赋值数据
|
||||
*/
|
||||
private String analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp) {
|
||||
/* private void analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp,HttpServletResponse response) {
|
||||
//根据content,获取v值并进行处理
|
||||
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
|
||||
JSONArray jsonArray;
|
||||
@@ -453,11 +524,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
//解决数据单位问题 @指标#类型@
|
||||
if (v.charAt(0) == '@' && v.contains("#")) {
|
||||
String replace = v.replace("@", "");
|
||||
if (unit.containsKey(replace)) {
|
||||
son.set("v", unit.get(replace));
|
||||
} else {
|
||||
son.set("v", "/");
|
||||
}
|
||||
son.set("v", unit.getOrDefault(replace, "/"));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -469,6 +536,8 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
InputStream reportStream = IoUtil.toStream(jsonArray.toString(), CharsetUtil.UTF_8);
|
||||
String newContent = fileStorageUtil.uploadStream(reportStream, OssPath.HARMONIC_EXCEL_REPORT, FileUtil.generateFileName("json"));
|
||||
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename="+"aa");
|
||||
//入库前判断是否有了,有了就更新
|
||||
ExcelRpt excelRpt = new ExcelRpt();
|
||||
excelRpt.setName(excelRptTemp.getName());
|
||||
@@ -480,10 +549,22 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
excelRpt.setState(DataStateEnum.ENABLE.getCode());
|
||||
|
||||
excelRptMapper.insert(excelRpt);
|
||||
|
||||
return newContent;
|
||||
OutputStream toClient = null;
|
||||
try {
|
||||
toClient = new BufferedOutputStream(response.getOutputStream());
|
||||
//通过IOUtils对接输入输出流,实现文件下载
|
||||
IOUtils.copy(reportStream, toClient);
|
||||
toClient.flush();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reportStream);
|
||||
IOUtils.closeQuietly(toClient);
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* 数据单位信息
|
||||
*
|
||||
@@ -564,9 +645,16 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
.append(InfluxDbSqlConstant.RBK)
|
||||
.append(InfluxDbSqlConstant.AS_VALUE);
|
||||
}
|
||||
|
||||
if (reportSearchParam.getResourceType() == 1) {
|
||||
sql.append(InfluxDbSqlConstant.FROM)
|
||||
.append(data.getClassId())
|
||||
.append(InfluxDbSqlConstant.WHERE)
|
||||
.append(data.getClassId().replace("data", "day"));
|
||||
} else {
|
||||
sql.append(InfluxDbSqlConstant.FROM)
|
||||
.append(data.getClassId());
|
||||
}
|
||||
|
||||
sql.append(InfluxDbSqlConstant.WHERE)
|
||||
.append(InfluxDBTableConstant.LINE_ID)
|
||||
.append(InfluxDbSqlConstant.EQ)
|
||||
.append(InfluxDbSqlConstant.QM)
|
||||
@@ -609,6 +697,8 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
.append(InfluxDbSqlConstant.AND)
|
||||
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.LT).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getEndTime()).append(InfluxDbSqlConstant.END_TIME).append(InfluxDbSqlConstant.QM);
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
sql.append(InfluxDbSqlConstant.TZ);
|
||||
|
||||
if (data.getTemplateName().equals("freq_dev") || data.getTemplateName().equals("freq")) {
|
||||
@@ -616,16 +706,499 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
}
|
||||
|
||||
|
||||
//根据不同的库表赋值
|
||||
StatisticalDataDTO statisticalDataDTO = commonService.selectBySql(sql);
|
||||
//根据不同的库表赋值
|
||||
if (Objects.isNull(statisticalDataDTO)) {
|
||||
data.setValue("/");
|
||||
} else {
|
||||
|
||||
data.setValue(String.format("%.3f", statisticalDataDTO.getValue()));
|
||||
}
|
||||
endList.add(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param data 同类型的cell模板
|
||||
* @param sql 单个cell模板
|
||||
* @param endList 用于返回最终组装好的数据,类似data
|
||||
* @param limitMap 指标是否合格模板
|
||||
* @param assNoPassMap 用于存储不合格的指标
|
||||
*
|
||||
* @date 2023/10/20
|
||||
*/
|
||||
private void assSqlNew(List<ReportTemplateDTO> data, StringBuilder sql, List<ReportTemplateDTO> endList, String method, ReportSearchParam reportSearchParam, Map<String, ReportTemplateDTO> limitMap,Map<String, Float> overLimitMap, Map<String, ReportTemplateDTO> assNoPassMap) {
|
||||
//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)) {
|
||||
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
if (i == data.size() - 1) {
|
||||
sql.append(method)
|
||||
.append(InfluxDbSqlConstant.LBK)
|
||||
.append(data.get(i).getTemplateName())
|
||||
.append(InfluxDbSqlConstant.NUM_95)
|
||||
.append(InfluxDbSqlConstant.RBK)
|
||||
.append(" as \"")
|
||||
.append(data.get(i).getItemName()).append("\" ");
|
||||
} else {
|
||||
sql.append(method)
|
||||
.append(InfluxDbSqlConstant.LBK)
|
||||
.append(data.get(i).getTemplateName())
|
||||
.append(InfluxDbSqlConstant.NUM_95)
|
||||
.append(InfluxDbSqlConstant.RBK)
|
||||
.append(" as \"")
|
||||
.append(data.get(i).getItemName()).append("\"").append(StrUtil.COMMA);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
if (i == data.size() - 1) {
|
||||
sql.append(method)
|
||||
.append(InfluxDbSqlConstant.LBK)
|
||||
.append(data.get(i).getTemplateName())
|
||||
.append(InfluxDbSqlConstant.RBK)
|
||||
.append(" as \"")
|
||||
.append(data.get(i).getItemName()).append("\" ");
|
||||
} else {
|
||||
sql.append(method)
|
||||
.append(InfluxDbSqlConstant.LBK)
|
||||
.append(data.get(i).getTemplateName())
|
||||
.append(InfluxDbSqlConstant.RBK)
|
||||
.append(" as \"")
|
||||
.append(data.get(i).getItemName()).append("\"").append(StrUtil.COMMA);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (reportSearchParam.getResourceType() == 1) {
|
||||
sql.append(InfluxDbSqlConstant.FROM)
|
||||
.append(data.get(0).getClassId().replace("data", "day"));
|
||||
} else {
|
||||
sql.append(InfluxDbSqlConstant.FROM)
|
||||
.append(data.get(0).getClassId());
|
||||
}
|
||||
|
||||
sql.append(InfluxDbSqlConstant.WHERE)
|
||||
.append(InfluxDBTableConstant.LINE_ID)
|
||||
.append(InfluxDbSqlConstant.EQ)
|
||||
.append(InfluxDbSqlConstant.QM)
|
||||
.append(reportSearchParam.getLineId())
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
//相别特殊处理
|
||||
if (!InfluxDBTableConstant.NO_PHASE.equals(data.get(0).getPhase())) {
|
||||
sql.append(InfluxDbSqlConstant.AND)
|
||||
.append(InfluxDBTableConstant.PHASIC_TYPE)
|
||||
.append(InfluxDbSqlConstant.EQ)
|
||||
.append(InfluxDbSqlConstant.QM)
|
||||
.append(data.get(0).getPhase())
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
}
|
||||
|
||||
|
||||
//data_flicker、data_fluc、data_plt 无 value_type
|
||||
if (!InfluxDBTableConstant.DATA_FLICKER.equals(data.get(0).getClassId()) && !InfluxDBTableConstant.DATA_FLUC.equals(data.get(0).getClassId()) && !InfluxDBTableConstant.DATA_PLT.equals(data.get(0).getClassId())) {
|
||||
sql.append(InfluxDbSqlConstant.AND)
|
||||
.append(InfluxDBTableConstant.VALUE_TYPE)
|
||||
.append(InfluxDbSqlConstant.EQ)
|
||||
.append(InfluxDbSqlConstant.QM)
|
||||
.append(data.get(0).getStatMethod())
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
}
|
||||
|
||||
//频率和频率偏差仅统计T相
|
||||
if (data.get(0).getTemplateName().equals("freq_dev") || data.get(0).getTemplateName().equals("freq")) {
|
||||
sql.append(InfluxDbSqlConstant.AND)
|
||||
.append(InfluxDBTableConstant.PHASIC_TYPE)
|
||||
.append(InfluxDbSqlConstant.EQ)
|
||||
.append(InfluxDbSqlConstant.QM)
|
||||
.append(InfluxDBTableConstant.PHASE_TYPE_T)
|
||||
.append(InfluxDbSqlConstant.QM);
|
||||
}
|
||||
//时间范围处理
|
||||
sql
|
||||
.append(InfluxDbSqlConstant.AND)
|
||||
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.GE).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getStartTime()).append(InfluxDbSqlConstant.START_TIME).append(InfluxDbSqlConstant.QM)
|
||||
.append(InfluxDbSqlConstant.AND)
|
||||
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.LT).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getEndTime()).append(InfluxDbSqlConstant.END_TIME).append(InfluxDbSqlConstant.QM);
|
||||
|
||||
System.out.println(sql);
|
||||
|
||||
sql.append(InfluxDbSqlConstant.TZ);
|
||||
|
||||
if (data.get(0).getTemplateName().equals("freq_dev") || data.get(0).getTemplateName().equals("freq")) {
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
||||
|
||||
List<Map<String, Object>> mapList = influxDbUtils.getMapResult(sql.toString());
|
||||
if (CollUtil.isEmpty(mapList)) {
|
||||
data = data.stream().peek(item -> item.setValue("/")).collect(Collectors.toList());
|
||||
} else {
|
||||
Map<String, Object> map = mapList.get(0);
|
||||
|
||||
for (ReportTemplateDTO item : data) {
|
||||
if (map.containsKey(item.getItemName())) {
|
||||
double v = (Double) map.get(item.getItemName());
|
||||
item.setValue(String.format("%.3f", v));
|
||||
|
||||
if(overLimitMap.containsKey(item.getLimitName())){
|
||||
Float tagVal = overLimitMap.get(item.getLimitName());
|
||||
if (v > tagVal) {
|
||||
item.setOverLimitFlag(1);
|
||||
}else {
|
||||
item.setOverLimitFlag(0);
|
||||
}
|
||||
}
|
||||
|
||||
//判断是否越限
|
||||
String key = item.getLimitName() + "#" + item.getStatMethod().toLowerCase() + "#pq_overlimit";
|
||||
if (limitMap.containsKey(key)) {
|
||||
ReportTemplateDTO tem = limitMap.get(key);
|
||||
double limitVal = Double.parseDouble(tem.getValue());
|
||||
if (v > limitVal) {
|
||||
tem.setOverLimitFlag(1);
|
||||
assNoPassMap.put(key, tem);
|
||||
} else if (!assNoPassMap.containsKey(key)) {
|
||||
tem.setOverLimitFlag(0);
|
||||
assNoPassMap.put(key, tem);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
item.setValue("/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
endList.addAll(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2023/10/8
|
||||
*/
|
||||
|
||||
private void analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp, HttpServletResponse response) {
|
||||
|
||||
long begin = System.currentTimeMillis();
|
||||
|
||||
//根据content,获取v值并进行处理
|
||||
//指标
|
||||
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
|
||||
//限值
|
||||
List<ReportTemplateDTO> reportLimitList = new ArrayList<>();
|
||||
JSONArray jsonArray;
|
||||
try (InputStream fileStream = fileStorageUtil.getFileStream(excelRptTemp.getContent())) {
|
||||
jsonArray = new JSONArray(new JSONTokener(fileStream, new JSONConfig()));
|
||||
pareTemplate(jsonArray,fileStream,excelRptTemp.getContent(),reportTemplateDTOList,reportLimitList);
|
||||
}catch (Exception e){
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}
|
||||
//处理查日表还是分钟表
|
||||
rangeDate(reportSearchParam);
|
||||
|
||||
long temEnd = System.currentTimeMillis();
|
||||
|
||||
//存放限值的map
|
||||
Map<String, Float> limitMap = new HashMap<>();
|
||||
|
||||
//存放限值指标的map
|
||||
Map<String, ReportTemplateDTO> limitTargetMapX = new HashMap<>();
|
||||
//处理指标是否合格
|
||||
if (CollUtil.isNotEmpty(reportLimitList)) {
|
||||
|
||||
StringBuilder sql = new StringBuilder("select ");
|
||||
for (int i = 0; i < reportLimitList.size(); i++) {
|
||||
if (i == reportLimitList.size() - 1) {
|
||||
sql.append(reportLimitList.get(i).getTemplateName());
|
||||
} else {
|
||||
sql.append(reportLimitList.get(i).getTemplateName()).append(",");
|
||||
}
|
||||
}
|
||||
|
||||
sql.append(" from ").append(reportLimitList.get(0).getClassId()).append(" where id ='").append(reportSearchParam.getLineId()).append("'");
|
||||
limitMap = excelRptTempMapper.dynamicSqlMap(sql.toString());
|
||||
|
||||
for (ReportTemplateDTO item : reportLimitList) {
|
||||
if (limitMap.containsKey(item.getTemplateName())) {
|
||||
item.setValue(limitMap.get(item.getTemplateName()).toString());
|
||||
}
|
||||
}
|
||||
limitTargetMapX = reportLimitList.stream().collect(Collectors.toMap(ReportTemplateDTO::getItemName, Function.identity()));
|
||||
}
|
||||
|
||||
List<ReportTemplateDTO> endList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(reportTemplateDTOList)) {
|
||||
long deal = System.currentTimeMillis();
|
||||
|
||||
|
||||
Map<String, ReportTemplateDTO> finalLimitMapX = limitTargetMapX;
|
||||
Map<String, Float> overLimitMap = limitMap;
|
||||
|
||||
//开始组织sql
|
||||
Map<String, List<ReportTemplateDTO>> classMap = reportTemplateDTOList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getClassId));
|
||||
Map<String, ReportTemplateDTO> assNoPassMap = new HashMap<>();
|
||||
classMap.forEach((classKey, templateValue) -> {
|
||||
Map<String, List<ReportTemplateDTO>> valueTypeMap = templateValue.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getStatMethod));
|
||||
|
||||
//avg.max,min,cp95
|
||||
valueTypeMap.forEach((valueTypeKey, valueTypeVal) -> {
|
||||
|
||||
//相别分组
|
||||
Map<String, List<ReportTemplateDTO>> phaseMap = valueTypeVal.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getPhase));
|
||||
phaseMap.forEach((phaseKey, phaseVal) -> {
|
||||
|
||||
StringBuilder sql = new StringBuilder(InfluxDbSqlConstant.SELECT);
|
||||
if (InfluxDbSqlConstant.MAX.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlNew(phaseVal, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam, finalLimitMapX,overLimitMap, assNoPassMap);
|
||||
} else if (InfluxDbSqlConstant.MIN.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlNew(phaseVal, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam, finalLimitMapX,overLimitMap, assNoPassMap);
|
||||
} else if (InfluxDbSqlConstant.AVG_WEB.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlNew(phaseVal, sql, endList, InfluxDbSqlConstant.AVG, reportSearchParam, finalLimitMapX,overLimitMap, assNoPassMap);
|
||||
} else if (InfluxDbSqlConstant.CP95.equalsIgnoreCase(valueTypeKey)) {
|
||||
assSqlNew(phaseVal, sql, endList, InfluxDbSqlConstant.PERCENTILE, reportSearchParam, finalLimitMapX,overLimitMap, assNoPassMap);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
assNoPassMap.forEach((key, val) -> {
|
||||
finalLimitMapX.remove(key);
|
||||
if (val.getOverLimitFlag() == 1) {
|
||||
val.setValue("不合格");
|
||||
} else {
|
||||
val.setValue("合格");
|
||||
}
|
||||
|
||||
endList.add(val);
|
||||
});
|
||||
|
||||
finalLimitMapX.forEach((key, val) -> {
|
||||
if (Objects.isNull(val.getOverLimitFlag())) {
|
||||
val.setValue("/");
|
||||
} else {
|
||||
val.setValue("合格");
|
||||
}
|
||||
endList.add(val);
|
||||
});
|
||||
|
||||
long dealEnd = System.currentTimeMillis();
|
||||
System.out.println("模板解析时间:" + (temEnd - begin) / 1000 + "S");
|
||||
System.out.println("查询数据库花费时间" + (dealEnd - deal) / 1000 + "S");
|
||||
}
|
||||
|
||||
if (CollUtil.isNotEmpty(endList)) {
|
||||
long jie = System.currentTimeMillis();
|
||||
//数据单位信息
|
||||
Map<String, String> unit = unitMap(reportSearchParam.getLineId());
|
||||
//进行反向赋值到模板
|
||||
//1、根据itemName分组
|
||||
Map<String, List<ReportTemplateDTO>> assMap = endList.stream().collect(Collectors.groupingBy(ReportTemplateDTO::getItemName));
|
||||
//2、把itemName的value赋给v和m
|
||||
jsonArray.forEach(item -> {
|
||||
JSONObject jsonObject = (JSONObject) item;
|
||||
JSONArray itemArr = (JSONArray) jsonObject.get("celldata");
|
||||
itemArr.forEach((it) -> {
|
||||
if (Objects.nonNull(it) && !"null".equals(it.toString())) {
|
||||
//获取到1列
|
||||
JSONObject data = (JSONObject) it;
|
||||
JSONObject son = (JSONObject) data.get("v");
|
||||
if (son.containsKey("v")) {
|
||||
String v = son.getStr("v");
|
||||
//数据格式:$HA[_25]#B#max#classId$ 或 $HA[_25]#max#classId$
|
||||
if (v.charAt(0) == '$' && v.contains("#")) {
|
||||
String str = "";
|
||||
List<ReportTemplateDTO> rDto = assMap.get(v.replace("$", ""));
|
||||
if (Objects.nonNull(rDto)) {
|
||||
str = rDto.get(0).getValue();
|
||||
//没有值,赋"/"
|
||||
if (StringUtils.isBlank(str)) {
|
||||
str = "/";
|
||||
}
|
||||
son.set("v", str);
|
||||
if (Objects.nonNull(rDto.get(0).getOverLimitFlag()) && rDto.get(0).getOverLimitFlag() == 1) {
|
||||
son.set("fc", "#990000");
|
||||
}
|
||||
}
|
||||
} else if (v.charAt(0) == '%' && v.contains("#")) {
|
||||
//指标合格情况
|
||||
String str = "";
|
||||
List<ReportTemplateDTO> rDto = assMap.get(v.replace("%", ""));
|
||||
if (Objects.nonNull(rDto)) {
|
||||
str = rDto.get(0).getValue();
|
||||
//没有值,赋"/"
|
||||
if (StringUtils.isBlank(str)) {
|
||||
str = "/";
|
||||
}
|
||||
son.set("v", str);
|
||||
if ("不合格".equals(str)) {
|
||||
son.set("fc", "#990000");
|
||||
}
|
||||
}
|
||||
}
|
||||
//解决数据单位问题 @指标#类型@
|
||||
if (v.charAt(0) == '@' && v.contains("#")) {
|
||||
String replace = v.replace("@", "");
|
||||
son.set("v", unit.getOrDefault(replace, "/"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
long jieEnd = System.currentTimeMillis();
|
||||
|
||||
System.out.println("组装信息耗时 " + (jieEnd - jie) / 1000 + "S");
|
||||
}
|
||||
|
||||
|
||||
long daochu = System.currentTimeMillis();
|
||||
|
||||
InputStream reportStream = IoUtil.toStream(jsonArray.toString(), CharsetUtil.UTF_8);
|
||||
//String newContent = fileStorageUtil.uploadStream(reportStream, OssPath.HARMONIC_EXCEL_REPORT, FileUtil.generateFileName("json"));
|
||||
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + "aa");
|
||||
//入库前判断是否有了,有了就更新
|
||||
/* ExcelRpt excelRpt = new ExcelRpt();
|
||||
excelRpt.setName(excelRptTemp.getName());
|
||||
excelRpt.setLineId(reportSearchParam.getLineId());
|
||||
excelRpt.setDataDate(DateUtil.parse(reportSearchParam.getStartTime()));
|
||||
excelRpt.setTempId(excelRptTemp.getId());
|
||||
excelRpt.setContent(newContent);
|
||||
excelRpt.setType(reportSearchParam.getType());
|
||||
excelRpt.setState(DataStateEnum.ENABLE.getCode());
|
||||
|
||||
excelRptMapper.insert(excelRpt);*/
|
||||
OutputStream toClient = null;
|
||||
try {
|
||||
toClient = new BufferedOutputStream(response.getOutputStream());
|
||||
//通过IOUtils对接输入输出流,实现文件下载
|
||||
IOUtils.copy(reportStream, toClient);
|
||||
toClient.flush();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reportStream);
|
||||
IOUtils.closeQuietly(toClient);
|
||||
long daochuEnd = System.currentTimeMillis();
|
||||
|
||||
System.out.println("导出耗时 " + (daochuEnd - daochu) / 1000 + "S");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析模板
|
||||
* @author cdf
|
||||
* @date 2023/10/20
|
||||
*/
|
||||
private void pareTemplate(JSONArray jsonArray,InputStream fileStream,String content,List<ReportTemplateDTO> reportTemplateDTOList,List<ReportTemplateDTO> reportLimitList){
|
||||
try {
|
||||
//通过文件服务器获取
|
||||
|
||||
jsonArray.forEach(item -> {
|
||||
JSONObject jsonObject = (JSONObject) item;
|
||||
JSONArray itemArr = (JSONArray) jsonObject.get("celldata");
|
||||
itemArr.forEach((it) -> {
|
||||
if (Objects.nonNull(it) && !"null".equals(it.toString())) {
|
||||
//获取到1列
|
||||
JSONObject data = (JSONObject) it;
|
||||
JSONObject son = (JSONObject) data.get("v");
|
||||
if (son.containsKey("v")) {
|
||||
String v = son.getStr("v");
|
||||
//数据格式:$HA[_25]#B#max#classId$ 或 $HA[_25]#max#classId$
|
||||
if (v.charAt(0) == '$' && v.contains("#")) {
|
||||
//剔除前后$
|
||||
v = v.replace("$", "");
|
||||
//封装ReportTemplateDTO
|
||||
ReportTemplateDTO reportTemplateDTO = new ReportTemplateDTO();
|
||||
reportTemplateDTO.setItemName(v);
|
||||
//根据#分割数据
|
||||
String[] vItem = v.split("#");
|
||||
if (vItem.length == 5) {
|
||||
//$HA[_25]#B#max#classId$
|
||||
reportTemplateDTO.setTemplateName(vItem[0]);
|
||||
reportTemplateDTO.setPhase(vItem[1].substring(0, 1));
|
||||
reportTemplateDTO.setStatMethod(vItem[2].toUpperCase());
|
||||
reportTemplateDTO.setClassId(vItem[3]);
|
||||
reportTemplateDTO.setLimitName(vItem[4]);
|
||||
} else if (vItem.length == 4) {
|
||||
//$HA[_25]#max#classId$
|
||||
reportTemplateDTO.setTemplateName(vItem[0]);
|
||||
reportTemplateDTO.setPhase("M");
|
||||
reportTemplateDTO.setStatMethod(vItem[1].toUpperCase());
|
||||
reportTemplateDTO.setClassId(vItem[2]);
|
||||
reportTemplateDTO.setLimitName(vItem[3]);
|
||||
}
|
||||
|
||||
reportTemplateDTOList.add(reportTemplateDTO);
|
||||
} else if (v.charAt(0) == '%' && v.contains("#")) {
|
||||
//封装ReportTemplateDTO
|
||||
ReportTemplateDTO reportTemplateDTO = new ReportTemplateDTO();
|
||||
|
||||
v = v.replace("%", "");
|
||||
reportTemplateDTO.setItemName(v);
|
||||
//根据#分割数据
|
||||
String[] vItem = v.split("#");
|
||||
if (vItem.length == 3) {
|
||||
//$HA[_25]#B#max#classId$
|
||||
reportTemplateDTO.setTemplateName(vItem[0]);
|
||||
reportTemplateDTO.setStatMethod(vItem[1].toUpperCase());
|
||||
reportTemplateDTO.setClassId(vItem[2]);
|
||||
}
|
||||
reportLimitList.add(reportTemplateDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两个时间之间的天数
|
||||
* @author cdf
|
||||
* @date 2023/10/20
|
||||
*/
|
||||
private void rangeDate(ReportSearchParam reportSearchParam){
|
||||
long a;
|
||||
DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
//开始时间
|
||||
Date star = dft.parse(reportSearchParam.getStartTime());
|
||||
//结束时间
|
||||
Date endDay = dft.parse(reportSearchParam.getEndTime());
|
||||
Long starTimes = star.getTime();
|
||||
Long endTimes = endDay.getTime();
|
||||
long num = endTimes - starTimes;//时间戳相差的毫秒数
|
||||
a = num / 24 / 60 / 60 / 1000;
|
||||
if (a > 5) {
|
||||
//返回天表
|
||||
reportSearchParam.setResourceType(1);
|
||||
} else {
|
||||
//返回分钟
|
||||
reportSearchParam.setResourceType(0);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new BusinessException("时间解析出错!"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,19 +39,19 @@ public class LineParam {
|
||||
* 标识从那个库里查询数据
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiModelProperty(name = "dataSource",value = "数据源(0:oracle,1:influxdb 2:mysql)")
|
||||
@ApiModelProperty(name = "dataSource",value = "数据源(0:oracle,1:influxdb 2:mysql)",hidden = true)
|
||||
private Integer dataSource;
|
||||
|
||||
/**
|
||||
* 调度任务开始时间
|
||||
*/
|
||||
@NotBlank(message = "调度任务开始时间不可为空")
|
||||
@NotBlank(message = "调度任务开始时间不可为空 yyyy-MM-dd hh:mm:ss")
|
||||
private String beginTime;
|
||||
|
||||
/**
|
||||
* 调度任务结束时间
|
||||
*/
|
||||
@NotBlank(message = "调度任务结束时间不可为空")
|
||||
@NotBlank(message = "调度任务结束时间不可为空 yyyy-MM-dd hh:mm:ss")
|
||||
private String endTime;
|
||||
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ public class DayDataController extends BaseController {
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
@ApiOperation("day表定时任务(MySQL库)")
|
||||
@ApiImplicitParam(value = "jobParam",name = "jobParam",required = true)
|
||||
@PostMapping("dataToDay")
|
||||
@@ -97,10 +98,10 @@ public class DayDataController extends BaseController {
|
||||
log.info(item+"-->开始执行");
|
||||
startTime = item+" "+"00:00:00";
|
||||
endTime = item+" "+"23:59:59";
|
||||
dayDataService.dataToDayHandler(indexLists,startTime,endTime);
|
||||
dayDataService.dataToDayHandler(indexLists,startTime,endTime,2);
|
||||
}
|
||||
} else {
|
||||
dayDataService.dataToDayHandler(indexLists,jobParam.getBeginTime(),jobParam.getEndTime());
|
||||
dayDataService.dataToDayHandler(indexLists,jobParam.getBeginTime(),jobParam.getEndTime(),2);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ package com.njcn.prepare.harmonic.service.mysql.Impl.line;
|
||||
import com.njcn.harmonic.pojo.po.*;
|
||||
import com.njcn.harmonic.pojo.po.day.*;
|
||||
import com.njcn.influx.deprecated.InfluxDBPublicParam;
|
||||
import com.njcn.influx.imapper.*;
|
||||
import com.njcn.influx.imapper.day.*;
|
||||
import com.njcn.influx.pojo.po.*;
|
||||
import com.njcn.influx.pojo.po.day.*;
|
||||
import com.njcn.influx.service.*;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import com.njcn.prepare.harmonic.constant.InfluxdbPOConverter;
|
||||
import com.njcn.prepare.harmonic.pojo.mysql.po.line.RMpFlickerReportDPO;
|
||||
@@ -27,6 +31,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
@@ -79,6 +84,24 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
|
||||
private final DayVMapper dayVMapper;
|
||||
private final DayIMapper dayIMapper;
|
||||
private final DayFlickerMapper dayFlickerMapper;
|
||||
private final DayFlucMapper dayFlucMapper;
|
||||
private final DayHarmPhasicIMapper dayHarmPhasicIMapper;
|
||||
private final DayHarmRateVMapper dayHarmRateVMapper;
|
||||
private final DayHarmRateIMapper dayHarmRateIMapper;
|
||||
|
||||
private final DayHarmPowerPMapper dayHarmPowerPMapper;
|
||||
private final DayHarmPhasicVMapper dayHarmPhasicVMapper;
|
||||
private final DayHarmPowerQMapper dayHarmPowerQMapper;
|
||||
private final DayHarmPowerSMapper dayHarmPowerSMapper;
|
||||
private final DayInHarmVRateMapper dayInHarmVRateMapper;
|
||||
private final DayInHarmIRateMapper dayInHarmIRateMapper;
|
||||
private final DayPltMapper dayPltMapper;
|
||||
|
||||
|
||||
/**
|
||||
* @param indexLists
|
||||
* @param startTime
|
||||
@@ -538,7 +561,7 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@Async("asyncExecutor")
|
||||
public void dataToDayHandler(List<String> indexLists, String startTime, String endTime) {
|
||||
public void dataToDayHandler(List<String> indexLists, String startTime, String endTime, Integer calType) {
|
||||
log.info(LocalDateTime.now() + "data表转day开始=====》");
|
||||
Date time = null;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
@@ -563,8 +586,25 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
List<RStatDataPltDPO> dataPltPOList = new ArrayList<>();
|
||||
|
||||
|
||||
List<DayV> dayVList = new ArrayList<>();
|
||||
List<DayI> dayIList = new ArrayList<>();
|
||||
List<DayFlicker> dayFlickerList = new ArrayList<>();
|
||||
List<DayFluc> dayFlucList = new ArrayList<>();
|
||||
List<DayHarmPhasicI> dayHarmPhasicIList = new ArrayList<>();
|
||||
List<DayHarmPhasicV> dayHarmPhasicVList = new ArrayList<>();
|
||||
List<DayHarmPowerP> dayHarmPowerPList = new ArrayList<>();
|
||||
List<DayHarmPowerS> dayHarmPowerSList = new ArrayList<>();
|
||||
List<DayHarmPowerQ> dayHarmPowerQList = new ArrayList<>();
|
||||
List<DayHarmRateV> dayHarmRateVList = new ArrayList<>();
|
||||
List<DayHarmRateI> dayHarmRateIList = new ArrayList<>();
|
||||
List<DayInHarmI> dayInHarmIList = new ArrayList<>();
|
||||
List<DayInHarmV> dayInHarmVList = new ArrayList<>();
|
||||
List<DayPlt> dayPltList = new ArrayList<>();
|
||||
|
||||
|
||||
for (String lineIndex : indexLists) {
|
||||
|
||||
|
||||
/*生成dayV表*/
|
||||
List<DataV> dataV = getDataV(lineIndex, startTime, endTime);
|
||||
if (!CollectionUtils.isEmpty(dataV)) {
|
||||
@@ -574,7 +614,14 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataVPOList.add(po1);
|
||||
|
||||
DayV dayV = new DayV();
|
||||
BeanUtils.copyProperties(item, dayV);
|
||||
dayVList.add(dayV);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*生成dayI表*/
|
||||
List<DataI> dataI = getDataI(lineIndex, startTime, endTime);
|
||||
@@ -585,6 +632,11 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataIPOList.add(po1);
|
||||
|
||||
|
||||
DayI dayI = new DayI();
|
||||
BeanUtils.copyProperties(item, dayI);
|
||||
dayIList.add(dayI);
|
||||
}
|
||||
}
|
||||
/*生成dayFlicker表*/
|
||||
@@ -596,6 +648,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataFlickerPOList.add(po1);
|
||||
|
||||
DayFlicker dayFlicker = new DayFlicker();
|
||||
BeanUtils.copyProperties(item, dayFlicker);
|
||||
dayFlickerList.add(dayFlicker);
|
||||
}
|
||||
}
|
||||
/*生成dayFluc表*/
|
||||
@@ -607,6 +663,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataFlucPOList.add(po1);
|
||||
|
||||
DayFluc dayFluc = new DayFluc();
|
||||
BeanUtils.copyProperties(item, dayFluc);
|
||||
dayFlucList.add(dayFluc);
|
||||
}
|
||||
}
|
||||
/*生成dayHarmphasicI表*/
|
||||
@@ -618,6 +678,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataHarmPhasicIPOList.add(po1);
|
||||
|
||||
DayHarmPhasicI dayHarmPhasicI = new DayHarmPhasicI();
|
||||
BeanUtils.copyProperties(item, dayHarmPhasicI);
|
||||
dayHarmPhasicIList.add(dayHarmPhasicI);
|
||||
}
|
||||
}
|
||||
/*生成dayHarmphasicV表*/
|
||||
@@ -629,6 +693,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataHarmPhasicVPOList.add(po1);
|
||||
|
||||
DayHarmPhasicV dayHarmPhasicV = new DayHarmPhasicV();
|
||||
BeanUtils.copyProperties(item, dayHarmPhasicV);
|
||||
dayHarmPhasicVList.add(dayHarmPhasicV);
|
||||
}
|
||||
}
|
||||
/*生成dayHarmPowerP表*/
|
||||
@@ -640,6 +708,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataHarmPowerPPOList.add(po1);
|
||||
|
||||
DayHarmPowerP dayHarmPowerP = new DayHarmPowerP();
|
||||
BeanUtils.copyProperties(item, dayHarmPowerP);
|
||||
dayHarmPowerPList.add(dayHarmPowerP);
|
||||
}
|
||||
}
|
||||
/*生成dayHarmPowerQ表*/
|
||||
@@ -651,6 +723,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataHarmPowerQPOList.add(po1);
|
||||
|
||||
DayHarmPowerQ dayHarmPowerQ = new DayHarmPowerQ();
|
||||
BeanUtils.copyProperties(item, dayHarmPowerQ);
|
||||
dayHarmPowerQList.add(dayHarmPowerQ);
|
||||
}
|
||||
}
|
||||
/*生成dayHarmPowerS表*/
|
||||
@@ -662,6 +738,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataHarmPowerSPOList.add(po1);
|
||||
|
||||
DayHarmPowerS dayHarmPowerS = new DayHarmPowerS();
|
||||
BeanUtils.copyProperties(item, dayHarmPowerS);
|
||||
dayHarmPowerSList.add(dayHarmPowerS);
|
||||
}
|
||||
}
|
||||
/*生成dayHarmRateI*/
|
||||
@@ -673,6 +753,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataHarmRateIPOList.add(po1);
|
||||
|
||||
DayHarmRateI dayHarmRateI = new DayHarmRateI();
|
||||
BeanUtils.copyProperties(item, dayHarmRateI);
|
||||
dayHarmRateIList.add(dayHarmRateI);
|
||||
}
|
||||
}
|
||||
/*生成dayHarmRateV*/
|
||||
@@ -684,6 +768,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataHarmRateVPOList.add(po1);
|
||||
|
||||
DayHarmRateV dayHarmRateV = new DayHarmRateV();
|
||||
BeanUtils.copyProperties(item, dayHarmRateV);
|
||||
dayHarmRateVList.add(dayHarmRateV);
|
||||
}
|
||||
}
|
||||
/*生成dayInHarmI*/
|
||||
@@ -695,6 +783,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataInHarmIPOList.add(po1);
|
||||
|
||||
DayInHarmI dayInHarmI = new DayInHarmI();
|
||||
BeanUtils.copyProperties(item, dayInHarmI);
|
||||
dayInHarmIList.add(dayInHarmI);
|
||||
}
|
||||
}
|
||||
/*生成dayInHarmV*/
|
||||
@@ -706,6 +798,10 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataInHarmVPOList.add(po1);
|
||||
|
||||
DayInHarmV dayInHarmV = new DayInHarmV();
|
||||
BeanUtils.copyProperties(item, dayInHarmV);
|
||||
dayInHarmVList.add(dayInHarmV);
|
||||
}
|
||||
}
|
||||
/*生成dayPlt*/
|
||||
@@ -717,10 +813,17 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
po1.setTime(time);
|
||||
po1.setQualityFlag(Integer.parseInt(item.getQualityFlag()));
|
||||
dataPltPOList.add(po1);
|
||||
}
|
||||
|
||||
DayPlt dayPlt = new DayPlt();
|
||||
BeanUtils.copyProperties(item, dayPlt);
|
||||
dayPltList.add(dayPlt);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (calType == 0 || calType == 2) {
|
||||
if (!CollectionUtils.isEmpty(dataVPOList)) {
|
||||
statDataVDService.insert(dataVPOList);
|
||||
}
|
||||
@@ -763,9 +866,57 @@ public class DayDataServiceImpl implements DayDataService {
|
||||
if (!CollectionUtils.isEmpty(dataPltPOList)) {
|
||||
statDataPltDService.insert(dataPltPOList);
|
||||
}
|
||||
}
|
||||
|
||||
if (calType == 1 || calType == 2) {
|
||||
if (!CollectionUtils.isEmpty(dayVList)) {
|
||||
dayVMapper.insertBatch(dayVList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayIList)) {
|
||||
dayIMapper.insertBatch(dayIList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayFlickerList)) {
|
||||
dayFlickerMapper.insertBatch(dayFlickerList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayFlucList)) {
|
||||
dayFlucMapper.insertBatch(dayFlucList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayHarmPhasicIList)) {
|
||||
dayHarmPhasicIMapper.insertBatch(dayHarmPhasicIList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayHarmPhasicVList)) {
|
||||
dayHarmPhasicVMapper.insertBatch(dayHarmPhasicVList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayHarmPowerPList)) {
|
||||
dayHarmPowerPMapper.insertBatch(dayHarmPowerPList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayHarmPowerQList)) {
|
||||
dayHarmPowerQMapper.insertBatch(dayHarmPowerQList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayHarmPowerSList)) {
|
||||
dayHarmPowerSMapper.insertBatch(dayHarmPowerSList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayHarmRateIList)) {
|
||||
dayHarmRateIMapper.insertBatch(dayHarmRateIList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayHarmRateVList)) {
|
||||
dayHarmRateVMapper.insertBatch(dayHarmRateVList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayInHarmIList)) {
|
||||
dayInHarmIRateMapper.insertBatch(dayInHarmIList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayInHarmVList)) {
|
||||
dayInHarmVRateMapper.insertBatch(dayInHarmVList);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dayPltList)) {
|
||||
dayPltMapper.insertBatch(dayPltList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log.info(LocalDateTime.now() + "data表转day结束=====》");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ public interface DayDataService {
|
||||
* @param indexLists
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @param calType 0.mysql 1.influxb 2.两个都处理
|
||||
*/
|
||||
void dataToDayHandler(List<String> indexLists, String startTime, String endTime);
|
||||
void dataToDayHandler(List<String> indexLists, String startTime, String endTime,Integer calType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user