sql优化

This commit is contained in:
hzj
2025-08-11 15:27:55 +08:00
parent 10729c44fc
commit f1777f8bf1
3 changed files with 77 additions and 24 deletions

View File

@@ -53,8 +53,20 @@
</select> </select>
<select id="selectDeviceDTOPage" resultType="com.njcn.gather.event.devcie.pojo.dto.DeviceDTO"> <select id="selectDeviceDTOPage" resultType="com.njcn.gather.event.devcie.pojo.dto.DeviceDTO">
select WITH temp AS(
DISTINCT pq_device.dev_index devId, SELECT DISTINCT
PQ_LINE.DEV_INDEX,
PQS_DEPTS.DEPTSNAME
FROM
PQ_LINE,
PQS_DEPTSLINE,
PQS_DEPTS
WHERE
PQ_LINE.LINE_INDEX = PQS_DEPTSLINE.LINE_INDEX
AND PQS_DEPTS.DEPTS_INDEX = PQS_DEPTSLINE.DEPTS_INDEX
)
SELECT DISTINCT
pq_device.dev_index devId,
pq_device.name devName, pq_device.name devName,
pq_device.UpdateTime updateTime, pq_device.UpdateTime updateTime,
pq_device.DevFlag devFlag, pq_device.DevFlag devFlag,
@@ -67,24 +79,15 @@
PQ_DEVICEDETAIL.ThisTimeCheck thisTimeCheck, PQ_DEVICEDETAIL.ThisTimeCheck thisTimeCheck,
PQ_DEVICEDETAIL.NextTimeCheck nextTimeCheck, PQ_DEVICEDETAIL.NextTimeCheck nextTimeCheck,
pq_device.LogonTime logonTime, pq_device.LogonTime logonTime,
PQS_DEPTS.DEPTSNAME deptName temp.DEPTSNAME deptName
from FROM
PQ_DEVICE, pq_device
PQ_SUBSTATION, LEFT JOIN PQ_SUBSTATION ON pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX
PQ_GDINFORMATION, LEFT JOIN PQ_GDINFORMATION ON pq_device.GD_INDEX = PQ_GDINFORMATION.GD_INDEX
PQ_DEVICEDETAIL, LEFT JOIN PQ_DEVICEDETAIL ON PQ_DEVICEDETAIL.dev_index = pq_device.dev_index
PQS_DICDATA, LEFT JOIN PQS_DICDATA on PQ_DEVICEDETAIL.MANUFACTURER = PQS_DICDATA.DIC_INDEX
PQ_LINE, LEFT JOIN temp on temp.DEV_INDEX = pq_device.dev_index
PQS_DEPTS, where 1=1
PQS_DEPTSLINE
where
pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX
and pq_device.GD_INDEX =PQ_GDINFORMATION.GD_INDEX
and PQ_DEVICEDETAIL.dev_index =pq_device.dev_index
and PQ_DEVICEDETAIL.MANUFACTURER = PQS_DICDATA.DIC_INDEX
and PQ_LINE.DEV_INDEX = PQ_DEVICE.DEV_INDEX
and PQ_LINE.LINE_INDEX = PQS_DEPTSLINE.LINE_INDEX
and PQS_DEPTSLINE.DEPTS_INDEX=PQS_DEPTS.DEPTS_INDEX
<if test="searchValue!= null and searchValue!= ''"> <if test="searchValue!= null and searchValue!= ''">
AND ( AND (
pq_device.name LIKE '%' || #{searchValue} || '%' pq_device.name LIKE '%' || #{searchValue} || '%'

View File

@@ -1,6 +1,13 @@
package com.njcn.gather.event.transientes.pojo.vo; package com.njcn.gather.event.transientes.pojo.vo;
import com.njcn.gather.event.transientes.pojo.po.PqsEventdetail;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineEvent;
import java.util.List;
/** /**
* Description: * Description:
@@ -16,8 +23,40 @@ public class SubStationCountVO {
private String gdName; private String gdName;
private double longitude; private double longitude;
private double latitude; private double latitude;
private Integer lineCount; private Integer lineCount;
private Integer eventCount; private Integer eventCount;
private List<LineEventDetail> lineEventDetails;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class LineEventDetail {
private String gdName;
private String gdIndex;
private Integer lineId;
private String lineName;
private Integer busBarId;
private String busBarName;
private Integer devId;
private String devName;
private String objName;
private Integer stationId;
private String stationName;
//通讯状态
private Integer runFlag=0;
private List<PqsEventdetail> pqsEventdetails;
}
} }

View File

@@ -986,7 +986,8 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService {
List<SubStationCountVO> subStationCountVOS = new ArrayList<>(); List<SubStationCountVO> subStationCountVOS = new ArrayList<>();
List<PqLine> pqLineList = (List<PqLine>) redisUtil.getObjectByKey( NAME_KEY+ StrUtil.DASHED+"pqLineList"); List<PqLine> pqLineList = (List<PqLine>) redisUtil.getObjectByKey( NAME_KEY+ StrUtil.DASHED+"pqLineList");
List<Integer> deptslineIds = (List<Integer>) redisUtil.getObjectByKey( NAME_KEY+ StrUtil.DASHED+largeScreenCountParam.getDeptId()); List<Integer> deptslineIds = (List<Integer>) redisUtil.getObjectByKey( NAME_KEY+ StrUtil.DASHED+largeScreenCountParam.getDeptId());
List<LedgerBaseInfoDTO> ledgerBaseInfoDTOS = pqLineService.getBaseLineInfo(deptslineIds);
Map<Integer,LedgerBaseInfoDTO> ledgerBaseInfoDTOMap = ledgerBaseInfoDTOS.stream().collect(Collectors.toMap(LedgerBaseInfoDTO::getLineId, Function.identity()));
pqLineList = pqLineList.stream().filter(temp->deptslineIds.contains(temp.getLineIndex())).collect(Collectors.toList()); pqLineList = pqLineList.stream().filter(temp->deptslineIds.contains(temp.getLineIndex())).collect(Collectors.toList());
List<Integer> subIndexs = pqLineList.stream().map(PqLine::getSubIndex).collect(Collectors.toList()); List<Integer> subIndexs = pqLineList.stream().map(PqLine::getSubIndex).collect(Collectors.toList());
@@ -1031,9 +1032,19 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService {
subStationCountVO.setEventCount(0); subStationCountVO.setEventCount(0);
return; return;
}else {
subStationCountVO.setEventCount(tempEventList.size());
} }
subStationCountVO.setEventCount(tempEventList.size());
Map<Integer, List<PqsEventdetail>> collect = tempEventList.stream().collect(Collectors.groupingBy(PqsEventdetail::getLineid));
List<SubStationCountVO.LineEventDetail> lineEventDetails = new ArrayList<>();
collect.forEach((k1,v1)->{
SubStationCountVO.LineEventDetail lineEventDetail = new SubStationCountVO.LineEventDetail();
LedgerBaseInfoDTO ledgerBaseInfoDTO = ledgerBaseInfoDTOMap.get(k1);
BeanUtils.copyProperties(ledgerBaseInfoDTO,lineEventDetail);
lineEventDetail.setPqsEventdetails(v1);
lineEventDetails.add(lineEventDetail);
});
subStationCountVO.setLineEventDetails(lineEventDetails);
subStationCountVOS.add(subStationCountVO); subStationCountVOS.add(subStationCountVO);
} }