Commit b7fc9dc4 authored by suhuiguang's avatar suhuiguang

1.分类树优化

parent 79218d84
......@@ -184,12 +184,18 @@ public class CarController extends AbstractBaseController {
}
@Async
public void refreshCount(String bizOrgCode) {
public void refreshCount(String... bizOrgCodes) {
try {
// 刷新分类数量缓存
iCarService.refreshStaData();
// 刷新分类树缓存
// 去重逻辑,目的时资源调整归属单位后 新单元和就单位都刷新单位分类数量统计
Set<String> repeatBizOrgCodes = new HashSet<>(Arrays.asList(bizOrgCodes));
repeatBizOrgCodes.forEach(bizOrgCode -> {
fireFightingSystemServiceImpl.refreshCarTypeAndCount(bizOrgCode);
});
} catch (Exception e) {
log.error("刷新车辆分类树缓存失败" + e.getMessage());
}
}
@Async
......@@ -199,6 +205,7 @@ public class CarController extends AbstractBaseController {
try {
fireFightingSystemServiceImpl.refreshCarTypeAndCount(i.getBizOrgCode());
} catch (Exception e) {
log.error("刷新车辆分类树缓存失败" + e.getMessage());
}
});
}
......@@ -261,9 +268,10 @@ public class CarController extends AbstractBaseController {
// carInstance = iCarService.saveCar(getUserInfo(), carInstance, carInfo, carpList);
// saveFile(carInstance);视频图片文件后期统一处理
EquipmentSpecificSerivceImpl.registerMqttTopic(car.getIotCode(), equipmentIotMqttReceiveConfig);
Car oldCar = iCarService.getById(car.getId());
Car car1 = iCarService.updateOneById(car);
CarController controllerProxy = SpringUtils.getBean(CarController.class);
controllerProxy.refreshCount(car.getBizOrgCode());
controllerProxy.refreshCount(car.getBizOrgCode(), oldCar.getBizOrgCode());
return car1;
}
......@@ -863,7 +871,8 @@ public class CarController extends AbstractBaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "获取九大类二级统计")
@RequestMapping(value = "/getCarList/{ercode}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public IPage<Car> getCarList(@PathVariable(value = "ercode") String ercode, String orgcode, Car car, String pageNum,
public IPage<Car> getCarList(@PathVariable(value = "ercode") String ercode, String orgcode, Car car, String
pageNum,
String pageSize) {
Page<Car> pageBean;
if (StringUtils.isBlank(pageNum) || StringUtils.isBlank(pageSize)) {
......
......@@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
import com.yeejoin.equipmanage.common.enums.SourceTypeEnum;
import com.yeejoin.equipmanage.common.utils.SpringUtils;
import com.yeejoin.equipmanage.service.ISourceStatistics;
import com.yeejoin.equipmanage.service.impl.SourcesStatisticsImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -80,6 +81,12 @@ public class EquipmentCategoryController extends AbstractBaseController {
@Autowired
ISourceStatistics iSourceStatistics;
@Value("${redis_car_type_count}")
private String carTypeAndCount;
@Value("${redis_equip_type_count}")
private String equipTypeAndCount;
private static final String equipmentTreeListAll = "equipmentTreeListAll";
private static final String equipmentTreeListIndustry = "equipmentTreeListIndustry";
// 装备redis缓存key前缀
......@@ -104,7 +111,15 @@ public class EquipmentCategoryController extends AbstractBaseController {
@Async
public void refreshAllCount() {
// 清空单位装备分类树缓存
redisUtils.getAndDeletePatternKeys(carTypeAndCount + "*");
// 清空车辆分类树缓存
redisUtils.getAndDeletePatternKeys(equipTypeAndCount + "*");
// 清空单位分类数量统计缓存
redisUtils.getAndDeletePatternKeys(SourcesStatisticsImpl.PREFIX_CATEGORY_COUNT + "*");
// 刷新装备单位分类数量缓存
iSourceStatistics.initAllCategoryStatisticsData(SourceTypeEnum.EQUIPMENT);
// 刷新车辆单位分类数量缓存
iSourceStatistics.initAllCategoryStatisticsData(SourceTypeEnum.CAR);
}
......
......@@ -25,12 +25,14 @@ import com.yeejoin.equipmanage.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -50,6 +52,7 @@ import java.util.*;
* @author wujiang
* @date 2020-07-07
*/
@Slf4j
@RestController
@Api(tags = "装备详情 Api")
@RequestMapping(value = "/equipment-detail", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
......@@ -108,11 +111,16 @@ public class EquipmentDetailController extends AbstractBaseController {
}
@Async
public void refreshCount(String bizOrgCode) {
equipmentSpecificSerivce.refreshStaData();
public void refreshCount(String ...bizOrgCodes) {
try {
equipmentSpecificSerivce.refreshStaData();
// 去重逻辑,目的时资源调整归属单位后 新单元和就单位都刷新单位分类数量统计
Set<String> repeatBizOrgCodes = new HashSet<>(Arrays.asList(bizOrgCodes));
repeatBizOrgCodes.forEach(bizOrgCode->{
fireFightingSystemServiceImpl.refreshEquipmentTypeAndCount(bizOrgCode);
});
} catch (Exception e) {
log.error("刷新装备分类树缓存失败" + e.getMessage());
}
}
......@@ -227,6 +235,8 @@ public class EquipmentDetailController extends AbstractBaseController {
public EquipmentDate updateByIdEquipmentDetail(HttpServletRequest request, @RequestBody EquipmentDate equipmentDate) {
EquipmentSpecific vo = equipmentDate.getEquipmentSpecific();
EquipmentSpecific oldEquipmentSpecific = equipmentSpecificSerivce.getById(vo.getId());
String oldBizOrgCode = oldEquipmentSpecific.getBizOrgCode();
String sysCode = vo.getCode();
if (StringUtils.isNotEmpty(sysCode) && StringUtils.isNotEmpty(sysCode.trim())) {
int code = equipmentSpecificSerivce.count(new QueryWrapper<EquipmentSpecific>().eq("code", vo.getCode()).ne("id", vo.getId()));
......@@ -268,8 +278,9 @@ public class EquipmentDetailController extends AbstractBaseController {
if (syncSwitch) {
equipmentSpecificSerivce.equipSpecificDataSync(bean.getEquipmentId());
}
// 刷新缓存,新的单位和之前的单位都刷新
EquipmentDetailController controllerProxy = SpringUtils.getBean(EquipmentDetailController.class);
controllerProxy.refreshCount(vo.getBizOrgCode());
controllerProxy.refreshCount(vo.getBizOrgCode(),oldBizOrgCode);
return equipmentDate;
}
......
......@@ -19,7 +19,7 @@ public class SourcesStatisticsImpl implements ISourceStatistics {
@Autowired
private RedisUtils redisUtil;
static String PREFIX_CATEGORY_COUNT = "CATEGORY_COUNT_";
public static String PREFIX_CATEGORY_COUNT = "CATEGORY_COUNT_";
@Override
......
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