sql优化
This commit is contained in:
@@ -3,6 +3,7 @@ package com.njcn.gather.event.devcie.mapper;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
||||||
|
import com.njcn.gather.event.devcie.pojo.dto.DeviceDeptDTO;
|
||||||
import com.njcn.gather.event.devcie.pojo.po.PqDevice;
|
import com.njcn.gather.event.devcie.pojo.po.PqDevice;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@@ -24,4 +25,5 @@ public interface PqDeviceMapper extends BaseMapper<PqDevice> {
|
|||||||
Page<DeviceDTO> queryListByLineIds(Page<DeviceDTO> pqsEventdetailPage, @Param("searchValue") String searchValue,@Param("lineIds") List<Integer> lineIds);
|
Page<DeviceDTO> queryListByLineIds(Page<DeviceDTO> pqsEventdetailPage, @Param("searchValue") String searchValue,@Param("lineIds") List<Integer> lineIds);
|
||||||
|
|
||||||
|
|
||||||
|
List<DeviceDeptDTO> selectDeviceDept();
|
||||||
}
|
}
|
||||||
@@ -53,18 +53,7 @@
|
|||||||
</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">
|
||||||
WITH temp AS(
|
|
||||||
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
|
SELECT DISTINCT
|
||||||
pq_device.dev_index devId,
|
pq_device.dev_index devId,
|
||||||
pq_device.name devName,
|
pq_device.name devName,
|
||||||
@@ -78,15 +67,13 @@
|
|||||||
PQS_DICDATA.DIC_Name MANUFACTURER_Name,
|
PQS_DICDATA.DIC_Name MANUFACTURER_Name,
|
||||||
PQ_DEVICEDETAIL.ThisTimeCheck thisTimeCheck,
|
PQ_DEVICEDETAIL.ThisTimeCheck thisTimeCheck,
|
||||||
PQ_DEVICEDETAIL.NextTimeCheck nextTimeCheck,
|
PQ_DEVICEDETAIL.NextTimeCheck nextTimeCheck,
|
||||||
pq_device.LogonTime logonTime,
|
pq_device.LogonTime logonTime
|
||||||
temp.DEPTSNAME deptName
|
|
||||||
FROM
|
FROM
|
||||||
pq_device
|
pq_device
|
||||||
LEFT JOIN PQ_SUBSTATION ON pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX
|
LEFT JOIN PQ_SUBSTATION ON pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX
|
||||||
LEFT JOIN PQ_GDINFORMATION ON pq_device.GD_INDEX = PQ_GDINFORMATION.GD_INDEX
|
LEFT JOIN PQ_GDINFORMATION ON pq_device.GD_INDEX = PQ_GDINFORMATION.GD_INDEX
|
||||||
LEFT JOIN PQ_DEVICEDETAIL ON PQ_DEVICEDETAIL.dev_index = pq_device.dev_index
|
LEFT JOIN PQ_DEVICEDETAIL ON PQ_DEVICEDETAIL.dev_index = pq_device.dev_index
|
||||||
LEFT JOIN PQS_DICDATA on PQ_DEVICEDETAIL.MANUFACTURER = PQS_DICDATA.DIC_INDEX
|
LEFT JOIN PQS_DICDATA on PQ_DEVICEDETAIL.MANUFACTURER = PQS_DICDATA.DIC_INDEX
|
||||||
LEFT JOIN temp on temp.DEV_INDEX = pq_device.dev_index
|
|
||||||
where 1=1
|
where 1=1
|
||||||
<if test="searchValue!= null and searchValue!= ''">
|
<if test="searchValue!= null and searchValue!= ''">
|
||||||
AND (
|
AND (
|
||||||
@@ -105,6 +92,59 @@
|
|||||||
order by pq_device.updatetime
|
order by pq_device.updatetime
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- <select id="selectDeviceDTOPage" resultType="com.njcn.gather.event.devcie.pojo.dto.DeviceDTO">-->
|
||||||
|
<!-- WITH temp AS(-->
|
||||||
|
<!-- 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.UpdateTime updateTime,-->
|
||||||
|
<!-- pq_device.DevFlag devFlag,-->
|
||||||
|
<!-- pq_device.IP ip,-->
|
||||||
|
<!-- pq_device.status status,-->
|
||||||
|
<!-- PQ_SUBSTATION.sub_index stationId,-->
|
||||||
|
<!-- PQ_SUBSTATION.name stationName,-->
|
||||||
|
<!-- PQ_GDINFORMATION.Name gdName,-->
|
||||||
|
<!-- PQS_DICDATA.DIC_Name MANUFACTURER_Name,-->
|
||||||
|
<!-- PQ_DEVICEDETAIL.ThisTimeCheck thisTimeCheck,-->
|
||||||
|
<!-- PQ_DEVICEDETAIL.NextTimeCheck nextTimeCheck,-->
|
||||||
|
<!-- pq_device.LogonTime logonTime,-->
|
||||||
|
<!-- temp.DEPTSNAME deptName-->
|
||||||
|
<!-- FROM-->
|
||||||
|
<!-- pq_device-->
|
||||||
|
<!-- LEFT JOIN PQ_SUBSTATION ON pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX-->
|
||||||
|
<!-- LEFT JOIN PQ_GDINFORMATION ON pq_device.GD_INDEX = PQ_GDINFORMATION.GD_INDEX-->
|
||||||
|
<!-- LEFT JOIN PQ_DEVICEDETAIL ON PQ_DEVICEDETAIL.dev_index = pq_device.dev_index-->
|
||||||
|
<!-- LEFT JOIN PQS_DICDATA on PQ_DEVICEDETAIL.MANUFACTURER = PQS_DICDATA.DIC_INDEX-->
|
||||||
|
<!-- LEFT JOIN temp on temp.DEV_INDEX = pq_device.dev_index-->
|
||||||
|
<!-- where 1=1-->
|
||||||
|
<!-- <if test="searchValue!= null and searchValue!= ''">-->
|
||||||
|
<!-- AND (-->
|
||||||
|
<!-- pq_device.name LIKE '%' || #{searchValue} || '%'-->
|
||||||
|
<!-- OR PQ_SUBSTATION.name LIKE '%' || #{searchValue} || '%'-->
|
||||||
|
<!-- OR PQ_GDINFORMATION.Name LIKE '%' || #{searchValue} || '%'-->
|
||||||
|
<!-- )-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- <if test="state!= null and state!= ''">-->
|
||||||
|
<!-- and pq_device.status = #{state}-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- and pq_device.DEV_INDEX in-->
|
||||||
|
<!-- <foreach collection="devIndexs" item="item" open="(" close=")" separator=",">-->
|
||||||
|
<!-- #{item}-->
|
||||||
|
<!-- </foreach>-->
|
||||||
|
<!-- order by pq_device.updatetime-->
|
||||||
|
<!-- </select>-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<select id="queryListByLineIds" resultType="com.njcn.gather.event.devcie.pojo.dto.DeviceDTO">
|
<select id="queryListByLineIds" resultType="com.njcn.gather.event.devcie.pojo.dto.DeviceDTO">
|
||||||
@@ -137,4 +177,20 @@
|
|||||||
#{item}
|
#{item}
|
||||||
</foreach>
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectDeviceDept" resultType="com.njcn.gather.event.devcie.pojo.dto.DeviceDeptDTO">
|
||||||
|
|
||||||
|
SELECT DISTINCT
|
||||||
|
PQ_LINE.DEV_INDEX devId,
|
||||||
|
PQS_DEPTS.DEPTSNAME deptName,
|
||||||
|
PQS_DEPTS.DEPTS_INDEX deptId
|
||||||
|
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>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.njcn.gather.event.devcie.pojo.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description:
|
||||||
|
* Date: 2025/06/27 下午 3:25【需求编号】
|
||||||
|
*
|
||||||
|
* @author clam
|
||||||
|
* @version V1.0.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DeviceDeptDTO {
|
||||||
|
private Integer devId;
|
||||||
|
private String deptId;
|
||||||
|
private String deptName;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.njcn.gather.event.devcie.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
||||||
|
import com.njcn.gather.event.devcie.pojo.dto.DeviceDeptDTO;
|
||||||
import com.njcn.gather.event.devcie.pojo.po.PqDevice;
|
import com.njcn.gather.event.devcie.pojo.po.PqDevice;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
@@ -20,4 +21,6 @@ public interface PqDeviceService extends IService<PqDevice>{
|
|||||||
List<DeviceDTO> queryListByIds(List<Integer> lineIds);
|
List<DeviceDTO> queryListByIds(List<Integer> lineIds);
|
||||||
|
|
||||||
Page<DeviceDTO> selectDeviceDTOPage(Page<DeviceDTO> pqsEventdetailPage, String searchValue, List<Integer> devIndexs, String state);
|
Page<DeviceDTO> selectDeviceDTOPage(Page<DeviceDTO> pqsEventdetailPage, String searchValue, List<Integer> devIndexs, String state);
|
||||||
|
|
||||||
|
List<DeviceDeptDTO> selectDeviceDept();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.njcn.gather.event.devcie.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
||||||
|
import com.njcn.gather.event.devcie.pojo.dto.DeviceDeptDTO;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,4 +30,9 @@ public class PqDeviceServiceImpl extends ServiceImpl<PqDeviceMapper, PqDevice> i
|
|||||||
public Page<DeviceDTO> selectDeviceDTOPage(Page<DeviceDTO> pqsEventdetailPage, String searchValue, List<Integer> devIndexs, String state) {
|
public Page<DeviceDTO> selectDeviceDTOPage(Page<DeviceDTO> pqsEventdetailPage, String searchValue, List<Integer> devIndexs, String state) {
|
||||||
return this.baseMapper.selectDeviceDTOPage(pqsEventdetailPage,searchValue,devIndexs,state);
|
return this.baseMapper.selectDeviceDTOPage(pqsEventdetailPage,searchValue,devIndexs,state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceDeptDTO> selectDeviceDept() {
|
||||||
|
return this.baseMapper.selectDeviceDept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ import com.njcn.gather.event.devcie.config.PqlineCache;
|
|||||||
import com.njcn.gather.event.devcie.mapper.PqLineMapper;
|
import com.njcn.gather.event.devcie.mapper.PqLineMapper;
|
||||||
import com.njcn.gather.event.devcie.mapper.PqLinedetailMapper;
|
import com.njcn.gather.event.devcie.mapper.PqLinedetailMapper;
|
||||||
import com.njcn.gather.event.devcie.mapper.PqsStationMapMapper;
|
import com.njcn.gather.event.devcie.mapper.PqsStationMapMapper;
|
||||||
import com.njcn.gather.event.devcie.pojo.dto.DeviceDTO;
|
import com.njcn.gather.event.devcie.pojo.dto.*;
|
||||||
import com.njcn.gather.event.devcie.pojo.dto.LedgerBaseInfoDTO;
|
|
||||||
import com.njcn.gather.event.devcie.pojo.dto.PqsDeptDTO;
|
|
||||||
import com.njcn.gather.event.devcie.pojo.dto.SubstationDTO;
|
|
||||||
import com.njcn.gather.event.devcie.pojo.po.*;
|
import com.njcn.gather.event.devcie.pojo.po.*;
|
||||||
import com.njcn.gather.event.transientes.mapper.PqUserLedgerMapper;
|
import com.njcn.gather.event.transientes.mapper.PqUserLedgerMapper;
|
||||||
import com.njcn.gather.event.transientes.mapper.PqUserLineAssMapper;
|
import com.njcn.gather.event.transientes.mapper.PqUserLineAssMapper;
|
||||||
@@ -1190,6 +1187,16 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService {
|
|||||||
log.info("完成设备查询sql:"+timeInterval.intervalMs()+"ms; "+timeInterval.intervalSecond()+"s");
|
log.info("完成设备查询sql:"+timeInterval.intervalMs()+"ms; "+timeInterval.intervalSecond()+"s");
|
||||||
List<Integer> runDevList = pqDeviceList.stream().map(PqDevice::getDevIndex).collect(Collectors.toList());
|
List<Integer> runDevList = pqDeviceList.stream().map(PqDevice::getDevIndex).collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<DeviceDeptDTO> deviceDeptDTOS= pqDeviceService.selectDeviceDept();
|
||||||
|
Map<Integer, String> deviceDeptMap = deviceDeptDTOS.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
DeviceDeptDTO::getDevId, // key mapper
|
||||||
|
DeviceDeptDTO::getDeptName, // value mapper
|
||||||
|
(value1, value2 )->{
|
||||||
|
return value2;
|
||||||
|
}
|
||||||
|
));
|
||||||
|
log.info("完成设备部门查询:"+timeInterval.intervalMs()+"ms; "+timeInterval.intervalSecond()+"s");
|
||||||
pqsEventdetailPage = pqDeviceService.selectDeviceDTOPage(pqsEventdetailPage,largeScreenCountParam.getSearchValue(),runDevList,largeScreenCountParam.getState());
|
pqsEventdetailPage = pqDeviceService.selectDeviceDTOPage(pqsEventdetailPage,largeScreenCountParam.getSearchValue(),runDevList,largeScreenCountParam.getState());
|
||||||
log.info("完成设备分页查询sql:"+timeInterval.intervalMs()+"ms; "+timeInterval.intervalSecond()+"s");
|
log.info("完成设备分页查询sql:"+timeInterval.intervalMs()+"ms; "+timeInterval.intervalSecond()+"s");
|
||||||
|
|
||||||
@@ -1216,6 +1223,7 @@ public class LargeScreenCountServiceImpl implements LargeScreenCountService {
|
|||||||
|
|
||||||
|
|
||||||
for (DeviceDTO record : pqsEventdetailPage.getRecords()) {
|
for (DeviceDTO record : pqsEventdetailPage.getRecords()) {
|
||||||
|
record.setDeptName(deviceDeptMap.get(record.getDevId()));
|
||||||
List<PqsOnlinerate> tempList = list.stream().filter(temp -> Objects.equals(temp.getDevIndex(), record.getDevId())).collect(Collectors.toList());
|
List<PqsOnlinerate> tempList = list.stream().filter(temp -> Objects.equals(temp.getDevIndex(), record.getDevId())).collect(Collectors.toList());
|
||||||
if(!CollectionUtils.isEmpty(tempList)){
|
if(!CollectionUtils.isEmpty(tempList)){
|
||||||
double asDouble = tempList.stream().mapToDouble(temp -> {
|
double asDouble = tempList.stream().mapToDouble(temp -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user