Commit 18e92d1b by 唐聪

完成抽奖模块

parent 769c29ea
...@@ -65,4 +65,9 @@ public interface UserFeign { ...@@ -65,4 +65,9 @@ public interface UserFeign {
@PostMapping(value = "/api/question/getAnswerRecs") @PostMapping(value = "/api/question/getAnswerRecs")
ResultVo getAnswerRecs(@RequestBody Map<String, Object> paramsMap); ResultVo getAnswerRecs(@RequestBody Map<String, Object> paramsMap);
@PostMapping(value = "/api/question/randomDraw")
ResultVo randomDraw(Map<String, Object> paramsMap);
// @PostMapping(value = "/api/lotteryInfo/like")
// ResultVo likeByName(@RequestBody Map<String, Object> paramsMap);
} }
...@@ -133,4 +133,21 @@ public interface IApiLogic extends IApiCommon { ...@@ -133,4 +133,21 @@ public interface IApiLogic extends IApiCommon {
*/ */
ApiResp getDefaultAddress(ApiForm form); ApiResp getDefaultAddress(ApiForm form);
/**
* 有奖问答随机抽奖
*
* @param form
* @return
*/
ApiResp randomDraw(ApiForm form);
// /**
////// * 根据姓名模糊查询货单信息
////// *
////// * @param form
////// * @return
////// */
////// ApiResp likeByName(ApiForm form);
} }
...@@ -144,4 +144,26 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic { ...@@ -144,4 +144,26 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic {
return ApiUtils.toApiResp(form, userFeign.getDefaultAddress(form.getString("userId"))); return ApiUtils.toApiResp(form, userFeign.getDefaultAddress(form.getString("userId")));
} }
/**
* 有奖问答随机抽奖
* @param form
* @return
*/
@Override
public ApiResp randomDraw(ApiForm form) {
return ApiUtils.toApiResp(form, userFeign.randomDraw(form.getParamsMap()));
}
// /**
// * 根据姓名模糊查询货单信息
// *
// * @param form
// * @return
// */
// @Override
// public ApiResp likeByName(ApiForm form) {
// return ApiUtils.toApiResp(form, userFeign.likeByName(form.getParamsMap()));
// }
} }
...@@ -2,6 +2,8 @@ package com.zq.user.controller; ...@@ -2,6 +2,8 @@ package com.zq.user.controller;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
...@@ -113,9 +115,15 @@ public class LotteryInfoController { ...@@ -113,9 +115,15 @@ public class LotteryInfoController {
@PostMapping(value = "/isOpen") @PostMapping(value = "/isOpen")
public ResultVo isOpen(@RequestBody LotteryInfoVo vo) { public ResultVo isOpen(@RequestBody LotteryInfoVo vo) {
AssertUtils.isTrue(vo.getIsOpen() != null, "传入开关状态为空"); AssertUtils.isTrue(vo.getIsOpen() != null, "传入开关状态为空");
AssertUtils.isTrue(lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>().eq("is_open", 1)) != null, "已经存在一个开启的活动"); if (vo.getIsOpen() == 2) {
lotteryInfoService.isOpen(vo); lotteryInfoService.isOpen(vo);
return ResultVo.success("操作成功"); return ResultVo.success("操作成功");
} else if (vo.getIsOpen() == 1) {
AssertUtils.isTrue(lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>().eq("is_open", 1)).size() == 0, "已经存在一个已经开启的活动");
lotteryInfoService.isOpen(vo);
return ResultVo.success("操作成功");
}
return ResultVo.fail("操作失败");
} }
/** /**
...@@ -127,10 +135,15 @@ public class LotteryInfoController { ...@@ -127,10 +135,15 @@ public class LotteryInfoController {
@PostMapping(value = "/getIsOpen") @PostMapping(value = "/getIsOpen")
public ResultVo getIsOpen(@RequestBody LotteryInfoVo vo) { public ResultVo getIsOpen(@RequestBody LotteryInfoVo vo) {
LotteryInfo lotteryInfo = lotteryInfoDao.selectOne(new QueryWrapper<LotteryInfo>().eq("is_open", 1)); LotteryInfo lotteryInfo = lotteryInfoDao.selectOne(new QueryWrapper<LotteryInfo>().eq("is_open", 1));
LotteryInfoVo vo1 = new LotteryInfoVo();
BeanUtil.copyProperties(lotteryInfo, vo1);
LambdaQueryWrapper<LotteryPrize> wrapper = new LambdaQueryWrapper<>();
List<LotteryPrize> prizes = lotteryPrizeDao.selectList(wrapper.eq(LotteryPrize::getLotteryInfoId, vo.getId()));
vo1.setPrizeVos(prizes);
if (lotteryInfo == null) { if (lotteryInfo == null) {
ResultVo.fail("不存在开启成功的抽奖活动"); ResultVo.fail("不存在开启成功的抽奖活动");
} }
return ResultVo.success(lotteryInfo); return ResultVo.success(vo1);
} }
...@@ -147,5 +160,16 @@ public class LotteryInfoController { ...@@ -147,5 +160,16 @@ public class LotteryInfoController {
return ResultVo.success("操作成功"); return ResultVo.success("操作成功");
} }
// /**
// * 根据姓名模糊查询活动信息
// *
// * @param vo
// * @return
// */
// @ApiOperation("模糊查询活动信息")
// @PostMapping(value = "/like")
// public ResultVo likeByName(@RequestBody LotteryInfoVo vo) {
// return ResultVo.success(lotteryInfoService.getLotteryInfoByLike(vo));
// }
} }
...@@ -120,11 +120,11 @@ public class PrizeController { ...@@ -120,11 +120,11 @@ public class PrizeController {
/************************************************************************************/ /************************************************************************************/
@ApiOperation("获取抽奖记录") // @ApiOperation("获取抽奖记录")
@PostMapping(value = "/getLotteryRecList") // @PostMapping(value = "/getLotteryRecList")
public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) { // public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
return ResultVo.success(prizeService.getLotteryRecList(vo)); // return ResultVo.success(prizeService.getLotteryRecList(vo));
} // }
@ApiOperation("确认派奖") @ApiOperation("确认派奖")
@PutMapping(value = "/confirmAward") @PutMapping(value = "/confirmAward")
...@@ -134,4 +134,14 @@ public class PrizeController { ...@@ -134,4 +134,14 @@ public class PrizeController {
return ResultVo.success(); return ResultVo.success();
} }
// @ApiOperation("获取抽奖记录")
// @PostMapping(value = "/getLotteryRecList")
// public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
// return ResultVo.success(prizeService.getLotteryRecList(vo));
// }
@ApiOperation("抽奖记录列表")
@PostMapping(value = "/getLotteryRecList")
public ResultVo getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
return ResultVo.success(prizeService.getLotteryRecList(vo));
}
} }
package com.zq.user.controller; package com.zq.user.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.IdVo; import com.zq.common.vo.IdVo;
import com.zq.common.vo.PageVo; import com.zq.common.vo.PageVo;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.user.entity.AnswerRec; import com.zq.user.dao.AnswerRecDao;
import com.zq.user.entity.Question; import com.zq.user.entity.*;
import com.zq.user.entity.QuestionType; import com.zq.user.service.PrizeService;
import com.zq.user.service.QuestionService; import com.zq.user.service.QuestionService;
import com.zq.user.vo.LotteryInfoVo;
import com.zq.user.vo.LotteryRecFindVo;
import com.zq.user.vo.QuestionFindVo; import com.zq.user.vo.QuestionFindVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -26,7 +29,11 @@ import java.util.List; ...@@ -26,7 +29,11 @@ import java.util.List;
@RequestMapping(value = "/user/question") @RequestMapping(value = "/user/question")
public class QuestionController { public class QuestionController {
private final QuestionService questionService; private final QuestionService questionService;
private final PrizeService prizeService;
private final AnswerRecDao answerRecDao;
@ApiOperation("获取全部题型") @ApiOperation("获取全部题型")
@GetMapping(value = "/getAllQuestionType") @GetMapping(value = "/getAllQuestionType")
...@@ -73,9 +80,15 @@ public class QuestionController { ...@@ -73,9 +80,15 @@ public class QuestionController {
} }
@ApiOperation("获取答题记录") @ApiOperation("获取答题记录")
@GetMapping(value = "/getAnswerRecs") @PostMapping(value = "/getAnswerRecs")
public ResultVo getAnswerRecs(@RequestBody AnswerRec answerRec) { public ResultVo getAnswerRecs(@RequestBody AnswerRec answerRec) {
return ResultVo.success(questionService.getAnswerRec(answerRec)); return ResultVo.success(questionService.getAnswerRec(answerRec));
} }
} @ApiOperation("有奖问答随机抽奖 randomDraw")
@PostMapping(value = "/randomDraw")
public ResultVo randomDraw(@RequestBody LotteryRecFindVo vo) {
AssertUtils.isTrue(answerRecDao.selectCount(new LambdaQueryWrapper<AnswerRec>().eq(AnswerRec::getLotteryId, vo.getId())) == 0, "该活动已经抽过奖了");
return ResultVo.success(prizeService.randomDraw(vo));
}
}
\ No newline at end of file
...@@ -9,6 +9,7 @@ import com.zq.user.entity.PrizeType; ...@@ -9,6 +9,7 @@ import com.zq.user.entity.PrizeType;
import com.zq.user.service.PrizeService; import com.zq.user.service.PrizeService;
import com.zq.user.vo.LotteryRecFindVo; import com.zq.user.vo.LotteryRecFindVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -33,18 +34,23 @@ public class PrizeApi { ...@@ -33,18 +34,23 @@ public class PrizeApi {
return ResultVo.success(prizeService.getAllPrizeType()); return ResultVo.success(prizeService.getAllPrizeType());
} }
@ApiOperation("抽奖") // @ApiOperation("抽奖")
@GetMapping(value = "/luckDraw") // @GetMapping(value = "/luckDraw")
public ResultVo<Prize> luckDraw(@RequestParam String userId) { // public ResultVo<Prize> luckDraw(@RequestParam String userId) {
// return ResultVo.success(prizeService.luckDraw(userId));
return ResultVo.success(prizeService.luckDraw(userId)); // }
}
// @ApiOperation("抽奖记录列表")
@ApiOperation("抽奖记录列表") // @PostMapping(value = "/getLotteryRecList")
@PostMapping(value = "/getLotteryRecList") // public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) { // AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
AssertUtils.hasText(vo.getUserId(), "缺少用户ID"); // return ResultVo.success(prizeService.getLotteryRecList(vo));
return ResultVo.success(prizeService.getLotteryRecList(vo)); // }
} @ApiOperation("抽奖记录列表(传入用户id返回用户,不传入返回全部) getLotteryRecList")
@PostMapping(value = "/getLotteryRecList")
public ResultVo getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
return ResultVo.success(prizeService.getLotteryRecList(vo));
}
} }
...@@ -3,7 +3,9 @@ package com.zq.user.controller.api; ...@@ -3,7 +3,9 @@ package com.zq.user.controller.api;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.user.entity.AnswerRec; import com.zq.user.entity.AnswerRec;
import com.zq.user.service.PrizeService;
import com.zq.user.service.QuestionService; import com.zq.user.service.QuestionService;
import com.zq.user.vo.LotteryRecFindVo;
import com.zq.user.vo.QuestionFindVo; import com.zq.user.vo.QuestionFindVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping(value = "/user/api/question") @RequestMapping(value = "/user/api/question")
public class QuestionApi { public class QuestionApi {
private final PrizeService prizeService;
private final QuestionService questionService; private final QuestionService questionService;
@ApiOperation("获取题目列表") @ApiOperation("获取题目列表")
...@@ -33,10 +36,15 @@ public class QuestionApi { ...@@ -33,10 +36,15 @@ public class QuestionApi {
public ResultVo answer(@RequestBody AnswerRec vo) { public ResultVo answer(@RequestBody AnswerRec vo) {
AssertUtils.hasText(vo.getUserId(), "缺少用户ID"); AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
AssertUtils.hasText(vo.getAnswerList(), "缺少答案"); AssertUtils.hasText(vo.getAnswerList(), "缺少答案");
return ResultVo.success(questionService.answer(vo)); return ResultVo.success(questionService.answer(vo));
} }
@ApiOperation("有奖问答随机抽奖")
@PostMapping(value = "/randomDraw")
public ResultVo randomDraw(@RequestBody LotteryRecFindVo vo) {
return ResultVo.success(prizeService.randomDraw(vo));
}
@ApiOperation("获取答题记录") @ApiOperation("获取答题记录")
@PostMapping(value = "/getAnswerRecs") @PostMapping(value = "/getAnswerRecs")
public ResultVo getAnswerRecs(@RequestBody AnswerRec answerRec) { public ResultVo getAnswerRecs(@RequestBody AnswerRec answerRec) {
......
package com.zq.user.controller.api; package com.zq.user.controller.api;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
...@@ -15,6 +17,7 @@ import lombok.RequiredArgsConstructor; ...@@ -15,6 +17,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
/** /**
* @Author: jcm * @Author: jcm
...@@ -103,9 +106,15 @@ public class lotteryInfoApi { ...@@ -103,9 +106,15 @@ public class lotteryInfoApi {
@PostMapping(value = "/isOpen") @PostMapping(value = "/isOpen")
public ResultVo isOpen(@RequestBody LotteryInfoVo vo) { public ResultVo isOpen(@RequestBody LotteryInfoVo vo) {
AssertUtils.isTrue(vo.getIsOpen() != null, "传入开关状态为空"); AssertUtils.isTrue(vo.getIsOpen() != null, "传入开关状态为空");
AssertUtils.isTrue(lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>().eq("is_open", 1)) != null, "已经存在一个开启的活动"); if (vo.getIsOpen() == 2) {
lotteryInfoService.isOpen(vo); lotteryInfoService.isOpen(vo);
return ResultVo.success("操作成功"); return ResultVo.success("操作成功");
} else if (vo.getIsOpen() == 1) {
AssertUtils.isTrue(lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>().eq("is_open", 1)).size() == 0, "已经存在一个已经开启的活动");
lotteryInfoService.isOpen(vo);
return ResultVo.success("操作成功");
}
return ResultVo.fail("操作失败");
} }
/** /**
...@@ -117,10 +126,15 @@ public class lotteryInfoApi { ...@@ -117,10 +126,15 @@ public class lotteryInfoApi {
@PostMapping(value = "/getIsOpen") @PostMapping(value = "/getIsOpen")
public ResultVo getIsOpen(@RequestBody LotteryInfoVo vo) { public ResultVo getIsOpen(@RequestBody LotteryInfoVo vo) {
LotteryInfo lotteryInfo = lotteryInfoDao.selectOne(new QueryWrapper<LotteryInfo>().eq("is_open", 1)); LotteryInfo lotteryInfo = lotteryInfoDao.selectOne(new QueryWrapper<LotteryInfo>().eq("is_open", 1));
LotteryInfoVo vo1 = new LotteryInfoVo();
BeanUtil.copyProperties(lotteryInfo, vo1);
LambdaQueryWrapper<LotteryPrize> wrapper = new LambdaQueryWrapper<>();
List<LotteryPrize> prizes = lotteryPrizeDao.selectList(wrapper.eq(LotteryPrize::getLotteryInfoId, vo1.getId()));
vo1.setPrizeVos(prizes);
if (lotteryInfo == null) { if (lotteryInfo == null) {
ResultVo.fail("不存在开启成功的抽奖活动"); ResultVo.fail("不存在开启成功的抽奖活动");
} }
return ResultVo.success(lotteryInfo); return ResultVo.success(vo1);
} }
...@@ -132,9 +146,21 @@ public class lotteryInfoApi { ...@@ -132,9 +146,21 @@ public class lotteryInfoApi {
@ApiOperation("删除该活动") @ApiOperation("删除该活动")
@PostMapping(value = "/delete") @PostMapping(value = "/delete")
public ResultVo delete(@RequestBody LotteryInfoVo vo) { public ResultVo delete(@RequestBody LotteryInfoVo vo) {
AssertUtils.isTrue(vo.getId() != null, "传入开关状态为空"); AssertUtils.isTrue(vo.getId() != null, "传入活动id为空");
lotteryInfoService.delete(vo); lotteryInfoService.delete(vo);
return ResultVo.success("操作成功"); return ResultVo.success("操作成功");
} }
/**
* 根据姓名模糊查询活动信息
*
* @param vo
* @return
*/
@ApiOperation("模糊查询活动信息")
@PostMapping(value = "/like")
public ResultVo likeByName(@RequestBody LotteryInfoVo vo) {
return ResultVo.success(lotteryInfoService.getLotteryInfoByLike(vo));
}
} }
...@@ -58,11 +58,13 @@ public class AnswerRec { ...@@ -58,11 +58,13 @@ public class AnswerRec {
/** /**
* 抽奖活动ID * 抽奖活动ID
*/ */
@ApiModelProperty("抽奖活动ID")
private Integer lotteryId; private Integer lotteryId;
/** /**
* 抽奖活动名 * 抽奖活动名
*/ */
@ApiModelProperty("抽奖活动名")
private String lotteryName; private String lotteryName;
} }
...@@ -32,6 +32,12 @@ class LotteryPrize implements Serializable { ...@@ -32,6 +32,12 @@ class LotteryPrize implements Serializable {
private Integer id; private Integer id;
/** /**
* 奖品类型 关联奖品类型(t_prize)表id
*/
@ApiModelProperty(value = "奖品id 关联奖品类型(t_prize)表id")
private Long prizeId;
/**
* 奖品类型 关联奖品类型(t_prize_type)表id * 奖品类型 关联奖品类型(t_prize_type)表id
*/ */
@ApiModelProperty(value = "奖品类型 关联奖品类型(t_prize_type)表id") @ApiModelProperty(value = "奖品类型 关联奖品类型(t_prize_type)表id")
......
...@@ -100,4 +100,16 @@ public class LotteryRec { ...@@ -100,4 +100,16 @@ public class LotteryRec {
@TableField(exist = false) @TableField(exist = false)
private Address address; private Address address;
/**
* 抽奖活动ID
*/
@ApiModelProperty("抽奖活动ID")
private Integer lotteryId;
/**
* 抽奖活动名
*/
@ApiModelProperty("抽奖活动名")
private String lotteryName;
} }
...@@ -55,7 +55,7 @@ public class LotteryInfoService { ...@@ -55,7 +55,7 @@ public class LotteryInfoService {
// List<LotteryPrizeVo> list = vo.getPrizeVos(); // List<LotteryPrizeVo> list = vo.getPrizeVos();
Integer id = Integer.parseInt(generateRandom()); Integer id = Integer.parseInt(generateRandom());
vo.setId(id); vo.setId(id);
// todo 2022813 这里的关联的类型标是type而不是type_id // todo 2022813 这里的关联的类型标是prize而不是prize_type
LotteryInfo lotteryInfo = new LotteryInfo(); LotteryInfo lotteryInfo = new LotteryInfo();
BeanUtil.copyProperties(vo, lotteryInfo); BeanUtil.copyProperties(vo, lotteryInfo);
lotteryInfo.setIsOpen(2); lotteryInfo.setIsOpen(2);
...@@ -67,6 +67,7 @@ public class LotteryInfoService { ...@@ -67,6 +67,7 @@ public class LotteryInfoService {
LotteryPrize lotteryPrize = LotteryPrize LotteryPrize lotteryPrize = LotteryPrize
.builder() .builder()
.lotteryInfoId(vo.getId()) .lotteryInfoId(vo.getId())
.prizeId(type.getId())
.prizeTypeId(type.getPrizeTypeId()) .prizeTypeId(type.getPrizeTypeId())
.prizeName(type.getPrizeName()) .prizeName(type.getPrizeName())
.createTime(DateUtil.date()) .createTime(DateUtil.date())
...@@ -76,7 +77,7 @@ public class LotteryInfoService { ...@@ -76,7 +77,7 @@ public class LotteryInfoService {
} }
public static synchronized String generateRandom(){ public static synchronized String generateRandom() {
//使用当前时间生成时间戳yyyyMMddHHmmssSSS //使用当前时间生成时间戳yyyyMMddHHmmssSSS
StringBuffer suf = new StringBuffer(DateFormatUtils.format(Calendar.getInstance(), "ssSSS")); StringBuffer suf = new StringBuffer(DateFormatUtils.format(Calendar.getInstance(), "ssSSS"));
//生成3位随机数 //生成3位随机数
...@@ -85,7 +86,7 @@ public class LotteryInfoService { ...@@ -85,7 +86,7 @@ public class LotteryInfoService {
} }
// public PageVo<Prize> getPrizeList(PrizeFindVo vo) { // public PageVo<Prize> getPrizeList(PrizeFindVo vo) {
// LambdaQueryWrapper<Prize> lambdaQuery = Wrappers.lambdaQuery(Prize.class); // LambdaQueryWrapper<Prize> lambdaQuery = Wrappers.lambdaQuery(Prize.class);
// lambdaQuery.orderByDesc(Prize::getCreateTime); // lambdaQuery.orderByDesc(Prize::getCreateTime);
// //
...@@ -105,7 +106,13 @@ public class LotteryInfoService { ...@@ -105,7 +106,13 @@ public class LotteryInfoService {
public PageVo<LotteryInfoVo> getLotteryInfo(LotteryInfoVo vo) { public PageVo<LotteryInfoVo> getLotteryInfo(LotteryInfoVo vo) {
LambdaQueryWrapper<LotteryInfo> lambdaQuery = Wrappers.lambdaQuery(LotteryInfo.class); LambdaQueryWrapper<LotteryInfo> lambdaQuery = Wrappers.lambdaQuery(LotteryInfo.class);
// 模糊查询活动名
if (vo.getLotteryInfoName() != null) {
lambdaQuery.like(LotteryInfo::getLotteryInfoName, vo.getLotteryInfoName());
}
lambdaQuery.orderByDesc(LotteryInfo::getCreateTime); lambdaQuery.orderByDesc(LotteryInfo::getCreateTime);
PageVo<LotteryInfo> paging = PagingUtils.paging(vo, lotteryInfoDao, lambdaQuery, LotteryInfo.class); PageVo<LotteryInfo> paging = PagingUtils.paging(vo, lotteryInfoDao, lambdaQuery, LotteryInfo.class);
...@@ -129,9 +136,7 @@ public class LotteryInfoService { ...@@ -129,9 +136,7 @@ public class LotteryInfoService {
public void isOpen(LotteryInfoVo vo) { public void isOpen(LotteryInfoVo vo) {
System.out.println(vo);
Integer id = vo.getId(); Integer id = vo.getId();
System.out.println(id);
LotteryInfo info = new LotteryInfo(); LotteryInfo info = new LotteryInfo();
info.setId(id); info.setId(id);
if (vo.getIsOpen() != null) { if (vo.getIsOpen() != null) {
...@@ -181,6 +186,7 @@ public class LotteryInfoService { ...@@ -181,6 +186,7 @@ public class LotteryInfoService {
LotteryPrize lotteryPrize = LotteryPrize LotteryPrize lotteryPrize = LotteryPrize
.builder() .builder()
.lotteryInfoId(vo.getId()) .lotteryInfoId(vo.getId())
.prizeId(type.getId())
.prizeTypeId(type.getPrizeTypeId()) .prizeTypeId(type.getPrizeTypeId())
.prizeName(type.getPrizeName()) .prizeName(type.getPrizeName())
.createTime(DateUtil.date()) .createTime(DateUtil.date())
...@@ -195,5 +201,34 @@ public class LotteryInfoService { ...@@ -195,5 +201,34 @@ public class LotteryInfoService {
lotteryPrizeDao.deleteBatchIds(lotteryPrizeDao.selectList(new QueryWrapper<LotteryPrize>().eq("lottery_info_id", vo.getId()))); lotteryPrizeDao.deleteBatchIds(lotteryPrizeDao.selectList(new QueryWrapper<LotteryPrize>().eq("lottery_info_id", vo.getId())));
} }
/**
* 根据姓名模糊查询活动介绍
*
* @param vo
* @return
*/
public PageVo<LotteryInfoVo> getLotteryInfoByLike(LotteryInfoVo vo) {
LambdaQueryWrapper<LotteryInfo> lambdaQuery = Wrappers.lambdaQuery(LotteryInfo.class);
lambdaQuery.like(LotteryInfo::getLotteryInfoName, vo.getLotteryInfoName()).orderByDesc(LotteryInfo::getCreateTime);
PageVo<LotteryInfo> paging = PagingUtils.paging(vo, lotteryInfoDao, lambdaQuery, LotteryInfo.class);
List<LotteryInfoVo> infoVos = new ArrayList<>();
List<LotteryInfo> infos = paging.getRows();
for (LotteryInfo info : infos) {
LotteryInfoVo infoVo = new LotteryInfoVo();
BeanUtil.copyProperties(info, infoVo);
List<LotteryPrize> lotteryPrizeVos = lotteryPrizeDao.selectList(new QueryWrapper<LotteryPrize>().eq("lottery_info_id", info.getId()));
infoVo.setPrizeVos(lotteryPrizeVos);
infoVos.add(infoVo);
}
PageVo<LotteryInfoVo> page = new PageVo<>();
page.setTotal(paging.getTotal());
page.setRows(infoVos);
page.setSize(paging.getSize());
page.setStart(paging.getStart());
return page;
}
} }
...@@ -5,20 +5,22 @@ import cn.hutool.core.date.DateUtil; ...@@ -5,20 +5,22 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.utils.PagingUtils; import com.zq.common.utils.PagingUtils;
import com.zq.common.vo.PageVo; import com.zq.common.vo.PageVo;
import com.zq.user.dao.LotteryRecDao; import com.zq.common.vo.ResultVo;
import com.zq.user.dao.PrizeDao; import com.zq.user.dao.*;
import com.zq.user.dao.PrizeTypeDao; import com.zq.user.entity.*;
import com.zq.user.entity.Address; import com.zq.user.vo.LotteryInfoVo;
import com.zq.user.entity.LotteryRec;
import com.zq.user.entity.Prize;
import com.zq.user.entity.PrizeType;
import com.zq.user.vo.LotteryRecFindVo; import com.zq.user.vo.LotteryRecFindVo;
import com.zq.user.vo.PrizeFindVo; import com.zq.user.vo.PrizeFindVo;
import com.zq.user.vo.PrizeTypeFindVo; import com.zq.user.vo.PrizeTypeFindVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -45,6 +47,14 @@ PrizeService { ...@@ -45,6 +47,14 @@ PrizeService {
private final LotteryRecDao lotteryRecDao; private final LotteryRecDao lotteryRecDao;
private final PrizeTypeDao prizeTypeDao; private final PrizeTypeDao prizeTypeDao;
private final AddressService addressService; private final AddressService addressService;
private final LotteryPrizeDao lotteryPrizeDao;
private final LotteryInfoDao lotteryInfoDao;
private final LotteryInfoService infoService;
private final QuestionService questionService;
private final AnswerRecDao answerRecDao;
private final AddressDao addressDao;
public List<PrizeType> getAllPrizeType() { public List<PrizeType> getAllPrizeType() {
return prizeTypeDao.selectList(Wrappers.lambdaQuery(PrizeType.class) return prizeTypeDao.selectList(Wrappers.lambdaQuery(PrizeType.class)
...@@ -116,28 +126,46 @@ PrizeService { ...@@ -116,28 +126,46 @@ PrizeService {
return prizeDao.selectById(prizeId); return prizeDao.selectById(prizeId);
} }
public Prize luckDraw(String userId) { // todo 抽奖模块尚未修改
List<Prize> prizeList = prizeDao.getLuckDrawPrize(); public LotteryRecFindVo luckDraw(String userId, LotteryInfoVo infoVo) {
// List<Prize> prizeList = prizeDao.getLuckDrawPrize();
// 当期活动奖品列表
List<LotteryPrize> prizes = infoService.getLotteryInfoByOne(infoVo).getPrizeVos();
// return null;
List<Prize> prizeList = new ArrayList<>();
for (LotteryPrize lotteryPrize : prizes) {
//得到奖品对象
Prize prize = prizeDao.selectById(lotteryPrize.getPrizeId());
prizeList.add(prize);
}
// prizeList = prizeList.stream()
// .filter(prize -> prize.getPublishCount() - prize.getHadOutCount() > 0)
// .collect(Collectors.toList());
prizeList = prizeList.stream()
.filter(prize -> prize.getPublishCount() - prize.getHadOutCount() > 0)
.collect(Collectors.toList());
List<Long> prizeIdList = new ArrayList<>(); List<Long> prizeIdList = new ArrayList<>();
for (Prize prize : prizeList) { for (Prize prize : prizeList) {
//概率x100
BigDecimal count = prize.getAwardRate().multiply(BigDecimal.valueOf(100)); BigDecimal count = prize.getAwardRate().multiply(BigDecimal.valueOf(100));
//遍历这个概率的次数,将礼品id添加到礼品列表中
for (int i = 0; i < count.intValue(); i++) { for (int i = 0; i < count.intValue(); i++) {
prizeIdList.add(prize.getId()); prizeIdList.add(prize.getId());
} }
} }
// 从礼品列表开始,知道100,没有礼品的列表则填满0
for (int i = prizeIdList.size(); i < 100; i++) { for (int i = prizeIdList.size(); i < 100; i++) {
prizeIdList.add(0L); prizeIdList.add(0L);
} }
// 对列表进行随机性排序
Collections.shuffle(prizeIdList); Collections.shuffle(prizeIdList);
// 获得一个随机数,范围为0 - 礼品列表的大小
int index = RandomUtil.randomInt(0, prizeIdList.size()); int index = RandomUtil.randomInt(0, prizeIdList.size());
// 获得礼品id根据随机下标获得
Long prizeId = prizeIdList.get(index); Long prizeId = prizeIdList.get(index);
// 如果礼品列表为0则将其视为未中奖
if (prizeId == 0) { if (prizeId == 0) {
LotteryRec build = LotteryRec.builder() LotteryRec build = LotteryRec.builder()
.prizeId(prizeId) .prizeId(prizeId)
...@@ -145,15 +173,17 @@ PrizeService { ...@@ -145,15 +173,17 @@ PrizeService {
.activityType(2) .activityType(2)
.awardStatus(0) .awardStatus(0)
.active(0) .active(0)
//新加的活动名称和活动ID
.lotteryId(infoVo.getId())
.lotteryName(infoVo.getLotteryInfoName())
.prizeTypeName("未中奖!") .prizeTypeName("未中奖!")
.createTime(DateUtil.date()) .createTime(DateUtil.date())
.updateTime(DateUtil.date()) .updateTime(DateUtil.date())
.build(); .build();
lotteryRecDao.insert(build); lotteryRecDao.insert(build);
return null; return null;
} }
// 如果礼品列表不为0则视为抽到该礼品,并修改数据库相关代码
Prize prize = prizeDao.selectById(prizeId); Prize prize = prizeDao.selectById(prizeId);
prize.setHadOutCount(prize.getHadOutCount() + 1); prize.setHadOutCount(prize.getHadOutCount() + 1);
prize.setUpdateTime(DateUtil.date()); prize.setUpdateTime(DateUtil.date());
...@@ -172,13 +202,28 @@ PrizeService { ...@@ -172,13 +202,28 @@ PrizeService {
.prizeTypeId(prize.getPrizeTypeId()) .prizeTypeId(prize.getPrizeTypeId())
.prizeTypeName(prizeType.getTypeName()) .prizeTypeName(prizeType.getTypeName())
.active(0) .active(0)
//新加的活动名称和活动ID
.lotteryId(infoVo.getId())
.lotteryName(infoVo.getLotteryInfoName())
.createTime(DateUtil.date()) .createTime(DateUtil.date())
.updateTime(DateUtil.date()) .updateTime(DateUtil.date())
.build(); .build();
int count = lotteryRecDao.insert(build);
// todo 返回值没想好返回什么
// 返回抽奖记录列表vo
QueryWrapper<LotteryRec> wrapper = new QueryWrapper<>();
LotteryRec rec = lotteryRecDao.selectOne(wrapper.eq("user_id", userId).eq("lottery_id", infoVo.getId()));
LotteryRecFindVo lotteryRecFindVo = new LotteryRecFindVo();
BeanUtil.copyProperties(rec, lotteryRecFindVo);
QueryWrapper<Address> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", userId);
lotteryRecFindVo.setConsignee(addressDao.selectOne(queryWrapper).getConsignee());
lotteryRecFindVo.setConsigneeAddress(addressDao.selectOne(queryWrapper).getConsigneeAddress());
lotteryRecFindVo.setConsigneePhone(addressDao.selectOne(queryWrapper).getConsigneePhone());
lotteryRecFindVo.setNickname(addressDao.selectOne(queryWrapper).getNickName());
return lotteryRecFindVo;
lotteryRecDao.insert(build);
return prize;
} }
public PageVo<PrizeType> getPrizeTypeList(PrizeTypeFindVo vo) { public PageVo<PrizeType> getPrizeTypeList(PrizeTypeFindVo vo) {
...@@ -225,13 +270,49 @@ PrizeService { ...@@ -225,13 +270,49 @@ PrizeService {
return prizeTypeDao.selectById(prizeTypeId); return prizeTypeDao.selectById(prizeTypeId);
} }
public PageVo<LotteryRec> getLotteryRecList(LotteryRecFindVo vo) { // public PageVo<LotteryRec> getLotteryRecList(LotteryRecFindVo vo) {
PageVo<LotteryRec> paging = PagingUtils.paging(vo, prizeDao::getLotteryRecList); // PageVo<LotteryRec> paging = PagingUtils.paging(vo, prizeDao::getLotteryRecList);
paging.getRows().forEach(lotteryRec -> { // paging.getRows().forEach(lotteryRec -> {
Address defaultAddress = addressService.getDefaultAddress(lotteryRec.getUserId()); // Address defaultAddress = addressService.getDefaultAddress(lotteryRec.getUserId());
lotteryRec.setAddress(defaultAddress); // lotteryRec.setAddress(defaultAddress);
}); // });
return paging; // return paging;
// }
public ResultVo getLotteryRecList(LotteryRecFindVo vo) {
// PageVo<LotteryRec> paging = PagingUtils.paging(vo, prizeDao::getLotteryRecList);
LambdaQueryWrapper<LotteryRec> wrapper = new LambdaQueryWrapper<>();
if (vo.getUserId() != null) {
wrapper.eq(LotteryRec::getUserId, vo.getUserId());
Page<LotteryRec> page = new Page<>(vo.getPage(), vo.getSize());
return ResultVo.success(lotteryRecDao.selectPage(page, wrapper));
} else {
Page<LotteryRec> page = new Page<>(vo.getPage(), vo.getSize());
page = lotteryRecDao.selectPage(page, wrapper);
List<LotteryRec> recs = page.getRecords();
List<LotteryRecFindVo> recFindVos = new ArrayList<>();
for (LotteryRec rec : recs) {
LotteryRecFindVo findVo = new LotteryRecFindVo();
BeanUtil.copyProperties(rec, findVo);
QueryWrapper<Address> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", rec.getUserId());
queryWrapper.eq("is_default", 1);
queryWrapper.last("limit 1");
// findVo.setConsignee(addressDao.selectOne(queryWrapper).getConsignee());
findVo.setConsigneeAddress(addressDao.selectOne(queryWrapper).getConsigneeAddress());
findVo.setConsigneePhone(addressDao.selectOne(queryWrapper).getConsigneePhone());
findVo.setNickname(addressDao.selectOne(queryWrapper).getNickName());
// 多个地址问题
recFindVos.add(findVo);
}
PageVo<LotteryRecFindVo> pageVo = new PageVo<>();
pageVo.setRows(recFindVos);
pageVo.setStart((int) page.getPages());
pageVo.setSize((int) page.getSize());
pageVo.setTotal((int) page.getTotal());
return ResultVo.success(pageVo);
}
} }
public void confirmAward(Long lotteryRecId) { public void confirmAward(Long lotteryRecId) {
...@@ -244,4 +325,36 @@ PrizeService { ...@@ -244,4 +325,36 @@ PrizeService {
lotteryRecDao.updateById(lotteryRec); lotteryRecDao.updateById(lotteryRec);
} }
public List<LotteryRecFindVo> randomDraw(LotteryRecFindVo vo) {
AssertUtils.isTrue(answerRecDao.selectCount(new LambdaQueryWrapper<AnswerRec>().eq(AnswerRec::getLotteryId, vo.getLotteryId())) == 0, "该活动已经抽过奖了");
// 当期活动参与答题的用户id列表
QueryWrapper<AnswerRec> wrapper = new QueryWrapper<>();
wrapper.select("DISTINCT user_id").eq("lottery_id", vo.getId());
List<String> answerRecUserIds = new ArrayList<>();
List<AnswerRec> answerRecs = answerRecDao.selectList(wrapper);
for (AnswerRec answerRec : answerRecs) {
answerRecUserIds.add(answerRec.getUserId());
}
LotteryInfoVo infoVo = new LotteryInfoVo();
BeanUtil.copyProperties(vo, infoVo);
infoVo.setLotteryInfoName(vo.getLotteryName());
// // 当期活动奖品列表
List<LotteryPrize> prizes = infoService.getLotteryInfoByOne(infoVo).getPrizeVos();
List<Prize> prizeList = new ArrayList<>();
for (LotteryPrize lotteryPrize : prizes) {
//得到奖品对象
Prize prize = prizeDao.selectById(lotteryPrize.getPrizeId());
prizeList.add(prize);
}
List<LotteryRecFindVo> findVos = new ArrayList<>();
for (String userId : answerRecUserIds) {
LotteryRecFindVo findVo = new LotteryRecFindVo();
findVo = luckDraw(userId, infoVo);
findVos.add(findVo);
}
return findVos;
}
} }
...@@ -179,17 +179,22 @@ public class QuestionService { ...@@ -179,17 +179,22 @@ public class QuestionService {
public List<AnswerRec> getAnswerRec(AnswerRec answerRec) { public List<AnswerRec> getAnswerRec(AnswerRec answerRec) {
LambdaQueryWrapper<AnswerRec> wrapper = new LambdaQueryWrapper<AnswerRec>(); if (answerRec.getUserId() != null) {
List<LotteryInfo> infos = lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>()); LambdaQueryWrapper<AnswerRec> wrapper = new LambdaQueryWrapper<AnswerRec>();
System.out.println("info="+infos); List<AnswerRec> recs = answerRecDao.selectList(wrapper.eq(AnswerRec::getUserId, answerRec.getUserId()));
List<AnswerRec> recs = new ArrayList<>(); return recs;
for (LotteryInfo info : infos) { } else {
wrapper.eq(AnswerRec::getLotteryId, info.getId()).eq(AnswerRec::getUserId, answerRec.getUserId()).orderByDesc(AnswerRec::getScore).last("limit 1"); LambdaQueryWrapper<AnswerRec> wrapper = new LambdaQueryWrapper<AnswerRec>();
AnswerRec rec = answerRecDao.selectOne(wrapper); List<LotteryInfo> infos = lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>());
recs.add(rec); System.out.println("info="+infos);
List<AnswerRec> recs = new ArrayList<>();
for (LotteryInfo info : infos) {
wrapper.eq(AnswerRec::getLotteryId, info.getId()).eq(AnswerRec::getUserId, answerRec.getUserId()).orderByDesc(AnswerRec::getScore).last("limit 1");
AnswerRec rec = answerRecDao.selectOne(wrapper);
recs.add(rec);
}
AssertUtils.isTrue(recs != null, "没有历史答题记录,请先完成答题");
return recs;
} }
AssertUtils.isTrue(recs != null, "没有历史答题记录,请先完成答题");
return recs;
} }
} }
...@@ -15,7 +15,6 @@ import java.util.Date; ...@@ -15,7 +15,6 @@ import java.util.Date;
* @Author: TangCong * @Author: TangCong
* @Date: 2022-8-13 10:45 * @Date: 2022-8-13 10:45
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
...@@ -55,4 +54,5 @@ public class AnswerRecVo extends PageReqVo { ...@@ -55,4 +54,5 @@ public class AnswerRecVo extends PageReqVo {
* 抽奖活动名 * 抽奖活动名
*/ */
private String lotteryName; private String lotteryName;
} }
...@@ -29,12 +29,20 @@ public class LotteryPrizeVo extends PageReqVo { ...@@ -29,12 +29,20 @@ public class LotteryPrizeVo extends PageReqVo {
private Integer id; private Integer id;
/** /**
* 奖品类型 关联奖品类型(t_prize)表id
*/
@ApiModelProperty(value = "奖品id 关联奖品类型(t_prize)表id")
private Long prizeId;
/**
* 奖品类型 关联奖品类型(t_prize_type)表id * 奖品类型 关联奖品类型(t_prize_type)表id
*/ */
@ApiModelProperty(value = "奖品类型 关联奖品类型(t_prize_type)表id") @ApiModelProperty(value = "奖品类型 关联奖品类型(t_prize_type)表id")
private Integer prizeTypeId; private Integer prizeTypeId;
/** /**
* 奖品名 * 奖品名
*/ */
......
...@@ -93,4 +93,37 @@ public class LotteryRecFindVo extends PageReqVo { ...@@ -93,4 +93,37 @@ public class LotteryRecFindVo extends PageReqVo {
@TableField(exist = false) @TableField(exist = false)
private String displayName; private String displayName;
/**
* 抽奖活动ID
*/
@ApiModelProperty("抽奖活动ID")
private Integer lotteryId;
/**
* 抽奖活动名
*/
@ApiModelProperty("抽奖活动名")
private String lotteryName;
/**
* 收货人
*/
@ApiModelProperty("收货人")
private String consignee;
/**
* 收货人手机号
*/
@ApiModelProperty("收货人手机号")
private String consigneePhone;
/**
* 地址
*/
@ApiModelProperty("地址")
private String consigneeAddress;
@ApiModelProperty("用户昵称")
private String nickName;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment