Merge remote-tracking branch 'origin/main'

This commit is contained in:
wr
2026-01-29 14:15:18 +08:00
21 changed files with 547 additions and 45 deletions

View File

@@ -48,6 +48,7 @@ import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -733,7 +734,7 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
List<AdvanceEventDetailVO> advanceEventDetailVOLsit = querySagEventsAll(startTime, endTime);
advanceEventDetailVOLsit = advanceEventDetailVOLsit.stream().filter(temp-> StringUtils.isNotEmpty(temp.getAdvanceType())).collect(Collectors.toList());
for (AdvanceEventDetailVO advanceEventDetailVO : advanceEventDetailVOLsit) { // 获取监测点线路序号
//母线id
String nodePhysics = advanceEventDetailVO.getVoltageId();

View File

@@ -1,7 +1,9 @@
package com.njcn.device.device.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
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.device.device.service.DeviceProcessService;
import com.njcn.device.device.service.IDeviceService;
@@ -28,10 +30,7 @@ import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -73,31 +72,59 @@ public class NodeDeviceServiceImpl implements NodeDeviceService {
Integer nodeDevNum = node.getNodeDevNum();
Integer maxProcessNum = node.getMaxProcessNum();
List<Device> list = iDeviceService.lambdaQuery().eq(Device::getNodeId, nodeId).list();
if(CollectionUtils.isEmpty(list)){
if(CollectionUtils.isEmpty(list)){
throw new BusinessException(PvDeviceResponseEnum.NO_DEVICE);
}
List<String> deviceIdList = list.stream().map(Device::getId).collect(Collectors.toList());
List<DeviceProcess> deviceProcessList = deviceProcessService.lambdaQuery().in(DeviceProcess::getId, deviceIdList).list();
Integer devNum = list.size();
if(nodeDevNum<devNum){
if(nodeDevNum<list.size()){
throw new BusinessException(PvDeviceResponseEnum.OVER_LIMIT);
}
//单个进程支持最大装置数
int maxDevNum = nodeDevNum / maxProcessNum;
List<List<DeviceProcess>> partition = ListUtils.partition(deviceProcessList, maxProcessNum);
for (int i = 0; i < partition.size(); i++) {
int processNo = i+1;
partition.get(i).forEach(temp->{
temp.setProcessNo(processNo);
});
List<String> deviceIdList = list.stream().map(Device::getId).collect(Collectors.toList());
List<DeviceProcess> existingProcesses = deviceProcessService.lambdaQuery().in(DeviceProcess::getId, deviceIdList).list();
if(existingProcesses.size() >= nodeDevNum){
throw new BusinessException(PvDeviceResponseEnum.OVER_LIMIT);
}
List<String> hasProcess = existingProcesses.stream().map(DeviceProcess::getId).distinct().collect(Collectors.toList());
//过滤掉已经分配的装置
List<String> needDevice = deviceIdList.stream().filter(it->!hasProcess.contains(it)).collect(Collectors.toList());
// 无待分配设备直接抛出异常(保留你的原判断)
if (CollUtil.isEmpty(needDevice)) {
throw new BusinessException(CommonResponseEnum.FAIL, "不存在未分配的进程的装置");
}
//单个进程支持最大装置数
int maxDevNumPerProcess = (int) Math.ceil((double) nodeDevNum / maxProcessNum);
Map<Integer, Long> mapCount = existingProcesses.stream().collect(Collectors.groupingBy(DeviceProcess::getProcessNo,Collectors.counting()));
List<DeviceProcess> poList = new ArrayList<>();
Iterator<String> deviceIterator = needDevice.iterator();
for (int processNo = 1; processNo <= maxProcessNum && deviceIterator.hasNext(); processNo++) {
Long usedCount = mapCount.getOrDefault(processNo, 0L);
int remainingCapacity = (int) (maxDevNumPerProcess - usedCount);
if (remainingCapacity <= 0) {
continue;
}
// 分配设备给当前进程
for (int i = 0; i < remainingCapacity && deviceIterator.hasNext(); i++) {
String deviceId = deviceIterator.next();
DeviceProcess deviceProcess = buildDeviceProcess(deviceId, processNo);
poList.add(deviceProcess);
}
}
if(CollUtil.isEmpty(poList)){
throw new BusinessException(CommonResponseEnum.FAIL,"不存在可以分配的进程或装置");
}
List<DeviceProcess> collect = partition.stream().flatMap(List::stream).collect(Collectors.toList());
//更新进程号
deviceProcessService.updateBatchById(collect);
deviceProcessService.saveBatch(poList,100);
}
private DeviceProcess buildDeviceProcess(String deviceId, Integer processNo) {
DeviceProcess deviceProcess = new DeviceProcess();
deviceProcess.setId(deviceId); // 核心修复设置设备关联字段而非主键id
deviceProcess.setProcessNo(processNo);
return deviceProcess;
}
@Override

View File

@@ -291,7 +291,14 @@ public class ReportServiceImpl implements ReportService {
.le(StrUtil.isNotBlank(businessParam.getSearchEndTime()), RmpEventDetailPO::getStartTime, DateUtil.endOfDay(DateUtil.parse(businessParam.getSearchEndTime())))
.orderByDesc(RmpEventDetailPO::getSeverity).last(" limit 20")
);
info = BeanUtil.copyToList(eventDetails, EventDetailNew.class);
info = eventDetails.stream().map(temp->{
EventDetailNew eventDetailNew = new EventDetailNew();
BeanUtils.copyProperties(temp,eventDetailNew);
eventDetailNew.setStartTime(LocalDateTimeUtil.format(temp.getStartTime(),DatePattern.NORM_DATETIME_MS_PATTERN));
return eventDetailNew;
}).collect(Collectors.toList());
// info = BeanUtil.copyToList(eventDetails, EventDetailNew.class);
} else {
throw new BusinessException(DeviceResponseEnum.DEPT_LINE_EMPTY);
}
@@ -309,6 +316,7 @@ public class ReportServiceImpl implements ReportService {
if (detail.getLineId().equals(vo.getLineId())) {
BeanUtils.copyProperties(detail, waveTypeVO);
BeanUtils.copyProperties(vo, waveTypeVO);
waveTypeVO.setStartTime(LocalDateTimeUtil.parse(detail.getStartTime(),DatePattern.NORM_DATETIME_MS_PATTERN));
result.add(waveTypeVO);
}
}
@@ -343,7 +351,7 @@ public class ReportServiceImpl implements ReportService {
count.put(datum.getName(), 0);
}
//过滤掉原因的是空的
info = info.stream().filter(temp->Objects.nonNull(temp.getAdvanceReason())).collect(Collectors.toList());
info = info.stream().filter(temp->StringUtils.isNotEmpty(temp.getAdvanceReason())).collect(Collectors.toList());
//替值
for (EventDetail eventDetail : info) {
// if (dictData.getId().equals(eventDetail.getEventType())) {
@@ -978,7 +986,7 @@ public class ReportServiceImpl implements ReportService {
cell9.setCellStyle(bodyStyle);
cell0.setCellValue(i + 1);
cell1.setCellValue(vo.getStartTime());
cell1.setCellValue(LocalDateTimeUtil.format(vo.getStartTime(),DatePattern.NORM_DATETIME_MS_PATTERN));
cell2.setCellValue(vo.getGdName());
cell3.setCellValue(vo.getSubName());
cell4.setCellValue(vo.getLineName());
@@ -1101,7 +1109,7 @@ public class ReportServiceImpl implements ReportService {
}
public void sheet4(HSSFWorkbook sheets, HSSFCellStyle cellStyle, HSSFCellStyle bodyStyle, DeviceInfoParam.BusinessParam businessParam) {
sheets.createSheet("详细事件列表");
sheets.createSheet("暂降事件列表");
HSSFSheet sheetAt = sheets.getSheetAt(3);
sheetAt.setColumnWidth(0, 24 * 256);
sheetAt.setColumnWidth(1, 24 * 256);

View File

@@ -949,7 +949,7 @@ public class EventAnalysisServiceImpl implements EventAnalysisService {
Map<String, Integer> reasonMap = new LinkedHashMap<>();
Map<String, Integer> typeMap = new LinkedHashMap<>();
info = info.stream().filter(temp->Objects.nonNull(temp.getAdvanceReason())||Objects.nonNull(temp.getAdvanceType())).collect(Collectors.toList());
info = info.stream().filter(temp->StringUtils.isNotEmpty(temp.getAdvanceReason())||StringUtils.isNotEmpty(temp.getAdvanceType())).collect(Collectors.toList());
//添加detail
for (RmpEventDetailPO detail : info) {
EventDetail details = null;
@@ -975,13 +975,13 @@ public class EventAnalysisServiceImpl implements EventAnalysisService {
//添加reason到map
for (EventDetail data : list) {
if (Objects.nonNull(data.getAdvanceReason())&&reasonMap.get(data.getAdvanceReason()) != null) {
if (StringUtils.isNotEmpty(data.getAdvanceReason())&&reasonMap.get(data.getAdvanceReason()) != null) {
reasonMap.put(data.getAdvanceReason(), reasonMap.get(data.getAdvanceReason()) + 1);
}
}
//添加type到map
for (EventDetail data : list) {
if (Objects.nonNull(data.getAdvanceType())&&typeMap.get(data.getAdvanceType()) != null) {
if (StringUtils.isNotEmpty(data.getAdvanceType())&&typeMap.get(data.getAdvanceType()) != null) {
typeMap.put(data.getAdvanceType(), typeMap.get(data.getAdvanceType()) + 1);
}
}
@@ -995,7 +995,7 @@ public class EventAnalysisServiceImpl implements EventAnalysisService {
}
result.setTypes(typesVOS);
result.setReason(reasonsVOS);
//result.setDetail(list);
result.setDetail(list);
return result;
}

View File

@@ -191,6 +191,11 @@ public class EventDetailServiceImpl extends ServiceImpl<RmpEventDetailMapper, Rm
}
DictData advancereason = dicDataFeignClient.getDicDataByCode(reason).getData();
DictData advanceType = dicDataFeignClient.getDicDataByCode(type).getData();
if(Objects.equals(result.getCauseFlag(),1)&&Objects.equals(result.getTypeFlag(),1)){
rmpEventDetailPO.setDealFlag(1);
}else {
rmpEventDetailPO.setDealFlag(0);
}
rmpEventDetailPO.setAdvanceReason(advancereason.getId());
rmpEventDetailPO.setAdvanceType(advanceType.getId());

View File

@@ -883,7 +883,7 @@ public class EventReportServiceImpl implements EventReportService {
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<EventDetailNew> eventDetailList = influxDBResultMapper.toPOJO(monitorQuery, EventDetailNew.class);
Map<String, List<EventDetailNew>> map = eventDetailList.stream().filter(x -> x.getEventType() == "1").collect(Collectors.groupingBy(s -> s.getStartTime().substring(0, 10)));
Map<String, List<EventDetailNew>> map = eventDetailList.stream().filter(x -> x.getEventType() == "1").collect(Collectors.groupingBy(s ->s.getStartTime().substring(0, 10)));
Set<String> keySet = map.keySet();
LocalDate parse1 = LocalDate.parse(startTime);

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());
}
}