Authored by tanling

本地提交

package com.yohoufo.order.annotation;
import com.yohoufo.order.common.BlackTypeEnum;
import org.springframework.stereotype.Component;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
@Component
public @interface BlackUserType {
BlackTypeEnum blackType();
}
... ...
... ... @@ -10,8 +10,8 @@ import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.annotation.BlackUserType;
import com.yohoufo.order.common.BlackTypeEnum;
import com.yohoufo.order.interceptor.BlackUserInterceptor;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.OrderSubmitResp;
... ... @@ -92,6 +92,7 @@ public class SellerOrderController {
*/
@RequestMapping(params = "method=ufo.sellerOrder.publishPrd")
@ResponseBody
@BlackUserType(blackType = BlackTypeEnum.SELL)
public ApiResponse publishPrd(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "storage_id", required = true)int storage_id,
@RequestParam(name="price", required = true)String price,
... ... @@ -108,8 +109,6 @@ public class SellerOrderController {
.build();
logger.info("in ufo.sellerOrder.publishPrd, req {}", req);
BlackUserInterceptor.getBlackUserInteceptor(BlackTypeEnum.SELL.getCode()).before(uid);
OrderSubmitResp resp = sellerOrderService.publishPrd(req);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("发布成功").build();
}
... ... @@ -524,6 +523,7 @@ public class SellerOrderController {
*/
@RequestMapping(params = "method=ufo.seller.publishImperfectPrd")
@ResponseBody
@BlackUserType(blackType = BlackTypeEnum.SELL)
public ApiResponse publishImperfectPrd(@RequestParam(name = "uid")int uid,
@RequestParam(name = "storage_id")int storage_id,
@RequestParam(name="price")String price,
... ... @@ -548,8 +548,6 @@ public class SellerOrderController {
.build();
logger.info("in ufo.sellerOrder.publishImperfectPrd, req {}", req);
BlackUserInterceptor.getBlackUserInteceptor(BlackTypeEnum.SELL.getCode()).before(uid);
OrderSubmitResp resp = imperfectGoodsService.publish(req);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("发布成功").build();
}
... ...
... ... @@ -2,12 +2,13 @@ package com.yohoufo.order.controller;
import com.google.common.collect.Lists;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.annotation.BlackUserType;
import com.yohoufo.order.common.BlackTypeEnum;
import com.yohoufo.order.constants.CouponConstants;
import com.yohoufo.order.model.request.ShoppingRequest;
import com.yohoufo.order.model.response.*;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IShoppingService;
import com.yohoufo.order.service.impl.SellerOrderService;
import com.yohoufo.order.service.impl.SellerOrderViewService;
import com.yohoufo.order.utils.CouponCodeUtils;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -99,6 +100,7 @@ public class ShoppingController {
* @return
*/
@RequestMapping(params = "method=ufo.order.submit")
@BlackUserType(blackType = BlackTypeEnum.BUY)
public ApiResponse submit(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup,
@RequestParam(name = "coupon_code",required = false) String couponCode,
... ...
... ... @@ -5,24 +5,57 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.dal.order.BlackUserMapper;
import com.yohoufo.dal.order.model.BlackUser;
import com.yohoufo.order.annotation.BlackUserType;
import com.yohoufo.order.common.BlackTypeEnum;
import org.apache.commons.collections.CollectionUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public abstract class BlackUserInterceptor implements ApplicationContextAware {
@Aspect
@Component
public class BlackUserAspect {
Logger logger = LoggerFactory.getLogger(BlackUserInterceptor.class);
private static Map<Integer, AbstractBlackUserInterceptor> blackUserInteceptorMap = Maps.newHashMap();
@Pointcut("@annotation(com.yohoufo.order.annotation.BlackUserType)")
private void pointId(){
}
@Before("pointId()")
private void before(JoinPoint joinPoint) throws Throwable{
Object[] argsa = joinPoint.getArgs();
Annotation[][] parameterTypes = ((MethodSignature)joinPoint.getSignature()).getMethod().getParameterAnnotations();
BlackUserType blackUserAnnotation = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(BlackUserType.class);
blackUserInteceptorMap.get(blackUserAnnotation.blackType()).before((int)argsa[0]);
}
private abstract static class AbstractBlackUserInterceptor implements ApplicationContextAware {
Logger logger = LoggerFactory.getLogger(AbstractBlackUserInterceptor.class);
@Autowired
BlackUserMapper blackUserMapper;
... ... @@ -52,22 +85,46 @@ public abstract class BlackUserInterceptor implements ApplicationContextAware {
abstract int getBlackType();
private static final Map<Integer, BlackUserInterceptor> blackUserInteceptorMap = Maps.newHashMap();
abstract ServiceException getServiceException();
public static BlackUserInterceptor getBlackUserInteceptor(Integer code){
return blackUserInteceptorMap.get(code);
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, AbstractBlackUserInterceptor> map = applicationContext.getBeansOfType(AbstractBlackUserInterceptor.class);
for (String beanName : map.keySet()){
AbstractBlackUserInterceptor abstractBlackUserInterceptor = map.get(beanName);
blackUserInteceptorMap.put(abstractBlackUserInterceptor.getBlackType(), abstractBlackUserInterceptor);
}
}
}
abstract ServiceException getServiceException();
@Component
private static class BuyBlackUserInterceptor extends AbstractBlackUserInterceptor {
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// 重构map中的拦截器key,value
Map<String, BlackUserInterceptor> map = applicationContext.getBeansOfType(BlackUserInterceptor.class);
for (String beanName: map.keySet()){
BlackUserInterceptor interceptor = (BlackUserInterceptor) applicationContext.getBean(beanName);
blackUserInteceptorMap.put(interceptor.getBlackType(), interceptor);
int getBlackType() {
return BlackTypeEnum.BUY.getCode();
}
@Override
ServiceException getServiceException() {
return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_BUY);
}
}
@Component
private static class SellBlackUserInterceptor extends AbstractBlackUserInterceptor {
@Override
int getBlackType() {
return BlackTypeEnum.SELL.getCode();
}
@Override
ServiceException getServiceException() {
return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_SELL);
}
}
... ...
package com.yohoufo.order.interceptor;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.order.common.BlackTypeEnum;
import org.springframework.stereotype.Component;
@Component
public class BuyBlackUserInterceptor extends BlackUserInterceptor {
@Override
int getBlackType() {
return BlackTypeEnum.BUY.getCode();
}
@Override
ServiceException getServiceException() {
return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_BUY);
}
}
\ No newline at end of file
package com.yohoufo.order.interceptor;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.order.common.BlackTypeEnum;
import org.springframework.stereotype.Component;
@Component
public class SellBlackUserInterceptor extends BlackUserInterceptor {
@Override
int getBlackType() {
return BlackTypeEnum.SELL.getCode();
}
@Override
ServiceException getServiceException() {
return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_SELL);
}
}
\ No newline at end of file
... ... @@ -27,12 +27,10 @@ import com.yohoufo.order.charge.model.ChargeGoods;
import com.yohoufo.order.charge.model.ChargeParam;
import com.yohoufo.order.charge.model.ChargeResult;
import com.yohoufo.order.charge.model.CouponMatchResult;
import com.yohoufo.order.common.BlackTypeEnum;
import com.yohoufo.order.event.BuyerCancelEvent;
import com.yohoufo.order.event.ErpBuyerOrderEvent;
import com.yohoufo.order.event.NotPaidNoticeEvent;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.order.interceptor.BlackUserInterceptor;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
import com.yohoufo.order.model.dto.OrderBuilder;
... ... @@ -276,9 +274,6 @@ public class ShoppingServiceImpl implements IShoppingService {
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
// 黑名单拦截
BlackUserInterceptor.getBlackUserInteceptor(BlackTypeEnum.BUY.getCode()).before(uid);
shoppingRiskWatchDog.checkWaitingPayCnt(uid);
//查询并校验用户地址
Pair<AddressInfo, AddressInfo> userAddressPair = getAndCheckAddressInfo(shoppingRequest);
... ...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<aop:aspectj-autoproxy />
</beans>
\ No newline at end of file
... ...