mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 加缓存
This commit is contained in:
@@ -23,6 +23,9 @@ public class CacheConstants {
|
|||||||
|
|
||||||
public static final int cache_expire_time_1d = 60 * 60 * 24;
|
public static final int cache_expire_time_1d = 60 * 60 * 24;
|
||||||
|
|
||||||
|
//
|
||||||
|
public static final String SELECT_PILE_BILLING_TEMPLATE_BY_ID = "select_Pile_Billing_Template_By_Id:";
|
||||||
|
|
||||||
// 站点计费模板列表
|
// 站点计费模板列表
|
||||||
public static final String QUERY_STATION_BILLING_TEMPLATE_LIST = "query_station_billing_template_list:";
|
public static final String QUERY_STATION_BILLING_TEMPLATE_LIST = "query_station_billing_template_list:";
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,16 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PileBillingTemplate selectPileBillingTemplateById(Long id) {
|
public PileBillingTemplate selectPileBillingTemplateById(Long id) {
|
||||||
return pileBillingTemplateMapper.selectPileBillingTemplateById(id);
|
// 加缓存
|
||||||
|
String redisKey = CacheConstants.SELECT_PILE_BILLING_TEMPLATE_BY_ID + id;
|
||||||
|
PileBillingTemplate pileBillingTemplate = redisCache.getCacheObject(redisKey);
|
||||||
|
if (pileBillingTemplate == null) {
|
||||||
|
pileBillingTemplate = pileBillingTemplateMapper.selectPileBillingTemplateById(id);
|
||||||
|
if (pileBillingTemplate != null) {
|
||||||
|
redisCache.setCacheObject(redisKey, pileBillingTemplate, CacheConstants.cache_expire_time_1d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pileBillingTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +127,7 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public int updatePileBillingTemplate(PileBillingTemplate pileBillingTemplate) {
|
public int updatePileBillingTemplate(PileBillingTemplate pileBillingTemplate) {
|
||||||
|
cleanCache(pileBillingTemplate.getStationId() + "", pileBillingTemplate.getId());
|
||||||
return pileBillingTemplateMapper.updatePileBillingTemplate(pileBillingTemplate);
|
return pileBillingTemplateMapper.updatePileBillingTemplate(pileBillingTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +146,9 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
List<String> templateCodes = pileBillingDetails.stream().map(PileBillingDetail::getTemplateCode).collect(Collectors.toList());
|
List<String> templateCodes = pileBillingDetails.stream().map(PileBillingDetail::getTemplateCode).collect(Collectors.toList());
|
||||||
pileBillingTemplateMapper.deletePileBillingDetailByTemplateCodes(templateCodes);
|
pileBillingTemplateMapper.deletePileBillingDetailByTemplateCodes(templateCodes);
|
||||||
}
|
}
|
||||||
|
for (Long id : ids) {
|
||||||
|
cleanCache(null , id);
|
||||||
|
}
|
||||||
return pileBillingTemplateMapper.deletePileBillingTemplateByIds(ids);
|
return pileBillingTemplateMapper.deletePileBillingTemplateByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +162,7 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
@Override
|
@Override
|
||||||
public int deletePileBillingTemplateById(Long id) {
|
public int deletePileBillingTemplateById(Long id) {
|
||||||
// pileBillingTemplateMapper.deletePileBillingDetailByTemplateCode(id);
|
// pileBillingTemplateMapper.deletePileBillingDetailByTemplateCode(id);
|
||||||
|
cleanCache(null , id);
|
||||||
return pileBillingTemplateMapper.deletePileBillingTemplateById(id);
|
return pileBillingTemplateMapper.deletePileBillingTemplateById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,6 +218,8 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
.build();
|
.build();
|
||||||
// 入库
|
// 入库
|
||||||
transactionService.doCreateBillingTemplate(build);
|
transactionService.doCreateBillingTemplate(build);
|
||||||
|
|
||||||
|
cleanCache(dto.getStationId() , null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -251,6 +267,8 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
.build();
|
.build();
|
||||||
// 入库
|
// 入库
|
||||||
transactionService.doUpdateBillingTemplate(build);
|
transactionService.doUpdateBillingTemplate(build);
|
||||||
|
|
||||||
|
cleanCache(dto.getStationId() , Long.valueOf(dto.getBillingTemplateId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -367,6 +385,31 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
return pileBillingTemplateMapper.queryStationBillingTemplateList(stationId, authorizedMap.getStationDeptIds());
|
return pileBillingTemplateMapper.queryStationBillingTemplateList(stationId, authorizedMap.getStationDeptIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除计费模板缓存
|
||||||
|
*
|
||||||
|
* @param stationId 站点id
|
||||||
|
* @param templateId 计费模板id
|
||||||
|
*/
|
||||||
|
private void cleanCache(String stationId, Long templateId) {
|
||||||
|
List<String> redisKeyList = Lists.newArrayList();
|
||||||
|
// 通过站点id清缓存
|
||||||
|
if (StringUtils.isNotBlank(stationId)) {
|
||||||
|
redisKeyList.add(CacheConstants.QUERY_STATION_BILLING_TEMPLATE_LIST + stationId);
|
||||||
|
}
|
||||||
|
// 通过计费模板id 清缓存
|
||||||
|
if (templateId != null) {
|
||||||
|
redisKeyList.add(CacheConstants.SELECT_PILE_BILLING_TEMPLATE_BY_ID + templateId);
|
||||||
|
}
|
||||||
|
redisCache.deleteObject(redisKeyList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过站点id查询站点计费模板
|
||||||
|
*
|
||||||
|
* @param stationId 站点id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<BillingTemplateVO> queryStationBillingTemplateListForUniApp(String stationId) {
|
public List<BillingTemplateVO> queryStationBillingTemplateListForUniApp(String stationId) {
|
||||||
String redisKey = CacheConstants.QUERY_STATION_BILLING_TEMPLATE_LIST + stationId;
|
String redisKey = CacheConstants.QUERY_STATION_BILLING_TEMPLATE_LIST + stationId;
|
||||||
@@ -384,6 +427,7 @@ public class PileBillingTemplateServiceImpl implements IPileBillingTemplateServi
|
|||||||
* 查询正在使用中的计费模板
|
* 查询正在使用中的计费模板
|
||||||
* 1 发布时间不为null
|
* 1 发布时间不为null
|
||||||
* 2 最近发布的为正在使用中的
|
* 2 最近发布的为正在使用中的
|
||||||
|
*
|
||||||
* @param stationId 站点id
|
* @param stationId 站点id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.jsowell.thirdparty.amap.util.AMapUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StopWatch;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -59,6 +60,7 @@ public class AMapServiceImpl implements AMapService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto) {
|
public List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto) {
|
||||||
|
StopWatch sw = new StopWatch("高德拉取充电站静态数据");
|
||||||
List<AMapStationInfo> resultList = new ArrayList<>();
|
List<AMapStationInfo> resultList = new ArrayList<>();
|
||||||
|
|
||||||
if (StringUtils.equals("page", dto.getType())) {
|
if (StringUtils.equals("page", dto.getType())) {
|
||||||
@@ -68,12 +70,15 @@ public class AMapServiceImpl implements AMapService {
|
|||||||
PageUtils.startPage(pageNo, pageSize);
|
PageUtils.startPage(pageNo, pageSize);
|
||||||
}
|
}
|
||||||
// 查询站点信息
|
// 查询站点信息
|
||||||
|
sw.start("查询站点信息");
|
||||||
List<PileStationInfo> stationInfos = pileStationInfoService.getStationInfosByThirdParty();
|
List<PileStationInfo> stationInfos = pileStationInfoService.getStationInfosByThirdParty();
|
||||||
|
sw.stop();
|
||||||
if (CollectionUtils.isEmpty(stationInfos)) {
|
if (CollectionUtils.isEmpty(stationInfos)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
AMapStationInfo aMapInfo;
|
AMapStationInfo aMapInfo;
|
||||||
// 拼装高德格式数据
|
// 拼装高德格式数据
|
||||||
|
sw.start("拼装高德格式数据");
|
||||||
for (PileStationInfo stationInfo : stationInfos) {
|
for (PileStationInfo stationInfo : stationInfos) {
|
||||||
aMapInfo = new AMapStationInfo();
|
aMapInfo = new AMapStationInfo();
|
||||||
|
|
||||||
@@ -113,7 +118,7 @@ public class AMapServiceImpl implements AMapService {
|
|||||||
|
|
||||||
resultList.add(aMapInfo);
|
resultList.add(aMapInfo);
|
||||||
}
|
}
|
||||||
|
sw.stop();
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user