处理实时数据加载慢问题

This commit is contained in:
wanggeng 2021-08-17 11:14:43 +08:00
parent 975cd48215
commit d038ae066d
7 changed files with 98 additions and 42 deletions

View File

@ -11,16 +11,21 @@ import com.cm.tenlion.pollutantdata.pojo.bos.datareal.DataRealBO;
import com.cm.tenlion.pollutantdata.pojo.dtos.datareal.DataRealDTO;
import com.cm.tenlion.pollutantdata.pojo.dtos.datareal.EnterprisePollDTO;
import com.cm.tenlion.pollutantdata.pojo.pos.datareal.DataRealPO;
import com.cm.tenlion.pollutantdata.pojo.pos.enterprise.EnterprisePO;
import com.cm.tenlion.pollutantdata.pojo.pos.instrument.InstrumentPO;
import com.cm.tenlion.pollutantdata.pojo.pos.poll.PollPO;
import com.cm.tenlion.pollutantdata.pojo.vos.datareal.DataRealVO;
import com.cm.tenlion.pollutantdata.service.datareal.IDataRealService;
import com.cm.tenlion.pollutantdata.service.enterprise.IEnterpriseService;
import com.cm.tenlion.pollutantdata.service.instrument.IInstrumentService;
import com.cm.tenlion.pollutantdata.service.poll.IPollService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @ClassName: DataMinuteServiceImpl
@ -34,6 +39,12 @@ public class DataRealServiceImpl extends AbstractService implements IDataRealSer
@Autowired
private IDataRealDao dataMinuteDao;
@Autowired
private IEnterpriseService enterpriseService;
@Autowired
private IInstrumentService instrumentService;
@Autowired
private IPollService pollService;
@Override
public void save(DataRealVO dataRealVO) throws Exception {
@ -146,7 +157,43 @@ public class DataRealServiceImpl extends AbstractService implements IDataRealSer
@Override
public List<DataRealDTO> list(Map<String, Object> params) {
return dataMinuteDao.list(params);
List<DataRealDTO> dataRealDTOs = dataMinuteDao.list(params);
Set<String> enterpriseIdSet = new HashSet<>();
Set<String> instrumentIdSet = new HashSet<>();
for (DataRealDTO dataRealDTO : dataRealDTOs) {
enterpriseIdSet.add(dataRealDTO.getEnterpriseId());
instrumentIdSet.add(dataRealDTO.getInstrumentId());
}
List<EnterprisePO> enterprisePOs = enterpriseService.listPO(new ArrayList<>(enterpriseIdSet));
List<InstrumentPO> instrumentPOs = instrumentService.listPO(new ArrayList<>(instrumentIdSet));
List<PollPO> pollPOs = pollService.listPO(new HashMap<>());
for (DataRealDTO dataRealDTO : dataRealDTOs) {
for (EnterprisePO enterprisePO : enterprisePOs) {
if (StringUtils.equals(dataRealDTO.getEnterpriseId(), enterprisePO.getEnterpriseId())) {
dataRealDTO.setEnterpriseName(enterprisePO.getEnterpriseName());
break;
}
}
for (InstrumentPO instrumentPO : instrumentPOs) {
if (StringUtils.equals(dataRealDTO.getInstrumentId(), instrumentPO.getInstrumentId())) {
dataRealDTO.setInstrumentName(instrumentPO.getInstrumentName());
break;
}
}
for (PollPO pollPO : pollPOs) {
if (StringUtils.equals(dataRealDTO.getPollId(), pollPO.getPollNo()) ||
StringUtils.equals(dataRealDTO.getPollId(), pollPO.getPollNoOld())) {
dataRealDTO.setPollName(pollPO.getPollName());
break;
}
}
}
return dataRealDTOs;
}
@Override

View File

@ -169,6 +169,14 @@ public interface IEnterpriseService {
*/
List<EnterprisePO> listPO(Map<String, Object> params);
/**
* 污染企业列表
*
* @param enterpriseIds
* @return
*/
List<EnterprisePO> listPO(List<String> enterpriseIds);
/**
* 污染企业分页列表
*

View File

@ -173,6 +173,13 @@ public class EnterpriseServiceImpl extends AbstractService implements IEnterpris
return enterpriseDao.listPO(params);
}
@Override
public List<EnterprisePO> listPO(List<String> enterpriseIds) {
Map<String, Object> params = getHashMap(2);
params.put("enterpriseIds", enterpriseIds);
return listPO(params);
}
@Override
public SuccessResultList<List<EnterpriseDTO>> listPage(ListPage page) {
PageHelper.startPage(page.getPage(), page.getRows());

View File

@ -177,6 +177,14 @@ public interface IInstrumentService {
*/
List<InstrumentPO> listPO(Map<String, Object> params);
/**
* 数采仪列表
*
* @param instrumentIds
* @return
*/
List<InstrumentPO> listPO(List<String> instrumentIds);
/**
* 数采仪分页列表
*

View File

@ -1,21 +1,19 @@
package com.cm.tenlion.pollutantdata.service.instrument.impl;
import com.cm.common.utils.ArrayListUtil;
import com.cm.tenlion.pollutantdata.dao.instrument.IInstrumentDao;
import com.cm.tenlion.pollutantdata.manager.InstrumentManager;
import com.cm.tenlion.pollutantdata.pojo.OnlineInstrument;
import com.cm.tenlion.pollutantdata.pojo.bos.instrument.InstrumentBO;
import com.cm.tenlion.pollutantdata.pojo.dtos.collector.CollectorDTO;
import com.cm.tenlion.pollutantdata.pojo.dtos.instrument.InstrumentDTO;
import com.cm.tenlion.pollutantdata.pojo.pos.instrument.InstrumentPO;
import com.cm.tenlion.pollutantdata.pojo.vos.instrument.InstrumentVO;
import com.cm.tenlion.pollutantdata.service.instrument.IInstrumentService;
import com.cm.common.base.AbstractService;
import com.cm.common.exception.SearchException;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResultList;
import com.cm.common.utils.HashMapUtil;
import com.cm.common.utils.UUIDUtil;
import com.cm.tenlion.pollutantdata.dao.instrument.IInstrumentDao;
import com.cm.tenlion.pollutantdata.manager.InstrumentManager;
import com.cm.tenlion.pollutantdata.pojo.OnlineInstrument;
import com.cm.tenlion.pollutantdata.pojo.bos.instrument.InstrumentBO;
import com.cm.tenlion.pollutantdata.pojo.dtos.instrument.InstrumentDTO;
import com.cm.tenlion.pollutantdata.pojo.pos.instrument.InstrumentPO;
import com.cm.tenlion.pollutantdata.pojo.vos.instrument.InstrumentVO;
import com.cm.tenlion.pollutantdata.service.instrument.IInstrumentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
@ -175,6 +173,13 @@ public class InstrumentServiceImpl extends AbstractService implements IInstrumen
return instrumentDao.listPO(params);
}
@Override
public List<InstrumentPO> listPO(List<String> instrumentIds) {
Map<String, Object> params = getHashMap(2);
params.put("instrumentIds", instrumentIds);
return listPO(params);
}
@Override
public SuccessResultList<List<InstrumentDTO>> listPage(ListPage page) {
PageHelper.startPage(page.getPage(), page.getRows());

View File

@ -22,11 +22,11 @@ spring:
max-request-size: 1GB
datasource:
druid:
url: jdbc:mysql://192.168.0.151:3306/db_pollutant_data?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
url: jdbc:mysql://106.12.218.237:8668/db_pollutant_data?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
db-type: mysql
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
username: wanggeng
password: TSkj@0471.123
initial-size: 2
min-idle: 2
max-active: 10
@ -57,11 +57,11 @@ spring:
# 安全
security:
oauth2:
oauth-server: http://192.168.0.152:7001/usercenter
oauth-server: http://106.12.218.237:8001/usercenter
oauth-logout: ${security.oauth2.oauth-server}/logout?redirect_uri=${server.url}
client:
client-id: 2a347bba1dc54def83a47493c7578ae2
client-secret: TEdsOHlnTnc4T2JwTXM3alZldzRSM1ROKzhaQkZaQ24vSWJxREd0TWVLMG1ac2wwZTJHWk5NbXh3L3h3U2c4Rg==
client-id: deb4f0137c4a4b76804acda58714b3bc
client-secret: U20yemhHQmJNWjc5QTZFcXlYaE50OXRFVlRVeCt3RmlnRnFpSXAraVJ6QW1ac2wwZTJHWk5NbXh3L3h3U2c4Rg==
user-authorization-uri: ${security.oauth2.oauth-server}/oauth_client/authorize
access-token-uri: ${security.oauth2.oauth-server}/oauth_client/token
grant-type: authorization_code
@ -75,7 +75,7 @@ security:
api-path:
user-center: ${security.oauth2.oauth-server}
inspection: http://124.67.110.246:8081/inspection
inspection: http://106.12.218.237:8081/inspection
system:
# 预警通知上限
alarm-notice-limit: 5
@ -102,7 +102,7 @@ swagger:
# 文件上传管理
file:
# 文件的保存路径
upload-path: /tenlion/projects/uploadFiles/
upload-path: /Users/wanggeng/Desktop/UploadFiles/
# 图片类型
image-types: png,jpg,jpeg,gif,blob
# 视频类型

View File

@ -243,11 +243,8 @@
SELECT
t1.data_id,
t1.enterprise_id,
jt1.enterprise_name,
t1.instrument_id,
jt2.instrument_name,
t1.poll_id,
jt3.poll_name,
t1.sample_time,
t1.flag,
t1.rtd,
@ -261,22 +258,6 @@
LEFT(t1.gmt_create, 19) gmt_create
FROM
pollute_data_real t1
LEFT JOIN
pollute_enterprise jt1
ON
t1.enterprise_id = jt1.enterprise_id
AND
jt1.is_delete = 0
LEFT JOIN
pollute_instrument jt2
ON
t1.instrument_id = jt2.instrument_id
AND
jt2.is_delete = 0
LEFT JOIN
pollute_poll jt3
ON
(t1.poll_id = jt3.poll_no OR t1.poll_id = jt3.poll_no_old)
WHERE
1 = 1
<if test="keywords != null and keywords != ''">
@ -314,7 +295,7 @@
AND
LEFT(t1.gmt_create, 10) = #{day}
</if>
<if test="descOrderBy != null and descOrderBy = 'gmtCreate'">
<if test="descOrderBy != null and descOrderBy == 'gmtCreate'">
ORDER BY
t1.gmt_create DESC
</if>