抽奖活动前端应用
This commit is contained in:
parent
d6188b90d8
commit
aba266c619
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.ruoyi.dto;
|
||||||
|
|
||||||
|
import com.sinosoft.activity.domain.DrawConfig;
|
||||||
|
import com.sinosoft.activity.domain.DrawPrizeInfo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class GtPrizeConfigTemp implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 3431401981054724955L;
|
||||||
|
private long baseNumer;
|
||||||
|
private long weightLength;
|
||||||
|
private long startNumer;
|
||||||
|
private long endNumber;
|
||||||
|
private DrawConfig config;
|
||||||
|
private DrawPrizeInfo prizeInfo;
|
||||||
|
public long getBaseNumer() {
|
||||||
|
return baseNumer;
|
||||||
|
}
|
||||||
|
public void setBaseNumer(long baseNumer) {
|
||||||
|
this.baseNumer = baseNumer;
|
||||||
|
}
|
||||||
|
public long getWeightLength() {
|
||||||
|
return weightLength;
|
||||||
|
}
|
||||||
|
public void setWeightLength(long weightLength) {
|
||||||
|
this.weightLength = weightLength;
|
||||||
|
}
|
||||||
|
public long getStartNumer() {
|
||||||
|
return startNumer;
|
||||||
|
}
|
||||||
|
public void setStartNumer(long startNumer) {
|
||||||
|
this.startNumer = startNumer;
|
||||||
|
}
|
||||||
|
public long getEndNumber() {
|
||||||
|
return endNumber;
|
||||||
|
}
|
||||||
|
public void setEndNumber(long endNumber) {
|
||||||
|
this.endNumber = endNumber;
|
||||||
|
}
|
||||||
|
public DrawConfig getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
public void setConfig(DrawConfig config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
public DrawPrizeInfo getPrizeInfo() {
|
||||||
|
return prizeInfo;
|
||||||
|
}
|
||||||
|
public void setPrizeInfo(DrawPrizeInfo prizeInfo) {
|
||||||
|
this.prizeInfo = prizeInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,19 +2,34 @@ package com.ruoyi.service;
|
||||||
|
|
||||||
import com.ruoyi.cache.Cache;
|
import com.ruoyi.cache.Cache;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.dto.GtPrizeConfigTemp;
|
||||||
|
import com.ruoyi.web.vo.Const;
|
||||||
|
import com.sinosoft.activity.domain.DrawConfig;
|
||||||
|
import com.sinosoft.activity.domain.DrawPrizeInfo;
|
||||||
import com.sinosoft.activity.domain.DrawRule;
|
import com.sinosoft.activity.domain.DrawRule;
|
||||||
|
import com.sinosoft.activity.service.IDrawConfigService;
|
||||||
|
import com.sinosoft.activity.service.IDrawPrizeInfoService;
|
||||||
import com.sinosoft.activity.service.IDrawRuleService;
|
import com.sinosoft.activity.service.IDrawRuleService;
|
||||||
|
import com.sinosoft.activity.vo.PrizeInfo;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class DrawService {
|
public class DrawService {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DrawService.class);
|
private static final Logger logger = LoggerFactory.getLogger(DrawService.class);
|
||||||
@Autowired
|
@Autowired
|
||||||
private IDrawRuleService drawRuleService;
|
private IDrawRuleService drawRuleService;
|
||||||
|
@Autowired
|
||||||
|
private IDrawConfigService drawConfigService;
|
||||||
|
@Autowired
|
||||||
|
private IDrawPrizeInfoService drawPrizeInfoService;
|
||||||
/**
|
/**
|
||||||
* 刷新抽奖需要的缓存信息
|
* 刷新抽奖需要的缓存信息
|
||||||
*
|
*
|
||||||
|
|
@ -41,53 +56,56 @@ public class DrawService {
|
||||||
DrawRule drawRule = drawRuleService.selectDrawRuleList(drawRuleParams).get(0);
|
DrawRule drawRule = drawRuleService.selectDrawRuleList(drawRuleParams).get(0);
|
||||||
cacheAdd("_" + drawCode + "_" + currentDateStr + "_rule_", drawRule, "_" + drawCode + "_" + yesterdayDateStr + "_rule_", timeOut);
|
cacheAdd("_" + drawCode + "_" + currentDateStr + "_rule_", drawRule, "_" + drawCode + "_" + yesterdayDateStr + "_rule_", timeOut);
|
||||||
// 奖项配置加入缓存
|
// 奖项配置加入缓存
|
||||||
QueryRule gtDrawConfigQueryRule = QueryRule.getInstance();
|
// gtDrawConfigQueryRule.addAscOrder("prizeLevel");
|
||||||
gtDrawConfigQueryRule.addEqual("drawCode", drawCode);
|
DrawConfig drawConfigParams = new DrawConfig();
|
||||||
gtDrawConfigQueryRule.addEqual("state", Constant.DRAW_CONFIG_STATUS_EFFECTIVE);
|
drawConfigParams.setDRAWCODE(drawCode);
|
||||||
gtDrawConfigQueryRule.addAscOrder("prizeLevel");
|
drawConfigParams.setSTATUS(Const.STATUS_VALID);
|
||||||
List<GtDrawConfig> gtDrawConfigs = gtDrawConfigService.queryByQueryRule(gtDrawConfigQueryRule);
|
List<DrawConfig> drawConfigs = drawConfigService.selectDrawConfigList(drawConfigParams);
|
||||||
cacheAdd("_" + drawCode + "_" + currentDateStr + "_config_", gtDrawConfigs, "_" + drawCode + "_" + yesterdayDateStr + "_config_", timeOut);
|
cacheAdd("_" + drawCode + "_" + currentDateStr + "_config_", drawConfigs, "_" + drawCode + "_" + yesterdayDateStr + "_config_", timeOut);
|
||||||
// 空奖品加入缓存
|
// 空奖奖项配置
|
||||||
QueryRule gtDrawConfigBlankCondition = QueryRule.getInstance();
|
DrawConfig drawConfigBlank = null;
|
||||||
gtDrawConfigBlankCondition.addEqual("drawCode", drawCode);
|
// 非空奖项配置
|
||||||
gtDrawConfigBlankCondition.addEqual("state", Constant.DRAW_CONFIG_STATUS_EFFECTIVE);
|
List<DrawConfig> gtDrawConfigList = new ArrayList<>();
|
||||||
gtDrawConfigBlankCondition.addEqual("prizeLevel", "blank");
|
for (DrawConfig drawConfig : drawConfigs) {
|
||||||
List<GtDrawConfig> gtDrawConfigBlankList = gtDrawConfigService.queryByQueryRule(gtDrawConfigBlankCondition);
|
String prizelevel = drawConfig.getPRIZELEVEL();
|
||||||
if (gtDrawConfigBlankList == null) {
|
if (Const.PRIZE_LEVEL_BLANK.equals(prizelevel)) {
|
||||||
|
drawConfigBlank = drawConfig;
|
||||||
|
} else {
|
||||||
|
gtDrawConfigList.add(drawConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (drawConfigBlank == null) {
|
||||||
throw new Exception("空奖品配置错误");
|
throw new Exception("空奖品配置错误");
|
||||||
}
|
}
|
||||||
QueryRule blankQueryRule = QueryRule.getInstance();
|
// 非空奖奖项配置加入缓存
|
||||||
blankQueryRule.addEqual("prizeCode", gtDrawConfigBlankList.get(0).getPrizeCode());
|
cacheAdd("_" + drawCode + "_" + currentDateStr + "_gtDrawConfigList_", gtDrawConfigList, "_" + drawCode + "_" + yesterdayDateStr + "_gtDrawConfigList_", timeOut);
|
||||||
blankQueryRule.addEqual("status", "1");
|
// 空奖奖项配置加入缓存
|
||||||
GtPrizeInfo blankPrize = gtPrizeInfoService.queryUniqueGtPrizeInfo(blankQueryRule);
|
Cache.remove("_" + drawCode + "_blankConfig_");
|
||||||
|
Cache.add("_" + drawCode + "_blankConfig_", drawConfigBlank);
|
||||||
|
//空奖奖品加入缓存
|
||||||
|
|
||||||
|
String prizeCodeBlank = drawConfigBlank.getPRIZECODE();
|
||||||
|
PrizeInfo prizeInfoParams = new PrizeInfo();
|
||||||
|
prizeInfoParams.setDRAWCODE(drawCode);
|
||||||
|
prizeInfoParams.setSTATUS(Const.STATUS_VALID);
|
||||||
|
List<DrawPrizeInfo> drawPrizeInfos = drawPrizeInfoService.selectDrawPrizeInfoByDrawCode(prizeInfoParams);
|
||||||
|
Map<String, DrawPrizeInfo> prizeMap = new HashMap<>();
|
||||||
|
for (DrawPrizeInfo prizeInfo : drawPrizeInfos) {
|
||||||
|
String prizeCode = prizeInfo.getPRIZECODE();
|
||||||
|
prizeMap.put(prizeCode, prizeInfo);
|
||||||
|
}
|
||||||
|
DrawPrizeInfo blankPrize = prizeMap.get(prizeCodeBlank);
|
||||||
Cache.remove("_" + drawCode + "_blank_");
|
Cache.remove("_" + drawCode + "_blank_");
|
||||||
Cache.add("_" + drawCode + "_blank_", blankPrize);
|
Cache.add("_" + drawCode + "_blank_", blankPrize);
|
||||||
// 空奖奖项配置加入缓存
|
|
||||||
QueryRule gtBlankDrawConfigCondition = QueryRule.getInstance();
|
|
||||||
gtBlankDrawConfigCondition.addEqual("drawCode", drawCode);
|
|
||||||
gtBlankDrawConfigCondition.addEqual("prizeLevel", "blank");
|
|
||||||
List<GtDrawConfig> gtBlankDrawConfigList = gtDrawConfigService.queryByQueryRule(gtBlankDrawConfigCondition);
|
|
||||||
if (gtBlankDrawConfigList != null && gtBlankDrawConfigList.size() > 0) {
|
|
||||||
GtDrawConfig gtDrawConfig = gtBlankDrawConfigList.get(0);
|
|
||||||
Cache.remove("_" + drawCode + "_blankConfig_");
|
|
||||||
Cache.add("_" + drawCode + "_blankConfig_", gtDrawConfig);
|
|
||||||
}
|
|
||||||
// 非空奖奖项配置加入缓存
|
|
||||||
QueryRule gtDrawConfigCondition = QueryRule.getInstance();
|
|
||||||
gtDrawConfigCondition.addEqual("drawCode", drawCode);
|
|
||||||
gtDrawConfigCondition.addEqual("state", Constant.DRAW_CONFIG_STATUS_EFFECTIVE);
|
|
||||||
gtDrawConfigCondition.addNotEqual("prizeLevel", "blank");
|
|
||||||
gtDrawConfigCondition.addAscOrder("prizeLevel");
|
|
||||||
List<GtDrawConfig> gtDrawConfigList = gtDrawConfigService.queryByQueryRule(gtDrawConfigCondition);
|
|
||||||
cacheAdd("_" + drawCode + "_" + currentDateStr + "_gtDrawConfigList_", gtDrawConfigList, "_" + drawCode + "_" + yesterdayDateStr + "_gtDrawConfigList_", timeOut);
|
|
||||||
// 计算总权重
|
// 计算总权重
|
||||||
BigDecimal totalProbability = BigDecimal.ZERO;
|
BigDecimal totalProbability = BigDecimal.ZERO;
|
||||||
// 最小概率
|
// 最小概率
|
||||||
BigDecimal minProbability = BigDecimal.ZERO;
|
BigDecimal minProbability = BigDecimal.ZERO;
|
||||||
if (gtDrawConfigList != null && gtDrawConfigList.size() > 0) {
|
if (gtDrawConfigList != null && gtDrawConfigList.size() > 0) {
|
||||||
for (int i = 0; i < gtDrawConfigList.size(); i++) {
|
for (int i = 0; i < gtDrawConfigList.size(); i++) {
|
||||||
GtDrawConfig gtDrawConfig = gtDrawConfigList.get(i);
|
DrawConfig gtDrawConfig = gtDrawConfigList.get(i);
|
||||||
String prizeWigth = new BigDecimal(gtDrawConfig.getProbability()).divide(new BigDecimal(100)).toString();
|
String prizeWigth = new BigDecimal(gtDrawConfig.getPROBABILITY()).divide(new BigDecimal(100)).toString();
|
||||||
totalProbability = totalProbability.add(new BigDecimal(prizeWigth));
|
totalProbability = totalProbability.add(new BigDecimal(prizeWigth));
|
||||||
String n = prizeWigth;
|
String n = prizeWigth;
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
|
@ -110,15 +128,12 @@ public class DrawService {
|
||||||
long tmp = 0;
|
long tmp = 0;
|
||||||
if (gtDrawConfigList != null && gtDrawConfigList.size() > 0) {
|
if (gtDrawConfigList != null && gtDrawConfigList.size() > 0) {
|
||||||
for (int i = 0; i < gtDrawConfigList.size(); i++) {
|
for (int i = 0; i < gtDrawConfigList.size(); i++) {
|
||||||
GtDrawConfig gtDrawConfig = gtDrawConfigList.get(i);
|
DrawConfig gtDrawConfig = gtDrawConfigList.get(i);
|
||||||
String probability = gtDrawConfig.getProbability();
|
String probability = gtDrawConfig.getPROBABILITY();
|
||||||
GtPrizeConfigTemp gtPrizeConfigTemp = new GtPrizeConfigTemp();
|
GtPrizeConfigTemp gtPrizeConfigTemp = new GtPrizeConfigTemp();
|
||||||
gtPrizeConfigTemp.setBaseNumer(baseNumer.longValue());
|
gtPrizeConfigTemp.setBaseNumer(baseNumer.longValue());
|
||||||
gtPrizeConfigTemp.setConfig(gtDrawConfig);
|
gtPrizeConfigTemp.setConfig(gtDrawConfig);
|
||||||
QueryRule prizeQueryRule = QueryRule.getInstance();
|
gtPrizeConfigTemp.setPrizeInfo(prizeMap.get(gtDrawConfig.getPRIZECODE()));
|
||||||
prizeQueryRule.addEqual("prizeCode", gtDrawConfig.getPrizeCode());
|
|
||||||
List<GtPrizeInfo> prizeInfo = gtPrizeInfoService.queryByQueryRule(prizeQueryRule);
|
|
||||||
gtPrizeConfigTemp.setPrizeInfo(prizeInfo.get(0));
|
|
||||||
// 区间1从0开始
|
// 区间1从0开始
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
// 区间数从1开始
|
// 区间数从1开始
|
||||||
|
|
@ -137,7 +152,7 @@ public class DrawService {
|
||||||
tmp = end;
|
tmp = end;
|
||||||
}
|
}
|
||||||
// 奖项开始结束区间加入缓存
|
// 奖项开始结束区间加入缓存
|
||||||
cacheAdd("_cache_" + drawCode + "_" + currentDateStr + "_" + gtDrawConfig.getPrizeLevel() + "_", gtPrizeConfigTemp, "_cache_" + drawCode + "_" + yesterdayDateStr + "_" + gtDrawConfig.getPrizeLevel() + "_", timeOut);
|
cacheAdd("_cache_" + drawCode + "_" + currentDateStr + "_" + gtDrawConfig.getPRIZELEVEL() + "_", gtPrizeConfigTemp, "_cache_" + drawCode + "_" + yesterdayDateStr + "_" + gtDrawConfig.getPRIZELEVEL() + "_", timeOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,6 @@ public interface Const {
|
||||||
|
|
||||||
String STATUS_VALID = "1";
|
String STATUS_VALID = "1";
|
||||||
String STATUS_INVALID = "0";
|
String STATUS_INVALID = "0";
|
||||||
|
|
||||||
|
String PRIZE_LEVEL_BLANK = "blank";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.sinosoft.activity.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.sinosoft.activity.domain.DrawPrizeInfo;
|
import com.sinosoft.activity.domain.DrawPrizeInfo;
|
||||||
|
import com.sinosoft.activity.vo.PrizeInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储奖品的基础信息Mapper接口
|
* 存储奖品的基础信息Mapper接口
|
||||||
|
|
@ -34,6 +35,7 @@ public interface DrawPrizeInfoMapper
|
||||||
public List<DrawPrizeInfo> selectDrawPrizeInfoList(DrawPrizeInfo drawPrizeInfo);
|
public List<DrawPrizeInfo> selectDrawPrizeInfoList(DrawPrizeInfo drawPrizeInfo);
|
||||||
|
|
||||||
List<DrawPrizeInfo> findDrawPrizeInfoList();
|
List<DrawPrizeInfo> findDrawPrizeInfoList();
|
||||||
|
List<DrawPrizeInfo> selectDrawPrizeInfoByDrawCode(PrizeInfo prizeInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增存储奖品的基础信息
|
* 新增存储奖品的基础信息
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.sinosoft.activity.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.sinosoft.activity.domain.DrawPrizeInfo;
|
import com.sinosoft.activity.domain.DrawPrizeInfo;
|
||||||
|
import com.sinosoft.activity.vo.PrizeInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储奖品的基础信息Service接口
|
* 存储奖品的基础信息Service接口
|
||||||
|
|
@ -32,6 +33,7 @@ public interface IDrawPrizeInfoService
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<DrawPrizeInfo> findDrawPrizeInfoList();
|
List<DrawPrizeInfo> findDrawPrizeInfoList();
|
||||||
|
List<DrawPrizeInfo> selectDrawPrizeInfoByDrawCode(PrizeInfo prizeInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增存储奖品的基础信息
|
* 新增存储奖品的基础信息
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.sinosoft.activity.service.impl;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.sinosoft.activity.vo.PrizeInfo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.sinosoft.activity.mapper.DrawPrizeInfoMapper;
|
import com.sinosoft.activity.mapper.DrawPrizeInfoMapper;
|
||||||
|
|
@ -49,6 +51,10 @@ public class DrawPrizeInfoServiceImpl implements IDrawPrizeInfoService
|
||||||
public List<DrawPrizeInfo> findDrawPrizeInfoList() {
|
public List<DrawPrizeInfo> findDrawPrizeInfoList() {
|
||||||
return drawPrizeInfoMapper.findDrawPrizeInfoList();
|
return drawPrizeInfoMapper.findDrawPrizeInfoList();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public List<DrawPrizeInfo> selectDrawPrizeInfoByDrawCode(PrizeInfo prizeInfo) {
|
||||||
|
return drawPrizeInfoMapper.selectDrawPrizeInfoByDrawCode(prizeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增存储奖品的基础信息
|
* 新增存储奖品的基础信息
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.sinosoft.activity.vo;
|
||||||
|
|
||||||
|
import com.sinosoft.activity.domain.DrawPrizeInfo;
|
||||||
|
|
||||||
|
public class PrizeInfo extends DrawPrizeInfo {
|
||||||
|
private String DRAWCODE;
|
||||||
|
|
||||||
|
public String getDRAWCODE() {
|
||||||
|
return DRAWCODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDRAWCODE(String DRAWCODE) {
|
||||||
|
this.DRAWCODE = DRAWCODE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,6 +21,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
select PRIZEID, PRIZECODE, PRIZENAME, PRIZETYPE, PRIZEVALUE, COMMENTS, CREATETIMESTAMP, LASTUPDATETIMESTAMP, STATUS, INTEGRALPROJECTCODE from draw_prize_info
|
select PRIZEID, PRIZECODE, PRIZENAME, PRIZETYPE, PRIZEVALUE, COMMENTS, CREATETIMESTAMP, LASTUPDATETIMESTAMP, STATUS, INTEGRALPROJECTCODE from draw_prize_info
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectDrawPrizeInfoByDrawCode" parameterType="com.sinosoft.activity.vo.PrizeInfo" resultMap="DrawPrizeInfoResult">
|
||||||
|
select dpi.* from draw_prize_info dpi left join draw_config dc on dpi.prizecode=dc.prizecode
|
||||||
|
<where>
|
||||||
|
<if test="DRAWCODE != null and DRAWCODE != ''"> and DRAWCODE = #{DRAWCODE}</if>
|
||||||
|
<if test="PRIZECODE != null and PRIZECODE != ''"> and PRIZECODE = #{PRIZECODE}</if>
|
||||||
|
<if test="STATUS != null and STATUS != ''"> and STATUS = #{STATUS}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
<select id="selectDrawPrizeInfoList" parameterType="com.sinosoft.activity.domain.DrawPrizeInfo" resultMap="DrawPrizeInfoResult">
|
<select id="selectDrawPrizeInfoList" parameterType="com.sinosoft.activity.domain.DrawPrizeInfo" resultMap="DrawPrizeInfoResult">
|
||||||
<include refid="selectDrawPrizeInfoVo"/>
|
<include refid="selectDrawPrizeInfoVo"/>
|
||||||
<where>
|
<where>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue