卡密兑换次数限制
This commit is contained in:
zhouwentao 2024-06-17 10:28:46 +08:00
parent b6a490e076
commit 98d9a7b493
4 changed files with 76 additions and 37 deletions

View File

@ -11,10 +11,13 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.AssertUtils;
import org.jeecg.common.util.IpUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.mini.dto.VipDTO;
import org.jeecg.modules.mini.service.MiniUserService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.yx.constant.YxConstant;
import org.jeecg.modules.yx.entity.YxOrder;
import org.jeecg.modules.yx.entity.YxVipCard;
import org.jeecg.modules.yx.entity.YxVipSku;
@ -25,6 +28,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@ -48,6 +53,8 @@ public class MiniVipController {
private IYxVipSkuService yxVipSkuService;
@Autowired
private MiniUserService miniUserService;
@Resource
private RedisUtil redisUtil;
@GetMapping(value = "/getVipInfo")
@ApiOperation(value = "获取vip信息")
@ -79,23 +86,36 @@ public class MiniVipController {
@PostMapping(value = "/card/activation")
@ApiOperation(value = "卡密激活")
public Result<?> cardActivation(@RequestBody JSONObject jsonObject) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
SysUser user = sysUserService.getById(sysUser.getId());
AssertUtils.notNull(user, "获取用户信息失败,请联系管理员");
String card = jsonObject.getString("card");
AssertUtils.notNull(card, "请输入卡密");
//检查card是否有效
boolean cardValid = yxVipCardService.cardIsValid(card);
AssertUtils.isTrue(cardValid, "当前卡密无效或已被使用");
YxVipCard yxVipCard = yxVipCardService.getOne(new LambdaQueryWrapper<YxVipCard>().eq(YxVipCard::getCardNum, card));
VipDTO userVip = miniUserService.getUserVip(user.getId());
if (userVip != null && userVip.getVipLevel() != 0) {
AssertUtils.notTrue(yxVipSkuService.convertVipLevel(yxVipCard.getSkuCode()) <= userVip.getVipLevel(), "该权益您已激活!不可重复兑换");
public Result<?> cardActivation(@RequestBody JSONObject jsonObject, HttpServletRequest request) {
String key =YxConstant.VIP_CARD_KEY + "_" + IpUtils.getIpAddr(request);
Integer ipAddrCardCount = (Integer) redisUtil.get(key);
if (ipAddrCardCount!=null) {
AssertUtils.notTrue(ipAddrCardCount>=5,"当前操作过快,稍后重试");
}
//使用卡密
boolean exchange = yxVipCardService.exchange(card, user.getId());
AssertUtils.isTrue(exchange, "当前卡密已被使用");
try {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
SysUser user = sysUserService.getById(sysUser.getId());
AssertUtils.notNull(user, "获取用户信息失败,请联系管理员");
String card = jsonObject.getString("card");
AssertUtils.notNull(card, "请输入卡密");
//检查card是否有效
boolean cardValid = yxVipCardService.cardIsValid(card);
AssertUtils.isTrue(cardValid, "当前卡密无效或已被使用");
YxVipCard yxVipCard = yxVipCardService.getOne(new LambdaQueryWrapper<YxVipCard>().eq(YxVipCard::getCardNum, card));
VipDTO userVip = miniUserService.getUserVip(user.getId());
if (userVip != null && userVip.getVipLevel() != 0) {
AssertUtils.notTrue(yxVipSkuService.convertVipLevel(yxVipCard.getSkuCode()) <= userVip.getVipLevel(), "该权益您已激活!不可重复兑换");
}
//使用卡密
boolean exchange = yxVipCardService.exchange(card, user.getId());
AssertUtils.isTrue(exchange, "当前卡密已被使用");
}catch (Exception e){
ipAddrCardCount++;
redisUtil.set(key,ipAddrCardCount,3600);
// 记录兑换次数
throw new JeecgBootException(e.getMessage());
}
return Result.OK("激活成功");
}

View File

@ -80,4 +80,7 @@ public class YxConstant {
//同ip仅可注册账户数量
public static final Integer ipRegisterNum = 3;
// vip card redis key
public static String VIP_CARD_KEY="vip_card";
}

View File

@ -242,35 +242,51 @@ public class YxHistoryMajorEnrollController extends JeecgController<YxHistoryMaj
@RequiresPermissions("yx:yx_history_major_enroll:exportXls")
@RequestMapping(value = "/exportXlsBySchoolMajor")
public ModelAndView exportXlsBySchoolMajor(HttpServletRequest request) {
List<YxHistoryMajorEnroll> dataList = yxHistoryMajorEnrollService.list(new LambdaQueryWrapper<YxHistoryMajorEnroll>()
List<YxHistoryMajorEnroll> dataList = new ArrayList<>();
List<YxHistoryMajorEnroll> historyMajorEnrollList = yxHistoryMajorEnrollService.list(new LambdaQueryWrapper<YxHistoryMajorEnroll>()
.eq(YxHistoryMajorEnroll::getYear,"2023")
.in(YxHistoryMajorEnroll::getBatch,"高职高专"));
.eq(YxHistoryMajorEnroll::getMajorType,"体育类"));
Set<String> notAddSet = new LinkedHashSet<>();
for (YxHistoryMajorEnroll y : dataList) {
Map<String,YxHistoryMajorEnroll> map =new LinkedHashMap<>();
for (YxHistoryMajorEnroll y : historyMajorEnrollList) {
notAddSet.add(y.getSchoolCode()+"_"+y.getEnrollmentCode()+"_"+y.getMajorType()+"_"+y.getCategory());
map.put(y.getSchoolCode()+"_"+y.getEnrollmentCode()+"_"+y.getMajorType()+"_"+y.getCategory(),y);
}
List<YxSchoolMajor> schoolMajorList = yxSchoolMajorService.list(new LambdaQueryWrapper<YxSchoolMajor>()
.in(YxSchoolMajor::getBatch,"高职高专"));
.eq(YxSchoolMajor::getMajorType,"体育类"));
List<YxSchoolChild> schoolChildList = yxSchoolChildService.list();
Map<String, String> schoolNameMap = schoolChildList.stream().collect(Collectors.toMap(YxSchoolChild::getSchoolCode, YxSchoolChild::getSchoolName));
String schoolName = "";
YxHistoryMajorEnroll yxHistoryMajorEnroll = null;
for (YxSchoolMajor yxSchoolMajor : schoolMajorList) {
if (notAddSet.contains(yxSchoolMajor.getSchoolCode()+"_"+yxSchoolMajor.getEnrollmentCode()+"_"+yxSchoolMajor.getMajorType()+"_"+yxSchoolMajor.getCategory())) {
continue;
int i =0;
try {
String key = null;
for (YxSchoolMajor yxSchoolMajor : schoolMajorList) {
key = yxSchoolMajor.getSchoolCode()+"_"+yxSchoolMajor.getEnrollmentCode()+"_"+yxSchoolMajor.getMajorType()+"_"+yxSchoolMajor.getCategory();
if (!notAddSet.contains(key)) {
yxHistoryMajorEnroll = new YxHistoryMajorEnroll();
schoolName = schoolNameMap.getOrDefault(yxSchoolMajor.getSchoolCode(), "");
BeanUtils.copyProperties(yxSchoolMajor,yxHistoryMajorEnroll);
yxHistoryMajorEnroll.setSchoolName(schoolName);
yxHistoryMajorEnroll.setEnrollNum(yxSchoolMajor.getPlanNum());
yxHistoryMajorEnroll.setRulesEnrollProbability(yxSchoolMajor.getPrivateRulesEnrollProbability());
yxHistoryMajorEnroll.setProbabilityOperator(yxSchoolMajor.getPrivateProbabilityOperator());
}else{
yxHistoryMajorEnroll = map.get(key);
}
if (yxSchoolMajor.getTuition()!=null) {
yxHistoryMajorEnroll.setTuition(yxSchoolMajor.getTuition().toString());
}
if (StringUtils.isNotBlank(yxSchoolMajor.getDetail())) {
yxHistoryMajorEnroll.setDetail(yxSchoolMajor.getDetail());
}
dataList.add(yxHistoryMajorEnroll);
i++;
}
yxHistoryMajorEnroll = new YxHistoryMajorEnroll();
schoolName = schoolNameMap.getOrDefault(yxSchoolMajor.getSchoolCode(), "");
BeanUtils.copyProperties(yxSchoolMajor,yxHistoryMajorEnroll);
yxHistoryMajorEnroll.setSchoolName(schoolName);
yxHistoryMajorEnroll.setEnrollNum(yxSchoolMajor.getPlanNum());
yxHistoryMajorEnroll.setRulesEnrollProbability(yxSchoolMajor.getPrivateRulesEnrollProbability());
yxHistoryMajorEnroll.setProbabilityOperator(yxSchoolMajor.getPrivateProbabilityOperator());
if (yxSchoolMajor.getTuition()!=null) {
yxHistoryMajorEnroll.setTuition(yxSchoolMajor.getTuition().toString());
}
dataList.add(yxHistoryMajorEnroll);
}catch (Exception e) {
System.out.println(i);
throw new JeecgBootException("导出数据有错误,第"+i+"行出错:"+e.getMessage());
}
//Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
@ -287,7 +303,7 @@ public class YxHistoryMajorEnrollController extends JeecgController<YxHistoryMaj
/**
* 通过excel导入数据
*/
*/
@RequiresPermissions("yx:yx_history_major_enroll:importExcel")
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {

View File

@ -523,8 +523,8 @@ public class ScoreUtil {
//当前年分差为0去年分差为0
enrollProbability = YxConstant.bigDecimal50;//录取率50
}else if(nowYearDiff.compareTo(YxConstant.bigDecimal0) > 0 && historyThreeYearDiff.compareTo(YxConstant.bigDecimal0)<=0){
//当前年分差不为0去年分差为0默认去年的分差为1
enrollProbability = nowYearDiff.multiply(YxConstant.bigDecimal075).multiply(YxConstant.bigDecimal100);
//当前年分差不为0去年分差为0默认去年的分差为1 .multiply(YxConstant.bigDecimal075)
enrollProbability = nowYearDiff.multiply(YxConstant.bigDecimal100).multiply(YxConstant.bigDecimal075);
}else if(nowYearDiff.compareTo(YxConstant.bigDecimal0) < 0 && historyThreeYearDiff.compareTo(YxConstant.bigDecimal0)<=0){
enrollProbability = YxConstant.bigDecimal0;
} else {