--优化国家地区缓存机制
This commit is contained in:
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package com.xjrsoft.module.mdm.client;
|
package com.xjrsoft.module.mdm.client;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import com.xjrsoft.common.constant.GlobalConstant;
|
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")
|
@FeignClient(value = GlobalConstant.CLIENT_PCITC_MDM_NAME, path = GlobalConstant.CLIENT_API_PRE + GlobalConstant.MDM_MODULE_PREFIX + "/countryRegion")
|
||||||
public interface ICountryRegionClient {
|
public interface ICountryRegionClient {
|
||||||
|
|
||||||
@GetMapping("/refreshCache")
|
@GetMapping("/getAllTranData")
|
||||||
void refreshCache();
|
Map<String,String> getAllTranData();
|
||||||
|
|
||||||
|
@GetMapping("/getTranById")
|
||||||
|
String getTranById(@RequestParam("id")String id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<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>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@ -1,20 +1,18 @@
|
|||||||
package com.xjrsoft.module.mdm.client;
|
package com.xjrsoft.module.mdm.client;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.xjrsoft.common.constant.GlobalConstant;
|
import com.xjrsoft.common.constant.GlobalConstant;
|
||||||
import com.xjrsoft.common.utils.RedisUtil;
|
|
||||||
import com.xjrsoft.common.utils.TenantUtil;
|
import com.xjrsoft.common.utils.TenantUtil;
|
||||||
import com.xjrsoft.module.mdm.entity.LngBRegion;
|
import com.xjrsoft.module.mdm.entity.LngBRegion;
|
||||||
import com.xjrsoft.module.mdm.service.ICountryRegionService;
|
import com.xjrsoft.module.mdm.service.ICountryRegionService;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: yjw
|
* @author: yjw
|
||||||
@ -24,26 +22,25 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(GlobalConstant.CLIENT_API_PRE + GlobalConstant.MDM_MODULE_PREFIX + "/countryRegion")
|
@RequestMapping(GlobalConstant.CLIENT_API_PRE + GlobalConstant.MDM_MODULE_PREFIX + "/countryRegion")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Slf4j
|
|
||||||
public class CountryRegionClientImpl implements ICountryRegionClient {
|
public class CountryRegionClientImpl implements ICountryRegionClient {
|
||||||
|
|
||||||
private final ICountryRegionService countryRegionService;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@GetMapping("/refreshCache")
|
public String getTranById(String code) {
|
||||||
public void refreshCache() {
|
countryRegionService.getByCode(code);
|
||||||
try {
|
return null;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,11 @@
|
|||||||
package com.xjrsoft.module.mdm.controller;
|
package com.xjrsoft.module.mdm.controller;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.esotericsoftware.kryo.kryo5.minlog.Log;
|
|
||||||
import com.pictc.datalog.DataOperationContent;
|
import com.pictc.datalog.DataOperationContent;
|
||||||
import com.pictc.datalog.DataOperationListener;
|
import com.pictc.datalog.DataOperationListener;
|
||||||
import com.pictc.enums.BusinessCode;
|
import com.pictc.enums.BusinessCode;
|
||||||
import com.pictc.enums.ExceptionCommonCode;
|
import com.pictc.enums.ExceptionCommonCode;
|
||||||
import com.pictc.enums.ValidEnum;
|
import com.pictc.enums.ValidEnum;
|
||||||
import com.pictc.utils.CollectionUtils;
|
import com.pictc.utils.CollectionUtils;
|
||||||
|
import com.xjrsoft.common.advice.tran.RegionDataProvider;
|
||||||
import com.xjrsoft.common.constant.GlobalConstant;
|
import com.xjrsoft.common.constant.GlobalConstant;
|
||||||
import com.xjrsoft.common.enums.YesOrNoEnum;
|
import com.xjrsoft.common.enums.YesOrNoEnum;
|
||||||
import com.xjrsoft.common.exception.BusinessException;
|
import com.xjrsoft.common.exception.BusinessException;
|
||||||
import com.xjrsoft.common.model.result.R;
|
import com.xjrsoft.common.model.result.R;
|
||||||
import com.xjrsoft.common.page.ConventPage;
|
import com.xjrsoft.common.page.ConventPage;
|
||||||
import com.xjrsoft.common.page.PageOutput;
|
import com.xjrsoft.common.page.PageOutput;
|
||||||
import com.xjrsoft.common.utils.CacheUtil;
|
|
||||||
import com.xjrsoft.common.utils.TreeUtil;
|
import com.xjrsoft.common.utils.TreeUtil;
|
||||||
import com.xjrsoft.common.utils.VoToColumnUtil;
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
||||||
import com.xjrsoft.module.common.db.utils.CommonCallUtils;
|
import com.xjrsoft.module.common.db.utils.CommonCallUtils;
|
||||||
import com.xjrsoft.module.datalog.service.DatalogService;
|
import com.xjrsoft.module.datalog.service.DatalogService;
|
||||||
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
||||||
import com.xjrsoft.module.mdm.dto.LngBRegionPageDto;
|
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.dto.UpdateLngBRegionDto;
|
||||||
import com.xjrsoft.module.mdm.entity.LngBRegion;
|
import com.xjrsoft.module.mdm.entity.LngBRegion;
|
||||||
import com.xjrsoft.module.mdm.enums.CountryRegionEnum;
|
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.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import shade.powerjob.com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title: 国家地区
|
* @title: 国家地区
|
||||||
@ -73,7 +67,11 @@ public class CountryRegionController {
|
|||||||
|
|
||||||
|
|
||||||
private final ICountryRegionService countryRegionService;
|
private final ICountryRegionService countryRegionService;
|
||||||
|
|
||||||
private final DatalogService dataService;
|
private final DatalogService dataService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RegionDataProvider tranProvider;
|
||||||
|
|
||||||
@GetMapping(value = "/page")
|
@GetMapping(value = "/page")
|
||||||
@ApiOperation(value="LngBRegion列表(分页)")
|
@ApiOperation(value="LngBRegion列表(分页)")
|
||||||
@ -139,10 +137,11 @@ public class CountryRegionController {
|
|||||||
@Override
|
@Override
|
||||||
public UpdateLngBRegionDto after(DataOperationContent<UpdateLngBRegionDto> content) {
|
public UpdateLngBRegionDto after(DataOperationContent<UpdateLngBRegionDto> content) {
|
||||||
String msg = CommonCallUtils.saveAfter(content.getTableName(),content.getIdValue());
|
String msg = CommonCallUtils.saveAfter(content.getTableName(),content.getIdValue());
|
||||||
if (StringUtils.isNotBlank(msg)) {
|
if (StringUtils.isNotBlank(msg)) {
|
||||||
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
|
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
|
||||||
}
|
}
|
||||||
refreshCahe();
|
UpdateLngBRegionDto obj = content.getObj();
|
||||||
|
tranProvider.saveData(obj.getCode(), obj.getFullName());
|
||||||
return content.getObj();
|
return content.getObj();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -173,10 +172,11 @@ public class CountryRegionController {
|
|||||||
@Override
|
@Override
|
||||||
public UpdateLngBRegionDto after(DataOperationContent<UpdateLngBRegionDto> content) {
|
public UpdateLngBRegionDto after(DataOperationContent<UpdateLngBRegionDto> content) {
|
||||||
String msg = CommonCallUtils.saveAfter(content.getTableName(),content.getIdValue());
|
String msg = CommonCallUtils.saveAfter(content.getTableName(),content.getIdValue());
|
||||||
if (StringUtils.isNotBlank(msg)) {
|
if (StringUtils.isNotBlank(msg)) {
|
||||||
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
|
throw new BusinessException(BusinessCode.ofArgs(ExceptionCommonCode.DB_FUNCTION_EXEC_ERROR, msg));
|
||||||
}
|
}
|
||||||
refreshCahe();
|
UpdateLngBRegionDto obj = content.getObj();
|
||||||
|
tranProvider.saveData(obj.getCode(), obj.getFullName());
|
||||||
return content.getObj();
|
return content.getObj();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -283,12 +283,6 @@ public class CountryRegionController {
|
|||||||
return R.ok(countryRegionService.getRegionByParentId(code,excludeType));
|
return R.ok(countryRegionService.getRegionByParentId(code,excludeType));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshCahe(){
|
|
||||||
//异步更新
|
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
CacheUtil.refreshRegionList();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -17,4 +17,6 @@ public interface ICountryRegionService extends IService<LngBRegion> {
|
|||||||
|
|
||||||
Map<String, Object> getRegionByParentId(String code, String excludeType);
|
Map<String, Object> getRegionByParentId(String code, String excludeType);
|
||||||
|
|
||||||
|
LngBRegion getByCode(String code);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ spring:
|
|||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
profiles:
|
profiles:
|
||||||
active: remote
|
active: dev
|
||||||
cloud:
|
cloud:
|
||||||
nacos: #nacos监控
|
nacos: #nacos监控
|
||||||
config:
|
config:
|
||||||
|
|||||||
Reference in New Issue
Block a user