报表添加接线方式、一二次值判断

This commit is contained in:
xy
2026-01-28 08:43:04 +08:00
parent d2945b0fb2
commit 32295f60c0
15 changed files with 475 additions and 14 deletions

View File

@@ -0,0 +1,50 @@
package com.njcn.harmonic.pojo.param.excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;
/**
* @author xy
*
*/
@Data
public class ExcelParam implements Serializable {
@ApiModelProperty("模板分类名称")
@NotBlank(message = "模板分类名称不可为空")
private String modelTypeName;
@ApiModelProperty("模板分类类型")
private String modelType;
@ApiModelProperty("排序")
private Integer sort;
@Data
public static class ListExcelParam implements Serializable {
@ApiModelProperty("模板分类id")
private String id;
@ApiModelProperty("模板id")
private List<String> modelIds;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class UpdateExcelParam extends ExcelParam implements Serializable {
@ApiModelProperty("模板id")
private String id;
}
}

View File

@@ -34,4 +34,6 @@ public class ExcelRptTemp extends BaseEntity {
private Integer sort;
private String wiringMethod;
}

View File

@@ -0,0 +1,37 @@
package com.njcn.harmonic.pojo.po.excel;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
*
* </p>
*
* @author xy
* @since 2026-01-27
*/
@Getter
@Setter
@TableName("sys_excel")
public class SysExcel extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 报表类型名称
*/
private String excelName;
private String excelType;
private Integer sort;
}

View File

@@ -0,0 +1,35 @@
package com.njcn.harmonic.pojo.po.excel;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author xy
* @since 2026-01-27
*/
@Getter
@Setter
@TableName("sys_excel_relation")
public class SysExcelRelation implements Serializable {
private static final long serialVersionUID = 1L;
/**
* sys_excel的主键id
*/
private String sysExcelId;
/**
* sys_excel_rpt_temp的主键id
*/
private String sysExcelRptTempId;
}

View File

@@ -27,6 +27,7 @@ public interface ExcelRptTempMapper extends BaseMapper<ExcelRptTemp> {
List<ReportTemplateVO> getReportTemplateByDept(@Param("ids") List<String> ids);
List<ReportTemplateVO> getReportTemplateByIds(@Param("ids") List<String> ids);
@Select("${sqlStr}")
StatisticalDataDTO dynamicSql(@Param("sqlStr")String sql);

View File

@@ -0,0 +1,16 @@
package com.njcn.harmonic.common.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.harmonic.pojo.po.excel.SysExcel;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xy
* @since 2026-01-27
*/
public interface SysExcelMapper extends BaseMapper<SysExcel> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.harmonic.common.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.harmonic.pojo.po.excel.SysExcelRelation;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xy
* @since 2026-01-27
*/
public interface SysExcelRelationMapper extends BaseMapper<SysExcelRelation> {
}

View File

@@ -8,9 +8,11 @@
a.name,
a.dept_id,
b.name deptName,
a.activation,
a.activation,,
a.wiring_method wiringMethod
a.update_time,
c.name updateBy
c.name updateBy,
a.sort sort
from sys_excel_rpt_temp a
left join sys_dept b on a.dept_id = b.id
left join sys_user c on a.update_by = c.id
@@ -21,6 +23,7 @@
b.name like CONCAT('%', #{baseParam.searchValue},'%')
)
</if>
order by a.sort asc
</select>
<select id="getReportTemplateList" resultType="com.njcn.harmonic.common.pojo.vo.ReportTemplateVO">
@@ -32,12 +35,15 @@
d.NAME updateBy,
a.Activation,
a.Report_Type,
a.Report_Form
a.Report_Form,
a.wiring_method wiringMethod,
a.sort sort
FROM
sys_excel_rpt_temp a
LEFT JOIN sys_user d ON a.update_by = d.id
WHERE
a.state = 1
order by a.sort asc
</select>
<select id="getReportTemplateByDept" resultType="com.njcn.harmonic.common.pojo.vo.ReportTemplateVO">
@@ -47,7 +53,8 @@
a.NAME,
a.activation,
a.report_form,
a.sort
a.sort,
a.wiring_method wiringMethod
FROM
sys_excel_rpt_temp a
LEFT JOIN sys_dept_temp b ON a.Id = b.temp_id
@@ -55,4 +62,27 @@
a.activation = 1
order by a.sort asc
</select>
<select id="getReportTemplateByIds" resultType="com.njcn.harmonic.common.pojo.vo.ReportTemplateVO">
SELECT
DISTINCT
a.id,
a.NAME,
a.activation,
a.report_form,
a.sort,
a.report_type reportType,
a.wiring_method wiringMethod
FROM
sys_excel_rpt_temp a
WHERE
a.activation = 1 and a.state = 1
<if test="ids!=null and ids.size()!=0">
and a.id IN
<foreach collection="ids" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
order by a.sort asc
</select>
</mapper>

View File

@@ -31,4 +31,7 @@ public class ReportTemplateVO extends BaseEntity {
private String reportForm;
private String wiringMethod;
private Integer sort;
}

View File

@@ -0,0 +1,18 @@
package com.njcn.harmonic.common.pojo.vo;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author xy
*/
@Data
public class SysExcelRelationVO implements Serializable {
private String sysExcelId;
private List<String> relationIds;
}

View File

@@ -0,0 +1,23 @@
package com.njcn.harmonic.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.harmonic.common.pojo.vo.SysExcelRelationVO;
import com.njcn.harmonic.pojo.param.excel.ExcelParam;
import com.njcn.harmonic.pojo.po.excel.SysExcelRelation;
/**
* <p>
* 服务类
* </p>
*
* @author xy
* @since 2026-01-27
*/
public interface ISysExcelRelationService extends IService<SysExcelRelation> {
//查询已绑定的关系
SysExcelRelationVO getRelation(String id);
//重新绑定模板
boolean bandRelation(ExcelParam.ListExcelParam param);
}

View File

@@ -0,0 +1,32 @@
package com.njcn.harmonic.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.pq.pojo.vo.LineStateVO;
import com.njcn.harmonic.pojo.param.excel.ExcelParam;
import com.njcn.harmonic.pojo.po.excel.SysExcel;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author xy
* @since 2026-01-27
*/
public interface ISysExcelService extends IService<SysExcel> {
//新增
boolean addSysExcel(ExcelParam param);
//删除
boolean deleteSysExcel(String id);
//修改
boolean updateSysExcel(ExcelParam.UpdateExcelParam param);
//查询
List<SysExcel> querySysExcel();
}

View File

@@ -19,14 +19,13 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsCommTerminalFeignClient;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
import com.njcn.harmonic.common.mapper.ExcelRptTempMapper;
import com.njcn.harmonic.common.pojo.dto.DeviceUnitCommDTO;
import com.njcn.harmonic.common.service.CustomReportTableService;
import com.njcn.harmonic.enums.HarmonicResponseEnum;
import com.njcn.harmonic.pojo.dto.ReportTemplateDTO;
import com.njcn.harmonic.pojo.param.ReportSearchParam;
import com.njcn.harmonic.pojo.po.ExcelRptTemp;
import com.njcn.harmonic.common.mapper.ExcelRptTempMapper;
import com.njcn.harmonic.common.service.CustomReportTableService;
import com.njcn.influx.constant.InfluxDbSqlConstant;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.oss.enums.OssResponseEnum;
@@ -91,6 +90,12 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
private final String STR_FOUR = "%";
private final String UVOLTAGE_DEV = "UVOLTAGE_DEV";
private final String VOLTAGE_DEV = "VOLTAGE_DEV";
private static final Map<String, String> PHASE_MAPPING = new HashMap<String, String>() {{
put("AB", "A");
put("BC", "B");
put("CA", "C");
put("M", "T");
}};
@Override
public void getCustomReport(ReportSearchParam reportSearchParam,Map<String,String> newMap,DeviceUnitCommDTO deviceUnitCommDTO, HttpServletResponse response) {
@@ -141,9 +146,20 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
throw new BusinessException(CommonResponseEnum.FAIL,"字典类型模板缺少!");
}
DictData epdDic = dicDataFeignClient.getDicDataByCodeAndType(DicDataEnum.EPD.getCode(),DicDataTypeEnum.CS_DATA_TYPE.getCode()).getData();
List<EleEpdPqd> eleEpdPqdList= epdFeignClient.dictMarkByDataType(epdDic.getId()).getData();
Map<String, String> tMap = new HashMap<>();
eleEpdPqdList.forEach(item->{
String phase;
if (Objects.isNull(PHASE_MAPPING.get(item.getPhase()))) {
phase = item.getPhase();
} else {
phase = PHASE_MAPPING.get(item.getPhase());
}
tMap.put((item.getOtherName() + phase + item.getResourcesId()).toUpperCase(), item.getPrimaryFormula());
});
eleEpdPqdList = eleEpdPqdList.stream().filter(it->"T".equals(it.getPhase())||"M".equals(it.getPhase())).collect(Collectors.toList());
List<String> noPhaseList = eleEpdPqdList.stream().filter(it->StrUtil.isNotBlank(it.getOtherName())).map(it->it.getOtherName().toUpperCase()).collect(Collectors.toList());
@@ -173,13 +189,13 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
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,noPhaseList);
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),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,noPhaseList);
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),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,noPhaseList);
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),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,noPhaseList);
assSqlByMysql(tMap,newMap.get("LEVEL"),newMap.get("PT"),newMap.get("CT"),phaseVal, sql, endList, InfluxDbSqlConstant.CP95, reportSearchParam, limitTargetMapX, limitMap, assNoPassMap,noPhaseList);
}
});
@@ -453,6 +469,37 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
}
public Double getData(String data) {
double ratio = 1.0;
String[] parts = data.split(":");
if (parts.length == 2) {
try {
int num1 = Integer.parseInt(parts[0]);
int num2 = Integer.parseInt(parts[1]);
// 如果需要计算比值
ratio = (double) num1 / num2;
} catch (NumberFormatException e) {
System.out.println("字符串格式错误");
}
}
return ratio;
}
public String appendData(Map<String,String> tMap,String name, double pt, double ct) {
String result;
String format = tMap.get(name);
if (Objects.equals(format, "*PT")) {
result = "*"+pt+"/1000";
} else if (Objects.equals(format, "*CT")) {
result = "*"+ct;
} else if (Objects.equals(format, "*PT*CT")) {
result = "*"+pt+"*"+ct+"/1000";
} else {
result = "";
}
return result;
}
/**
* @param data 同类型的cell模板
* @param sql 单个cell模板
@@ -461,8 +508,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
* @param assNoPassMap 用于存储不合格的指标
* @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,List<String> noPhaseList) {
private void assSqlByMysql(Map<String,String> tMap, String dataLevel, String pt, String ct, 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++) {
@@ -471,6 +517,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"");
} else {
@@ -478,6 +525,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"").append(StrUtil.COMMA);
}
@@ -489,6 +537,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"");
} else {
@@ -496,6 +545,7 @@ public class CustomReportTableServiceImpl implements CustomReportTableService {
.append(InfluxDbSqlConstant.LBK)
.append(data.get(i).getTemplateName())
.append(InfluxDbSqlConstant.RBK)
.append(Objects.equals(dataLevel, "Secondary") ? " " + appendData(tMap, data.get(i).getTemplateName()+data.get(i).getPhase()+data.get(0).getResourceId(), getData(pt), getData(ct)) : "")
.append(InfluxDbSqlConstant.AS)
.append("\""+data.get(i).getItemName()+"\"").append(StrUtil.COMMA);
}

View File

@@ -0,0 +1,65 @@
package com.njcn.harmonic.common.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.harmonic.common.mapper.SysExcelRelationMapper;
import com.njcn.harmonic.common.pojo.vo.SysExcelRelationVO;
import com.njcn.harmonic.common.service.ISysExcelRelationService;
import com.njcn.harmonic.pojo.param.excel.ExcelParam;
import com.njcn.harmonic.pojo.po.excel.SysExcelRelation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author xy
* @since 2026-01-27
*/
@Service
@Slf4j
@RequiredArgsConstructor
@DS("sjzx")
public class SysExcelRelationServiceImpl extends ServiceImpl<SysExcelRelationMapper, SysExcelRelation> implements ISysExcelRelationService {
@Override
public SysExcelRelationVO getRelation(String id) {
SysExcelRelationVO vo = new SysExcelRelationVO();
LambdaQueryWrapper<SysExcelRelation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysExcelRelation::getSysExcelId, id);
List<SysExcelRelation> list = this.list(queryWrapper);
vo.setSysExcelId(id);
if (!list.isEmpty()) {
vo.setRelationIds(list.stream().map(SysExcelRelation::getSysExcelRptTempId).collect(Collectors.toList()));
}
return vo;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean bandRelation(ExcelParam.ListExcelParam param) {
//先删除
LambdaQueryWrapper<SysExcelRelation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysExcelRelation::getSysExcelId, param.getId());
this.remove(queryWrapper);
//再绑定
if (!param.getModelIds().isEmpty()) {
List<SysExcelRelation> list = param.getModelIds().stream().map(id -> {
SysExcelRelation relation = new SysExcelRelation();
relation.setSysExcelId(param.getId());
relation.setSysExcelRptTempId(id);
return relation;
}).collect(Collectors.toList());
this.saveBatch(list);
}
return true;
}
}

View File

@@ -0,0 +1,83 @@
package com.njcn.harmonic.common.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.harmonic.common.mapper.SysExcelMapper;
import com.njcn.harmonic.common.mapper.SysExcelRelationMapper;
import com.njcn.harmonic.common.service.ISysExcelService;
import com.njcn.harmonic.pojo.param.excel.ExcelParam;
import com.njcn.harmonic.pojo.po.excel.SysExcel;
import com.njcn.harmonic.pojo.po.excel.SysExcelRelation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author xy
* @since 2026-01-27
*/
@Service
@Slf4j
@RequiredArgsConstructor
@DS("sjzx")
public class SysExcelServiceImpl extends ServiceImpl<SysExcelMapper, SysExcel> implements ISysExcelService {
private final SysExcelRelationMapper sysExcelRelationMapper;
@Override
public boolean addSysExcel(ExcelParam param) {
LambdaQueryWrapper<SysExcel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysExcel::getExcelName, param.getModelTypeName());
if (this.count(queryWrapper) > 0) {
throw new BusinessException("名称重复");
}
SysExcel sysExcel = new SysExcel();
sysExcel.setExcelName(param.getModelTypeName());
sysExcel.setExcelType(param.getModelType());
sysExcel.setSort(param.getSort());
return this.save(sysExcel);
}
@Override
public boolean deleteSysExcel(String id) {
LambdaQueryWrapper<SysExcelRelation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysExcelRelation::getSysExcelId, id);
if (sysExcelRelationMapper.selectCount(queryWrapper) > 0) {
throw new BusinessException("请先删除关联关系");
}
return this.removeById(id);
}
@Override
public boolean updateSysExcel(ExcelParam.UpdateExcelParam param) {
LambdaQueryWrapper<SysExcel> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysExcel::getExcelName, param.getModelTypeName()).ne(SysExcel::getId, param.getId());
if (this.count(queryWrapper) > 0) {
throw new BusinessException("名称重复");
}
SysExcel sysExcel = new SysExcel();
sysExcel.setId(param.getId());
sysExcel.setExcelName(param.getModelTypeName());
sysExcel.setExcelType(param.getModelType());
sysExcel.setSort(param.getSort());
return this.updateById(sysExcel);
}
@Override
public List<SysExcel> querySysExcel() {
return this.list().stream().sorted(Comparator.comparing(SysExcel::getSort)).collect(Collectors.toList());
}
}