Commit b7fc9dc4 authored by suhuiguang's avatar suhuiguang

1.分类树优化

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