11
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 抽奖奖品
|
||||
@@ -46,6 +47,11 @@ public class PrizeInfoController extends BaseController {
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
public R<List<PrizeInfo>> all() {
|
||||
return R.ok(prizeInfoService.list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取抽奖奖品详细信息
|
||||
*
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 已发布奖品
|
||||
@@ -41,9 +42,9 @@ public class PrizeOnlineController extends BaseController {
|
||||
*/
|
||||
@SaCheckPermission("cai:prizeOnline:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<PrizeOnline> list(PrizeOnline bo, PageQuery pageQuery) {
|
||||
Page<PrizeOnline> page = prizeOnlineService.page(pageQuery.build(), Wrappers.lambdaQuery(PrizeOnline.class));
|
||||
return TableDataInfo.build(page);
|
||||
public R<List<PrizeOnline>> list(PrizeOnline bo) {
|
||||
List<PrizeOnline> page = prizeOnlineService.list(Wrappers.lambdaQuery(bo));
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,32 +65,10 @@ public class PrizeOnlineController extends BaseController {
|
||||
@SaCheckPermission("cai:prizeOnline:add")
|
||||
@Log(title = "已发布奖品", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping()
|
||||
public R<Void> add(@Validated(AddGroup.class) @RequestBody PrizeOnline bo) {
|
||||
return toAjax(prizeOnlineService.save(bo));
|
||||
@PostMapping("/reset/{gender}")
|
||||
public R<Void> reset(@PathVariable Integer gender,@Validated(AddGroup.class) @RequestBody List<PrizeOnline> bo) {
|
||||
prizeOnlineService.reset(gender,bo);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改已发布奖品
|
||||
*/
|
||||
@SaCheckPermission("cai:prizeOnline:edit")
|
||||
@Log(title = "已发布奖品", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit()
|
||||
@PutMapping()
|
||||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody PrizeOnline bo) {
|
||||
return toAjax(prizeOnlineService.updateById(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除已发布奖品
|
||||
*
|
||||
* @param ids 主键串
|
||||
*/
|
||||
@SaCheckPermission("cai:prizeOnline:remove")
|
||||
@Log(title = "已发布奖品", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(prizeOnlineService.removeBatchByIds(Arrays.asList(ids), true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +65,11 @@ public enum SystemConfigEnum {
|
||||
/**
|
||||
* 抽奖和积分
|
||||
*/
|
||||
OPEN_DRAW("1","是否开启积分抽奖",SystemConfigGroupEnum.DRAW,new BooleanSystemConfigCheck()),
|
||||
OPEN_DRAW_WOMEN("1","是否开启女用户积分抽奖",SystemConfigGroupEnum.DRAW,new BooleanSystemConfigCheck()),
|
||||
OPEN_DRAW_MAN("1","是否开启男用户积分抽奖",SystemConfigGroupEnum.DRAW,new BooleanSystemConfigCheck()),
|
||||
WOMEN_DRAW_POINT("100","女用户抽奖分数",SystemConfigGroupEnum.DRAW,new NumberSystemConfigCheck()),
|
||||
MEN_DRAW_POINT("100","男用户抽奖分数",SystemConfigGroupEnum.DRAW,new NumberSystemConfigCheck()),
|
||||
MAX_POINT_DAY("0","用户每日可获取最大积分,0表示不限制",SystemConfigGroupEnum.DRAW,new NumberSystemConfigCheck()),
|
||||
/**
|
||||
* 域名配置
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ruoyi.cai.enums.prize;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
// 奖品类型 1-谢谢惠顾 2-普通奖 3-大奖
|
||||
@Getter
|
||||
public enum PrizeTypeEnum {
|
||||
NONE(1,"谢谢惠顾"),
|
||||
NORMAL(2,"普通奖"),
|
||||
GOOD(3,"大奖"),
|
||||
;
|
||||
private final Integer code;
|
||||
private final String text;
|
||||
|
||||
PrizeTypeEnum(Integer code, String text) {
|
||||
this.code = code;
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.ruoyi.cai.domain.PointChangeLog;
|
||||
import com.ruoyi.cai.domain.PrizeOnline;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.enums.GenderEnum;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.manager.IdManager;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.service.AccountService;
|
||||
@@ -17,7 +16,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.redisson.api.RBucket;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -63,20 +61,30 @@ public class LotteryService {
|
||||
return systemConfigManager.getSystemConfigOfInt(SystemConfigEnum.MEN_DRAW_POINT);
|
||||
}
|
||||
|
||||
|
||||
public boolean getOpenDraw(Integer gender){
|
||||
if(GenderEnum.WOMEN.getCode().equals(gender)){
|
||||
return systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_DRAW_WOMEN);
|
||||
}else if(GenderEnum.MAN.getCode().equals(gender)){
|
||||
return systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_DRAW_MAN);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户抽奖(核心方法,优化后)
|
||||
* @param userId 用户ID
|
||||
* @return 中奖奖品
|
||||
*/
|
||||
public PrizeOnline draw(Long userId) {
|
||||
boolean openDraw = systemConfigManager.getSystemConfigOfBool(SystemConfigEnum.OPEN_DRAW);
|
||||
if(!openDraw){
|
||||
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
|
||||
}
|
||||
User user = userService.getById(userId);
|
||||
if(user == null){
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
boolean openDraw = this.getOpenDraw(user.getGender());
|
||||
if(!openDraw){
|
||||
throw new ServiceException("暂未开启积分抽奖,请等待活动通知");
|
||||
}
|
||||
boolean select = GenderEnum.isSelect(user.getGender());
|
||||
if(select){
|
||||
throw new ServiceException("请选择性别后在抽奖");
|
||||
|
||||
@@ -14,4 +14,6 @@ import java.util.List;
|
||||
public interface PrizeOnlineService extends IService<PrizeOnline> {
|
||||
|
||||
List<PrizeOnline> selectPrizeOnlineList(Integer gender);
|
||||
|
||||
void reset(Integer gender, List<PrizeOnline> bo);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.PrizeOnline;
|
||||
import com.ruoyi.cai.enums.prize.PrizeTypeEnum;
|
||||
import com.ruoyi.cai.mapper.PrizeOnlineMapper;
|
||||
import com.ruoyi.cai.service.PrizeOnlineService;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 已发布奖品Service业务层处理
|
||||
@@ -22,7 +27,40 @@ public class PrizeOnlineServiceImpl extends ServiceImpl<PrizeOnlineMapper,PrizeO
|
||||
|
||||
@Override
|
||||
public List<PrizeOnline> selectPrizeOnlineList(Integer gender){
|
||||
return new ArrayList<>();
|
||||
return this.list(Wrappers.lambdaQuery(PrizeOnline.class).eq(PrizeOnline::getGender, gender));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void reset(Integer gender, List<PrizeOnline> bo) {
|
||||
if(bo.size() != 9){
|
||||
throw new ServiceException("奖品必须为9个");
|
||||
}
|
||||
boolean hasNone = false;
|
||||
List<Long> prizeIds = new ArrayList<>();
|
||||
for (PrizeOnline prizeOnline : bo) {
|
||||
prizeOnline.setGender(gender);
|
||||
if(PrizeTypeEnum.NONE.getCode().equals(prizeOnline.getPrizeType())){
|
||||
hasNone = true;
|
||||
}
|
||||
if(prizeOnline.getId() != null){
|
||||
prizeIds.add(prizeOnline.getId());
|
||||
}
|
||||
}
|
||||
if(!hasNone){
|
||||
throw new ServiceException("奖品必须包含谢谢惠顾");
|
||||
}
|
||||
List<PrizeOnline> dbList = this.selectPrizeOnlineList(gender);
|
||||
List<Long> dbIds = dbList.stream().map(PrizeOnline::getId).collect(Collectors.toList());
|
||||
for (PrizeOnline prizeOnline : bo) {
|
||||
if(prizeOnline.getId() != null){
|
||||
this.updateById(prizeOnline);
|
||||
continue;
|
||||
}
|
||||
this.save(prizeOnline);
|
||||
}
|
||||
dbIds.removeAll(prizeIds);
|
||||
this.removeByIds(dbIds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user