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

Commit 447afeb1 authored by wanglele's avatar wanglele

兑换活动增加uid

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