为风速系数增加缓存
This commit is contained in:
parent
6eedf5826f
commit
bc675664f7
@ -2,7 +2,9 @@ package com.das.modules.cache.service;
|
|||||||
|
|
||||||
import com.das.modules.cache.domain.WindSpeedCoefValue;
|
import com.das.modules.cache.domain.WindSpeedCoefValue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface CalcCache {
|
public interface CalcCache {
|
||||||
WindSpeedCoefValue getWindSpeedCoef(Long deviceId);
|
List<WindSpeedCoefValue> getWindSpeedCoef(Long deviceId);
|
||||||
void putWindSpeedCoef(Long deviceId, WindSpeedCoefValue windSpeedCoefValue);
|
void refreshWindSpeedCoef();
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,20 @@ public class CalcCacheImpl implements CalcCache {
|
|||||||
@Autowired
|
@Autowired
|
||||||
SysPowerCurveFactorMapper sysPowerCurveFactorMapper;
|
SysPowerCurveFactorMapper sysPowerCurveFactorMapper;
|
||||||
|
|
||||||
private ConcurrentHashMap<Long, WindSpeedCoefValue> windSpeedCoefMap = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<Long, List<WindSpeedCoefValue>> windSpeedCoefMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init(){
|
private void init(){
|
||||||
|
refreshWindSpeedCoef();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WindSpeedCoefValue> getWindSpeedCoef(Long deviceId) {
|
||||||
|
return windSpeedCoefMap.get(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshWindSpeedCoef() {
|
||||||
List<SysPowerCurveFactorVo> sysPowerCurveFactorVos = sysPowerCurveFactorMapper.querySysPowerCurveFactorList(new SysPowerCurveFactorDto());
|
List<SysPowerCurveFactorVo> sysPowerCurveFactorVos = sysPowerCurveFactorMapper.querySysPowerCurveFactorList(new SysPowerCurveFactorDto());
|
||||||
for (SysPowerCurveFactorVo sysPowerCurveFactorVo : sysPowerCurveFactorVos) {
|
for (SysPowerCurveFactorVo sysPowerCurveFactorVo : sysPowerCurveFactorVos) {
|
||||||
WindSpeedCoefValue windSpeedCoefValue = new WindSpeedCoefValue();
|
WindSpeedCoefValue windSpeedCoefValue = new WindSpeedCoefValue();
|
||||||
@ -29,17 +39,12 @@ public class CalcCacheImpl implements CalcCache {
|
|||||||
windSpeedCoefValue.setMaxValue(sysPowerCurveFactorVo.getSpeedMax());
|
windSpeedCoefValue.setMaxValue(sysPowerCurveFactorVo.getSpeedMax());
|
||||||
windSpeedCoefValue.setCoef(sysPowerCurveFactorVo.getFactorK());
|
windSpeedCoefValue.setCoef(sysPowerCurveFactorVo.getFactorK());
|
||||||
windSpeedCoefValue.setBase(sysPowerCurveFactorVo.getFactorB());
|
windSpeedCoefValue.setBase(sysPowerCurveFactorVo.getFactorB());
|
||||||
windSpeedCoefMap.put(sysPowerCurveFactorVo.getTurbineId(), windSpeedCoefValue);
|
List<WindSpeedCoefValue> windSpeedCoefValues = windSpeedCoefMap.get(sysPowerCurveFactorVo.getTurbineId());
|
||||||
|
if (windSpeedCoefValues == null) {
|
||||||
|
windSpeedCoefValues = new java.util.ArrayList<>();
|
||||||
|
}
|
||||||
|
windSpeedCoefValues.add(windSpeedCoefValue);
|
||||||
|
windSpeedCoefMap.put(sysPowerCurveFactorVo.getTurbineId(), windSpeedCoefValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public WindSpeedCoefValue getWindSpeedCoef(Long deviceId) {
|
|
||||||
return windSpeedCoefMap.get(deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putWindSpeedCoef(Long deviceId, WindSpeedCoefValue windSpeedCoefValue) {
|
|
||||||
windSpeedCoefMap.put(deviceId, windSpeedCoefValue);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.das.modules.calc.functions;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import com.das.modules.cache.domain.DeviceInfoCache;
|
||||||
|
import com.das.modules.cache.domain.WindSpeedCoefValue;
|
||||||
|
import com.das.modules.cache.service.CacheService;
|
||||||
|
import com.das.modules.data.service.DataService;
|
||||||
|
import com.googlecode.aviator.runtime.function.AbstractFunction;
|
||||||
|
import com.googlecode.aviator.runtime.type.AviatorNil;
|
||||||
|
import com.googlecode.aviator.runtime.type.AviatorObject;
|
||||||
|
import com.googlecode.aviator.runtime.type.AviatorRuntimeJavaType;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aviator扩展函数 - 获取时间维度内平均
|
||||||
|
* 函数格式: avg(deviceId, attr, timedim)
|
||||||
|
* timedim: day - 天, month - 月, year - 年
|
||||||
|
* 返回值:数值, nil - 获取错误
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class FunctionWindSpeedFactor extends AbstractFunction {
|
||||||
|
|
||||||
|
private DataService dataService = null;
|
||||||
|
private CacheService cacheService = null;
|
||||||
|
|
||||||
|
|
||||||
|
public FunctionWindSpeedFactor(DataService dataService, CacheService cacheService) {
|
||||||
|
this.dataService = dataService;
|
||||||
|
this.cacheService = cacheService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "windSpeedFactor";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AviatorObject call(Map<String, Object> env, AviatorObject deviceCode) {
|
||||||
|
//设备Code
|
||||||
|
String code = (String)deviceCode.getValue(env);
|
||||||
|
|
||||||
|
DeviceInfoCache deviceInfoCache = cacheService.getEquipmentCache().getDeviceInfoCacheByCode(code);
|
||||||
|
if (deviceInfoCache == null) {
|
||||||
|
return AviatorNil.NIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<WindSpeedCoefValue> windSpeedCoef = cacheService.getCalcCache().getWindSpeedCoef(deviceInfoCache.getDeviceId());
|
||||||
|
if (CollectionUtil.isEmpty(windSpeedCoef)){
|
||||||
|
return AviatorNil.NIL;
|
||||||
|
}
|
||||||
|
//未找到缓存,查询时序API获取数据
|
||||||
|
return AviatorRuntimeJavaType.valueOf(windSpeedCoef);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -96,14 +96,7 @@ public class WindSpeedCorrectServiceImpl implements WindSpeedCorrectService {
|
|||||||
//批量插入数据库
|
//批量插入数据库
|
||||||
sysPowerCurveFactorMapper.insertBatch(listData);
|
sysPowerCurveFactorMapper.insertBatch(listData);
|
||||||
//更新缓存数据
|
//更新缓存数据
|
||||||
listData.forEach(sysPowerCurveFactor -> {
|
cacheService.getCalcCache().refreshWindSpeedCoef();
|
||||||
WindSpeedCoefValue windSpeedCoefValue = new WindSpeedCoefValue();
|
|
||||||
windSpeedCoefValue.setMaxValue(sysPowerCurveFactor.getSpeedMax());
|
|
||||||
windSpeedCoefValue.setMinValue(sysPowerCurveFactor.getSpeedMin());
|
|
||||||
windSpeedCoefValue.setCoef(sysPowerCurveFactor.getFactorK());
|
|
||||||
windSpeedCoefValue.setBase(sysPowerCurveFactor.getFactorB());
|
|
||||||
cacheService.getCalcCache().putWindSpeedCoef(sysPowerCurveFactor.getTurbineId(),windSpeedCoefValue);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
and t.turbine_id = #{info.turbineId}
|
and t.turbine_id = #{info.turbineId}
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
order by sq.name asc
|
order by sq.name asc, t.speed_min asc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="querySysPowerCurveFactorList" resultMap="resultMap">
|
<select id="querySysPowerCurveFactorList" resultMap="resultMap">
|
||||||
@ -46,7 +46,7 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
order by sq.name asc
|
order by sq.name asc, t.speed_min asc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user