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

Commit e82653ff authored by wanglele's avatar wanglele

Merge branch 'hjc_goblin_list_fix_code' into pre

parents 85247184 ba21db36
......@@ -94,4 +94,12 @@ public interface GoblinNftExCodeMapper extends BaseMapper<GoblinNftExCode> {
* @return
*/
int updateCodeAdminUids(@Param("codes") String codes, @Param("adminUid") String adminUid);
/**
* excel导出打乱兑换码顺序
* @param goblinNftExCode
* @return
*/
List<GoblinNftExCode> selectGoblinNftCodeExcel(GoblinNftExCode goblinNftExCode);
}
......@@ -129,6 +129,58 @@
</select>
<select id="selectGoblinNftCodeExcel" parameterType="com.liquidnet.service.goblin.entity.GoblinNftExCode"
resultMap="BeseResult">
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 and gnes.activity_id
= gnec.activity_id
<where>
<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 (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 (((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>
</where>
ORDER BY gnec.code desc
</select>
<select id="selectCodeAvailableByActivityId" resultMap="BeseResult">
select DISTINCT gnec.code,
gnec.code_id,
......
......@@ -284,7 +284,7 @@ public class GoblinNftExCodeServiceImpl implements IGoblinNftExCodeService {
// PageHelper.startPage(goblinNftExCodeParam.getPageNum(), 20, true);
List<GoblinNftExCode> goblinNftExCodes = goblinNftExCodeMapper.selectGoblinNftCode(goblinNftExCode);
List<GoblinNftExCode> goblinNftExCodes = goblinNftExCodeMapper.selectGoblinNftCodeExcel(goblinNftExCode);
StringBuffer skuIds = new StringBuffer();
StringBuffer acticityIds = new StringBuffer();
......
......@@ -106,10 +106,18 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectBySpuIds(spuIds.toString());
int countStockNumber = 0;
int checkNumberSku = 0;
// 是否存在概率为空
boolean isHit = false;
// 概率相加
BigDecimal hitRatioCount = new BigDecimal(0);
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) {
if (goblinGoodsSku.getUnbox().equals("1")) {
continue;
}
// 判断开售、停售时间
LocalDateTime saleStartTime = goblinGoodsSku.getSaleStartTime();
LocalDateTime saleStopTime = goblinGoodsSku.getSaleStopTime();
......@@ -124,8 +132,15 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
if (!goblinGoodsSku.getSkuCanbuy().equals("1")) {
continue;
}
// 不能购买的 没库存的 概率是0的 过滤
if (getSkuAllStatusShow(goblinGoodsSku) && goblinRedisUtils.getSkuAllStatusStock(goblinGoodsSku) > 0 && goblinGoodsSku.getHitRatio() != null) {
if (getSkuAllStatusShow(goblinGoodsSku) && goblinRedisUtils.getSkuAllStatusStock(goblinGoodsSku) > 0) {
log.debug("skuId:"+goblinGoodsSku.getSkuId()+"----hitRatio:"+goblinGoodsSku.getHitRatio());
if (goblinGoodsSku.getHitRatio() == null) {
isHit = true;
} else {
hitRatioCount = hitRatioCount.add(goblinGoodsSku.getHitRatio());
}
countStockNumber += goblinRedisUtils.getSkuStock(goblinGoodsSku.getSkuId());
map.put(goblinGoodsSku.getSkuId(), goblinGoodsSku.getHitRatio());
checkNumberSku++;
......@@ -140,6 +155,12 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
ResponseDto.failure("配置库存大于sku总库存!");
}
if (isHit && hitRatioCount.doubleValue() < 100.00 && map.size() > 0) {
arrangeHitRatioMap(map, hitRatioCount);
}
}
......@@ -220,6 +241,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
return ResponseDto.success(true);
}
/**
* 获取每个sku的兑换码生成数量
* <p>
......@@ -284,50 +306,94 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
Map<String, Map<String, Object>> mapMap = new HashMap<>();
Map<String, Object> objectMap = new HashMap<>();
objectMap.put("hitRatio", 30);
objectMap.put("stock", 900);
objectMap.put("hitRatio", 3.33);
objectMap.put("stock", 100);
mapMap.put("1", objectMap);
Map<String, Object> objectMap1 = new HashMap<>();
objectMap1.put("hitRatio", 0.3);
objectMap1.put("stock", 9);
objectMap1.put("hitRatio", 57.7);
objectMap1.put("stock", 20);
mapMap.put("2", objectMap1);
Map<String, Object> objectMap2 = new HashMap<>();
objectMap2.put("hitRatio", 23.3);
objectMap2.put("stock", 697);
objectMap2.put("hitRatio", 9);
objectMap2.put("stock", 30);
mapMap.put("3", objectMap2);
Map<String, Object> objectMap3 = new HashMap<>();
objectMap3.put("hitRatio", 2.2);
objectMap3.put("stock", 66);
objectMap3.put("hitRatio", 1);
objectMap3.put("stock", 50);
mapMap.put("4", objectMap3);
Map<String, Object> objectMap4 = new HashMap<>();
/* Map<String, Object> objectMap4 = new HashMap<>();
objectMap4.put("hitRatio", 26.7);
objectMap4.put("stock", 797);
objectMap4.put("stock", 165);
mapMap.put("5", objectMap4);
Map<String, Object> objectMap5 = new HashMap<>();
objectMap5.put("hitRatio", 2.2);
objectMap5.put("stock", 66);
objectMap5.put("stock", 12);
mapMap.put("6", objectMap5);
Map<String, Object> objectMap6 = new HashMap<>();
objectMap6.put("hitRatio", 15.3);
objectMap6.put("stock", 458);
mapMap.put("7", objectMap6);
objectMap6.put("hitRatio", 15.6);
objectMap6.put("stock", 90);
mapMap.put("7", objectMap6);*/
Map<String, Integer> stockMap = new HashMap<>();
ArrayList<String> eliminateSkuIdList = CollectionUtil.arrayListString();
getStock(594, new BigDecimal(100), mapMap, stockMap, 2993, eliminateSkuIdList);
getStock(155, new BigDecimal(71.03), mapMap, stockMap, 179, eliminateSkuIdList);
for (String key : stockMap.keySet()) {
System.out.println("skuId" + key + "***********数量" + stockMap.get(key));
System.out.println("skuId:" + key + "***********数量:" + stockMap.get(key));
}
System.out.println("kkk");
/* Map<String, BigDecimal> hmap = new HashMap<>();
hmap.put("1", new BigDecimal(40));
hmap.put("2", new BigDecimal(49));
hmap.put("3", null);
hmap.put("4", null);
hmap.put("5", null);
arrangeHitRatioMap(hmap, new BigDecimal(89));
for (String key : hmap.keySet()) {
}*/
}
/**
* 整理map集合中存在空概率的值
*
* @param map,hitRatioCount
*/
private static void arrangeHitRatioMap(Map<String, BigDecimal> map, BigDecimal hitRatioCount) {
// 定义最大概率
BigDecimal maxHitRatio = new BigDecimal(100);
// 剩余概率
BigDecimal remainHitRatio = maxHitRatio.subtract(hitRatioCount);
// 获取值为空的数量
int number = 0;
for (String key : map.keySet()) {
if (map.get(key) == null) {
number++;
}
}
// 平均值
BigDecimal averageNumber = remainHitRatio.divide(BigDecimal.valueOf(number), 2, BigDecimal.ROUND_DOWN);
for (String key : map.keySet()) {
if (map.get(key) == null) {
map.put(key, averageNumber);
}
}
}
/**
* 获取单个sku库存
*
......@@ -351,11 +417,11 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
continue;
}
BigDecimal bigDecimal = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP)));
BigDecimal bigDecimal = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 5, BigDecimal.ROUND_HALF_UP)));
bigDecimalHashMap.put(key, bigDecimal);
// 要减去的库存
int subStock = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_UP).intValue();
int subStock = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 5, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_UP).intValue();
if (subStock > Integer.valueOf(stock.toString())) {
subNumber += Integer.valueOf(stock.toString());
......
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