为风速系数增加缓存

This commit is contained in:
谷成伟 2024-12-05 17:16:45 +08:00
parent 700375a64c
commit 2d9179f0af
6 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package com.das.modules.cache.domain;
import lombok.Data;
@Data
public class WindSpeedCoefValue {
private Double minValue;
private Double maxValue;
private Double coef;
private Double base;
}

View File

@ -16,4 +16,6 @@ public interface CacheService {
* @return
*/
IotModelCache getIotModelCache();
CalcCache getCalcCache();
}

View File

@ -0,0 +1,8 @@
package com.das.modules.cache.service;
import com.das.modules.cache.domain.WindSpeedCoefValue;
public interface CalcCache {
WindSpeedCoefValue getWindSpeedCoef(Long deviceId);
void putWindSpeedCoef(Long deviceId, WindSpeedCoefValue windSpeedCoefValue);
}

View File

@ -1,6 +1,7 @@
package com.das.modules.cache.service.impl;
import com.das.modules.cache.service.CacheService;
import com.das.modules.cache.service.CalcCache;
import com.das.modules.cache.service.EquipmentCache;
import com.das.modules.cache.service.IotModelCache;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,6 +16,9 @@ public class CacheServiceImpl implements CacheService {
@Autowired
IotModelCache iotModelCache;
@Autowired
CalcCache calcCache;
@Override
public EquipmentCache getEquipmentCache() {
return equipmentCache;
@ -25,5 +29,10 @@ public class CacheServiceImpl implements CacheService {
return iotModelCache;
}
@Override
public CalcCache getCalcCache() {
return calcCache;
}
}

View File

@ -0,0 +1,45 @@
package com.das.modules.cache.service.impl;
import com.das.modules.cache.domain.WindSpeedCoefValue;
import com.das.modules.cache.service.CalcCache;
import com.das.modules.page.domian.dto.SysPowerCurveFactorDto;
import com.das.modules.page.domian.vo.SysPowerCurveFactorVo;
import com.das.modules.page.mapper.SysPowerCurveFactorMapper;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class CalcCacheImpl implements CalcCache {
@Autowired
SysPowerCurveFactorMapper sysPowerCurveFactorMapper;
private ConcurrentHashMap<Long, WindSpeedCoefValue> windSpeedCoefMap = new ConcurrentHashMap<>();
@PostConstruct
private void init(){
List<SysPowerCurveFactorVo> sysPowerCurveFactorVos = sysPowerCurveFactorMapper.querySysPowerCurveFactorList(new SysPowerCurveFactorDto());
for (SysPowerCurveFactorVo sysPowerCurveFactorVo : sysPowerCurveFactorVos) {
WindSpeedCoefValue windSpeedCoefValue = new WindSpeedCoefValue();
windSpeedCoefValue.setMinValue(sysPowerCurveFactorVo.getSpeedMin());
windSpeedCoefValue.setMaxValue(sysPowerCurveFactorVo.getSpeedMax());
windSpeedCoefValue.setCoef(sysPowerCurveFactorVo.getFactorK());
windSpeedCoefValue.setBase(sysPowerCurveFactorVo.getFactorB());
windSpeedCoefMap.put(sysPowerCurveFactorVo.getTurbineId(), windSpeedCoefValue);
}
}
@Override
public WindSpeedCoefValue getWindSpeedCoef(Long deviceId) {
return windSpeedCoefMap.get(deviceId);
}
@Override
public void putWindSpeedCoef(Long deviceId, WindSpeedCoefValue windSpeedCoefValue) {
windSpeedCoefMap.put(deviceId, windSpeedCoefValue);
}
}

View File

@ -12,6 +12,8 @@ import com.das.common.utils.BeanCopyUtils;
import com.das.common.utils.PageDataInfo;
import com.das.common.utils.PageQuery;
import com.das.modules.auth.domain.vo.SysUserVo;
import com.das.modules.cache.domain.WindSpeedCoefValue;
import com.das.modules.cache.service.CacheService;
import com.das.modules.equipment.entity.SysEquipment;
import com.das.modules.equipment.mapper.SysEquipmentMapper;
import com.das.modules.page.domian.dto.IntervalDto;
@ -52,6 +54,9 @@ public class WindSpeedCorrectServiceImpl implements WindSpeedCorrectService {
@Autowired
private SysPowerCurveFactorMapper sysPowerCurveFactorMapper;
@Autowired
private CacheService cacheService;
@Override
public void importWindSpeedCorrect(MultipartFile file) throws IOException {
// 通过文件获取输入流
@ -90,6 +95,15 @@ public class WindSpeedCorrectServiceImpl implements WindSpeedCorrectService {
}
//批量插入数据库
sysPowerCurveFactorMapper.insertBatch(listData);
//更新缓存数据
listData.forEach(sysPowerCurveFactor -> {
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