Skip to content

Commit

Permalink
api端防重复提交
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper711 committed Jan 25, 2022
1 parent 039e85d commit 3972e02
Show file tree
Hide file tree
Showing 33 changed files with 181 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.distribution;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class DistributionCashBuyerController {
private DistributionCashService distributorCashService;


@PreventDuplicateSubmissions
@ApiOperation(value = "分销员提现")
@ApiImplicitParams({
@ApiImplicitParam(name = "price", value = "申请金额", required = true, paramType = "query", dataType = "double")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.distribution;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
Expand Down Expand Up @@ -50,6 +51,7 @@ public ResultMessage<IPage<DistributionGoodsVO>> distributionGoods(DistributionG
return ResultUtil.data(distributionGoodsService.goodsPage(distributionGoodsSearchParams));
}

@PreventDuplicateSubmissions
@ApiOperation(value = "选择分销商品")
@ApiImplicitParams({
@ApiImplicitParam(name = "distributionGoodsId", value = "分销ID", required = true, dataType = "String", paramType = "path"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.member;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.enums.SwitchEnum;
import cn.lili.common.security.context.UserContext;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class MemberEvaluationBuyerController {
@Autowired
private MemberEvaluationService memberEvaluationService;

@PreventDuplicateSubmissions
@ApiOperation(value = "添加会员评价")
@PostMapping
public ResultMessage<MemberEvaluationDTO> save(@Valid MemberEvaluationDTO memberEvaluationDTO) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.member;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.member.entity.dos.MemberSign;
Expand Down Expand Up @@ -27,6 +28,8 @@ public class MemberSignBuyerController {
@Autowired
private MemberSignService memberSignService;


@PreventDuplicateSubmissions
@PostMapping
@ApiOperation(value = "会员签到")
public ResultMessage<Boolean> memberSign() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.order;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.OperationalJudgment;
import cn.lili.common.vo.ResultMessage;
Expand Down Expand Up @@ -77,6 +78,7 @@ public ResultMessage<AfterSaleApplyVO> applyAfterSaleInfo(@PathVariable String s
return ResultUtil.data(afterSaleService.getAfterSaleVO(sn));
}

@PreventDuplicateSubmissions
@PostMapping(value = "/save/{orderItemSn}")
@ApiImplicitParam(name = "orderItemSn", value = "订单货物编号", required = true, paramType = "query")
@ApiOperation(value = "申请售后")
Expand All @@ -101,6 +103,7 @@ public ResultMessage<AfterSale> delivery(@NotNull(message = "售后编号不能
return ResultUtil.data(afterSaleService.buyerDelivery(afterSaleSn, logisticsNo, logisticsId, mDeliverTime));
}

@PreventDuplicateSubmissions
@ApiOperation(value = "售后,取消售后")
@ApiImplicitParams({
@ApiImplicitParam(name = "afterSaleSn", value = "售后sn", required = true, dataType = "String", paramType = "path")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.order;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
Expand Down Expand Up @@ -235,6 +236,7 @@ public ResultMessage<Object> selectCoupon(String way, @NotNull(message = "优惠
}


@PreventDuplicateSubmissions
@ApiOperation(value = "创建交易")
@PostMapping(value = "/create/trade", consumes = "application/json", produces = "application/json")
public ResultMessage<Object> crateTrade(@RequestBody TradeParams tradeParams) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.order;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
Expand Down Expand Up @@ -62,6 +63,7 @@ public ResultMessage<OrderDetailVO> detail(@NotNull(message = "订单编号不
return ResultUtil.data(orderDetailVO);
}

@PreventDuplicateSubmissions
@ApiOperation(value = "确认收货")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderSn", value = "订单编号", required = true, paramType = "path")
Expand All @@ -80,6 +82,7 @@ public ResultMessage<Object> receiving(@NotNull(message = "订单编号不能为
return ResultUtil.success();
}

@PreventDuplicateSubmissions
@ApiOperation(value = "取消订单")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderSn", value = "订单编号", required = true, dataType = "String", paramType = "path"),
Expand All @@ -91,6 +94,7 @@ public ResultMessage<Object> cancel(@ApiIgnore @PathVariable String orderSn, @Re
return ResultUtil.success();
}

@PreventDuplicateSubmissions
@ApiOperation(value = "删除订单")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderSn", value = "订单编号", required = true, dataType = "String", paramType = "path")
Expand All @@ -113,6 +117,7 @@ public ResultMessage<Object> getTraces(@NotBlank(message = "订单编号不能
}


@PreventDuplicateSubmissions
@ApiOperation(value = "开票")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderSn", value = "订单编号", required = true, dataType = "String", paramType = "path")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.order;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.AuthUser;
import cn.lili.common.security.OperationalJudgment;
Expand Down Expand Up @@ -66,6 +67,7 @@ public ResultMessage<IPage<OrderComplaint>> get(OrderComplaintSearchParams searc

}

@PreventDuplicateSubmissions
@ApiOperation(value = "添加交易投诉")
@PostMapping
public ResultMessage<OrderComplaint> add(@Valid OrderComplaintDTO orderComplaintDTO) {
Expand All @@ -85,6 +87,7 @@ public ResultMessage<OrderComplaintCommunicationVO> addCommunication(@RequestPar
return ResultUtil.data(communicationVO);
}

@PreventDuplicateSubmissions
@ApiOperation(value = "取消售后")
@ApiImplicitParam(name = "id", value = "投诉单ID", required = true, paramType = "path")
@PutMapping(value = "/status/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.order;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
Expand Down Expand Up @@ -41,6 +42,7 @@ public ResultMessage<IPage<OrderReceiptDTO>> getPage(ReceiptSearchParams searchP
return ResultUtil.data(this.receiptService.getReceiptData(searchParams, pageVO));
}

@PreventDuplicateSubmissions
@ApiOperation(value = "保存发票信息")
@PostMapping
public ResultMessage<Receipt> save(@Valid Receipt receipt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.order;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.wallet.entity.dos.Recharge;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class RechargeTradeBuyerController {
@Autowired
private RechargeService rechargeService;

@PreventDuplicateSubmissions
@PostMapping
@ApiOperation(value = "创建余额充值订单")
@ApiImplicitParams({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.other;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.vo.ResultMessage;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class FeedbackBuyerController {
@Autowired
private FeedbackService feedbackService;

@PreventDuplicateSubmissions
@ApiOperation(value = "添加意见反馈")
@PostMapping()
public ResultMessage<Object> save(@Valid Feedback feedback) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.other.purchase;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.context.UserContext;
Expand Down Expand Up @@ -48,6 +49,8 @@ public ResultMessage<IPage<GoodsUnit>> goodsUnitPage(PageVO pageVO) {
return ResultUtil.data(goodsUnitService.page(PageUtil.initPage(pageVO)));
}


@PreventDuplicateSubmissions
@ApiOperation(value = "添加采购单")
@PostMapping
public ResultMessage<PurchaseOrderVO> addPurchaseOrderVO(@RequestBody PurchaseOrderVO purchaseOrderVO) {
Expand All @@ -74,6 +77,7 @@ public ResultMessage<IPage<PurchaseOrder>> getByMember(PurchaseOrderSearchParams
return ResultUtil.data(purchaseOrderService.page(purchaseOrderSearchParams));
}

@PreventDuplicateSubmissions
@ApiOperation(value = "关闭采购单")
@ApiImplicitParam(name = "id", value = "采购单ID", required = true, dataType = "Long", paramType = "path")
@PutMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.lili.controller.wallet;


import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.vo.PageVO;
Expand Down Expand Up @@ -35,6 +36,7 @@ public ResultMessage<Object> page(MemberReceiptVO memberReceiptVO, PageVO page)
return ResultUtil.data(memberReceiptService.getPage(memberReceiptVO, page));
}

@PreventDuplicateSubmissions
@ApiOperation(value = "新增会员发票")
@PostMapping
public ResultMessage<Object> add(MemberReceiptAddVO memberReceiptAddVO) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.controller.wallet;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
Expand Down Expand Up @@ -120,6 +121,7 @@ public Boolean checkPassword() {
}


@PreventDuplicateSubmissions
@PostMapping(value = "/withdrawal")
@ApiOperation(value = "会员中心余额提现")
@ApiImplicitParams({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.lili.controller.common;

import cn.lili.cache.limit.annotation.LimitPoint;
import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.verification.entity.enums.VerificationEnums;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.lili.cache.limit.annotation.LimitPoint;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.IpUtils;
import com.google.common.collect.ImmutableList;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -54,7 +55,8 @@ public void interceptor(LimitPoint limitPointAnnotation) {
key = limitPointAnnotation.key();
break;
default:
key = limitPointAnnotation.key() + getIpAddress();
key = limitPointAnnotation.key() + IpUtils
.getIpAddress(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
ImmutableList<String> keys = ImmutableList.of(StringUtils.join(limitPointAnnotation.prefix(), key));
try {
Expand All @@ -71,32 +73,8 @@ public void interceptor(LimitPoint limitPointAnnotation) {
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("服务器异常,请稍后再试");
throw new ServiceException(ResultCode.ERROR);
}
}


/**
* 默认unknown常量值
*/
private static final String UNKNOWN = "unknown";

/**
* 获取ip
* @return ip
*/
public String getIpAddress() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/**
* 演示站点注解
* <p>
* PS 此注解需要用户登录之后才可以使用
*
* @author Bulbasaur
* @since 2021/7/9 1:40 上午
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cn.lili.common.aop.annotation;

import java.lang.annotation.*;
import java.util.concurrent.TimeUnit;

/**
* 防止重复提交注解
*
* @author liushuai(liushuai711 @ gmail.com)
* @version v4.0
* @Description:
* @since 2022/1/25 09:17
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface PreventDuplicateSubmissions {


/**
* 过期时间
*/
long expire() default 3;
}
Loading

0 comments on commit 3972e02

Please sign in to comment.