Commit 40c55000 authored by huangcb's avatar huangcb

货主接口:优化发货地址、收货地址列表功能

parent 2299e8be
package com.esv.freight.customer.common.component;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.feign.FeignBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @description: 基础数据组件
* @project: freight-customer-service
* @name: com.esv.freight.customer.common.component.BaseDataComponent
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/08 15:57
* @version:1.0
*/
@Component
@Slf4j
public class BaseDataComponent {
private FeignBaseService feignBaseService;
private RedisComponent redisComponent;
public static final String ALL_REGION_MAP_CACHE_KEY = "freight-customer-service::base-data::city::allMap";
public static final Long ALL_REGION_MAP_CACHE_TIME = 36000L;
@Autowired
public BaseDataComponent(FeignBaseService feignBaseService, RedisComponent redisComponent) {
this.feignBaseService = feignBaseService;
this.redisComponent = redisComponent;
}
/**
* description 获取全国省市行政区划(键值对)
* param []
* return com.alibaba.fastjson.JSONObject
* author Administrator
* createTime 2020/05/08 16:10
**/
public JSONObject getAllRegionMap() {
JSONObject allRegionMap = new JSONObject();
if (redisComponent.hasKey(ALL_REGION_MAP_CACHE_KEY)) {
allRegionMap = JSONObject.parseObject((String) redisComponent.get(ALL_REGION_MAP_CACHE_KEY));
} else {
try {
JSONObject feignResultJson = feignBaseService.getAllRegionMap(new JSONObject());
if (ECode.SUCCESS.code() == feignResultJson.getIntValue("code")) {
allRegionMap = feignResultJson.getJSONObject("data");
redisComponent.set(ALL_REGION_MAP_CACHE_KEY, allRegionMap.toJSONString(), ALL_REGION_MAP_CACHE_TIME);
}
} catch (Exception e) {
log.error("调用[基础服务]获取全国省市行政区划(键值对)失败:" + e.getMessage());
}
}
return allRegionMap;
}
}
package com.esv.freight.customer.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.time.Duration;
/**
* @description: Cache配置类
* @project: freight-customer-service
* @name: com.esv.freight.customer.config.CacheConfig
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/05/08 15:53
* @version:1.0
*/
@Configuration
@EnableCaching
public class CacheConfig {
/**
* description 为SpringCache注册缓存管理器
* param [redisConnectionFactory]
* return org.springframework.cache.CacheManager
* author Administrator
* createTime 2020/03/19 14:26
**/
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
long timeToLive = 60L;
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
// 解决查询缓存转换异常的问题
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
// 配置序列化(解决乱码的问题)
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(timeToLive))
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer));
RedisCacheManager cacheManager = RedisCacheManager.builder(redisConnectionFactory)
.cacheDefaults(config)
.build();
return cacheManager;
}
/**
* RedisTemplate相关配置
* @param factory
* @return
*/
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
// 配置连接工厂
template.setConnectionFactory(factory);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jacksonSeial.setObjectMapper(om);
// 值采用json序列化
template.setValueSerializer(jacksonSeial);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
// 设置hash key 和value序列化模式
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(jacksonSeial);
template.afterPropertiesSet();
return template;
}
/**
* 对hash类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForHash();
}
/**
* 对redis字符串类型数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForValue();
}
/**
* 对链表类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForList();
}
/**
* 对无序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForSet();
}
/**
* 对有序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForZSet();
}
}
......@@ -25,4 +25,14 @@ public interface FeignBaseService {
**/
@PostMapping(value = "/base/batchId/generate")
JSONObject getBatchId(JSONObject bodyJson);
/**
* description 获取全国省市行政区划(键值对)
* param [bodyJson]
* return com.alibaba.fastjson.JSONObject
* author Administrator
* createTime 2020/05/08 15:54
**/
@PostMapping(value = "/base/geo/city/getAllRegionMap")
JSONObject getAllRegionMap(JSONObject bodyJson);
}
......@@ -135,7 +135,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
// 5.新增帐号审核记录
AuditHistoryEntity auditHistoryEntity = new AuditHistoryEntity();
auditHistoryEntity.setAccountId(Long.parseLong(String.valueOf(accountId)));
auditHistoryEntity.setAccountId(accountId);
auditHistoryEntity.setAuditStatus(GoodsOwnerConstants.OWNER_AUDIT_STATUS_SUCCESS);
auditHistoryEntity.setOperateUser(ReqUtils.getRequestHeader(GatewayHeaders.USER_ACCOUNT));
auditHistoryService.getBaseMapper().insert(auditHistoryEntity);
......@@ -279,7 +279,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
@Override
public Long registerAccount(String account) {
// 判断帐号是否存在
// 1.判断帐号是否已存在
AccountEntity accountEntity = this.getAccountRecordByAccount(account);
if (null != accountEntity) {
throw new EException(1001, errorMessageComponent.getGoodsOwnerAccountRegister1001());
......@@ -287,7 +287,21 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
accountEntity = new AccountEntity();
}
// 新增注册帐号
// 2.获取客户编码
JSONObject batchIdReqJson = new JSONObject();
batchIdReqJson.put("prefix", "HZ");
batchIdReqJson.put("formatter", "yyyyMMdd");
batchIdReqJson.put("length", 13);
JSONObject batchIdResJson;
try {
batchIdResJson = FeignUtils.getFeignResultData(feignBaseService.getBatchId(batchIdReqJson));
} catch (Exception e) {
log.error("调用[基础服务]生成客户编号失败:" + e.getMessage());
throw new EException("生成客户编号时发生错误");
}
String ownerNumber = batchIdResJson.getString("batchId");
// 3.新增帐号
accountEntity.setAccount(account);
accountEntity.setSalt(passwordComponent.generateAccountPwdSalt());
accountEntity.setSourceType(GoodsOwnerConstants.OWNER_SOURCE_TYPE_REGISTER);
......@@ -295,6 +309,20 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
this.baseMapper.insert(accountEntity);
Long accountId = accountEntity.getId();
// 4.新增帐号信息
InfoEntity infoEntity = new InfoEntity();
infoEntity.setOwnerNumber(ownerNumber);
infoEntity.setAccountId(accountId);
infoService.getBaseMapper().insert(infoEntity);
// 5.新增帐号审核记录
AuditHistoryEntity auditHistoryEntity = new AuditHistoryEntity();
auditHistoryEntity.setAccountId(accountId);
auditHistoryEntity.setAuditStatus(GoodsOwnerConstants.OWNER_AUDIT_STATUS_UNAUDITED);
auditHistoryEntity.setOperateUser(account);
auditHistoryEntity.setRemark("用户通过终端APP注册帐号");
auditHistoryService.getBaseMapper().insert(auditHistoryEntity);
return accountId;
}
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.common.component.BaseDataComponent;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.util.FeignUtils;
......@@ -36,10 +37,14 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
private ErrorMessageComponent errorMessageComponent;
private BaseDataComponent baseDataComponent;
@Autowired
public DeliveryAddressServiceImpl(FeignBaseService feignBaseService, ErrorMessageComponent errorMessageComponent) {
public DeliveryAddressServiceImpl(FeignBaseService feignBaseService, ErrorMessageComponent errorMessageComponent,
BaseDataComponent baseDataComponent) {
this.feignBaseService = feignBaseService;
this.errorMessageComponent = errorMessageComponent;
this.baseDataComponent = baseDataComponent;
}
@Override
......@@ -178,6 +183,7 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
// 数据转换
List<DeliveryAddressDto> addressDtoList = page.getRecords();
JSONObject allRegionMap = baseDataComponent.getAllRegionMap();
List<DeliveryAddressListVO> addressListVOList = new ArrayList<>();
addressDtoList.forEach(entity -> {
DeliveryAddressListVO vo = new DeliveryAddressListVO();
......@@ -188,6 +194,11 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
} else {
vo.setGoodsOwnerName(entity.getOwnerFullName());
}
StringBuffer sb = new StringBuffer().append(StringUtils.trimToEmpty(allRegionMap.getString(entity.getProvinceCode())))
.append(",").append(StringUtils.trimToEmpty(allRegionMap.getString(entity.getCityCode())))
.append(",").append(StringUtils.trimToEmpty(allRegionMap.getString(entity.getDistrictCode())))
.append(",").append(StringUtils.trimToEmpty(entity.getDetailAddress()));
vo.setFullAddress(sb.toString());
addressListVOList.add(vo);
});
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.common.component.BaseDataComponent;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.util.FeignUtils;
......@@ -36,10 +37,14 @@ public class ReceiveAddressServiceImpl extends ServiceImpl<ReceiveAddressDao, Re
private ErrorMessageComponent errorMessageComponent;
private BaseDataComponent baseDataComponent;
@Autowired
public ReceiveAddressServiceImpl(FeignBaseService feignBaseService, ErrorMessageComponent errorMessageComponent) {
public ReceiveAddressServiceImpl(FeignBaseService feignBaseService, ErrorMessageComponent errorMessageComponent,
BaseDataComponent baseDataComponent) {
this.feignBaseService = feignBaseService;
this.errorMessageComponent = errorMessageComponent;
this.baseDataComponent = baseDataComponent;
}
@Override
......@@ -178,6 +183,7 @@ public class ReceiveAddressServiceImpl extends ServiceImpl<ReceiveAddressDao, Re
// 数据转换
List<ReceiveAddressDto> addressDtoList = page.getRecords();
JSONObject allRegionMap = baseDataComponent.getAllRegionMap();
List<ReceiveAddressListVO> addressListVOList = new ArrayList<>();
addressDtoList.forEach(entity -> {
ReceiveAddressListVO vo = new ReceiveAddressListVO();
......@@ -188,6 +194,11 @@ public class ReceiveAddressServiceImpl extends ServiceImpl<ReceiveAddressDao, Re
} else {
vo.setGoodsOwnerName(entity.getOwnerFullName());
}
StringBuffer sb = new StringBuffer().append(StringUtils.trimToEmpty(allRegionMap.getString(entity.getProvinceCode())))
.append(",").append(StringUtils.trimToEmpty(allRegionMap.getString(entity.getCityCode())))
.append(",").append(StringUtils.trimToEmpty(allRegionMap.getString(entity.getDistrictCode())))
.append(",").append(StringUtils.trimToEmpty(entity.getDetailAddress()));
vo.setFullAddress(sb.toString());
addressListVOList.add(vo);
});
......
......@@ -33,21 +33,9 @@ public class DeliveryAddressListVO {
*/
private String addressName;
/**
* 省份代码
* 完整地址
*/
private String provinceCode;
/**
* 市代码
*/
private String cityCode;
/**
* 区县代码
*/
private String districtCode;
/**
* 详细地址
*/
private String detailAddress;
private String fullAddress;
/**
* 发货人
*/
......
......@@ -33,21 +33,9 @@ public class ReceiveAddressListVO {
*/
private String addressName;
/**
* 省份代码
* 完整地址
*/
private String provinceCode;
/**
* 市代码
*/
private String cityCode;
/**
* 区县代码
*/
private String districtCode;
/**
* 详细地址
*/
private String detailAddress;
private String fullAddress;
/**
* 收货人
*/
......
......@@ -21,6 +21,18 @@ spring:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
redis:
database: 0
host: 192.168.31.248
port: 6379
password:
timeout: 1000
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
#mybatis
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*Dao.xml
......
......@@ -21,6 +21,18 @@ spring:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
redis:
database: 0
host: 192.168.31.248
port: 6379
password:
timeout: 1000
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
#mybatis
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*Dao.xml
......
......@@ -3,8 +3,8 @@ server:
servlet:
context-path: /customer
nacos:
url: 127.0.0.1:8848
namespace: 548b506d-8d19-4d54-9715-bb0ac3a655b2
url: 192.168.31.248:8848
namespace: aad5aa26-5351-4e7a-a65e-ecb332f3c52c
group: DEFAULT_GROUP
spring:
application:
......
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