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

Commit f5b6e0c9 authored by wanglele's avatar wanglele

兑换码定时任务 空投

parent 162c7396
...@@ -31,7 +31,8 @@ public class GoblinNftExCodeParam implements Serializable { ...@@ -31,7 +31,8 @@ public class GoblinNftExCodeParam implements Serializable {
private String userId; private String userId;
@ApiModelProperty(position = 17,required = true,value = "手机号/ 发送空投时传入") @ApiModelProperty(position = 17,required = true,value = "手机号/ 发送空投时传入")
private String phone; private String phone;
@ApiModelProperty(position = 18,required = true,value = "当操作用户id/发送空投时传入")
private String adminUid;
} }
...@@ -27,7 +27,7 @@ public interface IGoblinNftExCodeService { ...@@ -27,7 +27,7 @@ public interface IGoblinNftExCodeService {
* @param goblinNftExCodeParam * @param goblinNftExCodeParam
* @return * @return
*/ */
ResponseDto<Object> addAirdrop(GoblinNftExCodeParam goblinNftExCodeParam); ResponseDto<Boolean> addAirdrop(GoblinNftExCodeParam goblinNftExCodeParam);
/** /**
* 兑换码导出 * 兑换码导出
......
package com.liquidnet.service.goblin.service;
public interface IGoblinNftExCodeTaskService {
/**
* 定时生成兑换码
*/
void generateCode();
}
...@@ -158,8 +158,6 @@ public class IDGenerator { ...@@ -158,8 +158,6 @@ public class IDGenerator {
* @return * @return
*/ */
public static String createCode(int num,int sec,boolean bol) { public static String createCode(int num,int sec,boolean bol) {
//
StringBuffer str = new StringBuffer(); StringBuffer str = new StringBuffer();
for (int k=0;k<num;k++) { for (int k=0;k<num;k++) {
for(int i=0;i < sec;i++){ for(int i=0;i < sec;i++){
......
package com.liquidnet.service.goblin.entity;
import java.time.LocalDateTime;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 兑换码定时任务生成副表
* </p>
*
* @author jiangxiulong
* @since 2022-04-28
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class GoblinNftExCodeTaskRelation implements Serializable {
private static final long serialVersionUID = 1L;
private String mid;
/**
* 定时id
*/
private String taskId;
/**
* sku_id
*/
private String skuId;
/**
* 库存
*/
private Integer stock;
/**
* 创建时间
*/
private LocalDateTime createdAt;
/**
* 修改时间
*/
private LocalDateTime updatedAt;
private final static GoblinNftExCodeTaskRelation obj = new GoblinNftExCodeTaskRelation();
public static GoblinNftExCodeTaskRelation getNew(){
try {
return (GoblinNftExCodeTaskRelation) obj.clone();
}catch (CloneNotSupportedException e){
return new GoblinNftExCodeTaskRelation();
}
}
}
...@@ -69,4 +69,11 @@ public interface GoblinNftExCodeMapper extends BaseMapper<GoblinNftExCode> { ...@@ -69,4 +69,11 @@ public interface GoblinNftExCodeMapper extends BaseMapper<GoblinNftExCode> {
* 获取数量 * 获取数量
*/ */
int selectGoblinNftCodeCount(GoblinNftExCode goblinNftExCode); int selectGoblinNftCodeCount(GoblinNftExCode goblinNftExCode);
/**
* 修改操作用户
* @param goblinNftExCode
* @return
*/
int updateCodeAdminUid(GoblinNftExCode goblinNftExCode);
} }
package com.liquidnet.service.goblin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liquidnet.service.goblin.entity.GoblinNftExCodeTaskRelation;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <p>
* 兑换码定时任务生成副表 Mapper 接口
* </p>
*
* @author jiangxiulong
* @since 2022-04-28
*/
@Repository
public interface GoblinNftExCodeTaskRelationMapper extends BaseMapper<GoblinNftExCodeTaskRelation> {
/**
* 根据定时任务ids查询
* @param taskIds
* @return
*/
List<GoblinNftExCodeTaskRelation> selectByTaskIds(@Param("taskIds") String taskIds);
/**
* 批量添加定时任务附表
* @param goblinNftExCodeTaskRelations
* @return
*/
int inserts(@Param("goblinNftExCodeTaskRelations") List<GoblinNftExCodeTaskRelation> goblinNftExCodeTaskRelations);
}
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</select> </select>
<select id="selectGoblinNftCodeByCode" resultMap="BeseResult"> <select id="selectGoblinNftCodeByCode" resultMap="BeseResult">
select code_id, activity_id, code, box_sku_id 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">
...@@ -55,6 +55,15 @@ ...@@ -55,6 +55,15 @@
</foreach> </foreach>
</update> </update>
<update id="updateCodeAdminUid" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExCode">
update goblin_nft_ex_code
<set>
admin_uid = #{adminUid}
</set>
where code_id = #{codeId}
</update>
<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 code_id,code,sku_id,box_sku_id,activity_id,state,redeem_uid,redeem_at,admin_uid,created_at from goblin_nft_ex_code
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.liquidnet.service.goblin.mapper.GoblinNftExCodeTaskRelationMapper">
<resultMap id="BaseResult" type="com.liquidnet.service.goblin.entity.GoblinNftExCodeTaskRelation">
<result column="task_id" property="taskId" jdbcType="VARCHAR"/>
<result column="sku_id" property="skuId" jdbcType="VARCHAR"/>
<result column="stock" property="stock" jdbcType="VARCHAR"/>
<result column="created_at" property="createdAt" jdbcType="TIMESTAMP"/>
<result column="updated_at" property="updatedAt" jdbcType="TIMESTAMP"/>
</resultMap>
<select id="selectByTaskIds" resultMap="BaseResult">
select task_id,sku_id,stock,created_at,updated_at from goblin_nft_ex_code_task_relation where task_id in
<foreach collection="taskIds.split(',')" item="taskId" open="(" separator="," close=")">
#{taskId}
</foreach>
</select>
<insert id="inserts">
insert into goblin_nft_ex_code_task_relation (task_id,sku_id,stock,created_at)
values
<foreach collection="goblinNftExCodeTaskRelations" item="goblinNftExCodeTaskRelation" separator=",">
(
#{goblinNftExCodeTaskRelation.taskId},
#{goblinNftExCodeTaskRelation.skuId},
#{goblinNftExCodeTaskRelation.stock},
#{goblinNftExCodeTaskRelation.createdAt}
)
</foreach>
</insert>
</mapper>
...@@ -25,4 +25,9 @@ public interface FeignPlatformGoblinTaskClient { ...@@ -25,4 +25,9 @@ public interface FeignPlatformGoblinTaskClient {
@PostMapping("spu/goblin/setCount") @PostMapping("spu/goblin/setCount")
ResponseDto<String> setCount(); ResponseDto<String> setCount();
@PostMapping("codeTask/generateCode")
ResponseDto<String> codeCount();
} }
...@@ -43,4 +43,14 @@ public class PlatformGoblinTaskHandler { ...@@ -43,4 +43,14 @@ public class PlatformGoblinTaskHandler {
} }
} }
@XxlJob(value = "sev-platform:codeCount")
public void codeCount() {// 设置商城 商品数量
try {
XxlJobHelper.handleSuccess("结果:" + feignPlatformGoblinTaskClient.codeCount().toJson());
} catch (Exception e) {
XxlJobHelper.log(e);
XxlJobHelper.handleFail();
}
}
} }
...@@ -82,3 +82,16 @@ CREATE TABLE `goblin_nft_ex_code_task` ...@@ -82,3 +82,16 @@ CREATE TABLE `goblin_nft_ex_code_task`
PRIMARY KEY (`mid`) USING BTREE PRIMARY KEY (`mid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '兑换码定时任务表' ROW_FORMAT = Dynamic; ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '兑换码定时任务表' ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `goblin_nft_ex_code_task_relation`;
CREATE TABLE `goblin_nft_ex_code_task_relation`
(
`mid` bigint(0) NOT NULL AUTO_INCREMENT,
`task_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '定时id',
`sku_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'sku_id',
`stock` int(0) NOT NULL COMMENT '库存',
`created_at` datetime(0) NOT NULL COMMENT '创建时间',
`updated_at` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`mid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '兑换码定时任务生成副表' ROW_FORMAT = Dynamic;
...@@ -49,8 +49,8 @@ public class GoblinNftExCodeController { ...@@ -49,8 +49,8 @@ public class GoblinNftExCodeController {
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
@ApiOperation(value = "空投发送") @ApiOperation(value = "空投发送")
@PostMapping("addAirdrop") @PostMapping("addAirdrop")
public ResponseDto<Object> addAirdrop(@RequestBody GoblinNftExCodeParam goblinNftExCodeParam){ public ResponseDto<Boolean> addAirdrop(@RequestBody GoblinNftExCodeParam goblinNftExCodeParam){
return ResponseDto.success(iGoblinNftExCodeService.addAirdrop(goblinNftExCodeParam)); return iGoblinNftExCodeService.addAirdrop(goblinNftExCodeParam);
} }
......
package com.liquidnet.service.platform.controller.goblin.code.task;
import com.liquidnet.service.goblin.service.IGoblinNftExCodeTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "code定时任务")
@Slf4j
@Validated
@RestController
@RequestMapping("codeTask")
public class GoblinNftExCodeTaskController {
@Autowired
IGoblinNftExCodeTaskService iGoblinNftExCodeTaskService;
@PostMapping("generateCode")
@ApiOperation(value = "定时自动生成兑换码")
public void generateCode(){
iGoblinNftExCodeTaskService.generateCode();
}
}
...@@ -101,19 +101,19 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi ...@@ -101,19 +101,19 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi
activityIds.deleteCharAt(activityIds.length() - 1); activityIds.deleteCharAt(activityIds.length() - 1);
// 根据活动ids查询正在生成的兑换码 // 根据活动ids查询正在生成的兑换码
// List<GoblinNftExCodeTask> goblinNftExCodeTasks = goblinNftExCodeTaskMapper.selectByActivityIds(activityIds.toString()); List<GoblinNftExCodeTask> goblinNftExCodeTasks = goblinNftExCodeTaskMapper.selectByActivityIds(activityIds.toString());
long k = System.currentTimeMillis(); long k = System.currentTimeMillis();
List<GoblinNftExCode> goblinNftExCodes = goblinNftExCodeMapper.selectByActivityIds(activityIds.toString()); List<GoblinNftExCode> goblinNftExCodes = goblinNftExCodeMapper.selectByActivityIds(activityIds.toString());
log.debug("#MYS耗时:{}ms", System.currentTimeMillis() - k); log.debug("#MYS耗时:{}ms", System.currentTimeMillis() - k);
for (GoblinNftExActivity goblinNftExActivity : goblinNftExActivities) { for (GoblinNftExActivity goblinNftExActivity : goblinNftExActivities) {
/* for (GoblinNftExCodeTask goblinNftExCodeTask: goblinNftExCodeTasks) { for (GoblinNftExCodeTask goblinNftExCodeTask : goblinNftExCodeTasks) {
if (goblinNftExActivity.getActivityId().equals(goblinNftExCodeTask.getActivityId())){ if (goblinNftExActivity.getActivityId().equals(goblinNftExCodeTask.getActivityId())) {
goblinNftExActivity.setIsDisplay(1); goblinNftExActivity.setIsDisplay(1);
break; break;
} }
}*/ }
Integer countNumber = 0; Integer countNumber = 0;
Integer useNumber = 0; Integer useNumber = 0;
...@@ -139,7 +139,7 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi ...@@ -139,7 +139,7 @@ public class GoblinNftExActivityServiceImpl implements IGoblinNftExActivityServi
} }
} }
PageInfoVo pageInfo = new PageInfoVo(goblinNftExActivityArrayList,count,0); PageInfoVo pageInfo = new PageInfoVo(goblinNftExActivityArrayList, count, 0);
return pageInfo; return pageInfo;
} }
......
...@@ -5,6 +5,7 @@ import com.alibaba.excel.support.ExcelTypeEnum; ...@@ -5,6 +5,7 @@ import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.type.TypeReference;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.liquidnet.commons.lang.util.*; import com.liquidnet.commons.lang.util.*;
...@@ -32,6 +33,7 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment; ...@@ -32,6 +33,7 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
...@@ -67,8 +69,6 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService { ...@@ -67,8 +69,6 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
private AdamUserMapper adamUserMapper; private AdamUserMapper adamUserMapper;
@Value("${liquidnet.service.order.url}") @Value("${liquidnet.service.order.url}")
private String orderUrl; private String orderUrl;
/* @Autowired
private */
@Override @Override
public PageInfoVo selectCodePageList(GoblinNftExCodeParam goblinNftExCodeParam) { public PageInfoVo selectCodePageList(GoblinNftExCodeParam goblinNftExCodeParam) {
...@@ -172,7 +172,7 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService { ...@@ -172,7 +172,7 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
} }
PageInfoVo pageInfo = new PageInfoVo(goblinNftExCodeArrayList,count); PageInfoVo pageInfo = new PageInfoVo(goblinNftExCodeArrayList, count);
return pageInfo; return pageInfo;
} }
...@@ -208,33 +208,50 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService { ...@@ -208,33 +208,50 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
skuMap.put(skuId, number + 1); skuMap.put(skuId, number + 1);
} }
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;
} }
@Override @Override
public ResponseDto<Object> addAirdrop(GoblinNftExCodeParam goblinNftExCodeParam) { @Transactional
public ResponseDto<Boolean> addAirdrop(GoblinNftExCodeParam goblinNftExCodeParam) {
String code = goblinNftExCodeParam.getCode(); String code = goblinNftExCodeParam.getCode();
String phone = goblinNftExCodeParam.getPhone(); String phone = goblinNftExCodeParam.getPhone();
AdamUserInfoDto adamUserInfoDto = adamUserMapper.selectByPhone(phone); AdamUserInfoDto adamUserInfoDto = adamUserMapper.selectByPhone(phone);
if (adamUserInfoDto == null) { if (adamUserInfoDto == null) {
return ResponseDto.failure("兑换码不正确或已失效"); return ResponseDto.failure("用户不存在!");
} }
// 根据兑换code查询兑换码信息 // 根据兑换code查询兑换码信息
GoblinNftExCode goblinNftExCode = goblinNftExCodeMapper.selectGoblinNftCodeByCode(code); GoblinNftExCode goblinNftExCode = goblinNftExCodeMapper.selectGoblinNftCodeByCode(code);
if (goblinNftExCode == null) {
return ResponseDto.failure("兑换码不存在!");
}
if (goblinNftExCode.getState().equals(2)) {
return ResponseDto.failure("兑换码已领取!");
}
GoblinNftExCodeVo goblinNftExCodeVo = goblinRedisUtils.getGoblinNftExCodeVo(goblinNftExCode.getCode());
if (goblinNftExCodeVo == null) {
return ResponseDto.failure("兑换码已失效!");
}
if (goblinNftExCodeVo.getState().equals(2)) {
return ResponseDto.failure("兑换码已领取!");
}
// 验证吗时间校验
try { try {
MultiValueMap<String, String> params = new LinkedMultiValueMap(); MultiValueMap<String, String> params = new LinkedMultiValueMap();
params.add("code", code); params.add("code", code);
...@@ -243,10 +260,18 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService { ...@@ -243,10 +260,18 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
headers.add("Accept", "application/json;charset=UTF-8"); headers.add("Accept", "application/json;charset=UTF-8");
headers.add("Authorization", "Bearer " + CurrentUtil.getToken()); headers.add("Authorization", "Bearer " + CurrentUtil.getToken());
String post = HttpUtil.post(orderUrl + "/order/goblin/nft/airdrop", params, headers); String post = HttpUtil.post(orderUrl + "/order/goblin/nft/airdrop", params, headers);
return ResponseDto.success(); ResponseDto<Boolean> rsp = JsonUtils.fromJson(post, new TypeReference<ResponseDto<Boolean>>() {
});
if (rsp.getData() != null && rsp.getData()) {
goblinNftExCode.setAdminUid(goblinNftExCodeParam.getAdminUid());
goblinNftExCodeMapper.updateCodeAdminUid(goblinNftExCode);
}else {
return ResponseDto.failure(rsp.getMessage());
}
return rsp;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return ResponseDto.failure(); return ResponseDto.failure("发送公投失败!");
} }
} }
......
package com.liquidnet.service.platform.task.code; package com.liquidnet.service.platform.service.impl.goblin;
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.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;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku;
import com.liquidnet.service.goblin.entity.GoblinNftExCode; import com.liquidnet.service.goblin.entity.GoblinNftExCode;
import com.liquidnet.service.goblin.entity.GoblinNftExCodeTask; import com.liquidnet.service.goblin.entity.GoblinNftExCodeTask;
import com.liquidnet.service.goblin.mapper.GoblinGoodsSkuMapper; import com.liquidnet.service.goblin.entity.GoblinNftExCodeTaskRelation;
import com.liquidnet.service.goblin.mapper.GoblinNftExCodeMapper; import com.liquidnet.service.goblin.entity.GoblinNftExSku;
import com.liquidnet.service.goblin.mapper.GoblinNftExCodeTaskMapper; import com.liquidnet.service.goblin.mapper.*;
import com.liquidnet.service.goblin.param.GoblinNftExSkuParam; import com.liquidnet.service.goblin.service.IGoblinNftExCodeTaskService;
import com.liquidnet.service.platform.utils.GoblinRedisUtils; import com.liquidnet.service.platform.utils.GoblinRedisUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
...@@ -29,24 +24,25 @@ import java.util.HashMap; ...@@ -29,24 +24,25 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Service
@Slf4j @Slf4j
@Configuration public class GoblinNftExCodeTaskServiceImpl implements IGoblinNftExCodeTaskService {
// @EnableScheduling
public class GoblinCodeTask {
@Autowired @Autowired
private GoblinNftExCodeMapper goblinNftExCodeMapper; private GoblinNftExCodeMapper goblinNftExCodeMapper;
@Autowired @Autowired
GoblinNftExCodeTaskMapper goblinNftExCodeTaskMapper; GoblinNftExCodeTaskMapper goblinNftExCodeTaskMapper;
@Autowired @Autowired
private GoblinGoodsSkuMapper goblinGoodsSkuMapper;
@Autowired
private GoblinRedisUtils goblinRedisUtils; private GoblinRedisUtils goblinRedisUtils;
@Autowired
private GoblinNftExCodeTaskRelationMapper goblinNftExCodeTaskRelationMapper;
@Autowired
private GoblinNftExSkuMapper goblinNftExSkuMapper;
// @Scheduled(cron = "0/5 * * * * ?") // 当前为同步 每隔5秒触发一次 @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void scheduleCode() { public void generateCode() {
/** /**
* 获取所有定时任务列表 * 获取所有定时任务列表
*/ */
...@@ -57,70 +53,55 @@ public class GoblinCodeTask { ...@@ -57,70 +53,55 @@ public class GoblinCodeTask {
} }
Boolean bol = false; StringBuffer taskIds = new StringBuffer();
StringBuffer spuIds = new StringBuffer();
for (GoblinNftExCodeTask goblinNftExCodeTask : goblinNftExCodeTasks) { for (GoblinNftExCodeTask goblinNftExCodeTask : goblinNftExCodeTasks) {
if (goblinNftExCodeTask.getUnbox().equals("1")) { if (goblinNftExCodeTask.getUnbox().equals("1")) {
bol = true; taskIds.append(goblinNftExCodeTask.getTaskId()).append(",");
spuIds.append(goblinNftExCodeTask.getSpuId()).append(",");
}
}
// spu ---> sku集合
Map<String, Map<String, BigDecimal>> spuMap = new HashMap<>();
if (bol) {
spuIds.deleteCharAt(spuIds.length() - 1);
List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectBySpuIds(spuIds.toString());
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) {
if (goblinGoodsSku.getUnbox().equals("1")) {
continue;
} }
if (spuMap.get(goblinGoodsSku.getSpuId()) == null) {
spuMap.put(goblinGoodsSku.getSpuId(), new HashMap<>());
} }
if (getSkuAllStatusShow(goblinGoodsSku) && goblinRedisUtils.getSkuAllStatusStock(goblinGoodsSku) > 0 && goblinGoodsSku.getHitRatio() != null) { List<GoblinNftExCodeTaskRelation> goblinNftExCodeTaskRelations = null;
spuMap.get(goblinGoodsSku.getSpuId()).put(goblinGoodsSku.getSkuId(), goblinGoodsSku.getHitRatio()); if (StringUtil.isNotBlank(taskIds)) {
} taskIds.deleteCharAt(taskIds.length() - 1);
goblinNftExCodeTaskRelations = goblinNftExCodeTaskRelationMapper.selectByTaskIds(taskIds.toString());
}
} }
// sku ---> 兑换码关联 // sku ---> 兑换码关联
Map<String, GoblinNftExCodeTask> goblinNftExCodeTaskHashMap = new HashMap<>(); Map<String, GoblinNftExCodeTask> goblinNftExCodeTaskHashMap = new HashMap<>();
// 构建对象
List<GoblinNftExCode> goblinNftExCodes = new ArrayList<>();
// 当前时间 // 当前时间
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
// 构建对象
List<GoblinNftExCode> goblinNftExCodes = new ArrayList<>();
List<GoblinNftExSku> goblinNftExSkus = new ArrayList<>();
StringBuffer taskIds = new StringBuffer(); StringBuffer updTaskIds = new StringBuffer();
for (GoblinNftExCodeTask goblinNftExCodeTask : goblinNftExCodeTasks) { for (GoblinNftExCodeTask goblinNftExCodeTask : goblinNftExCodeTasks) {
taskIds.append(goblinNftExCodeTask.getTaskId()).append(","); GoblinNftExSku goblinNftExSku = new GoblinNftExSku();
switch (goblinNftExCodeTask.getUnbox()) { goblinNftExSku.setActivityId(goblinNftExCodeTask.getActivityId());
case "1": goblinNftExSku.setSpuId(goblinNftExCodeTask.getSpuId());
goblinNftExSku.setSkuId(goblinNftExCodeTask.getSkuId());
// sku ---> 命中率 goblinNftExSku.setStoreId(goblinNftExCodeTask.getStoreId());
Map<String, BigDecimal> map = spuMap.get(goblinNftExCodeTask.getSpuId()); goblinNftExSku.setExStock(goblinNftExCodeTask.getExStock());
goblinNftExSku.setUnbox(goblinNftExCodeTask.getUnbox());
goblinNftExSku.setExLimit(goblinNftExCodeTask.getExLimit());
goblinNftExSku.setExStartTime(goblinNftExCodeTask.getExStartTime());
goblinNftExSku.setExStopTime(goblinNftExCodeTask.getExStopTime());
goblinNftExSku.setCreatedAt(now);
goblinNftExSkus.add(goblinNftExSku);
// sku ---> 库存
Map<String, Integer> skuMap = getSkuHitRatio(goblinNftExCodeTask.getExStock(), map);
for (String key : skuMap.keySet()) { updTaskIds.append(goblinNftExCodeTask.getTaskId()).append(",");
Integer stockNum = skuMap.get(key); switch (goblinNftExCodeTask.getUnbox()) {
case "1":
// 根据sku减库存 // 获取盲盒 sku-->库存
int stock = goblinRedisUtils.decrSkuStock(null, key, stockNum); for (GoblinNftExCodeTaskRelation goblinNftExCodeTaskRelation : goblinNftExCodeTaskRelations) {
if (stock < 0) { if (goblinNftExCodeTaskRelation.getTaskId().equals(goblinNftExCodeTask.getTaskId())) {
goblinRedisUtils.incrSkuStock(null, key, stockNum); if (goblinNftExCodeTaskRelation.getStock() > 0) {
} else { for (int j = 0; j < goblinNftExCodeTaskRelation.getStock(); j++) {
for (int k = 0; k < stockNum; k++) {
GoblinNftExCode goblinNftExCode = GoblinNftExCode.getNew(); GoblinNftExCode goblinNftExCode = GoblinNftExCode.getNew();
goblinNftExCode.setCodeId(IDGenerator.nextSnowId()); goblinNftExCode.setCodeId(IDGenerator.nextSnowId());
goblinNftExCode.setActivityId(goblinNftExCodeTask.getActivityId()); goblinNftExCode.setActivityId(goblinNftExCodeTask.getActivityId());
...@@ -128,47 +109,44 @@ public class GoblinCodeTask { ...@@ -128,47 +109,44 @@ public class GoblinCodeTask {
// 样例 2978-6496-9269-0694-XX // 样例 2978-6496-9269-0694-XX
String code = IDGenerator.createCode(3, 4, true); String code = IDGenerator.createCode(3, 4, true);
goblinNftExCode.setCode(code); goblinNftExCode.setCode(code);
goblinNftExCode.setBoxSkuId(key); goblinNftExCode.setBoxSkuId(goblinNftExCodeTaskRelation.getSkuId());
goblinNftExCode.setState(1); goblinNftExCode.setState(1);
goblinNftExCode.setCreatedAt(now); goblinNftExCode.setCreatedAt(now);
goblinNftExCodes.add(goblinNftExCode);
// 赋值额外属性 // 赋值额外属性
GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(goblinNftExCode); GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(goblinNftExCode);
goblinNftExCodeVo.setExLimit(goblinNftExCodeTask.getExLimit()); goblinNftExCodeVo.setExLimit(goblinNftExCodeTask.getExLimit());
goblinNftExCodeVo.setExStartTime(goblinNftExCodeTask.getExStartTime()); goblinNftExCodeVo.setExStartTime(goblinNftExCodeTask.getExStartTime());
goblinNftExCodeVo.setExStopTime(goblinNftExCodeTask.getExStartTime()); goblinNftExCodeVo.setExStopTime(goblinNftExCodeTask.getExStopTime());
goblinNftExCodeVo.setStoreId(goblinNftExCodeTask.getStoreId()); goblinNftExCodeVo.setStoreId(goblinNftExCodeTask.getStoreId());
goblinNftExCodeVo.setSpuId(goblinNftExCodeTask.getSpuId()); goblinNftExCodeVo.setSpuId(goblinNftExCodeTask.getSpuId());
LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime(); LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime();
// 时间差 以秒表示 // 时间差 以秒表示
long millisNum = Duration.between(LocalDateTime.now(), exStopTime).toMillis(); long millisNum = Duration.between(LocalDateTime.now(), exStopTime).toMillis();
// redis 存储 // redis 存储
goblinRedisUtils.addCode(code, goblinNftExCodeVo, millisNum); goblinRedisUtils.addCode(code, goblinNftExCodeVo, millisNum);
goblinNftExCode.setSkuId(goblinNftExCodeTask.getSkuId());
goblinNftExCode.setSkuId(goblinNftExCodeTask.getSkuId());
goblinNftExCodes.add(goblinNftExCode);
} }
goblinNftExCodeTaskHashMap.put(key, goblinNftExCodeTask);
} }
if (goblinNftExCodeTaskHashMap.get(goblinNftExCodeTask.getSkuId()) == null) {
goblinNftExCodeTaskHashMap.put(goblinNftExCodeTaskRelation.getSkuId(), goblinNftExCodeTask);
} }
}
}
break; break;
default: default:
// 根据sku减库存
int stock = goblinRedisUtils.decrSkuStock(null, goblinNftExCodeTask.getSkuId(), goblinNftExCodeTask.getExStock());
if (stock < 0) {
goblinRedisUtils.incrSkuStock(null, goblinNftExCodeTask.getSkuId(), goblinNftExCodeTask.getExStock());
} else {
for (int i = 0; i < goblinNftExCodeTask.getExStock(); i++) { for (int i = 0; i < goblinNftExCodeTask.getExStock(); i++) {
GoblinNftExCode goblinNftExCode = GoblinNftExCode.getNew(); GoblinNftExCode goblinNftExCode = GoblinNftExCode.getNew();
goblinNftExCode.setCodeId(IDGenerator.nextSnowId()); goblinNftExCode.setCodeId(IDGenerator.nextSnowId());
goblinNftExCode.setActivityId(goblinNftExCodeTask.getActivityId()); goblinNftExCode.setActivityId(goblinNftExCodeTask.getActivityId());
// 获取兑换码ZA // 获取兑换码ZA
// 样例 2978-6496-9269-0694-XX // 样例 2978-6496-9269-0694-XX
String code = IDGenerator.createCode(3, 4, true); String code = IDGenerator.createCode(3, 4, true);
...@@ -182,11 +160,10 @@ public class GoblinCodeTask { ...@@ -182,11 +160,10 @@ public class GoblinCodeTask {
GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(goblinNftExCode); GoblinNftExCodeVo goblinNftExCodeVo = GoblinNftExCodeVo.getNew().copy(goblinNftExCode);
goblinNftExCodeVo.setExLimit(goblinNftExCodeTask.getExLimit()); goblinNftExCodeVo.setExLimit(goblinNftExCodeTask.getExLimit());
goblinNftExCodeVo.setExStartTime(goblinNftExCodeTask.getExStartTime()); goblinNftExCodeVo.setExStartTime(goblinNftExCodeTask.getExStartTime());
goblinNftExCodeVo.setExStopTime(goblinNftExCodeTask.getExStartTime()); goblinNftExCodeVo.setExStopTime(goblinNftExCodeTask.getExStopTime());
goblinNftExCodeVo.setStoreId(goblinNftExCodeTask.getStoreId()); goblinNftExCodeVo.setStoreId(goblinNftExCodeTask.getStoreId());
goblinNftExCodeVo.setSpuId(goblinNftExCodeTask.getSpuId()); goblinNftExCodeVo.setSpuId(goblinNftExCodeTask.getSpuId());
LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime(); LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime();
// 时间差 以秒表示 // 时间差 以秒表示
long millisNum = Duration.between(LocalDateTime.now(), exStopTime).toMillis(); long millisNum = Duration.between(LocalDateTime.now(), exStopTime).toMillis();
...@@ -200,29 +177,23 @@ public class GoblinCodeTask { ...@@ -200,29 +177,23 @@ public class GoblinCodeTask {
if (nftExCodeTask == null) { if (nftExCodeTask == null) {
goblinNftExCodeTaskHashMap.put(goblinNftExCodeTask.getSkuId(), goblinNftExCodeTask); goblinNftExCodeTaskHashMap.put(goblinNftExCodeTask.getSkuId(), goblinNftExCodeTask);
} }
}
} }
} }
/** // sku ---> 时间存储
* sku redis 时间存储
*/
for (String key : goblinNftExCodeTaskHashMap.keySet()) { for (String key : goblinNftExCodeTaskHashMap.keySet()) {
GoblinNftExSkuVo goblinNftExSkuVo = goblinRedisUtils.getSkuTime(key); GoblinNftExSkuVo goblinNftExSkuVo = goblinRedisUtils.getSkuTime(key);
GoblinNftExCodeTask goblinNftExCodeTask = goblinNftExCodeTaskHashMap.get(key); GoblinNftExCodeTask goblinNftExCodeTask = goblinNftExCodeTaskHashMap.get(key);
LocalDateTime exStartTime = goblinNftExCodeTask.getExStartTime(); // "2022-06-26 19:00:00"; LocalDateTime exStartTime = goblinNftExCodeTask.getExStartTime(); // "2022-06-26 19:00:00";
LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime(); // "2024-06-26 19:00:00"; LocalDateTime exStopTime = goblinNftExCodeTask.getExStopTime(); // "2024-06-26 19:00:00";
if (!StringUtil.isEmpty(goblinNftExSkuVo)) { if (!StringUtil.isEmpty(goblinNftExSkuVo)) {
// redis存储 单个sku的开始和结束时间 // redis存储 单个sku的开始和结束时间
LocalDateTime rdExStartTime = LocalDateTime.parse(goblinNftExSkuVo.getRdStartTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00"; LocalDateTime rdExStartTime = LocalDateTime.parse(goblinNftExSkuVo.getRdStartTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00";
LocalDateTime rdExStopTime = LocalDateTime.parse(goblinNftExSkuVo.getRdStopTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00"; LocalDateTime rdExStopTime = LocalDateTime.parse(goblinNftExSkuVo.getRdStopTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // "2019-06-26 19:00:00";
// 时间比对 // 时间比对
if (!rdExStartTime.isAfter(exStartTime)) { if (!rdExStartTime.isAfter(exStartTime)) {
exStartTime = rdExStartTime; exStartTime = rdExStartTime;
...@@ -239,58 +210,18 @@ public class GoblinCodeTask { ...@@ -239,58 +210,18 @@ public class GoblinCodeTask {
goblinNftExSku.setRdStartTime(exStartTime.toString()); goblinNftExSku.setRdStartTime(exStartTime.toString());
goblinNftExSku.setRdStopTime(exStopTime.toString()); goblinNftExSku.setRdStopTime(exStopTime.toString());
goblinRedisUtils.addSkuTime(key, goblinNftExSku); goblinRedisUtils.addSkuTime(key, goblinNftExSku);
} }
goblinNftExSkuMapper.addGoblinNftExSkus(goblinNftExSkus);
long startm = System.currentTimeMillis(); long startm = System.currentTimeMillis();
goblinNftExCodeMapper.addGoblinNftExCodes(goblinNftExCodes); goblinNftExCodeMapper.addGoblinNftExCodes(goblinNftExCodes);
// 修改定时 // 修改定时
goblinNftExCodeTaskMapper.updateByTaskIds(taskIds.toString()); goblinNftExCodeTaskMapper.updateByTaskIds(updTaskIds.toString());
log.debug("MSQ耗时:ms", System.currentTimeMillis() - startm); log.debug("MSQ耗时:ms", System.currentTimeMillis() - startm);
}
/**
* 获取每个sku的兑换码生成数量
*
* @param exStock
* @param map
* @return
*/
private Map<String, Integer> getSkuHitRatio(Integer exStock, Map<String, BigDecimal> map) {
// sku ---> 次数
Map<String, Integer> skuNumMap = new HashMap<>();
for (String key : map.keySet()) {
if (map.get(key) == null) {
System.out.println(map.get(key));
} }
// 概率
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;
}
// 各种状态下判断藏品是否可以展示
public boolean getSkuAllStatusShow(GoblinGoodsSku info) {
if (info != null
&& info.getSkuType() == 1
&& info.getStatus().equals("3")
&& info.getShelvesStatus().equals("3")
&& (info.getSkuAppear() == null || info.getSkuAppear().equals("0"))
&& info.getDelFlg().equals("0")
&& info.getUnbox().equals("0")) {
return true;
} else {
return false;
}
}
} }
...@@ -7,18 +7,13 @@ import com.liquidnet.commons.lang.util.StringUtil; ...@@ -7,18 +7,13 @@ import com.liquidnet.commons.lang.util.StringUtil;
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;
import com.liquidnet.service.goblin.entity.GoblinGoodsSku; import com.liquidnet.service.goblin.entity.*;
import com.liquidnet.service.goblin.entity.GoblinNftExCode; import com.liquidnet.service.goblin.mapper.*;
import com.liquidnet.service.goblin.entity.GoblinNftExCodeTask;
import com.liquidnet.service.goblin.entity.GoblinNftExSku;
import com.liquidnet.service.goblin.mapper.GoblinGoodsSkuMapper;
import com.liquidnet.service.goblin.mapper.GoblinNftExCodeMapper;
import com.liquidnet.service.goblin.mapper.GoblinNftExCodeTaskMapper;
import com.liquidnet.service.goblin.mapper.GoblinNftExSkuMapper;
import com.liquidnet.service.goblin.param.GoblinNftExSkuParam; 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 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;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -51,6 +46,8 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -51,6 +46,8 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
private GoblinGoodsSkuMapper goblinGoodsSkuMapper; private GoblinGoodsSkuMapper goblinGoodsSkuMapper;
@Autowired @Autowired
GoblinNftExCodeTaskMapper goblinNftExCodeTaskMapper; GoblinNftExCodeTaskMapper goblinNftExCodeTaskMapper;
@Autowired
private GoblinNftExCodeTaskRelationMapper goblinNftExCodeTaskRelationMapper;
@Transactional @Transactional
...@@ -96,23 +93,17 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -96,23 +93,17 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
} }
List<GoblinNftExSku> goblinNftExSkus = new ArrayList<>(); List<GoblinNftExCodeTask> goblinNftExCodeTasks = new ArrayList<>();
// List<GoblinNftExCodeTask> goblinNftExCodeTasks = new ArrayList<>(); // List<GoblinNftExCode> goblinNftExCodes = new ArrayList<>();
List<GoblinNftExCode> goblinNftExCodes = new ArrayList<>();
// sku ---> 兑换码关联 // sku ---> 兑换码关联
Map<String, GoblinNftExSkuParam> goblinNftExSkuParamMap = new HashMap<>(); // Map<String, GoblinNftExSkuParam> goblinNftExSkuParamMap = new HashMap<>();
// 构建对象 // 构建对象
for (GoblinNftExSkuParam goblinNftExSkuParam : goblinNftExSkuParams) { for (GoblinNftExSkuParam goblinNftExSkuParam : goblinNftExSkuParams) {
GoblinNftExSku goblinNftExSku = new GoblinNftExSku();
BeanUtils.copyProperties(goblinNftExSkuParam, goblinNftExSku);
goblinNftExSku.setCreatedAt(now);
goblinNftExSkus.add(goblinNftExSku);
// 定时任务对象构建 // 定时任务对象构建
/* GoblinNftExCodeTask goblinNftExCodeTask = GoblinNftExCodeTask.getNew(); GoblinNftExCodeTask goblinNftExCodeTask = GoblinNftExCodeTask.getNew();
goblinNftExCodeTask.setTaskId(IDGenerator.nextSnowId()); goblinNftExCodeTask.setTaskId(IDGenerator.nextSnowId());
goblinNftExCodeTask.setActivityId(goblinNftExSkuParam.getActivityId()); goblinNftExCodeTask.setActivityId(goblinNftExSkuParam.getActivityId());
goblinNftExCodeTask.setStoreId(goblinNftExSkuParam.getStoreId()); goblinNftExCodeTask.setStoreId(goblinNftExSkuParam.getStoreId());
...@@ -125,14 +116,50 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -125,14 +116,50 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
goblinNftExCodeTask.setExStopTime(goblinNftExSkuParam.getExStopTime()); goblinNftExCodeTask.setExStopTime(goblinNftExSkuParam.getExStopTime());
goblinNftExCodeTask.setTyp(1); goblinNftExCodeTask.setTyp(1);
goblinNftExCodeTask.setCreatedAt(now); goblinNftExCodeTask.setCreatedAt(now);
goblinNftExCodeTasks.add(goblinNftExCodeTask);*/ if (goblinNftExSkuParam.getUnbox().equals("1")) {
List<GoblinNftExCodeTaskRelation> goblinNftExCodeTaskRelations = new ArrayList<>();
// sku ---> 库存
Map<String, Integer> skuMap = getSkuHitRatio(goblinNftExSkuParam.getExStock(), map);
Integer sNumber = 0;
for (String key : skuMap.keySet()) {
Integer stockNum = skuMap.get(key);
// 根据sku减库存
int stock = goblinRedisUtils.decrSkuStock(null, key, stockNum);
if (stock < 0) {
goblinRedisUtils.incrSkuStock(null, key, stockNum);
} else {
GoblinNftExCodeTaskRelation goblinNftExCodeTaskRelation = new GoblinNftExCodeTaskRelation();
goblinNftExCodeTaskRelation.setTaskId(goblinNftExCodeTask.getTaskId());
goblinNftExCodeTaskRelation.setSkuId(key);
goblinNftExCodeTaskRelation.setStock(stockNum);
goblinNftExCodeTaskRelation.setCreatedAt(now);
goblinNftExCodeTaskRelations.add(goblinNftExCodeTaskRelation);
}
sNumber += stockNum;
}
goblinNftExCodeTaskRelationMapper.inserts(goblinNftExCodeTaskRelations);
goblinNftExCodeTask.setExStock(sNumber);
} else {
int stock = goblinRedisUtils.decrSkuStock(null, goblinNftExSkuParam.getSkuId(), goblinNftExSkuParam.getExStock());
if (stock < 0) {
goblinRedisUtils.incrSkuStock(null, goblinNftExSkuParam.getSkuId(), goblinNftExSkuParam.getExStock());
}
}
goblinNftExCodeTasks.add(goblinNftExCodeTask);
// 盲盒 概率 // 盲盒 概率
switch (goblinNftExSkuParam.getUnbox()) { /*switch (goblinNftExSkuParam.getUnbox()) {
case "1": case "1":
// sku ---> 库存 // sku ---> 库存
Map<String, Integer> skuMap = getSkuHitRatio(goblinNftExSkuParam.getExStock(), map); Map<String, Integer> skuMap = getSkuHitRatio(goblinNftExSkuParam.getExStock(), map);
for (String key : skuMap.keySet()) { for (String key : skuMap.keySet()) {
Integer stockNum = skuMap.get(key); Integer stockNum = skuMap.get(key);
...@@ -176,7 +203,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -176,7 +203,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
goblinNftExCode.setSkuId(goblinNftExSkuParam.getSkuId()); goblinNftExCode.setSkuId(goblinNftExSkuParam.getSkuId());
} }
goblinNftExSkuParamMap.put(key, goblinNftExSkuParam); // goblinNftExSkuParamMap.put(key, goblinNftExSkuParam);
} }
} }
...@@ -232,12 +259,13 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -232,12 +259,13 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
// goblinNftExSkuArrayList.add(GoblinNftExSkuVo.getNew().copy(goblinNftExSku)); // goblinNftExSkuArrayList.add(GoblinNftExSkuVo.getNew().copy(goblinNftExSku));
} }*/
} }
/*
for (String key : goblinNftExSkuParamMap.keySet()) { for (String key : goblinNftExSkuParamMap.keySet()) {
GoblinNftExSkuVo goblinNftExSkuVo = goblinRedisUtils.getSkuTime(key); GoblinNftExSkuVo goblinNftExSkuVo = goblinRedisUtils.getSkuTime(key);
...@@ -270,13 +298,13 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -270,13 +298,13 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
goblinRedisUtils.addSkuTime(key, goblinNftExSku); goblinRedisUtils.addSkuTime(key, goblinNftExSku);
} }
*/
// 数据库操作 // 数据库操作
long startm = System.currentTimeMillis(); long startm = System.currentTimeMillis();
goblinNftExSkuMapper.addGoblinNftExSkus(goblinNftExSkus); 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 true;
......
...@@ -208,6 +208,19 @@ public class GoblinRedisUtils { ...@@ -208,6 +208,19 @@ public class GoblinRedisUtils {
return getRedis().set(key,goblinNftExCodeVo,millisNum); return getRedis().set(key,goblinNftExCodeVo,millisNum);
} }
/**
* 兑换码
*/
public GoblinNftExCodeVo getGoblinNftExCodeVo(String code) {
String redisKey = GoblinRedisConst.ACTIVITY_SKU_CODE.concat(code);
Object obj = getRedis().get(redisKey);
if (obj == null) {
return null;
} else {
return (GoblinNftExCodeVo) obj;
}
}
// 获取盲盒下藏品的库存 各种状态下不能算库存的排除掉 // 获取盲盒下藏品的库存 各种状态下不能算库存的排除掉
public int getSkuAllStatusStock(GoblinGoodsSku info) { public int getSkuAllStatusStock(GoblinGoodsSku info) {
if ( if (
......
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