--优化国家地区缓存机制

This commit is contained in:
2025-11-11 15:00:06 +08:00
parent faaf465554
commit 505327b6f5
8 changed files with 59 additions and 48 deletions

View File

@ -1162,7 +1162,11 @@ public class DataLogTools {
}
public static void main(String[] args) {
long id = IdWorker.getId();
System.out.println(""+id);
System.out.println((""+id).length());
}
}

View File

@ -1,7 +1,10 @@
package com.xjrsoft.module.mdm.client;
import java.util.Map;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.xjrsoft.common.constant.GlobalConstant;
@ -12,6 +15,10 @@ import com.xjrsoft.common.constant.GlobalConstant;
@FeignClient(value = GlobalConstant.CLIENT_PCITC_MDM_NAME, path = GlobalConstant.CLIENT_API_PRE + GlobalConstant.MDM_MODULE_PREFIX + "/countryRegion")
public interface ICountryRegionClient {
@GetMapping("/refreshCache")
void refreshCache();
@GetMapping("/getAllTranData")
Map<String,String> getAllTranData();
@GetMapping("/getTranById")
String getTranById(@RequestParam("id")String id);
}

View File

@ -17,7 +17,7 @@
<properties>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<docker-image-name>pcitc/itc-pcitc-mdm</docker-image-name>
<docker-image-name>docker.ges.bjgastx.com/itc-pcitc-mdm</docker-image-name>
</properties>
<dependencies>

View File

@ -1,20 +1,18 @@
package com.xjrsoft.module.mdm.client;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.common.utils.RedisUtil;
import com.xjrsoft.common.utils.TenantUtil;
import com.xjrsoft.module.mdm.entity.LngBRegion;
import com.xjrsoft.module.mdm.service.ICountryRegionService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* @author: yjw
@ -24,26 +22,25 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@RequestMapping(GlobalConstant.CLIENT_API_PRE + GlobalConstant.MDM_MODULE_PREFIX + "/countryRegion")
@AllArgsConstructor
@Slf4j
public class CountryRegionClientImpl implements ICountryRegionClient {
private final ICountryRegionService countryRegionService;
private final RedisUtil redisUtil;
@Override
public Map<String, String> getAllTranData() {
try {
TenantUtil.ignore(true);
List<LngBRegion> list = countryRegionService.list();
return list.stream().collect(Collectors.toMap(LngBRegion::getCode,LngBRegion::getFullPath));
}finally {
TenantUtil.clear();
}
}
@GetMapping("/refreshCache")
public void refreshCache() {
try {
TenantUtil.ignore(true);
log.info("MDM: 加载所有国家地区表缓存开始");
List<LngBRegion> list = countryRegionService.list();
redisUtil.set(GlobalConstant.REGION_CACHE_KEY, list);
redisUtil.set(GlobalConstant.REGION_NAME_CACHE_KEY, list.stream().collect(Collectors.toMap(LngBRegion::getCode,LngBRegion::getFullPath)));
log.info("MDM: 加载所有国家地区表缓存结束");
}finally {
TenantUtil.clear();
}
}
@Override
public String getTranById(String code) {
countryRegionService.getByCode(code);
return null;
}
}

View File

@ -1,14 +1,11 @@
package com.xjrsoft.module.mdm.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import javax.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -21,27 +18,25 @@ import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.esotericsoftware.kryo.kryo5.minlog.Log;
import com.pictc.datalog.DataOperationContent;
import com.pictc.datalog.DataOperationListener;
import com.pictc.enums.BusinessCode;
import com.pictc.enums.ExceptionCommonCode;
import com.pictc.enums.ValidEnum;
import com.pictc.utils.CollectionUtils;
import com.xjrsoft.common.advice.tran.RegionDataProvider;
import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.common.enums.YesOrNoEnum;
import com.xjrsoft.common.exception.BusinessException;
import com.xjrsoft.common.model.result.R;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.utils.CacheUtil;
import com.xjrsoft.common.utils.TreeUtil;
import com.xjrsoft.common.utils.VoToColumnUtil;
import com.xjrsoft.module.common.db.utils.CommonCallUtils;
import com.xjrsoft.module.datalog.service.DatalogService;
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
import com.xjrsoft.module.mdm.dto.LngBRegionPageDto;
import com.xjrsoft.module.mdm.dto.UpdateLngBBankDto;
import com.xjrsoft.module.mdm.dto.UpdateLngBRegionDto;
import com.xjrsoft.module.mdm.entity.LngBRegion;
import com.xjrsoft.module.mdm.enums.CountryRegionEnum;
@ -57,7 +52,6 @@ import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import shade.powerjob.com.google.common.collect.Lists;
/**
* @title: 国家地区
@ -73,7 +67,11 @@ public class CountryRegionController {
private final ICountryRegionService countryRegionService;
private final DatalogService dataService;
@Autowired
private RegionDataProvider tranProvider;
@GetMapping(value = "/page")
@ApiOperation(value="LngBRegion列表(分页)")
@ -139,10 +137,11 @@ public class CountryRegionController {
@Override
public UpdateLngBRegionDto after(DataOperationContent<UpdateLngBRegionDto> content) {
String msg = CommonCallUtils.saveAfter(content.getTableName(),content.getIdValue());
if (StringUtils.isNotBlank(msg)) {
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
}
refreshCahe();
if (StringUtils.isNotBlank(msg)) {
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
}
UpdateLngBRegionDto obj = content.getObj();
tranProvider.saveData(obj.getCode(), obj.getFullName());
return content.getObj();
}
}));
@ -173,10 +172,11 @@ public class CountryRegionController {
@Override
public UpdateLngBRegionDto after(DataOperationContent<UpdateLngBRegionDto> content) {
String msg = CommonCallUtils.saveAfter(content.getTableName(),content.getIdValue());
if (StringUtils.isNotBlank(msg)) {
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
}
refreshCahe();
if (StringUtils.isNotBlank(msg)) {
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
}
UpdateLngBRegionDto obj = content.getObj();
tranProvider.saveData(obj.getCode(), obj.getFullName());
return content.getObj();
}
}));
@ -283,12 +283,6 @@ public class CountryRegionController {
return R.ok(countryRegionService.getRegionByParentId(code,excludeType));
}
private void refreshCahe(){
//异步更新
CompletableFuture.runAsync(() -> {
CacheUtil.refreshRegionList();
});
}
}

View File

@ -17,4 +17,6 @@ public interface ICountryRegionService extends IService<LngBRegion> {
Map<String, Object> getRegionByParentId(String code, String excludeType);
LngBRegion getByCode(String code);
}

View File

@ -95,4 +95,11 @@ public class CountryRegionServiceImpl extends ServiceImpl<LngBRegionMapper, LngB
}
}
@Override
public LngBRegion getByCode(String code) {
LambdaQueryWrapper<LngBRegion> queryWrapper = new LambdaQueryWrapper<LngBRegion>();
queryWrapper.eq(LngBRegion::getCode,code);
return baseMapper.selectOne(queryWrapper);
}
}

View File

@ -7,7 +7,7 @@ spring:
main:
allow-bean-definition-overriding: true
profiles:
active: remote
active: dev
cloud:
nacos: #nacos监控
config: