去除省市区及大区业务区域的缓存
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.RedisConstant;
|
||||
import com.cool.store.dto.response.MDMResultDTO;
|
||||
import com.cool.store.entity.MDMAreaDO;
|
||||
import com.cool.store.exception.ApiException;
|
||||
@@ -13,13 +10,11 @@ import com.cool.store.response.mdm.BusinessRegion;
|
||||
import com.cool.store.service.MDMAreaService;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -41,13 +36,13 @@ public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
*/
|
||||
@Override
|
||||
public List<MDMAreaDO> getProvince() {
|
||||
String provincesJson = redisUtilPool.getString(RedisConstant.MDM_AREA_PROVINCE);
|
||||
if (StringUtils.isNotEmpty(provincesJson)) {
|
||||
return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
|
||||
}
|
||||
// String provincesJson = redisUtilPool.getString(RedisConstant.MDM_AREA_PROVINCE);
|
||||
// if (StringUtils.isNotEmpty(provincesJson)) {
|
||||
// return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
|
||||
// }
|
||||
List<MDMAreaDO> areaDOList = mdmAreaMapper.getProvince();
|
||||
//过期时间三小时
|
||||
redisUtilPool.setString(RedisConstant.MDM_AREA_PROVINCE, JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
// redisUtilPool.setString(RedisConstant.MDM_AREA_PROVINCE, JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
return areaDOList;
|
||||
}
|
||||
|
||||
@@ -57,17 +52,17 @@ public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
*/
|
||||
@Override
|
||||
public List<MDMAreaDO> getSonArea(String code) {
|
||||
String provincesJson = redisUtilPool.getString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code));
|
||||
if (StringUtils.isNotEmpty(provincesJson)) {
|
||||
return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
|
||||
}
|
||||
// String provincesJson = redisUtilPool.getString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code));
|
||||
// if (StringUtils.isNotEmpty(provincesJson)) {
|
||||
// return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
|
||||
// }
|
||||
List<MDMAreaDO> areaDOList = mdmAreaMapper.getSonArea(code);
|
||||
//数据库也没有该数据就缓存空值,但是只缓存一分钟
|
||||
if (areaDOList == null || areaDOList.size() == 0) {
|
||||
redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), "", 60);
|
||||
}
|
||||
// if (areaDOList == null || areaDOList.size() == 0) {
|
||||
// redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), "", 60);
|
||||
// }
|
||||
//过期时间三小时
|
||||
redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
// redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
|
||||
return areaDOList;
|
||||
}
|
||||
|
||||
@@ -114,16 +109,16 @@ public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
*/
|
||||
@Override
|
||||
public List<BelongRegion> getBelongRegion() throws ApiException {
|
||||
String belongRegionsString = redisUtilPool.getString(RedisConstant.MDM_BELONG_REGION);
|
||||
if (StringUtil.isNotEmpty(belongRegionsString)) {
|
||||
return (List<BelongRegion>) JSONObject.parseObject(belongRegionsString, List.class);
|
||||
}
|
||||
// String belongRegionsString = redisUtilPool.getString(RedisConstant.MDM_BELONG_REGION);
|
||||
// if (StringUtil.isNotEmpty(belongRegionsString)) {
|
||||
// return (List<BelongRegion>) JSONObject.parseObject(belongRegionsString, List.class);
|
||||
// }
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", mdmHttpRequest.getMdmAccessToken());
|
||||
ResponseEntity<MDMResultDTO> belongRegionResp = mdmHttpRequest.getBelongRegion(headers);
|
||||
List<BelongRegion> belongRegions = (List<BelongRegion>) belongRegionResp.getBody().getData();
|
||||
//缓存,半个小时过期
|
||||
redisUtilPool.setString(RedisConstant.MDM_BELONG_REGION, JSON.toJSONString(belongRegions), 30 * 60);
|
||||
// redisUtilPool.setString(RedisConstant.MDM_BELONG_REGION, JSON.toJSONString(belongRegions), 30 * 60);
|
||||
return belongRegions;
|
||||
}
|
||||
|
||||
@@ -133,16 +128,16 @@ public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
*/
|
||||
@Override
|
||||
public List<BusinessRegion> getBusinessRegion() throws ApiException {
|
||||
String belongRegionsString = redisUtilPool.getString(RedisConstant.MDM_BUSINESS_REGION);
|
||||
if (StringUtil.isNotEmpty(belongRegionsString)) {
|
||||
return (List<BusinessRegion>) JSONObject.parseObject(belongRegionsString, List.class);
|
||||
}
|
||||
// String belongRegionsString = redisUtilPool.getString(RedisConstant.MDM_BUSINESS_REGION);
|
||||
// if (StringUtil.isNotEmpty(belongRegionsString)) {
|
||||
// return (List<BusinessRegion>) JSONObject.parseObject(belongRegionsString, List.class);
|
||||
// }
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", mdmHttpRequest.getMdmAccessToken());
|
||||
ResponseEntity<MDMResultDTO> belongRegionResp = mdmHttpRequest.getBusinessRegion(headers);
|
||||
List<BusinessRegion> businessRegions = (List<BusinessRegion>) belongRegionResp.getBody().getData();
|
||||
//缓存,半个小时过期
|
||||
redisUtilPool.setString(RedisConstant.MDM_BUSINESS_REGION, JSON.toJSONString(businessRegions), 30 * 60);
|
||||
// redisUtilPool.setString(RedisConstant.MDM_BUSINESS_REGION, JSON.toJSONString(businessRegions), 30 * 60);
|
||||
return businessRegions;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user