Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
answer-backend
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
answer
answer-backend
Commits
18e92d1b
Commit
18e92d1b
authored
Aug 17, 2022
by
唐聪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成抽奖模块
parent
769c29ea
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
420 additions
and
74 deletions
+420
-74
api-server/src/main/java/com/zq/api/feign/UserFeign.java
+5
-0
api-server/src/main/java/com/zq/api/service/IApiLogic.java
+17
-0
api-server/src/main/java/com/zq/api/service/impl/ApiV100Logic.java
+22
-0
user-server/src/main/java/com/zq/user/controller/LotteryInfoController.java
+28
-4
user-server/src/main/java/com/zq/user/controller/PrizeController.java
+15
-5
user-server/src/main/java/com/zq/user/controller/QuestionController.java
+19
-5
user-server/src/main/java/com/zq/user/controller/api/PrizeApi.java
+19
-13
user-server/src/main/java/com/zq/user/controller/api/QuestionApi.java
+9
-1
user-server/src/main/java/com/zq/user/controller/api/lotteryInfoApi.java
+31
-5
user-server/src/main/java/com/zq/user/entity/AnswerRec.java
+2
-0
user-server/src/main/java/com/zq/user/entity/LotteryPrize.java
+6
-0
user-server/src/main/java/com/zq/user/entity/LotteryRec.java
+12
-0
user-server/src/main/java/com/zq/user/service/LotteryInfoService.java
+40
-5
user-server/src/main/java/com/zq/user/service/PrizeService.java
+137
-24
user-server/src/main/java/com/zq/user/service/QuestionService.java
+16
-11
user-server/src/main/java/com/zq/user/vo/AnswerRecVo.java
+1
-1
user-server/src/main/java/com/zq/user/vo/LotteryPrizeVo.java
+8
-0
user-server/src/main/java/com/zq/user/vo/LotteryRecFindVo.java
+33
-0
No files found.
api-server/src/main/java/com/zq/api/feign/UserFeign.java
View file @
18e92d1b
...
...
@@ -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);
}
api-server/src/main/java/com/zq/api/service/IApiLogic.java
View file @
18e92d1b
...
...
@@ -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);
}
api-server/src/main/java/com/zq/api/service/impl/ApiV100Logic.java
View file @
18e92d1b
...
...
@@ -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()));
// }
}
user-server/src/main/java/com/zq/user/controller/LotteryInfoController.java
View file @
18e92d1b
...
...
@@ -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
,
"已经存在一个开启的活动"
);
lotteryInfoService
.
isOpen
(
vo
);
return
ResultVo
.
success
(
"操作成功"
);
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));
// }
}
user-server/src/main/java/com/zq/user/controller/PrizeController.java
View file @
18e92d1b
...
...
@@ -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
));
}
}
user-server/src/main/java/com/zq/user/controller/QuestionController.java
View file @
18e92d1b
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.QuestionTyp
e
;
import
com.zq.user.
dao.AnswerRecDao
;
import
com.zq.user.entity.
*
;
import
com.zq.user.
service.PrizeServic
e
;
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
(
"获取答题记录"
)
@
Ge
tMapping
(
value
=
"/getAnswerRecs"
)
@
Pos
tMapping
(
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
user-server/src/main/java/com/zq/user/controller/api/PrizeApi.java
View file @
18e92d1b
...
...
@@ -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,18 +34,23 @@ 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
(
"抽奖记录列表"
)
@PostMapping
(
value
=
"/getLotteryRecList"
)
public
ResultVo
<
PageVo
<
LotteryRec
>>
getLotteryRecList
(
@RequestBody
LotteryRecFindVo
vo
)
{
AssertUtils
.
hasText
(
vo
.
getUserId
(),
"缺少用户ID"
);
return
ResultVo
.
success
(
prizeService
.
getLotteryRecList
(
vo
));
}
// @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
getLotteryRecList
(
@RequestBody
LotteryRecFindVo
vo
)
{
return
ResultVo
.
success
(
prizeService
.
getLotteryRecList
(
vo
));
}
}
user-server/src/main/java/com/zq/user/controller/api/QuestionApi.java
View file @
18e92d1b
...
...
@@ -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
)
{
...
...
user-server/src/main/java/com/zq/user/controller/api/lotteryInfoApi.java
View file @
18e92d1b
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
,
"已经存在一个开启的活动"
);
lotteryInfoService
.
isOpen
(
vo
);
return
ResultVo
.
success
(
"操作成功"
);
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
));
}
}
user-server/src/main/java/com/zq/user/entity/AnswerRec.java
View file @
18e92d1b
...
...
@@ -58,11 +58,13 @@ public class AnswerRec {
/**
* 抽奖活动ID
*/
@ApiModelProperty
(
"抽奖活动ID"
)
private
Integer
lotteryId
;
/**
* 抽奖活动名
*/
@ApiModelProperty
(
"抽奖活动名"
)
private
String
lotteryName
;
}
user-server/src/main/java/com/zq/user/entity/LotteryPrize.java
View file @
18e92d1b
...
...
@@ -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"
)
...
...
user-server/src/main/java/com/zq/user/entity/LotteryRec.java
View file @
18e92d1b
...
...
@@ -100,4 +100,16 @@ public class LotteryRec {
@TableField
(
exist
=
false
)
private
Address
address
;
/**
* 抽奖活动ID
*/
@ApiModelProperty
(
"抽奖活动ID"
)
private
Integer
lotteryId
;
/**
* 抽奖活动名
*/
@ApiModelProperty
(
"抽奖活动名"
)
private
String
lotteryName
;
}
user-server/src/main/java/com/zq/user/service/LotteryInfoService.java
View file @
18e92d1b
...
...
@@ -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
;
}
}
user-server/src/main/java/com/zq/user/service/PrizeService.java
View file @
18e92d1b
...
...
@@ -5,20 +5,22 @@ import cn.hutool.core.date.DateUtil;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.StrUtil
;
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.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.PagingUtils
;
import
com.zq.common.vo.PageVo
;
import
com.zq.user.dao.LotteryRecDao
;
import
com.zq.user.dao.PrizeDao
;
import
com.zq.user.dao.PrizeTypeDao
;
import
com.zq.user.entity.Address
;
import
com.zq.user.entity.LotteryRec
;
import
com.zq.user.entity.Prize
;
import
com.zq.user.entity.PrizeType
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.user.dao.*
;
import
com.zq.user.entity.*
;
import
com.zq.user.vo.LotteryInfoVo
;
import
com.zq.user.vo.LotteryRecFindVo
;
import
com.zq.user.vo.PrizeFindVo
;
import
com.zq.user.vo.PrizeTypeFindVo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
...
...
@@ -45,6 +47,14 @@ PrizeService {
private
final
LotteryRecDao
lotteryRecDao
;
private
final
PrizeTypeDao
prizeTypeDao
;
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
()
{
return
prizeTypeDao
.
selectList
(
Wrappers
.
lambdaQuery
(
PrizeType
.
class
)
...
...
@@ -116,28 +126,46 @@ PrizeService {
return
prizeDao
.
selectById
(
prizeId
);
}
public
Prize
luckDraw
(
String
userId
)
{
List
<
Prize
>
prizeList
=
prizeDao
.
getLuckDrawPrize
();
// todo 抽奖模块尚未修改
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
<>();
for
(
Prize
prize
:
prizeList
)
{
//概率x100
BigDecimal
count
=
prize
.
getAwardRate
().
multiply
(
BigDecimal
.
valueOf
(
100
));
//遍历这个概率的次数,将礼品id添加到礼品列表中
for
(
int
i
=
0
;
i
<
count
.
intValue
();
i
++)
{
prizeIdList
.
add
(
prize
.
getId
());
}
}
// 从礼品列表开始,知道100,没有礼品的列表则填满0
for
(
int
i
=
prizeIdList
.
size
();
i
<
100
;
i
++)
{
prizeIdList
.
add
(
0L
);
}
// 对列表进行随机性排序
Collections
.
shuffle
(
prizeIdList
);
// 获得一个随机数,范围为0 - 礼品列表的大小
int
index
=
RandomUtil
.
randomInt
(
0
,
prizeIdList
.
size
());
// 获得礼品id根据随机下标获得
Long
prizeId
=
prizeIdList
.
get
(
index
);
// 如果礼品列表为0则将其视为未中奖
if
(
prizeId
==
0
)
{
LotteryRec
build
=
LotteryRec
.
builder
()
.
prizeId
(
prizeId
)
...
...
@@ -145,15 +173,17 @@ PrizeService {
.
activityType
(
2
)
.
awardStatus
(
0
)
.
active
(
0
)
//新加的活动名称和活动ID
.
lotteryId
(
infoVo
.
getId
())
.
lotteryName
(
infoVo
.
getLotteryInfoName
())
.
prizeTypeName
(
"未中奖!"
)
.
createTime
(
DateUtil
.
date
())
.
updateTime
(
DateUtil
.
date
())
.
build
();
lotteryRecDao
.
insert
(
build
);
return
null
;
}
// 如果礼品列表不为0则视为抽到该礼品,并修改数据库相关代码
Prize
prize
=
prizeDao
.
selectById
(
prizeId
);
prize
.
setHadOutCount
(
prize
.
getHadOutCount
()
+
1
);
prize
.
setUpdateTime
(
DateUtil
.
date
());
...
...
@@ -172,13 +202,28 @@ PrizeService {
.
prizeTypeId
(
prize
.
getPrizeTypeId
())
.
prizeTypeName
(
prizeType
.
getTypeName
())
.
active
(
0
)
//新加的活动名称和活动ID
.
lotteryId
(
infoVo
.
getId
())
.
lotteryName
(
infoVo
.
getLotteryInfoName
())
.
createTime
(
DateUtil
.
date
())
.
updateTime
(
DateUtil
.
date
())
.
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
)
{
...
...
@@ -225,13 +270,49 @@ PrizeService {
return
prizeTypeDao
.
selectById
(
prizeTypeId
);
}
public
PageVo
<
LotteryRec
>
getLotteryRecList
(
LotteryRecFindVo
vo
)
{
PageVo
<
LotteryRec
>
paging
=
PagingUtils
.
paging
(
vo
,
prizeDao:
:
getLotteryRecList
);
paging
.
getRows
().
forEach
(
lotteryRec
->
{
Address
defaultAddress
=
addressService
.
getDefaultAddress
(
lotteryRec
.
getUserId
());
lotteryRec
.
setAddress
(
defaultAddress
);
});
return
paging
;
// public PageVo<LotteryRec> getLotteryRecList(LotteryRecFindVo vo) {
// PageVo<LotteryRec> paging = PagingUtils.paging(vo, prizeDao::getLotteryRecList);
// paging.getRows().forEach(lotteryRec -> {
// Address defaultAddress = addressService.getDefaultAddress(lotteryRec.getUserId());
// lotteryRec.setAddress(defaultAddress);
// });
// 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
)
{
...
...
@@ -244,4 +325,36 @@ PrizeService {
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
;
}
}
user-server/src/main/java/com/zq/user/service/QuestionService.java
View file @
18e92d1b
...
...
@@ -179,17 +179,22 @@ public class QuestionService {
public
List
<
AnswerRec
>
getAnswerRec
(
AnswerRec
answerRec
)
{
LambdaQueryWrapper
<
AnswerRec
>
wrapper
=
new
LambdaQueryWrapper
<
AnswerRec
>();
List
<
LotteryInfo
>
infos
=
lotteryInfoDao
.
selectList
(
new
QueryWrapper
<
LotteryInfo
>());
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
);
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
);
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
;
}
}
user-server/src/main/java/com/zq/user/vo/AnswerRecVo.java
View file @
18e92d1b
...
...
@@ -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
;
}
user-server/src/main/java/com/zq/user/vo/LotteryPrizeVo.java
View file @
18e92d1b
...
...
@@ -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
;
/**
* 奖品名
*/
...
...
user-server/src/main/java/com/zq/user/vo/LotteryRecFindVo.java
View file @
18e92d1b
...
...
@@ -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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment