Authored by mlge

Merge branch 'test6.8.4' of http://git.yoho.cn/ufo/yohoufo-fore into test6.8.4

package com.yohoufo.common.interceptor;
import com.yohoufo.common.annotation.InnerApi;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.net.InetAddress;
/**
* 内网IP 接口访问控制
* 主要实现: 打上 注解 @InnerApi 的接口 需要校验是否是内网ip
*/
public class InnerApiInterceptor implements HandlerInterceptor {
private final Logger logger = LoggerFactory.getLogger(InnerApiInterceptor.class);
//是否启用
private boolean enableDebug = false;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (isEnableDebug() && "XYZ".equals(request.getParameter("debug"))) {
return true;
}
// 不是内部接口
if (!hasInnerApiAnnotation(handler)) {
return true;
}
String ip = getRemoteIP(request);
try {
// 判断是否是内网IP
String[] ipArr = ip.split(",");
InetAddress inetAddress = InetAddress.getByName(ipArr[ipArr.length - 1].trim());
if (inetAddress.isSiteLocalAddress()) {
// 是内网IP
return true;
} else {
// 不是内网接口拒绝访问
logger.info("handler inner api interceptor, {} can not run inner api.", ip);
return false;
}
} catch (Exception e) {
// 判断是否内网IP异常
logger.warn("handler inner api interceptor fail, decide {} is site local address", ip, e);
return true;
}
}
private boolean hasInnerApiAnnotation(Object handler) {
try {
if (handler.getClass().isAssignableFrom(HandlerMethod.class)) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method bridgedMethod = handlerMethod.getMethod();
return bridgedMethod.isAnnotationPresent(InnerApi.class);
} else {
return false;
}
} catch (Exception e) {
// 判断是否存在InnerApi annotation 异常
logger.warn("handler inner api interceptor fail, find inner api annotation", e);
return false;
}
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
/**
* 获取用户IP
*
* @param httpServletRequest 1) x-forwarded-for 2).getRemoteAddr(); ---> , 最后一个IP
* @return 用户IP
*/
private String getRemoteIP(final HttpServletRequest httpServletRequest) {
String ip = httpServletRequest.getHeader("X-Forwarded-For");
if (StringUtils.isEmpty(ip)) {
ip = httpServletRequest.getRemoteAddr();
}
return ip;
}
public boolean isEnableDebug() {
return enableDebug;
}
public void setEnableDebug(boolean enableDebug) {
this.enableDebug = enableDebug;
}
}
... ...
... ... @@ -45,6 +45,9 @@
</property>
</bean>
<bean id="localIpInterceptor" class="com.yohoufo.common.interceptor.RemoteIPInterceptor" />
<bean id="innerApiInterceptor" class="com.yohoufo.common.interceptor.InnerApiInterceptor">
<property name="enableDebug" value="${is_debug_enable:false}" />
</bean>
<!-- end -->
<bean id="redisGwCacheClient" class="com.yohoufo.common.cache.RedisGwCacheClient">
... ...
... ... @@ -18,16 +18,20 @@ public interface ExpressInfoMapper {
int updateByPrimaryKey(ExpressInfo record);
/**
/*
* 根据uid和快递单号查询快递信息
* @param uid
* @param orderCode 订单号
* @param expressType 物流类型; 1:卖家到鉴定中心,2:鉴定中心到买家,3:鉴定中心退回到卖家
* @return
*/
List<ExpressInfo> selectAllExpressInfo(@Param("uid") Integer uid, @Param("orderCode") Long orderCode, @Param("expressType") Integer expressType);
//List<ExpressInfo> selectAllExpressInfo(@Param("uid") Integer uid, @Param("orderCode") Long orderCode, @Param("expressType") Integer expressType);
List<ExpressInfo> selectExpressInfoListByWaybillCodeAndLogisticsType(@Param("waybillCode") String waybillCode, @Param("logisticsType") Integer logisticsType);
//ExpressInfo selectLast(@Param("orderCode") Long orderCode, @Param("expressType") Integer expressType);
ExpressInfo selectLast(@Param("orderCode") Long orderCode, @Param("expressType") Integer expressType);
List<ExpressInfo> selectByOrderCodeAndExpressType(@Param("orderCode") Long orderCode, @Param("expressType") Integer expressType);
/**
* 根据uid、订单号、物流类型和快递状态查询快递信息
... ...
... ... @@ -20,11 +20,10 @@ public interface ExpressRecordMapper {
/**
* 根据uid、订单号、物流类型和快递状态查询快递信息
* @param uid
* @param orderCode
* @param expressType 物流类型; 1:卖家到鉴定中心,2:鉴定中心到买家,3:鉴定中心退回到卖家
* @return
*/
ExpressRecord selectByUidAndOrderCodeAndExpressType(@Param("uid") Integer uid, @Param("orderCode") Long orderCode, @Param("expressType") Integer expressType);
ExpressRecord selectByOrderCodeAndExpressType( @Param("orderCode") Long orderCode, @Param("expressType") Integer expressType);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class ExpressRecord {
private Integer id;
... ...
... ... @@ -145,12 +145,29 @@
where id = #{id,jdbcType=INTEGER}
</update>
<!--
<select id="selectAllExpressInfo" resultMap="BaseResultMap">
SELECT id, uid, order_code, waybill_code, accept_address, accept_remark, logistics_type, create_time, express_type, state
FROM express_info
where uid = #{uid} and order_code = #{orderCode} and express_type = #{expressType}
ORDER BY create_time DESC
</select>
-->
<select id="selectByOrderCodeAndExpressType" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM express_info
where order_code = #{orderCode} and express_type = #{expressType}
ORDER BY create_time DESC
</select>
<select id="selectExpressInfoListByWaybillCodeAndLogisticsType" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM express_info
where waybill_code = #{waybillCode} and logistics_type = #{logisticsType}
ORDER BY create_time DESC
</select>
<select id="selectLast" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
... ...
... ... @@ -34,10 +34,10 @@
limit 1
</select>
<select id="selectByUidAndOrderCodeAndExpressType" resultMap="BaseResultMap">
<select id="selectByOrderCodeAndExpressType" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM express_record
where uid = #{uid} and order_code = #{orderCode} and express_type = #{expressType}
where order_code = #{orderCode} and express_type = #{expressType}
limit 1
</select>
... ...
... ... @@ -171,7 +171,10 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
long orderCode = erpExpressBo.getOrderCode();
int uid = erpExpressBo.getUid();
int createTime = DateUtil.getCurrentTimeSecond();
int createTime = erpExpressBo.getCreateTime();
if(createTime<=0){
createTime = DateUtil.getCurrentTimeSecond();
}
List<ExpressInfo> expressInfos = expressInfoMapper.selectByOrderCodeAndStatesAndUidAndExpressType(uid, orderCode, Lists.newArrayList(ExpressInfoConstant.EXPRESS_STATUS_SIGN), expressType);
processExpressInfo(expressInfos, state, logisticsType, orderCode, waybillCode, acceptAddress, acceptRemark, createTime, uid, expressType);
... ...
... ... @@ -18,6 +18,8 @@ import java.util.Objects;
*/
public interface IExpressInfoService {
void triggerExpressMQ(Integer uid,Integer expressCompanyId,Long orderCode,String wayBillCode,String mobile );
/**
* 卖家发货到鉴定中心
*
... ... @@ -84,7 +86,7 @@ public interface IExpressInfoService {
//Integer getExpressType(Long orderCode);
ExpressInfoRespBo queryLastExpressDetailInfo(Long orderCode,int type);
//ExpressInfoRespBo queryLastExpressDetailInfo(Long orderCode,int type);
ExpressInfoDetail getLastExpressInfoDetail(TabType actor,int status, Long orderCode);
/**
... ...
... ... @@ -11,10 +11,7 @@ import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.BillTradeStatus;
import com.yohoufo.order.common.RefundCase;
... ... @@ -93,6 +90,9 @@ public class AppraiseService {
@Autowired
private AppraiseAddressService appraiseAddressService;
@Autowired
private ExpressRecordMapper expressRecordMapper;
public ApiResponse appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum,String mobile){
ApiResponse apiResponse=new ApiResponse();
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
... ... @@ -229,14 +229,11 @@ public class AppraiseService {
* 触发物流
*/
public void triggerSellerToPlatformExpress(AppraiseExpressInfoBo appraiseExpressInfoBo ){
Integer expressCompanyId = appraiseExpressInfoBo.getExpressCompanyId();
LOGGER.info("AppraiseService triggerSellerToPlatformExpress enter , appraiseExpressInfoBo {} ",appraiseExpressInfoBo);
String wayBillCode = appraiseExpressInfoBo.getWayBillCode();
Long orderCode = appraiseExpressInfoBo.getOrderCode();
Integer depotNum = appraiseExpressInfoBo.getDepotNum();
if(depotNum==null){
depotNum = 0;
}
if(expressCompanyId==null|| StringUtils.isBlank(wayBillCode)){
if(StringUtils.isBlank(wayBillCode)||orderCode==null){
LOGGER.warn("triggerSellerToPlatformExpress error param {}", appraiseExpressInfoBo);
throw new ServiceException(ServiceError.PARAM_ERROR);
}
... ... @@ -244,16 +241,29 @@ public class AppraiseService {
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if (buyerOrder == null){
LOGGER.warn("returnBack getOrderInfo order not exist, orderCode {}", orderCode);
LOGGER.warn("triggerSellerToPlatformExpress getOrderInfo order not exist, orderCode {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
Integer uid = buyerOrder.getSellerUid();
String mobile ="";
AppraiseAddressResp appraiseAddressResp =appraiseAddressService.queryInitAddressByDepotNum(depotNum);
if(appraiseAddressResp!=null){
mobile = appraiseAddressResp.getMobile();
//只有卖家已发货才能更改物流
if(buyerOrder.getStatus().byteValue() == OrderStatus.SELLER_SEND_OUT.getCode()) {
ExpressRecord record = expressRecordMapper.selectByOrderCodeAndExpressType(orderCode,expressInfoService.getExpressTypeSeller(OrderStatus.SELLER_SEND_OUT.getCode()));
LOGGER.info("triggerSellerToPlatformExpress begin trigger , orderCode {} ,record = {}", orderCode,record);
if(record!=null&&StringUtils.equals(wayBillCode,record.getWaybillCode())){
Integer uid = record.getUid();
String mobile ="";
AppraiseAddressResp appraiseAddressResp =appraiseAddressService.queryInitAddressByDepotNum(record.getDepotNum());
if(appraiseAddressResp!=null){
mobile = appraiseAddressResp.getMobile();
}
expressInfoService.triggerExpressMQ(uid,record.getLogisticsType(),orderCode,wayBillCode,mobile);
}else{
LOGGER.warn("triggerSellerToPlatformExpress begin trigger fail ,express record is null or wayBillCode not the same, orderCode {},changed wayBillCode {},record {} ", orderCode,wayBillCode,record);
}
}else{
LOGGER.info("triggerSellerToPlatformExpress not trigger because of error status , orderCode {} ,status {}", orderCode,buyerOrder.getStatus());
}
//sendExpressMQ(uid,expressCompanyId,orderCode,wayBillCode,mobile);
}
/**
... ...
... ... @@ -229,6 +229,12 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
expressRecordMapper.insert(record);
}
@Override
public void triggerExpressMQ(Integer uid,Integer expressCompanyId,Long orderCode,String wayBillCode,String mobile ){
// 发送mq获取物流信息
sendExpressMQ(uid,expressCompanyId,orderCode,wayBillCode,mobile);
LOGGER.info("triggerExpressMQ end ! send express to erp ");
}
/**
* 发送mq消息,获取物流信息
*/
... ... @@ -286,12 +292,12 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
ExpressInfoRespBo expressInfoRespBo = new ExpressInfoRespBo();
Integer expressType = getExpressType(buyerOrder.getStatus(), actor);
LOGGER.info("getExpressType result = {}", expressType);
List<ExpressInfo> expressInfoList = expressInfoMapper.selectAllExpressInfo(uid, orderCode, expressType);
List<ExpressInfo> expressInfoList = getExpressInfoListByStage( orderCode, expressType);
processExpressInfo(expressInfoList, expressInfoRespBo);
//没有物流详情,但是有物流单号信息
if(CollectionUtils.isEmpty(expressInfoList)){
ExpressRecord expressRecord = expressRecordMapper.selectByUidAndOrderCodeAndExpressType(uid,orderCode,expressType);
ExpressRecord expressRecord = expressRecordMapper.selectByOrderCodeAndExpressType(orderCode,expressType);
if(expressRecord!=null){
expressInfoRespBo.setExpressInfoDetailList(new ArrayList<>());
// 快递单号
... ... @@ -316,14 +322,14 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
expressInfoRespBo.setExpressSender(EnumExpressSender.getSenderName(ExpressInfoConstant.EXPRESS_TYPE_1.intValue()));
}
//卖家物流详细
List<ExpressInfo> previousExpressInfoList = expressInfoMapper.selectAllExpressInfo(buyerOrder.getSellerUid(), orderCode, ExpressInfoConstant.EXPRESS_TYPE_1);
List<ExpressInfo> previousExpressInfoList = getExpressInfoListByStage( orderCode, ExpressInfoConstant.EXPRESS_TYPE_1);
constructExpressInfo(previousExpressInfoList, supplementExpressInfoDetailList);
}else if(ExpressInfoConstant.EXPRESS_TYPE_3.intValue()==expressType.intValue()
||ExpressInfoConstant.EXPRESS_TYPE_REBACK.intValue()==expressType.intValue()){
//卖家这个时候看自己上一阶段的物流
//如果还没有新的物流信息,卖家显示上一个阶段的物流
if(StringUtils.isBlank(expressInfoRespBo.getExpressSender())){
ExpressRecord expressRecord = expressRecordMapper.selectByUidAndOrderCodeAndExpressType(uid,orderCode,ExpressInfoConstant.EXPRESS_TYPE_1);
ExpressRecord expressRecord = expressRecordMapper.selectByOrderCodeAndExpressType(orderCode,ExpressInfoConstant.EXPRESS_TYPE_1);
if(expressRecord!=null){
// 快递单号
expressInfoRespBo.setWayBillCode(expressRecord.getWaybillCode());
... ... @@ -336,7 +342,7 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
expressInfoRespBo.setExpressInfoDetailList(new ArrayList<>());
}
}
List<ExpressInfo> previousExpressInfoList = expressInfoMapper.selectAllExpressInfo(uid, orderCode, ExpressInfoConstant.EXPRESS_TYPE_1);
List<ExpressInfo> previousExpressInfoList = getExpressInfoListByStage(orderCode, ExpressInfoConstant.EXPRESS_TYPE_1);
constructExpressInfo(previousExpressInfoList, supplementExpressInfoDetailList);
}
}
... ... @@ -345,15 +351,49 @@ public class ExpressInfoServiceImpl implements IExpressInfoService {
}
@Override
public ExpressInfoRespBo queryLastExpressDetailInfo(Long orderCode, int expressType) {
/**
* 获取物流详情
* 逻辑变更:以前是直接从express_info获取
* 变更为:先从express_record获取物流单号,再通过物流单号关联express_info ,从而解决多个订单一个物流号问题
* @return
*/
private List<ExpressInfo> getExpressInfoListByStage(Long orderCode, Integer expressType){
ExpressRecord expressRecord = expressRecordMapper.selectByOrderCodeAndExpressType(orderCode,expressType);
if(expressRecord==null){
LOGGER.info("getExpressInfoListByStage out because of empty record ,orderCode = {} ,expressType = {} ",orderCode,expressType);
return Lists.newArrayList();
}
String waybillCode = expressRecord.getWaybillCode();
Integer logisticsType = expressRecord.getLogisticsType();
List<ExpressInfo> list = expressInfoMapper.selectByOrderCodeAndExpressType(orderCode,expressType);
//有可能存在一个订单号,多个物流的情况,比如原来的物流填错了,修改了新的物流,只保留新的物流号的信息
if(CollectionUtils.isNotEmpty(list)){
list = list.stream().filter(info -> StringUtils.equals(waybillCode,info.getWaybillCode())).collect(Collectors.toList());
}
if(CollectionUtils.isNotEmpty(list)){
LOGGER.info("getExpressInfoListByStage success have data in express info ,orderCode = {} ,expressType = {} ",orderCode,expressType);
return list;
}
LOGGER.info("getExpressInfoListByStage begin , orderCode = {} ,expressType = {}, expressRecord = {} ",orderCode,expressType,expressRecord);
List<ExpressInfo> expressInfoList = expressInfoMapper.selectExpressInfoListByWaybillCodeAndLogisticsType(waybillCode,logisticsType);
return expressInfoList;
}
//@Override
private ExpressInfoRespBo queryLastExpressDetailInfo(Long orderCode, int expressType) {
LOGGER.info("queryLastExpressDetailInfo orderCode {}, expressType {}", orderCode, expressType);
ExpressInfoRespBo expressInfoRespBo = new ExpressInfoRespBo();
LOGGER.info("queryLastExpressDetailInfo, getExpressType result = {}", expressType);
ExpressInfo last = expressInfoMapper.selectLast(orderCode, expressType);
if (last == null){
List<ExpressInfo> expressInfoList_All = getExpressInfoListByStage(orderCode, expressType);
if (expressInfoList_All==null||expressInfoList_All.size()<=0){
return null;
}
//已经是按照时间倒叙排列了,直接取第一条就可以了
ExpressInfo last=expressInfoList_All.get(0);
List<ExpressInfo> expressInfoList = Arrays.asList(last);
processExpressInfo(expressInfoList, expressInfoRespBo);
LOGGER.info("queryLastExpressDetailInfo.queryExpressDetailInfo result = {}", JSON.toJSONString(expressInfoRespBo));
... ...
... ... @@ -70,10 +70,6 @@ public class ShoppingServiceImpl implements IShoppingService {
@Autowired
private UserProxyService userProxyService;
//
// @Value("${buyer.delivery.way.cost.sf:15}")
// private double delivery_way_sf_cost;
@Autowired
private InBoxFacade inBoxFacade;
... ... @@ -121,7 +117,7 @@ public class ShoppingServiceImpl implements IShoppingService {
PaymentResponse response = new PaymentResponse();
response.setPaymentWay(shoppingSupport.getPaymentWay());
response.setDeliveryWay(shoppingSupport.getDeliverWay());
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeContext.getChargeResult().getShippingAmount()));
response.setGood(shoppingSupport.getGoodsInfo(skupGood));
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
... ...
package com.yohoufo.order.service.support;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -13,14 +14,15 @@ import org.springframework.stereotype.Component;
* @date 2018/12/19 19:04
*/
@Component
@Slf4j
public class DeliveryWayCostSupport {
@Autowired
private UfoServiceCaller ufoServiceCaller;
private ThreadLocal<Double> costOfSf = ThreadLocal.withInitial(() -> {
public double getCostOfSf() {
String key = "buyer.delivery.way.cost.sf";
double defaultValue = 15;
double defaultValue = 25;
try {
ApiResponse resp = ufoServiceCaller.call(
... ... @@ -34,12 +36,9 @@ public class DeliveryWayCostSupport {
}
} catch (Exception e) {
log.warn("request cost of sf fail", e);
return defaultValue;
}
});
public double getCostOfSf() {
return costOfSf.get();
}
}
... ...
... ... @@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.order.charge.ChargeContext;
import com.yohoufo.order.charge.model.ChargeResult;
import com.yohoufo.order.charge.model.CouponPayResult;
import com.yohoufo.order.model.response.GoodsInfo;
... ... @@ -16,14 +17,11 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.function.Supplier;
@Service
public class ShoppingSupport {
@Autowired
private DeliveryWayCostSupport deliveryWayCostSupport;
/**
* 支付方式
* @return
... ... @@ -41,10 +39,7 @@ public class ShoppingSupport {
* 配送方式
* @return
*/
public PaymentResponse.DeliveryWay getDeliverWay() {
double deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
public PaymentResponse.DeliveryWay getDeliverWay(double deliveryWayCost) {
// 快递方式
PaymentResponse.DeliveryWay deliveryWay = new PaymentResponse.DeliveryWay();
deliveryWay.setDeliveryWayId(OrderConstant.DELIVERY_WAY_SF);
... ...
... ... @@ -3,6 +3,8 @@ package com.yohoufo.resource.controller;
import com.yoho.tools.docs.ApiOperation;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.annotation.InnerApi;
import com.yohoufo.resource.service.IConfigTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -57,6 +59,8 @@ public class ConfigTypeController {
@RequestMapping(params = "method=ufo.resource.updateConfigTypeContent")
@ResponseBody
@IgnoreSession
@IgnoreSignature
@InnerApi
public ApiResponse updateConfigTypeContent(@RequestParam(name = "code") String code,
@RequestParam(name = "content") String content) {
int rows = configTypeService.updateContentByCode(code, content);
... ...
... ... @@ -16,6 +16,7 @@ import com.yohoufo.resource.util.RedisLoadingCache;
import com.yohoufo.resource.util.ValueSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -28,7 +29,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
public class ConfigTypeServiceImpl implements IConfigTypeService {
public class ConfigTypeServiceImpl implements IConfigTypeService, InitializingBean {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigTypeServiceImpl.class);
private LocalCache localCache = new LocalCache();
... ... @@ -44,41 +45,49 @@ public class ConfigTypeServiceImpl implements IConfigTypeService {
@Redis("yohoNoSyncRedis")
private YHValueOperations valueOperations;
private final RedisLoadingCache<String, ConfigType> codeConfigTypeRedisCache = RedisCacheBuilder.newBuilder()
.withYhRedis(redisTemplate, valueOperations)
.withExpire(5, TimeUnit.SECONDS)
.withKeySerializer(new KeySerializer<String>() {
@Override
public RedisKeyBuilder serialize(String obj) {
return new RedisKeyBuilder().appendFixed("ufo:resources:configType:code:").appendVar(obj);
}
@Override
public String deserialize(RedisKeyBuilder keyBuilder) {
return keyBuilder.getKey().substring(keyBuilder.getKey().lastIndexOf("ufo:resources:configType:") + 1);
}
})
.withValueSerializer(new ValueSerializer<ConfigType>() {
@Override
public String serialize(ConfigType obj) {
return JSONObject.toJSONString(obj);
}
@Override
public ConfigType deserialize(String objectData) {
return JSONObject.parseObject(objectData, ConfigType.class);
}
})
.build(new CacheLoader<String, ConfigType>() {
@Override
public ConfigType load(String code) throws Exception {
return configTypeMapper.selectByCode(code);
}
});
private RedisLoadingCache<String, ConfigType> codeConfigTypeRedisCache;
@Override
public void afterPropertiesSet() throws Exception {
codeConfigTypeRedisCache = RedisCacheBuilder.newBuilder()
.withYhRedis(redisTemplate, valueOperations)
.withExpire(1, TimeUnit.HOURS)
.withKeySerializer(new KeySerializer<String>() {
private String keyPrefix = "ufo:resources:configType:code:";
@Override
public RedisKeyBuilder serialize(String obj) {
return new RedisKeyBuilder().appendFixed(keyPrefix).appendVar(obj);
}
@Override
public String deserialize(RedisKeyBuilder keyBuilder) {
return keyBuilder.getKey().substring(keyBuilder.getKey().lastIndexOf(keyPrefix) + 1);
}
})
.withValueSerializer(new ValueSerializer<ConfigType>() {
@Override
public String serialize(ConfigType obj) {
return JSONObject.toJSONString(obj);
}
@Override
public ConfigType deserialize(String objectData) {
return JSONObject.parseObject(objectData, ConfigType.class);
}
})
.build(new CacheLoader<String, ConfigType>() {
@Override
public ConfigType load(String code) throws Exception {
return configTypeMapper.selectByCode(code);
}
});
}
@PostConstruct
private void init() {
... ... @@ -126,4 +135,5 @@ public class ConfigTypeServiceImpl implements IConfigTypeService {
return rows;
}
}
... ...
... ... @@ -106,6 +106,7 @@
<ref bean="localIpInterceptor" />
<ref bean="securityInterceptor" />
<ref bean="signatureVerifyInterceptor" />
<ref bean="innerApiInterceptor" />
</mvc:interceptors>
</beans>
\ No newline at end of file
... ...
... ... @@ -90,7 +90,6 @@ redis.proxy.address=192.168.102.45
redis.proxy.auth=redis9646
redis.proxy.port=6379
buyer.delivery.way.cost.sf=0
order.seller.earnestmoney.min=1
order.seller.earnestmoney.max=200
order.seller.packageFee=0.1
... ...
... ... @@ -63,7 +63,6 @@ wechat.app.appid=wx049fdaa3ba9cdd7a
wechat.notifyurl=${wechat.notifyurl}
alipay.notifyurl=${alipay.notifyurl}
buyer.delivery.way.cost.sf=${buyer.delivery.way.cost.sf}
order.seller.earnestmoney.min=${order.seller.earnestmoney.min}
order.seller.earnestmoney.max=${order.seller.earnestmoney.max}
order.seller.packageFee=${order.seller.packageFee}
... ...