怎么解决后台查询慢的问题啊?
总共有19个站,全选的话,后台循环查询需要4分钟,然后就把sql语句#{ }换成了${ },快了点,但是有没有其他办法让查询时间更快一点啊
@Override
public Object selectTotal(JNameVo jNameVo) {
DecimalFormat decimalFormat = new DecimalFormat("0.00");
List<String> syzNameList = jNameVo.getSyzName();
List<Object> object = new ArrayList<>();
if (ListUtil.isNull(syzNameList)) {
syzNameList = jSyzinfoMapper.selectName();
}
if (StringUtil.isNotEmpty(jNameVo.getStartTime()) && StringUtil.isNotEmpty(jNameVo.getEndTime())) {
for (String name : syzNameList) {
Map<Object, Object> data = new HashMap<>();
JRbhis Total = jRbhisMapper.selectTotal(jNameVo.getStartTime(), jNameVo.getEndTime(), name);
if(Total!=null){
data.put("syzName", name);
data.put("energy", Total.getEnergy());
data.put("energyLj", Total.getEnergyLj());
data.put("syje", Total.getSyje());
data.put("power", Total.getPower());
data.put("flow", Total.getFlow());
data.put("row",object.size()+1);
//判断时间是否到了每年的11月15号,不到11月15号,按上一年11月15号开始查
String date = jNameVo.getStartTime();
String[] dateRange = getDateRange(date);
if(dateRange != null && dateRange.length >0 ) {
String startDate = dateRange[0];//改过的时间
String endDate = dateRange[1];//原本时间
JRbhis jenergy = jRbhisMapper.selectTotal(startDate, jNameVo.getEndTime(), name);
data.put("jenergy", Total.getEnergy());
}
}else{
data.put("syzName", name);
data.put("energy", 0);
data.put("energyLj", 0);
data.put("syje", 0);
data.put("power",0);
data.put("flow", 0);
data.put("row",object.size()+1);
data.put("jenergy", 0);
}
object.add(data);
}
}
return object;
}
<select id="selectTotal" resultType="com.hnzy.ymserver.entity.JRbhis">
select a.syzName,a.energy,a.energyLj,b.syje,b.power,b.flow from
(select max(energy)-min(energy) as energy , max(energyLj)-min(energyLj) as energyLj,syzName from J_RbHis
where recordTime>= '${startTime}' and recordTime <= '${endTime}'
group by syzName) a,
(select * from J_RbInfo) b
where a.syzName=b.syzName
and a.syzName = '${syzName}'
</select>