Browse Source

CustomerAgencyDTO=》AgencyInfoCache

release
yinzuomei 3 years ago
parent
commit
10fc17df91
  1. 22
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/AgencyInfoCache.java
  2. 8
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java
  3. 50
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java

22
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/AgencyInfoCache.java

@ -145,4 +145,26 @@ public class AgencyInfoCache implements Serializable {
* 中心位置纬度
*/
private String latitude;
/**
* 组织编码
*/
private String code;
/**
* 负责人姓名
*/
private String contacts;
/**
* 联系电话
*/
private String mobile;
//内部接口使用
/**
* open:当前客户新增组织需要选择areaCodeclosed: 无需选择区域编码
*/
private String areaCodeSwitch;
}

8
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java

@ -20,7 +20,7 @@ package com.epmet.redis;
import cn.hutool.core.bean.BeanUtil;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@ -44,19 +44,19 @@ public class CustomerAgencyRedis {
redisUtils.delete(key);
}
public void set(String agencyId, CustomerAgencyDTO value){
public void set(String agencyId, AgencyInfoCache value){
String key = RedisKeys.getAgencyByIdKey(agencyId);
Map<String, Object> map = BeanUtil.beanToMap(value, false, true);
redisUtils.hMSet(key, map);
}
public CustomerAgencyDTO get(String agencyId){
public AgencyInfoCache get(String agencyId){
String key = RedisKeys.getAgencyByIdKey(agencyId);
Map<String, Object> resultMap = redisUtils.hGetAll(key);
if (CollectionUtils.isEmpty(resultMap)) {
return null;
}
return BeanUtil.mapToBean(resultMap, CustomerAgencyDTO.class, true);
return BeanUtil.mapToBean(resultMap, AgencyInfoCache.class, true);
}
}

50
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java

@ -20,6 +20,7 @@ package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.epmet.commons.tools.constant.Constant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
@ -490,16 +491,53 @@ public class AgencyServiceImpl implements AgencyService {
@Override
public CustomerAgencyDTO getAgencyById(String agencyId) {
CustomerAgencyDTO cachedAgency = customerAgencyRedis.get(agencyId);
if (cachedAgency == null) {
cachedAgency = new CustomerAgencyDTO();
AgencyInfoCache agencyInfoCache = customerAgencyRedis.get(agencyId);
if (agencyInfoCache == null) {
agencyInfoCache = new AgencyInfoCache();
CustomerAgencyEntity agencyEntity = customerAgencyDao.selectById(agencyId);
if (agencyEntity != null) {
BeanUtils.copyProperties(agencyEntity, cachedAgency);
//设置行政地区编码全路径
if (StringUtils.isNotBlank(agencyEntity.getAreaCode()) && StringUtils.isNotBlank(agencyEntity.getParentAreaCode())) {
agencyInfoCache.setAreaCodePath(queryAreaCodePath(agencyEntity));
}
BeanUtils.copyProperties(agencyEntity, agencyInfoCache);
}
customerAgencyRedis.set(agencyId, cachedAgency);
customerAgencyRedis.set(agencyId, agencyInfoCache);
}
CustomerAgencyDTO customerAgencyDTO=ConvertUtils.sourceToTarget(agencyInfoCache,CustomerAgencyDTO.class);
return customerAgencyDTO;
}
private List<String> queryAreaCodePath(CustomerAgencyEntity customerAgencyEntity) {
List<String> areaCodePath = new ArrayList<>();
switch (customerAgencyEntity.getLevel()) {
case Constant.COMMUNITY:
areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.TWO));
areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.FOUR));
areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.SIX));
areaCodePath.add(customerAgencyEntity.getParentAreaCode());
areaCodePath.add(customerAgencyEntity.getAreaCode());
break;
case Constant.STREET:
areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.TWO));
areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.FOUR));
areaCodePath.add(customerAgencyEntity.getParentAreaCode());
areaCodePath.add(customerAgencyEntity.getAreaCode());
break;
case Constant.DISTRICT:
areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.TWO));
areaCodePath.add(customerAgencyEntity.getParentAreaCode());
areaCodePath.add(customerAgencyEntity.getAreaCode());
break;
case Constant.CITY:
areaCodePath.add(customerAgencyEntity.getParentAreaCode());
areaCodePath.add(customerAgencyEntity.getAreaCode());
break;
case Constant.PROVINCE:
areaCodePath.add(customerAgencyEntity.getAreaCode());
break;
}
return cachedAgency;
return areaCodePath;
}
@Override

Loading…
Cancel
Save