fix: 优化流量站缓存数据
This commit is contained in:
parent
e362d42410
commit
71eab1423a
@ -22,6 +22,7 @@ import com.yfd.platform.qgc_env.wq.entity.ao.JobBaseAo;
|
||||
import com.yfd.platform.qgc_env.wq.service.EnvWqDataService;
|
||||
import com.yfd.platform.qgc_job.service.IDwJobService;
|
||||
import com.yfd.platform.qgc_job.service.IEqJobService;
|
||||
import com.yfd.platform.qgc_job.service.IFhJobService;
|
||||
import com.yfd.platform.system.domain.QuartzJob;
|
||||
import com.yfd.platform.system.mapper.QuartzJobMapper;
|
||||
import com.yfd.platform.utils.QuartzManage;
|
||||
@ -51,6 +52,7 @@ public class JobRunner implements ApplicationRunner {
|
||||
private final EnvWqDataService envWqDataService;
|
||||
private final IEqJobService eqJobService;
|
||||
private final IDwJobService dwJobService;
|
||||
private final IFhJobService fhJobService;
|
||||
|
||||
/**
|
||||
* 项目启动时重新激活启用的定时任务
|
||||
@ -81,5 +83,8 @@ public class JobRunner implements ApplicationRunner {
|
||||
dwJobService.wtLastData(ao);
|
||||
log.info("--------------------wt最新一条数据---------------------");
|
||||
dwJobService.wtvtPointData(ao);
|
||||
log.info("--------------------wt最新一条数据---------------------");
|
||||
fhJobService.zqLastData(ao);
|
||||
log.info("--------------------fh最新一条数据---------------------");
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,9 @@ import com.yfd.platform.qgc_env.zq.entity.vo.ZqRiverDrtpDataVo;
|
||||
import com.yfd.platform.qgc_env.zq.entity.vo.ZqRiverDataVo;
|
||||
import com.yfd.platform.qgc_env.wt.utils.SiteAvoidanceUtils;
|
||||
import com.yfd.platform.qgc_env.zq.service.ZqMonitorService;
|
||||
import com.yfd.platform.qgc_job.vo.ZqLastDataVo;
|
||||
import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
||||
import com.yfd.platform.utils.RedisCacheUtil;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@ -50,7 +52,6 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
private static final String ZQ_MONTH_TABLE_NAME = "SD_RIVERDRTP_S";
|
||||
private static final Map<String, String> ZQ_UPDATE_COLUMN_MAP = new LinkedHashMap<>();
|
||||
private static final Map<String, String> ZQ_FIELD_MEANING_MAP = new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
ZQ_UPDATE_COLUMN_MAP.put("z", "Z");
|
||||
ZQ_UPDATE_COLUMN_MAP.put("q", "Q");
|
||||
@ -90,6 +91,8 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
|
||||
@Resource
|
||||
private MsOperationLogDetailMapper msOperationLogDetailMapper;
|
||||
@Resource
|
||||
private RedisCacheUtil redisCacheUtil;
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "zqCache#7200", keyGenerator = "cacheKeyGenerator")
|
||||
@ -2441,7 +2444,16 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
|
||||
Page<?> page = QgcQueryWrapperUtil.buildPage(loadOptions, loadOptions.getSkip(), loadOptions.getTake());
|
||||
List<ZqPoint> resultList = microservicDynamicSQLMapper.pageAllListWithResultType(page, sql.toString(), paramMap, ZqPoint.class);
|
||||
|
||||
resultList.forEach(item->{
|
||||
//获取流量站最新数据
|
||||
ZqLastDataVo zqLastData = redisCacheUtil.fromJson(redisCacheUtil.getString("zqLastData:"+item.getStcd()), ZqLastDataVo.class);
|
||||
if(zqLastData !=null){
|
||||
item.setTm(zqLastData.getTm());
|
||||
item.setQ(zqLastData.getQ());
|
||||
item.setZ(zqLastData.getZ());
|
||||
item.setV(zqLastData.getV());
|
||||
}
|
||||
});
|
||||
SiteAvoidanceUtils.calcSiteMapLev(resultList,
|
||||
ZqPoint::getStcd,
|
||||
ZqPoint::getLgtd,
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
package com.yfd.platform.qgc_job.service;
|
||||
|
||||
import com.yfd.platform.qgc_env.wq.entity.ao.JobBaseAo;
|
||||
|
||||
public interface IFhJobService {
|
||||
|
||||
void zqLastData(JobBaseAo ao);
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
package com.yfd.platform.qgc_job.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.yfd.platform.common.MicroservicDynamicSQLMapper;
|
||||
import com.yfd.platform.qgc_env.wq.entity.ao.JobBaseAo;
|
||||
import com.yfd.platform.qgc_job.service.IFhJobService;
|
||||
import com.yfd.platform.qgc_job.vo.ZqLastDataVo;
|
||||
import com.yfd.platform.utils.RedisCacheUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class FhJobServiceImpl implements IFhJobService {
|
||||
|
||||
private static final String ZQ_LAST_DATA_KEY_PREFIX = "zqLastData:";
|
||||
|
||||
@Resource
|
||||
private MicroservicDynamicSQLMapper<?> microservicDynamicSQLMapper;
|
||||
|
||||
@Resource
|
||||
private RedisCacheUtil redisCacheUtil;
|
||||
|
||||
@Override
|
||||
public void zqLastData(JobBaseAo ao) {
|
||||
Set<String> stcds = ao == null ? null : ao.getStcds();
|
||||
List<ZqLastDataVo> zqDataVos = getZqLastData(stcds);
|
||||
if (CollUtil.isEmpty(zqDataVos)) {
|
||||
return;
|
||||
}
|
||||
for (ZqLastDataVo zqDataVo : zqDataVos) {
|
||||
if (zqDataVo == null || zqDataVo.getStcd() == null) {
|
||||
continue;
|
||||
}
|
||||
redisCacheUtil.setString(ZQ_LAST_DATA_KEY_PREFIX + zqDataVo.getStcd(), JSONUtil.toJsonStr(zqDataVo));
|
||||
}
|
||||
log.info("本次更新河道水情缓存{}条", zqDataVos.size());
|
||||
}
|
||||
|
||||
private List<ZqLastDataVo> getZqLastData(Set<String> stcds) {
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ")
|
||||
.append("t.STCD AS stcd, ")
|
||||
.append("t.Z AS z, ")
|
||||
.append("t.Q AS q, ")
|
||||
.append("t.V AS v, ")
|
||||
.append("t.TM AS tm ")
|
||||
.append("FROM SD_RIVER_R t ")
|
||||
.append("INNER JOIN ( ")
|
||||
.append(" SELECT STCD, MAX(TM) AS tm ")
|
||||
.append(" FROM SD_RIVER_R ")
|
||||
.append(" WHERE NVL(IS_DELETED, 0) = 0 ");
|
||||
appendInCondition(sql, paramMap, "STCD", stcds, "zqLastDataInnerStcd");
|
||||
sql.append(" GROUP BY STCD ")
|
||||
.append(") t1 ON t.STCD = t1.STCD AND t.TM = t1.tm ")
|
||||
.append("WHERE NVL(t.IS_DELETED, 0) = 0 ");
|
||||
appendInCondition(sql, paramMap, "t.STCD", stcds, "zqLastDataOuterStcd");
|
||||
return microservicDynamicSQLMapper.getAllListWithResultType(sql.toString(), paramMap, ZqLastDataVo.class);
|
||||
}
|
||||
|
||||
private void appendInCondition(StringBuilder sql,
|
||||
Map<String, Object> paramMap,
|
||||
String column,
|
||||
Set<String> values,
|
||||
String prefix) {
|
||||
if (CollUtil.isEmpty(values)) {
|
||||
return;
|
||||
}
|
||||
List<String> placeholders = new ArrayList<>();
|
||||
int index = 0;
|
||||
for (String value : values) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String key = prefix + index++;
|
||||
paramMap.put(key, value.trim());
|
||||
placeholders.add("#{map." + key + "}");
|
||||
}
|
||||
if (CollUtil.isEmpty(placeholders)) {
|
||||
return;
|
||||
}
|
||||
sql.append(" AND ").append(column).append(" IN (")
|
||||
.append(String.join(", ", placeholders))
|
||||
.append(") ");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package com.yfd.platform.qgc_job.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(description = "河道水情最新缓存")
|
||||
public class ZqLastDataVo {
|
||||
|
||||
@Schema(description = "站码")
|
||||
private String stcd;
|
||||
|
||||
@Schema(description = "水位")
|
||||
private BigDecimal z;
|
||||
|
||||
@Schema(description = "流量")
|
||||
private BigDecimal q;
|
||||
|
||||
@Schema(description = "流速")
|
||||
private BigDecimal v;
|
||||
|
||||
@Schema(description = "时间")
|
||||
private Date tm;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user