记得上下班打卡 | git大法好,push需谨慎

Commit 447afeb1 authored by wanglele's avatar wanglele

兑换活动增加uid

parent 2c6464b8
......@@ -13,16 +13,15 @@ public class PageInfoVo {
private Object list;
public PageInfoVo(){
}
public PageInfoVo(ArrayList<GoblinNftExActivityVo> goblinNftExActivityArrayList, int count,int num) {
this.list = goblinNftExActivityArrayList;
total= count;
this.total= count;
}
public PageInfoVo(ArrayList<GoblinNftExCodeVo> goblinNftExCodeVos,int count){
public PageInfoVo(ArrayList<GoblinNftExCodeVo> goblinNftExCodeVos,int count,String vio){
this.list = goblinNftExCodeVos;
total= count;
this.total= count;
}
}
package com.liquidnet.service.goblin.service;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.param.GoblinNftExSkuParam;
import java.util.List;
......@@ -9,5 +10,5 @@ public interface IGoblinNftExSkuService {
/**
* 新增nft兑换活动和sku的关联
*/
Boolean add(List<GoblinNftExSkuParam> goblinNftExSkuParams);
ResponseDto<Object> add(List<GoblinNftExSkuParam> goblinNftExSkuParams);
}
......@@ -48,11 +48,11 @@ public interface GoblinNftExActivityMapper extends BaseMapper<GoblinNftExActivit
* @param title
* @return
*/
GoblinNftExActivity selectByTitle(@Param("title") String title);
GoblinNftExActivity selectByTitle(@Param("title") String title,@Param("uid")String uid);
/**
* 获取
* @return
*/
int selectActivityCount();
int selectActivityCount(@Param("title") String title, @Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime,@Param("uid") String uid);
}
......@@ -24,7 +24,7 @@
</select>
<select id="selectBySkuIds" resultMap="BaseResult">
select sku_id,name,sku_pic,unbox from goblin_goods_sku where
select sku_id,name,sku_pic,hit_ratio,unbox,sku_type,status,shelves_status,sku_appear,del_flg,soldout_status,sale_start_time from goblin_goods_sku where
sku_id in
<foreach collection="skuIds.split(',')" item="skuId" open="(" separator="," close=")">
#{skuId,jdbcType=VARCHAR}
......
......@@ -13,7 +13,7 @@
<select id="selectByTitle" resultMap="BaseResult">
select activity_id, uid, title, created_at
from goblin_nft_ex_activity
where title = #{title}
where title = #{title} and uid = #{uid}
</select>
<select id="selectPageList" resultMap="BaseResult">
......@@ -33,6 +33,7 @@
and created_at &lt; #{endTime,jdbcType=TIMESTAMP}
</if>
</where>
order by created_at desc
</select>
<select id="selectByActivityId" resultMap="BaseResult">
......@@ -44,7 +45,21 @@
<select id="selectActivityCount" resultType="java.lang.Integer">
select count(0)
from goblin_nft_ex_activity
where uid = #{uid}
<where>
<if test="uid != null and uid != ''">
and uid = #{uid,jdbcType=VARCHAR}
</if>
<if test="title != null and title != ''">
<bind name="likeTitle" value="'%' + title + '%'"/>
and title like #{likeTitle}
</if>
<if test="startTime != null">
and created_at &gt; #{startTime,jdbcType=TIMESTAMP}
</if>
<if test="endTime != null">
and created_at &lt; #{endTime,jdbcType=TIMESTAMP}
</if>
</where>
</select>
<insert id="addGoblinNftExActivity" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExActivity">
......
......@@ -25,7 +25,9 @@
</select>
<select id="selectGoblinNftCodeByCode" resultMap="BeseResult">
select code_id, activity_id, code, box_sku_id,state from goblin_nft_ex_code where code = #{code}
select code_id, activity_id, code, box_sku_id, state
from goblin_nft_ex_code
where code = #{code}
</select>
<insert id="addGoblinNftExCodes">
......@@ -51,7 +53,7 @@
</set>
where code_id in
<foreach collection="goblinNftExCodes" item="goblinNftExCode" index="index" open="(" separator="," close=")">
#{goblinNftExCode.codeId}
#{goblinNftExCode.codeId}
</foreach>
</update>
......@@ -66,72 +68,97 @@
<select id="selectGoblinNftCode" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExCode"
resultMap="BeseResult">
select code_id,code,sku_id,box_sku_id,activity_id,state,redeem_uid,redeem_at,admin_uid,created_at from goblin_nft_ex_code
<where>
<if test="code != null and code != ''">
and code = #{code,jdbcType=VARCHAR}
</if>
<if test="activityId != null and activityId != ''">
and activity_id = #{activityId,jdbcType=VARCHAR}
</if>
<if test="state != null">
and state = #{state,jdbcType=INTEGER}
</if>
<if test="redeemUid != null and redeemUid != ''">
and redeem_uid = #{redeemUid,jdbcType=VARCHAR}
</if>
<if test="skuId != null and skuId != ''">
and sku_id in
<foreach collection="skuId.split(',')" item="sId" open="(" separator="," close=")">
#{sId,jdbcType=VARCHAR}
</foreach>
</if>
<if test="isDrivi != null">
<choose>
<when test="isDrivi == 1">
and admin_uid = ''
</when>
<when test="isDrivi == 2">
and admin_uid != ''
</when>
</choose>
</if>
</where>
select
DISTINCT gnec.code,gnec.code_id,gnec.sku_id,gnec.box_sku_id,gnec.activity_id,gnec.state,gnec.redeem_uid,gnec.redeem_at,gnec.admin_uid,gnec.created_at
from goblin_nft_ex_code gnec inner join goblin_nft_ex_sku gnes on gnec.sku_id = gnes.sku_id
<if test="code != null and code != ''">
and gnec.code = #{code,jdbcType=VARCHAR}
</if>
<if test="activityId != null and activityId != ''">
and gnec.activity_id = #{activityId,jdbcType=VARCHAR}
</if>
<if test="state != null">
<choose>
<when test="state == 1">
and gnec.sku_id = gnes.sku_id and (now() BETWEEN gnes.ex_start_time and gnes.ex_stop_time) and
gnec.state =1
</when>
<when test="state == 2">
and gnec.state = 2
</when>
<when test="state == 3">
and gnec.sku_id = gnes.sku_id and (((now() &gt; gnes.ex_stop_time) AND gnec.state = 1) ||
gnec.state = 3)
</when>
</choose>
</if>
<if test="redeemUid != null and redeemUid != ''">
and gnec.redeem_uid = #{redeemUid,jdbcType=VARCHAR}
</if>
<if test="skuId != null and skuId != ''">
and gnec.sku_id in
<foreach collection="skuId.split(',')" item="sId" open="(" separator="," close=")">
#{sId,jdbcType=VARCHAR}
</foreach>
</if>
<if test="isDrivi != null">
<choose>
<when test="isDrivi == 1">
and gnec.admin_uid = ''
</when>
<when test="isDrivi == 2">
and gnec.admin_uid != ''
</when>
</choose>
</if>
</select>
<select id="selectGoblinNftCodeCount" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExCode"
resultType="java.lang.Integer">
select count(0) from goblin_nft_ex_code
<where>
<if test="code != null and code != ''">
and code = #{code,jdbcType=VARCHAR}
</if>
<if test="activityId != null and activityId != ''">
and activity_id = #{activityId,jdbcType=VARCHAR}
</if>
<if test="state != null">
and state = #{state,jdbcType=INTEGER}
</if>
<if test="redeemUid != null and redeemUid != ''">
and redeem_uid = #{redeemUid,jdbcType=VARCHAR}
</if>
<if test="skuId != null and skuId != ''">
and sku_id in
<foreach collection="skuId.split(',')" item="sId" open="(" separator="," close=")">
#{sId,jdbcType=VARCHAR}
</foreach>
</if>
<if test="isDrivi != null">
<choose>
<when test="isDrivi == 1">
and admin_uid = ''
</when>
<when test="isDrivi == 2">
and admin_uid != ''
</when>
</choose>
</if>
</where>
select count(DISTINCT gnec.code)
from goblin_nft_ex_code gnec inner join goblin_nft_ex_sku gnes
on
gnec.sku_id = gnes.sku_id
<if test="code != null and code != ''">
and gnec.code = #{code,jdbcType=VARCHAR}
</if>
<if test="activityId != null and activityId != ''">
and gnec.activity_id = #{activityId,jdbcType=VARCHAR}
</if>
<if test="state != null">
<choose>
<when test="state == 1">
and gnec.sku_id = gnes.sku_id and (now() BETWEEN gnes.ex_start_time and gnes.ex_stop_time) and
gnec.state =1
</when>
<when test="state == 2">
and gnec.state = 2
</when>
<when test="state == 3">
and gnec.sku_id = gnes.sku_id and (((now() &gt; gnes.ex_stop_time) AND gnec.state = 1) ||
gnec.state = 3)
</when>
</choose>
</if>
<if test="redeemUid != null and redeemUid != ''">
and gnec.redeem_uid = #{redeemUid,jdbcType=VARCHAR}
</if>
<if test="skuId != null and skuId != ''">
and gnec.sku_id in
<foreach collection="skuId.split(',')" item="sId" open="(" separator="," close=")">
#{sId,jdbcType=VARCHAR}
</foreach>
</if>
<if test="isDrivi != null">
<choose>
<when test="isDrivi == 1">
and gnec.admin_uid = ''
</when>
<when test="isDrivi == 2">
and gnec.admin_uid != ''
</when>
</choose>
</if>
</select>
<select id="selectByActivityIds" resultMap="BeseResult">
......
......@@ -46,8 +46,6 @@
<foreach collection="activityIds.split(',')" item="activityId" open="(" separator="," close=")">
#{activityId}
</foreach>
group by activity_id
</select>
<insert id="addGoblinNftExCodeTasks">
......
......@@ -26,12 +26,11 @@ CREATE TABLE `goblin_nft_ex_code`
INDEX `idx_nft_redeem_uid`(`redeem_uid`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'NFT兑换码表' ROW_FORMAT = Dynamic;
-- >>------------------------------------------------------------------------------------
DROP TABLE IF EXISTS `goblin_nft_ex_activity`;
CREATE TABLE `goblin_nft_ex_activity`
(
`mid` bigint(0) UNSIGNED NOT NULL AUTO_INCREMENT,
`uid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`activity_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '活动id',
`title` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '活动标题',
`created_at` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
......@@ -40,6 +39,8 @@ CREATE TABLE `goblin_nft_ex_activity`
INDEX `idx_nft_activity_id`(`activity_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'NFT兑换活动表' ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `goblin_nft_ex_sku`;
CREATE TABLE `goblin_nft_ex_sku`
(
......
......@@ -55,7 +55,7 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi
// 根据名称查询
String title = goblinNftExActivityParam.getTitle();
GoblinNftExActivity goblinNftExActivityShow = goblinNftExActivityMapper.selectByTitle(title);
GoblinNftExActivity goblinNftExActivityShow = goblinNftExActivityMapper.selectByTitle(title,goblinNftExActivityParam.getUid());
if (goblinNftExActivityShow != null) {
return ResponseDto.failure("活动名称已存在!");
}
......@@ -86,8 +86,9 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi
List<GoblinNftExActivity> goblinNftExActivities = goblinNftExActivityMapper.selectPageList(goblinNftExActivityParam.getTitle(), goblinNftExActivityParam.getStartTime(),
goblinNftExActivityParam.getEndTime(), goblinNftExActivityParam.getUid());
//
int count = goblinNftExActivityMapper.selectActivityCount();
// 获取活动数量
int count = goblinNftExActivityMapper.selectActivityCount(goblinNftExActivityParam.getTitle(), goblinNftExActivityParam.getStartTime(),
goblinNftExActivityParam.getEndTime(), goblinNftExActivityParam.getUid());
log.debug("#MYS耗时:{}ms", System.currentTimeMillis() - s);
......@@ -236,6 +237,7 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi
* 获取分页nft兑换活动数据
*/
long s = System.currentTimeMillis();
PageHelper.startPage(goblinNftExActivityParam.getPageNum(), 20, true);
List<GoblinNftExActivity> goblinNftExActivities = goblinNftExActivityMapper.selectPageList(goblinNftExActivityParam.getTitle(), goblinNftExActivityParam.getStartTime(),
goblinNftExActivityParam.getEndTime(), goblinNftExActivityParam.getUid());
log.debug("#MYS耗时:{}ms", System.currentTimeMillis() - s);
......@@ -286,7 +288,6 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi
log.error("导出excel失败!");
}
}
......
......@@ -108,33 +108,29 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
} else {
skuIds.append(gnc.getBoxSkuId()).append(",");
}
acticityIds.append(gnc.getActivityId()).append(",");
}
// 获取返回对象实例
ArrayList<GoblinNftExCodeVo> goblinNftExCodeArrayList = ObjectUtil.getGoblinNftExCodeArrayList();
if (StringUtil.isNotBlank(skuIds)) {
// 批量查询
List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectBySkuIds(skuIds.toString());
for (GoblinNftExCode gnc : goblinNftExCodes) {
GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(gnc);
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) {
GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(gnc);
if (StringUtil.isNotBlank(gnc.getBoxSkuId()) && gnc.getBoxSkuId().equals(goblinGoodsSku.getSkuId())) {
goblinNftExCodeVo.setSkuName(goblinGoodsSku.getName());
goblinNftExCodeArrayList.add(goblinNftExCodeVo);
break;
} else {
if (gnc.getSkuId().equals(goblinGoodsSku.getSkuId())) {
goblinNftExCodeVo.setSkuName(goblinGoodsSku.getName());
goblinNftExCodeArrayList.add(goblinNftExCodeVo);
break;
}
}
}
goblinNftExCodeArrayList.add(goblinNftExCodeVo);
}
}
......@@ -158,7 +154,7 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
if (StringUtil.isNotBlank(gnc.getBoxSkuId()) && gnc.getSkuId().equals(goblinNftExSku.getSkuId())) {
gnc.setExStartTime(goblinNftExSku.getExStartTime());
gnc.setExStopTime(goblinNftExSku.getExStopTime());
if (now.isBefore(goblinNftExSku.getExStartTime()) || now.isAfter(goblinNftExSku.getExStopTime())) {
if (now.isAfter(goblinNftExSku.getExStopTime())) {
gnc.setState(3);
}
break;
......@@ -166,7 +162,7 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
if (gnc.getSkuId().equals(goblinNftExSku.getSkuId())) {
gnc.setExStartTime(goblinNftExSku.getExStartTime());
gnc.setExStopTime(goblinNftExSku.getExStopTime());
if (now.isBefore(goblinNftExSku.getExStartTime()) || now.isAfter(goblinNftExSku.getExStopTime())) {
if (now.isAfter(goblinNftExSku.getExStopTime())) {
gnc.setState(3);
}
break;
......@@ -175,7 +171,7 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
}
}
PageInfoVo pageInfo = new PageInfoVo(goblinNftExCodeArrayList, count);
PageInfoVo pageInfo = new PageInfoVo(goblinNftExCodeArrayList, count,"");
return pageInfo;
}
......@@ -213,11 +209,11 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
goblinRedisUtils.removeCode(goblinNftExCode.getCode());
}
if (skuMap.size() > 0) {
/* if (skuMap.size() > 0) {
for (String key : skuMap.keySet()) {
// goblinRedisUtils.incrSkuStock(null, key, skuMap.get(key));
}
}
}*/
// 批量修改
goblinNftExCodeMapper.updateCodes(goblinNftExCodes);
return true;
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsSkuInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExCodeVo;
import com.liquidnet.service.goblin.dto.vo.GoblinNftExSkuVo;
......@@ -13,6 +14,7 @@ import com.liquidnet.service.goblin.param.GoblinNftExSkuParam;
import com.liquidnet.service.goblin.service.IGoblinNftExSkuService;
import com.liquidnet.service.platform.utils.GoblinRedisUtils;
import com.liquidnet.service.platform.utils.ObjectUtil;
import com.microsoft.schemas.office.visio.x2012.main.ShapeSheetType;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
......@@ -36,10 +38,6 @@ import java.util.*;
@Slf4j
public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
@Autowired
private GoblinNftExCodeMapper goblinNftExCodeMapper;
@Autowired
private GoblinNftExSkuMapper goblinNftExSkuMapper;
@Autowired
private GoblinRedisUtils goblinRedisUtils;
@Autowired
......@@ -52,7 +50,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
@Transactional
@Override
public Boolean add(List<GoblinNftExSkuParam> goblinNftExSkuParams) {
public ResponseDto<Object> add(List<GoblinNftExSkuParam> goblinNftExSkuParams) {
LocalDateTime now = LocalDateTime.now();
......@@ -61,27 +59,50 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
Boolean bol = false;
String spuId = "";
Integer stockNumber = 0;
StringBuffer skuIds = new StringBuffer();
for (GoblinNftExSkuParam goblinNftExSkuParam : goblinNftExSkuParams) {
if (goblinNftExSkuParam.getUnbox().equals("1")) {
bol = true;
spuId = goblinNftExSkuParam.getSpuId();
break;
}
stockNumber += goblinNftExSkuParam.getExStock();
skuIds.append(goblinNftExSkuParam.getSkuId()).append(",");
}
if (stockNumber <= 0) {
return false;
return ResponseDto.failure("配置库存为0,无法生成!");
}
if (StringUtil.isBlank(skuIds)) {
return ResponseDto.failure("sku数据不可传空!");
}
// 获取sku数据校验是否正确
List<GoblinGoodsSku> goblinGoodsSkuListCheck = goblinGoodsSkuMapper.selectBySkuIds(skuIds.toString());
List<String> skuIdList = new ArrayList<>();
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkuListCheck) {
// 不能购买的 没库存的 概率是0的 过滤
if (getSkuAllStatusShow(goblinGoodsSku)) {
skuIdList.add(goblinGoodsSku.getSkuId());
}
}
if (skuIdList.size() <= 0) {
return ResponseDto.failure("当前选中的sku不处于可售卖状态!");
}
if (goblinGoodsSkuListCheck == null || (goblinGoodsSkuListCheck.size() != (bol ? goblinNftExSkuParams.size() - 1 : goblinNftExSkuParams.size()))) {
return ResponseDto.failure("sku数据异常!");
}
Map<String, BigDecimal> map = new HashMap<>();
if (bol) {
// 获取spu下所有sku
List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectBySpuIds(spuId);
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) {
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkuListCheck) {
if (goblinGoodsSku.getUnbox().equals("1")) {
continue;
}
......@@ -102,6 +123,10 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
// 构建对象
for (GoblinNftExSkuParam goblinNftExSkuParam : goblinNftExSkuParams) {
if (!goblinNftExSkuParam.getUnbox().equals("1") && !skuIdList.contains(goblinNftExSkuParam.getSkuId())) {
continue;
}
// 定时任务对象构建
GoblinNftExCodeTask goblinNftExCodeTask = GoblinNftExCodeTask.getNew();
goblinNftExCodeTask.setTaskId(IDGenerator.nextSnowId());
......@@ -123,7 +148,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
// sku ---> 库存
Map<String, Integer> skuMap = getSkuHitRatio(goblinNftExSkuParam.getExStock(), map);
if (skuMap.size() > 0){
if (skuMap.size() > 0) {
Integer sNumber = 0;
for (String key : skuMap.keySet()) {
Integer stockNum = skuMap.get(key);
......@@ -267,7 +292,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
}
/*
/*
for (String key : goblinNftExSkuParamMap.keySet()) {
GoblinNftExSkuVo goblinNftExSkuVo = goblinRedisUtils.getSkuTime(key);
......@@ -305,37 +330,112 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
// 数据库操作
long startm = System.currentTimeMillis();
goblinNftExCodeTaskMapper.addGoblinNftExCodeTasks(goblinNftExCodeTasks);
if (goblinNftExCodeTasks.size() > 0) {
goblinNftExCodeTaskMapper.addGoblinNftExCodeTasks(goblinNftExCodeTasks);
}
// goblinNftExCodeMapper.addGoblinNftExCodes(goblinNftExCodes);
log.debug("MSQ耗时:ms", System.currentTimeMillis() - startm);
return true;
return ResponseDto.success(true);
}
/**
* 获取每个sku的兑换码生成数量
* <p>
* sku兑换码数 = 生码总数 * sku概率/总概率
* 若sku兑换码数 > sku剩余库存
* 用 sku兑换码数 - sku剩余库存 * (其他sku概率/其他总概率)
* <p>
* 例:生成兑换码 120 有sku1,sku2,sku3
* sku1 库存5 概率 10%
* sku2 库存100 概率 20%
* sku3 库存100 概率 30%
* <p>
* sku1兑换码数=120 * (10/60) = 20 >5
* sku2兑换码数=120 * (20/60) = 40 <100
* sku3兑换码数=120 * (30/60) = 60 <100
* <p>
* sku2第二轮兑换码数 = (20-5) * (20/50) = 6 < 60
* sku3第二轮兑换码数 = (20-5) * (30/50) = 9 < 40
* <p>
* 总兑换码 = sku1兑换码数+sku2兑换码数+sku3兑换码数+sku2第二轮兑换码数+sku3第二轮兑换码数
*
* @param exStock
* @param map
* @return
*/
private Map<String, Integer> getSkuHitRatio(Integer exStock, Map<String, BigDecimal> map) {
private Map<String, Integer> getSkuHitRatio(Integer exStock, Map<String, BigDecimal> map) {
// sku ---> 次数
Map<String, Integer> skuNumMap = new HashMap<>();
// 获取sku总概率
BigDecimal hitRatioCount = new BigDecimal(0);
// sku --> 概率/库存
Map<String, Map<String, Object>> mapMap = new HashMap<>();
int j = 0;
for (String key : map.keySet()) {
BigDecimal skuHitRatio = map.get(key);
Map<String, Object> objectMap = new HashMap<>();
if (skuHitRatio == null) {
continue;
}
hitRatioCount = hitRatioCount.add(skuHitRatio);
objectMap.put("hitRatio", skuHitRatio);
objectMap.put("stock", goblinRedisUtils.getSkuStock(key));
mapMap.put(key, objectMap);
j += 100;
}
// sku ---> 库存
Map<String, Integer> stockMap = new HashMap<>();
getStock(exStock, hitRatioCount, mapMap, stockMap);
return stockMap;
}
if (map.get(key) == null) {
System.out.println(map.get(key));
/**
* 获取单个sku库存
*
* @param exStock
* @param hitRatioCount
* @param mapMap
* @return
*/
private void getStock(Integer exStock, BigDecimal hitRatioCount, Map<String, Map<String, Object>> mapMap, Map<String, Integer> stockMap) {
if (exStock < 0) {
return;
}
for (String key : mapMap.keySet()) {
Object stock = mapMap.get(key).get("stock");
Object hitRatio = mapMap.get(key).get("hitRatio");
// 要减去的库存
int subStock = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
if (subStock > Integer.valueOf(stock.toString())) {
exStock = exStock - Integer.valueOf(stock.toString());
mapMap.get(key).put("stock", 0);
if (stockMap.get(key) == null) {
stockMap.put(key, Integer.valueOf(stock.toString()));
} else {
stockMap.put(key, stockMap.get(key) + Integer.valueOf(stock.toString()));
}
} else {
exStock = exStock - subStock;
if (stockMap.get(key) == null) {
stockMap.put(key, subStock);
} else {
stockMap.put(key, stockMap.get(key) + subStock);
}
}
}
if (exStock > 0) {
for (String key : mapMap.keySet()) {
Object hitRatio = mapMap.get(key).get("hitRatio");
Object stock = mapMap.get(key).get("stock");
if (Integer.valueOf(stock.toString()) < 0) {
}
hitRatioCount.subtract(new BigDecimal(hitRatio.toString()));
}
// 概率
BigDecimal hitNum = map.get(key).divide(BigDecimal.valueOf(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
Integer stock = hitNum.multiply(BigDecimal.valueOf(exStock)).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
skuNumMap.put(key, stock);
getStock(exStock, hitRatioCount, mapMap, stockMap);
}
return skuNumMap;
}
......@@ -347,8 +447,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
&& info.getStatus().equals("3")
&& info.getShelvesStatus().equals("3")
&& (info.getSkuAppear() == null || info.getSkuAppear().equals("0"))
&& info.getDelFlg().equals("0")
&& info.getUnbox().equals("0")) {
&& info.getDelFlg().equals("0")) {
return true;
} else {
return false;
......
......@@ -10,6 +10,7 @@ import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.base.constant.MQConst;
import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.GoblinQueueBizIntegralDto;
import com.liquidnet.service.goblin.dto.GoblinStoreMarketDto;
import com.liquidnet.service.goblin.dto.vo.*;
......@@ -116,6 +117,9 @@ public class GoblinRedisUtils {
return (int) getRedis().incr(rk, stock);
}
// 获取sku库存
// 减少库存
public int decrSkuStock(String marketPre, String skuId, Integer stock){
String rk = GoblinRedisConst.REAL_STOCK_SKU;
......@@ -225,7 +229,7 @@ public class GoblinRedisUtils {
public int getSkuAllStatusStock(GoblinGoodsSku info) {
if (
info != null
&& LocalDateTime.now().isAfter(info.getSaleStartTime())
// && LocalDateTime.now().isAfter(info.getSaleStartTime())
&& (null == info.getSoldoutStatus() || info.getSoldoutStatus().equals("0"))
&& (null == info.getHitRatio() || info.getHitRatio().compareTo(BigDecimal.ZERO) > 0)
) {// 可以返回库存
......@@ -237,7 +241,6 @@ public class GoblinRedisUtils {
}
}
/**
* redis codes主动失效
* @param code
......@@ -272,6 +275,26 @@ public class GoblinRedisUtils {
return getRedis().set(key,goblinNftExSkuVo);
}
/**
* 获取sku库存
* @param skuId
* @return
*/
public int getSkuStock(String skuId) {
String rk = GoblinRedisConst.REAL_STOCK_SKU.concat(skuId);
Object obj = getRedis().get(rk);
if (obj == null) {
return 0;
} else {
return (int) obj;
}
}
// 获取sku配置库存
/* ---------------------------------------- ---------------------------------------- */
/* ---------------------------------------- ---------------------------------------- */
/* ---------------------------------------- ---------------------------------------- */
......
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