Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop into feature/pg

This commit is contained in:
paulGao
2022-01-26 17:54:15 +08:00
40 changed files with 233 additions and 46 deletions

View File

@@ -4,6 +4,7 @@ import cn.lili.cache.limit.enums.LimitTypeEnums;
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;
@@ -54,7 +55,8 @@ public class LimitInterceptor {
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 {
@@ -71,32 +73,8 @@ public class LimitInterceptor {
} 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;
}
}

View File

@@ -4,6 +4,8 @@ import java.lang.annotation.*;
/**
* 演示站点注解
* <p>
* PS 此注解需要用户登录之后才可以使用
*
* @author Bulbasaur
* @since 2021/7/9 1:40 上午

View File

@@ -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;
}

View File

@@ -0,0 +1,67 @@
package cn.lili.common.aop.interceptor;
/**
* 防重复提交业务
*
* @author Chopper
* @version v1.0
* 2022-01-25 09:20
*/
import cn.lili.cache.Cache;
import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.security.context.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
@Aspect
@Component
@Slf4j
public class PreventDuplicateSubmissionsInterceptor {
@Autowired
private Cache<String> cache;
@Before("@annotation(preventDuplicateSubmissions)")
public void interceptor(PreventDuplicateSubmissions preventDuplicateSubmissions) {
try {
Long count = cache.incr(getParams(), preventDuplicateSubmissions.expire());
//如果超过1或者设置的参数则表示重复提交了
if (count.intValue() >= preventDuplicateSubmissions.expire()) {
throw new ServiceException(ResultCode.LIMIT_ERROR);
}
}
//如果参数为空,则表示用户未登录,直接略过,不做处理
catch (NullPointerException e) {
return;
} catch (ServiceException e) {
throw e;
} catch (Exception e) {
throw new ServiceException(ResultCode.ERROR);
}
}
/**
* 获取表单参数
*
* @return
*/
private String getParams() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//请求地址
return request.getRequestURI() + UserContext.getCurrentUser().getId() + UserContext.getCurrentUser().getUsername();
}
}

View File

@@ -41,9 +41,10 @@ public interface MemberEvaluationService extends IService<MemberEvaluation> {
* 4.发送用户评价消息修改商品的评价数量以及好评率
*
* @param memberEvaluationDTO 评论
* @param isSelf 是否自己操作true买家操作/false 系统操作)
* @return 操作状态
*/
MemberEvaluationDTO addMemberEvaluation(MemberEvaluationDTO memberEvaluationDTO);
MemberEvaluationDTO addMemberEvaluation(MemberEvaluationDTO memberEvaluationDTO, Boolean isSelf);
/**
* 根据ID查询会员评价

View File

@@ -106,13 +106,15 @@ public class MemberEvaluationServiceImpl extends ServiceImpl<MemberEvaluationMap
}
@Override
public MemberEvaluationDTO addMemberEvaluation(MemberEvaluationDTO memberEvaluationDTO) {
public MemberEvaluationDTO addMemberEvaluation(MemberEvaluationDTO memberEvaluationDTO, Boolean isSelf) {
//获取子订单信息
OrderItem orderItem = orderItemService.getBySn(memberEvaluationDTO.getOrderItemSn());
//获取订单信息
Order order = orderService.getBySn(orderItem.getOrderSn());
//检测是否可以添加会员评价
checkMemberEvaluation(orderItem, order);
if (isSelf) {
checkMemberEvaluation(orderItem, order);
}
//获取用户信息
Member member = memberService.getUserInfo();
//获取商品信息

View File

@@ -67,14 +67,6 @@ public class MemberSignServiceImpl extends ServiceImpl<MemberSignMapper, MemberS
//获取当前会员信息
AuthUser authUser = UserContext.getCurrentUser();
if (authUser != null) {
QueryWrapper<MemberSign> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("member_id", authUser.getId());
queryWrapper.between("create_time", new Date(DateUtil.startOfTodDay() * 1000), DateUtil.getCurrentDayEndTime());
//校验今天是否已经签到
List<MemberSign> todaySigns = this.baseMapper.getTodayMemberSign(queryWrapper);
if (todaySigns.size() > 0) {
throw new ServiceException(ResultCode.MEMBER_SIGN_REPEAT);
}
//当前签到天数的前一天日期
List<MemberSign> signs = this.baseMapper.getBeforeMemberSign(authUser.getId());
//构建参数
@@ -89,14 +81,17 @@ public class MemberSignServiceImpl extends ServiceImpl<MemberSignMapper, MemberS
} else {
memberSign.setSignDay(1);
}
Integer result = this.baseMapper.insert(memberSign);
//签到成功后发送消息赠送积分
if (result > 0) {
//手动写入创建时间,以保证唯一索引生效
memberSign.setCreateTime(DateUtil.getCurrentDayEndTime());
try {
this.baseMapper.insert(memberSign);
//签到成功后发送消息赠送积分
String destination = rocketmqCustomProperties.getMemberTopic() + ":" + MemberTagsEnum.MEMBER_SING.name();
rocketMQTemplate.asyncSend(destination, memberSign, RocketmqSendCallbackBuilder.commonCallback());
return true;
} catch (Exception e) {
throw new ServiceException(ResultCode.MEMBER_SIGN_REPEAT);
}
return false;
}
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
}

View File

@@ -5,6 +5,8 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.modules.payment.kit.core.PaymentHttpResponse;
import cn.lili.modules.payment.kit.core.enums.RequestMethodEnums;
import cn.lili.modules.payment.kit.core.enums.SignType;
@@ -114,6 +116,30 @@ public class WxPayKit {
}
}
/**
* APP 单独生成签名
* app 支付环境中,如果遇到签名错误,百思不得其解,则可以使用这个方法调用签名尝试解决
*
* @param params 需要签名的参数
* @return 签名后的数据
*/
public static String createAppSign(Map<String, String> params, String privateKey) {
String appid = params.get("appid");
String timestamp = params.get("timestamp");
String noncestr = params.get("noncestr");
String prepayid = params.get("prepayid");
String encrypt = appid + "\n" + timestamp + "\n" + noncestr + "\n" + prepayid + "\n";
try {
return PayKit.createSign(encrypt, privateKey);
} catch (Exception e) {
throw new ServiceException(ResultCode.ERROR);
}
}
/**
* 生成签名
*
@@ -351,6 +377,8 @@ public class WxPayKit {
signType = SignType.MD5;
}
String packageSign = createSign(packageParams, partnerKey, signType);
// 部分微信APP支付 提示签名错误 解开下方注释 替换上边的代码就好。
// String packageSign = createAppSign(packageParams, partnerKey);
packageParams.put("sign", packageSign);
return packageParams;
}