Commit 18e92d1b by 唐聪

完成抽奖模块

parent 769c29ea
......@@ -65,4 +65,9 @@ public interface UserFeign {
@PostMapping(value = "/api/question/getAnswerRecs")
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 {
*/
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 {
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;
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.extension.plugins.pagination.Page;
import com.zq.common.utils.AssertUtils;
......@@ -113,9 +115,15 @@ public class LotteryInfoController {
@PostMapping(value = "/isOpen")
public ResultVo isOpen(@RequestBody LotteryInfoVo vo) {
AssertUtils.isTrue(vo.getIsOpen() != null, "传入开关状态为空");
AssertUtils.isTrue(lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>().eq("is_open", 1)) != null, "已经存在一个开启的活动");
if (vo.getIsOpen() == 2) {
lotteryInfoService.isOpen(vo);
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 {
@PostMapping(value = "/getIsOpen")
public ResultVo getIsOpen(@RequestBody LotteryInfoVo vo) {
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) {
ResultVo.fail("不存在开启成功的抽奖活动");
}
return ResultVo.success(lotteryInfo);
return ResultVo.success(vo1);
}
......@@ -147,5 +160,16 @@ public class LotteryInfoController {
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 {
/************************************************************************************/
@ApiOperation("获取抽奖记录")
@PostMapping(value = "/getLotteryRecList")
public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
return ResultVo.success(prizeService.getLotteryRecList(vo));
}
// @ApiOperation("获取抽奖记录")
// @PostMapping(value = "/getLotteryRecList")
// public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
// return ResultVo.success(prizeService.getLotteryRecList(vo));
// }
@ApiOperation("确认派奖")
@PutMapping(value = "/confirmAward")
......@@ -134,4 +134,14 @@ public class PrizeController {
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;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.IdVo;
import com.zq.common.vo.PageVo;
import com.zq.common.vo.ResultVo;
import com.zq.user.entity.AnswerRec;
import com.zq.user.entity.Question;
import com.zq.user.entity.QuestionType;
import com.zq.user.dao.AnswerRecDao;
import com.zq.user.entity.*;
import com.zq.user.service.PrizeService;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -26,7 +29,11 @@ import java.util.List;
@RequestMapping(value = "/user/question")
public class QuestionController {
private final QuestionService questionService;
private final PrizeService prizeService;
private final AnswerRecDao answerRecDao;
@ApiOperation("获取全部题型")
@GetMapping(value = "/getAllQuestionType")
......@@ -73,9 +80,15 @@ public class QuestionController {
}
@ApiOperation("获取答题记录")
@GetMapping(value = "/getAnswerRecs")
@PostMapping(value = "/getAnswerRecs")
public ResultVo getAnswerRecs(@RequestBody AnswerRec 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;
import com.zq.user.service.PrizeService;
import com.zq.user.vo.LotteryRecFindVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
......@@ -33,17 +34,22 @@ public class PrizeApi {
return ResultVo.success(prizeService.getAllPrizeType());
}
@ApiOperation("抽奖")
@GetMapping(value = "/luckDraw")
public ResultVo<Prize> luckDraw(@RequestParam String userId) {
return ResultVo.success(prizeService.luckDraw(userId));
}
@ApiOperation("抽奖记录列表")
// @ApiOperation("抽奖")
// @GetMapping(value = "/luckDraw")
// public ResultVo<Prize> luckDraw(@RequestParam String userId) {
// return ResultVo.success(prizeService.luckDraw(userId));
// }
// @ApiOperation("抽奖记录列表")
// @PostMapping(value = "/getLotteryRecList")
// public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
// AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
// return ResultVo.success(prizeService.getLotteryRecList(vo));
// }
@ApiOperation("抽奖记录列表(传入用户id返回用户,不传入返回全部) getLotteryRecList")
@PostMapping(value = "/getLotteryRecList")
public ResultVo<PageVo<LotteryRec>> getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
public ResultVo getLotteryRecList(@RequestBody LotteryRecFindVo vo) {
return ResultVo.success(prizeService.getLotteryRecList(vo));
}
......
......@@ -3,7 +3,9 @@ package com.zq.user.controller.api;
import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo;
import com.zq.user.entity.AnswerRec;
import com.zq.user.service.PrizeService;
import com.zq.user.service.QuestionService;
import com.zq.user.vo.LotteryRecFindVo;
import com.zq.user.vo.QuestionFindVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping(value = "/user/api/question")
public class QuestionApi {
private final PrizeService prizeService;
private final QuestionService questionService;
@ApiOperation("获取题目列表")
......@@ -33,10 +36,15 @@ public class QuestionApi {
public ResultVo answer(@RequestBody AnswerRec vo) {
AssertUtils.hasText(vo.getUserId(), "缺少用户ID");
AssertUtils.hasText(vo.getAnswerList(), "缺少答案");
return ResultVo.success(questionService.answer(vo));
}
@ApiOperation("有奖问答随机抽奖")
@PostMapping(value = "/randomDraw")
public ResultVo randomDraw(@RequestBody LotteryRecFindVo vo) {
return ResultVo.success(prizeService.randomDraw(vo));
}
@ApiOperation("获取答题记录")
@PostMapping(value = "/getAnswerRecs")
public ResultVo getAnswerRecs(@RequestBody AnswerRec answerRec) {
......
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.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo;
......@@ -15,6 +17,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @Author: jcm
......@@ -103,9 +106,15 @@ public class lotteryInfoApi {
@PostMapping(value = "/isOpen")
public ResultVo isOpen(@RequestBody LotteryInfoVo vo) {
AssertUtils.isTrue(vo.getIsOpen() != null, "传入开关状态为空");
AssertUtils.isTrue(lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>().eq("is_open", 1)) != null, "已经存在一个开启的活动");
if (vo.getIsOpen() == 2) {
lotteryInfoService.isOpen(vo);
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 {
@PostMapping(value = "/getIsOpen")
public ResultVo getIsOpen(@RequestBody LotteryInfoVo vo) {
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) {
ResultVo.fail("不存在开启成功的抽奖活动");
}
return ResultVo.success(lotteryInfo);
return ResultVo.success(vo1);
}
......@@ -132,9 +146,21 @@ public class lotteryInfoApi {
@ApiOperation("删除该活动")
@PostMapping(value = "/delete")
public ResultVo delete(@RequestBody LotteryInfoVo vo) {
AssertUtils.isTrue(vo.getId() != null, "传入开关状态为空");
AssertUtils.isTrue(vo.getId() != null, "传入活动id为空");
lotteryInfoService.delete(vo);
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 {
/**
* 抽奖活动ID
*/
@ApiModelProperty("抽奖活动ID")
private Integer lotteryId;
/**
* 抽奖活动名
*/
@ApiModelProperty("抽奖活动名")
private String lotteryName;
}
......@@ -32,6 +32,12 @@ class LotteryPrize implements Serializable {
private Integer id;
/**
* 奖品类型 关联奖品类型(t_prize)表id
*/
@ApiModelProperty(value = "奖品id 关联奖品类型(t_prize)表id")
private Long prizeId;
/**
* 奖品类型 关联奖品类型(t_prize_type)表id
*/
@ApiModelProperty(value = "奖品类型 关联奖品类型(t_prize_type)表id")
......
......@@ -100,4 +100,16 @@ public class LotteryRec {
@TableField(exist = false)
private Address address;
/**
* 抽奖活动ID
*/
@ApiModelProperty("抽奖活动ID")
private Integer lotteryId;
/**
* 抽奖活动名
*/
@ApiModelProperty("抽奖活动名")
private String lotteryName;
}
......@@ -55,7 +55,7 @@ public class LotteryInfoService {
// List<LotteryPrizeVo> list = vo.getPrizeVos();
Integer id = Integer.parseInt(generateRandom());
vo.setId(id);
// todo 2022813 这里的关联的类型标是type而不是type_id
// todo 2022813 这里的关联的类型标是prize而不是prize_type
LotteryInfo lotteryInfo = new LotteryInfo();
BeanUtil.copyProperties(vo, lotteryInfo);
lotteryInfo.setIsOpen(2);
......@@ -67,6 +67,7 @@ public class LotteryInfoService {
LotteryPrize lotteryPrize = LotteryPrize
.builder()
.lotteryInfoId(vo.getId())
.prizeId(type.getId())
.prizeTypeId(type.getPrizeTypeId())
.prizeName(type.getPrizeName())
.createTime(DateUtil.date())
......@@ -76,7 +77,7 @@ public class LotteryInfoService {
}
public static synchronized String generateRandom(){
public static synchronized String generateRandom() {
//使用当前时间生成时间戳yyyyMMddHHmmssSSS
StringBuffer suf = new StringBuffer(DateFormatUtils.format(Calendar.getInstance(), "ssSSS"));
//生成3位随机数
......@@ -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);
// lambdaQuery.orderByDesc(Prize::getCreateTime);
//
......@@ -105,7 +106,13 @@ public class LotteryInfoService {
public PageVo<LotteryInfoVo> getLotteryInfo(LotteryInfoVo vo) {
LambdaQueryWrapper<LotteryInfo> lambdaQuery = Wrappers.lambdaQuery(LotteryInfo.class);
// 模糊查询活动名
if (vo.getLotteryInfoName() != null) {
lambdaQuery.like(LotteryInfo::getLotteryInfoName, vo.getLotteryInfoName());
}
lambdaQuery.orderByDesc(LotteryInfo::getCreateTime);
PageVo<LotteryInfo> paging = PagingUtils.paging(vo, lotteryInfoDao, lambdaQuery, LotteryInfo.class);
......@@ -129,9 +136,7 @@ public class LotteryInfoService {
public void isOpen(LotteryInfoVo vo) {
System.out.println(vo);
Integer id = vo.getId();
System.out.println(id);
LotteryInfo info = new LotteryInfo();
info.setId(id);
if (vo.getIsOpen() != null) {
......@@ -181,6 +186,7 @@ public class LotteryInfoService {
LotteryPrize lotteryPrize = LotteryPrize
.builder()
.lotteryInfoId(vo.getId())
.prizeId(type.getId())
.prizeTypeId(type.getPrizeTypeId())
.prizeName(type.getPrizeName())
.createTime(DateUtil.date())
......@@ -195,5 +201,34 @@ public class LotteryInfoService {
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;
}
}
......@@ -179,6 +179,11 @@ public class QuestionService {
public List<AnswerRec> getAnswerRec(AnswerRec answerRec) {
if (answerRec.getUserId() != null) {
LambdaQueryWrapper<AnswerRec> wrapper = new LambdaQueryWrapper<AnswerRec>();
List<AnswerRec> recs = answerRecDao.selectList(wrapper.eq(AnswerRec::getUserId, answerRec.getUserId()));
return recs;
} else {
LambdaQueryWrapper<AnswerRec> wrapper = new LambdaQueryWrapper<AnswerRec>();
List<LotteryInfo> infos = lotteryInfoDao.selectList(new QueryWrapper<LotteryInfo>());
System.out.println("info="+infos);
......@@ -188,8 +193,8 @@ public class QuestionService {
AnswerRec rec = answerRecDao.selectOne(wrapper);
recs.add(rec);
}
AssertUtils.isTrue(recs != null, "没有历史答题记录,请先完成答题");
return recs;
}
}
}
......@@ -15,7 +15,6 @@ import java.util.Date;
* @Author: TangCong
* @Date: 2022-8-13 10:45
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
......@@ -55,4 +54,5 @@ public class AnswerRecVo extends PageReqVo {
* 抽奖活动名
*/
private String lotteryName;
}
......@@ -29,12 +29,20 @@ public class LotteryPrizeVo extends PageReqVo {
private Integer id;
/**
* 奖品类型 关联奖品类型(t_prize)表id
*/
@ApiModelProperty(value = "奖品id 关联奖品类型(t_prize)表id")
private Long prizeId;
/**
* 奖品类型 关联奖品类型(t_prize_type)表id
*/
@ApiModelProperty(value = "奖品类型 关联奖品类型(t_prize_type)表id")
private Integer prizeTypeId;
/**
* 奖品名
*/
......
......@@ -93,4 +93,37 @@ public class LotteryRecFindVo extends PageReqVo {
@TableField(exist = false)
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