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

Commit 4395a16b authored by wanglele's avatar wanglele

时间判断修改

parent 7e15cb7c
...@@ -99,15 +99,22 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -99,15 +99,22 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
if (bol) { if (bol) {
// 获取spu下所有sku // 获取spu下所有sku
List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectBySpuIds(spuIds.toString()); List<GoblinGoodsSku> goblinGoodsSkus = goblinGoodsSkuMapper.selectBySpuIds(spuIds.toString());
int countStockNumber = 0;
for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) { for (GoblinGoodsSku goblinGoodsSku : goblinGoodsSkus) {
if (goblinGoodsSku.getUnbox().equals("1")) { if (goblinGoodsSku.getUnbox().equals("1")) {
continue; continue;
} }
// 不能购买的 没库存的 概率是0的 过滤 // 不能购买的 没库存的 概率是0的 过滤
if (getSkuAllStatusShow(goblinGoodsSku) && goblinRedisUtils.getSkuAllStatusStock(goblinGoodsSku) > 0 && goblinGoodsSku.getHitRatio() != null) { if (getSkuAllStatusShow(goblinGoodsSku) && goblinRedisUtils.getSkuAllStatusStock(goblinGoodsSku) > 0 && goblinGoodsSku.getHitRatio() != null) {
countStockNumber += goblinRedisUtils.getSkuStock(goblinGoodsSku.getSkuId());
map.put(goblinGoodsSku.getSkuId(), goblinGoodsSku.getHitRatio()); map.put(goblinGoodsSku.getSkuId(), goblinGoodsSku.getHitRatio());
} }
} }
if (countStockNumber < stockNumber) {
ResponseDto.failure("配置库存大于sku总库存!");
}
} }
...@@ -367,7 +374,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -367,7 +374,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
// sku --> 概率/库存 // sku --> 概率/库存
Map<String, Map<String, Object>> mapMap = new HashMap<>(); Map<String, Map<String, Object>> mapMap = new HashMap<>();
int j = 0; int countNumber = 0;
for (String key : map.keySet()) { for (String key : map.keySet()) {
BigDecimal skuHitRatio = map.get(key); BigDecimal skuHitRatio = map.get(key);
Map<String, Object> objectMap = new HashMap<>(); Map<String, Object> objectMap = new HashMap<>();
...@@ -378,15 +385,36 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -378,15 +385,36 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
objectMap.put("hitRatio", skuHitRatio); objectMap.put("hitRatio", skuHitRatio);
objectMap.put("stock", goblinRedisUtils.getSkuStock(key)); objectMap.put("stock", goblinRedisUtils.getSkuStock(key));
mapMap.put(key, objectMap); mapMap.put(key, objectMap);
j += 100;
} }
// sku ---> 库存 // sku ---> 库存
Map<String, Integer> stockMap = new HashMap<>(); Map<String, Integer> stockMap = new HashMap<>();
getStock(exStock, hitRatioCount, mapMap, stockMap); getStock(exStock, hitRatioCount, mapMap, stockMap);
return stockMap; return stockMap;
} }
public static void main(String[] args) {
Map<String, Map<String, Object>> mapMap = new HashMap<>();
Map<String, Object> objectMap = new HashMap<>();
objectMap.put("hitRatio", 10);
objectMap.put("stock", 5);
mapMap.put("1", objectMap);
Map<String, Object> objectMap1 = new HashMap<>();
objectMap1.put("hitRatio", 20);
objectMap1.put("stock", 100);
mapMap.put("2", objectMap1);
Map<String, Object> objectMap2 = new HashMap<>();
objectMap2.put("hitRatio", 30);
objectMap2.put("stock", 100);
mapMap.put("3", objectMap2);
Map<String, Integer> stockMap = new HashMap<>();
getStock(10, new BigDecimal(60), mapMap, stockMap);
System.out.println("kkk");
}
/** /**
* 获取单个sku库存 * 获取单个sku库存
* *
...@@ -395,17 +423,26 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -395,17 +423,26 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
* @param mapMap * @param mapMap
* @return * @return
*/ */
private void getStock(Integer exStock, BigDecimal hitRatioCount, Map<String, Map<String, Object>> mapMap, Map<String, Integer> stockMap) { private static void getStock(Integer exStock, BigDecimal hitRatioCount, Map<String, Map<String, Object>> mapMap, Map<String, Integer> stockMap) {
if (exStock < 0) { if (exStock <= 0) {
return; return;
} }
int subNumber = 0;
for (String key : mapMap.keySet()) { for (String key : mapMap.keySet()) {
Object stock = mapMap.get(key).get("stock"); Object stock = mapMap.get(key).get("stock");
Object hitRatio = mapMap.get(key).get("hitRatio"); Object hitRatio = mapMap.get(key).get("hitRatio");
if (Integer.valueOf(stock.toString()) < 0) {
continue;
}
BigDecimal bigDecimal = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_HALF_UP);
// 要减去的库存 // 要减去的库存
int subStock = BigDecimal.valueOf(exStock).multiply((new BigDecimal(hitRatio.toString()).divide(hitRatioCount, 2, BigDecimal.ROUND_HALF_UP))).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); 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())) { if (subStock > Integer.valueOf(stock.toString())) {
exStock = exStock - Integer.valueOf(stock.toString()); subNumber += Integer.valueOf(stock.toString());
mapMap.get(key).put("stock", 0); mapMap.get(key).put("stock", 0);
if (stockMap.get(key) == null) { if (stockMap.get(key) == null) {
stockMap.put(key, Integer.valueOf(stock.toString())); stockMap.put(key, Integer.valueOf(stock.toString()));
...@@ -414,7 +451,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -414,7 +451,7 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
} }
} else { } else {
exStock = exStock - subStock; subNumber += subStock;
if (stockMap.get(key) == null) { if (stockMap.get(key) == null) {
stockMap.put(key, subStock); stockMap.put(key, subStock);
} else { } else {
...@@ -422,14 +459,15 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService { ...@@ -422,14 +459,15 @@ public class GoblinNftExSkuServiceImpl implements IGoblinNftExSkuService {
} }
} }
} }
exStock -= subNumber;
if (exStock > 0) { if (exStock > 0) {
for (String key : mapMap.keySet()) { for (String key : mapMap.keySet()) {
Object hitRatio = mapMap.get(key).get("hitRatio"); Object hitRatio = mapMap.get(key).get("hitRatio");
Object stock = mapMap.get(key).get("stock"); Object stock = mapMap.get(key).get("stock");
if (Integer.valueOf(stock.toString()) < 0) { if (Integer.valueOf(stock.toString()) <= 0) {
hitRatioCount = hitRatioCount.subtract(new BigDecimal(hitRatio.toString()));
} }
hitRatioCount.subtract(new BigDecimal(hitRatio.toString()));
} }
getStock(exStock, hitRatioCount, mapMap, stockMap); getStock(exStock, hitRatioCount, mapMap, stockMap);
} }
......
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