卡密兑换次数限制
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.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.AssertUtils; 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.dto.VipDTO;
import org.jeecg.modules.mini.service.MiniUserService; import org.jeecg.modules.mini.service.MiniUserService;
import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService; 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.YxOrder;
import org.jeecg.modules.yx.entity.YxVipCard; import org.jeecg.modules.yx.entity.YxVipCard;
import org.jeecg.modules.yx.entity.YxVipSku; 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.context.annotation.Scope;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -48,6 +53,8 @@ public class MiniVipController {
private IYxVipSkuService yxVipSkuService; private IYxVipSkuService yxVipSkuService;
@Autowired @Autowired
private MiniUserService miniUserService; private MiniUserService miniUserService;
@Resource
private RedisUtil redisUtil;
@GetMapping(value = "/getVipInfo") @GetMapping(value = "/getVipInfo")
@ApiOperation(value = "获取vip信息") @ApiOperation(value = "获取vip信息")
@ -79,7 +86,13 @@ public class MiniVipController {
@PostMapping(value = "/card/activation") @PostMapping(value = "/card/activation")
@ApiOperation(value = "卡密激活") @ApiOperation(value = "卡密激活")
public Result<?> cardActivation(@RequestBody JSONObject jsonObject) { 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,"当前操作过快,稍后重试");
}
try {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
SysUser user = sysUserService.getById(sysUser.getId()); SysUser user = sysUserService.getById(sysUser.getId());
AssertUtils.notNull(user, "获取用户信息失败,请联系管理员"); AssertUtils.notNull(user, "获取用户信息失败,请联系管理员");
@ -96,6 +109,13 @@ public class MiniVipController {
//使用卡密 //使用卡密
boolean exchange = yxVipCardService.exchange(card, user.getId()); boolean exchange = yxVipCardService.exchange(card, user.getId());
AssertUtils.isTrue(exchange, "当前卡密已被使用"); AssertUtils.isTrue(exchange, "当前卡密已被使用");
}catch (Exception e){
ipAddrCardCount++;
redisUtil.set(key,ipAddrCardCount,3600);
// 记录兑换次数
throw new JeecgBootException(e.getMessage());
}
return Result.OK("激活成功"); return Result.OK("激活成功");
} }

View File

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

View File

@ -242,24 +242,29 @@ public class YxHistoryMajorEnrollController extends JeecgController<YxHistoryMaj
@RequiresPermissions("yx:yx_history_major_enroll:exportXls") @RequiresPermissions("yx:yx_history_major_enroll:exportXls")
@RequestMapping(value = "/exportXlsBySchoolMajor") @RequestMapping(value = "/exportXlsBySchoolMajor")
public ModelAndView exportXlsBySchoolMajor(HttpServletRequest request) { 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") .eq(YxHistoryMajorEnroll::getYear,"2023")
.in(YxHistoryMajorEnroll::getBatch,"高职高专")); .eq(YxHistoryMajorEnroll::getMajorType,"体育类"));
Set<String> notAddSet = new LinkedHashSet<>(); 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()); 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>() List<YxSchoolMajor> schoolMajorList = yxSchoolMajorService.list(new LambdaQueryWrapper<YxSchoolMajor>()
.in(YxSchoolMajor::getBatch,"高职高专")); .eq(YxSchoolMajor::getMajorType,"体育类"));
List<YxSchoolChild> schoolChildList = yxSchoolChildService.list(); List<YxSchoolChild> schoolChildList = yxSchoolChildService.list();
Map<String, String> schoolNameMap = schoolChildList.stream().collect(Collectors.toMap(YxSchoolChild::getSchoolCode, YxSchoolChild::getSchoolName)); Map<String, String> schoolNameMap = schoolChildList.stream().collect(Collectors.toMap(YxSchoolChild::getSchoolCode, YxSchoolChild::getSchoolName));
String schoolName = ""; String schoolName = "";
YxHistoryMajorEnroll yxHistoryMajorEnroll = null; YxHistoryMajorEnroll yxHistoryMajorEnroll = null;
int i =0;
try {
String key = null;
for (YxSchoolMajor yxSchoolMajor : schoolMajorList) { for (YxSchoolMajor yxSchoolMajor : schoolMajorList) {
if (notAddSet.contains(yxSchoolMajor.getSchoolCode()+"_"+yxSchoolMajor.getEnrollmentCode()+"_"+yxSchoolMajor.getMajorType()+"_"+yxSchoolMajor.getCategory())) { key = yxSchoolMajor.getSchoolCode()+"_"+yxSchoolMajor.getEnrollmentCode()+"_"+yxSchoolMajor.getMajorType()+"_"+yxSchoolMajor.getCategory();
continue; if (!notAddSet.contains(key)) {
}
yxHistoryMajorEnroll = new YxHistoryMajorEnroll(); yxHistoryMajorEnroll = new YxHistoryMajorEnroll();
schoolName = schoolNameMap.getOrDefault(yxSchoolMajor.getSchoolCode(), ""); schoolName = schoolNameMap.getOrDefault(yxSchoolMajor.getSchoolCode(), "");
BeanUtils.copyProperties(yxSchoolMajor,yxHistoryMajorEnroll); BeanUtils.copyProperties(yxSchoolMajor,yxHistoryMajorEnroll);
@ -267,10 +272,21 @@ public class YxHistoryMajorEnrollController extends JeecgController<YxHistoryMaj
yxHistoryMajorEnroll.setEnrollNum(yxSchoolMajor.getPlanNum()); yxHistoryMajorEnroll.setEnrollNum(yxSchoolMajor.getPlanNum());
yxHistoryMajorEnroll.setRulesEnrollProbability(yxSchoolMajor.getPrivateRulesEnrollProbability()); yxHistoryMajorEnroll.setRulesEnrollProbability(yxSchoolMajor.getPrivateRulesEnrollProbability());
yxHistoryMajorEnroll.setProbabilityOperator(yxSchoolMajor.getPrivateProbabilityOperator()); yxHistoryMajorEnroll.setProbabilityOperator(yxSchoolMajor.getPrivateProbabilityOperator());
}else{
yxHistoryMajorEnroll = map.get(key);
}
if (yxSchoolMajor.getTuition()!=null) { if (yxSchoolMajor.getTuition()!=null) {
yxHistoryMajorEnroll.setTuition(yxSchoolMajor.getTuition().toString()); yxHistoryMajorEnroll.setTuition(yxSchoolMajor.getTuition().toString());
} }
if (StringUtils.isNotBlank(yxSchoolMajor.getDetail())) {
yxHistoryMajorEnroll.setDetail(yxSchoolMajor.getDetail());
}
dataList.add(yxHistoryMajorEnroll); dataList.add(yxHistoryMajorEnroll);
i++;
}
}catch (Exception e) {
System.out.println(i);
throw new JeecgBootException("导出数据有错误,第"+i+"行出错:"+e.getMessage());
} }
//Step.2 AutoPoi 导出Excel //Step.2 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());

View File

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