Commit a2bbd1eb authored by suhuiguang's avatar suhuiguang

1.分类树缓存刷新修改

parent 0912a7f1
......@@ -240,12 +240,10 @@ public class CarController extends AbstractBaseController {
@Async
public void refreshCount(String bizOrgCode) {
// 刷新分类数量缓存
iCarService.refreshStaData();
try {
fireFightingSystemServiceImpl.refreshCarTypeAndCount(bizOrgCode);
} catch (Exception e) {
}
// 刷新分类树缓存
fireFightingSystemServiceImpl.refreshCarTypeAndCount(bizOrgCode);
}
@Async
public void refreshCount(List<Car> list) {
......
package com.yeejoin.equipmanage.service.impl;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.equipmanage.common.enums.ConfigPageTopicEnum;
import com.yeejoin.equipmanage.listener.IntegratePageDataListener;
import com.yeejoin.equipmanage.service.IMaintenanceResourceDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
......@@ -29,9 +31,24 @@ public class ApplicationRunnerImpl implements ApplicationRunner {
@Autowired
IntegratePageDataListener integratePageDataListener;
@Autowired
RedisUtils redisUtils;
@Value("${redis_car_type_count}")
private String carTypeAndCount;
@Value("${redis_equip_type_count}")
private String equipTypeAndCount;
@Override
public void run(ApplicationArguments args) throws Exception {
// 清空装备分类树缓存
redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*");
// 清空车辆分类树缓存
redisUtils.getAndDeletePatternKeys(equipTypeAndCount + "*");
// 清空单位分类数量统计缓存
redisUtils.getAndDeletePatternKeys(SourcesStatisticsImpl.PREFIX_CATEGORY_COUNT + "*");
maintenanceResourceDataService.subscribeTopic();
emqKeeper.getMqttClient().subscribe(ConfigPageTopicEnum.INTEGRATE.getTopic(),2, integratePageDataListener);
emqKeeper.getMqttClient().subscribe(ConfigPageTopicEnum.INTEGRATE.getTopic(), 2, integratePageDataListener);
}
}
......@@ -1620,10 +1620,10 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarS
@Override
public void refreshStaData() {
List<Map<String, Object>> result = this.baseMapper.queryCompanyCarStaData();
result.forEach(m -> redisUtils.set((buildKey(m)), m.get("total"),86400));
result.forEach(m -> redisUtils.set((buildKey(m)), m.get("total"), 86400));
}
private String buildKey(Map<String, Object> row) {
return row.get("bizOrgCode").toString() + "_" + SourceTypeEnum.CAR.getCode() + "_" + row.get("categoryCode").toString();
return SourcesStatisticsImpl.PREFIX_CATEGORY_COUNT + row.get("bizOrgCode").toString() + "_" + SourceTypeEnum.CAR.getCode() + "_" + row.get("categoryCode").toString();
}
}
......@@ -1595,7 +1595,7 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
}
private String buildKey(Map<String, Object> row) {
return row.get("bizOrgCode").toString() + "_" + SourceTypeEnum.EQUIPMENT.getCode() + "_" + row.get("categoryCode").toString();
return SourcesStatisticsImpl.PREFIX_CATEGORY_COUNT + row.get("bizOrgCode").toString() + "_" + SourceTypeEnum.EQUIPMENT.getCode() + "_" + row.get("categoryCode").toString();
}
}
......@@ -1010,16 +1010,17 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
return Collections.singletonList(parentNode);
}
public Object getEquipmentTypeAndCount(String bizOrgCode) throws Exception {
@Override
public Object getEquipmentTypeAndCount(String bizOrgCode) {
if (redisUtils.hasKey(equipTypeAndCount + bizOrgCode)) {
List<EquipmentCategory> typeList = JSONArray.parseArray(
return JSONArray.parseArray(
JSONArray.toJSONString(redisUtils.get(equipTypeAndCount + bizOrgCode)), EquipmentCategory.class);
return typeList;
} else {
return refreshEquipmentTypeAndCount(bizOrgCode);
}
}
public Object refreshEquipmentTypeAndCount(String bizOrgCode) throws Exception {
@Override
public Object refreshEquipmentTypeAndCount(String bizOrgCode) {
List<EquipmentCategory> responseList = this.typeList();
if (responseList == null || responseList.size() < 1) {
return null;
......@@ -1028,21 +1029,22 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
.filter(i -> !i.getCode().startsWith("2") && "2".equals(i.getIndustryCode()))
.collect(Collectors.toList());
List<EquipmentCategory> list = typeListTree(equipmentTypeList, bizOrgCode, SourceTypeEnum.EQUIPMENT);
redisUtils.set(equipTypeAndCount + bizOrgCode, list);
redisUtils.set(equipTypeAndCount + bizOrgCode, list, 86400);
return list;
}
public Object getCarTypeAndCount(String bizOrgCode) throws Exception {
@Override
public Object getCarTypeAndCount(String bizOrgCode) {
if (redisUtils.hasKey(carTypeAndCount + bizOrgCode)) {
List<EquipmentCategory> typeList = JSONArray.parseArray(
JSONArray.toJSONString(redisUtils.get(carTypeAndCount + bizOrgCode)), EquipmentCategory.class);
return typeList;
} else {
return refreshCarTypeAndCount(bizOrgCode);
}
}
public Object refreshCarTypeAndCount(String bizOrgCode) throws Exception {
@Override
public Object refreshCarTypeAndCount(String bizOrgCode) {
List<EquipmentCategory> responseList = this.typeList();
if (responseList == null || responseList.size() < 1) {
return null;
......
......@@ -2,8 +2,6 @@ package com.yeejoin.equipmanage.service.impl;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.equipmanage.common.enums.SourceTypeEnum;
import com.yeejoin.equipmanage.service.ICarService;
import com.yeejoin.equipmanage.service.IEquipmentDetailService;
import com.yeejoin.equipmanage.service.ISourceStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -21,12 +19,14 @@ public class SourcesStatisticsImpl implements ISourceStatistics {
@Autowired
private RedisUtils redisUtil;
public static String PREFIX_CATEGORY_COUNT = "CATEGORY_COUNT_";
@Override
public int equipCategoryStatistics(String bizOrgCode, SourceTypeEnum sourceType, String categoryCode) {
// 计算处通用code,用来上下级匹配如12001010000->1200101
String treeCode = subStringZero(categoryCode);
Set<String> keys = redisUtil.getKeys(buildKey(bizOrgCode, sourceType.getCode(), treeCode));
Set<String> keys = redisUtil.getKeys(buildPattenKey(bizOrgCode, sourceType.getCode(), treeCode));
if (keys.size() > 0) {
//求和
return this.sumNumber(keys);
......@@ -43,10 +43,18 @@ public class SourcesStatisticsImpl implements ISourceStatistics {
}
}
}
return this.sumNumber(keys);
return this.sumNumberAndInitRedis(bizOrgCode,sourceType,treeCode, keys);
}
}
private int sumNumberAndInitRedis(String bizOrgCode, SourceTypeEnum sourceType, String treeCode, Set<String> keys) {
int result = this.sumNumber(keys);
if(result == 0){
redisUtil.set(buildKey(bizOrgCode,sourceType.getCode(),treeCode),0,86400);
}
return result;
}
private int sumNumber(Set<String> keys) {
return keys.stream().filter(k -> redisUtil.get(k) != null).mapToInt(k -> Integer.parseInt(redisUtil.get(k).toString())).sum();
}
......@@ -57,7 +65,11 @@ public class SourcesStatisticsImpl implements ISourceStatistics {
return new StringBuffer(String.valueOf(noZero)).reverse().toString();
}
private String buildPattenKey(String bizOrgCode, String sourceType, String treeCode) {
return PREFIX_CATEGORY_COUNT + bizOrgCode + "*_" + sourceType + "_" + treeCode + "*";
}
private String buildKey(String bizOrgCode, String sourceType, String treeCode) {
return bizOrgCode + "*_" + sourceType + "_" + treeCode + "*";
return PREFIX_CATEGORY_COUNT + bizOrgCode + "_" + sourceType + "_" + treeCode;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment