增加抢购货品接口
This commit is contained in:
@@ -375,81 +375,50 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> rushBuy(String token, Integer maxBuyCount, List<Long> idList) {
|
||||
public Map<String, Object> rushBuy(String token, Integer maxBuyCount) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (token == null || token.isBlank()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "token不能为空");
|
||||
return result;
|
||||
}
|
||||
if (maxBuyCount == null || maxBuyCount <= 0) {
|
||||
result.put("success", false);
|
||||
result.put("message", "maxBuyCount必须大于0");
|
||||
return result;
|
||||
}
|
||||
if (idList == null || idList.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "idList不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Long> distinctIds = idList.stream()
|
||||
.filter(id -> id != null)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (distinctIds.isEmpty()) {
|
||||
LambdaQueryWrapper<LbGoods> w = new LambdaQueryWrapper<>();
|
||||
w.isNotNull(LbGoods::getSellerId);
|
||||
w.orderByDesc(LbGoods::getTotalMoney).orderByDesc(LbGoods::getId);
|
||||
List<LbGoods> goodsList = this.list(w);
|
||||
if (goodsList.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "idList无有效id");
|
||||
result.put("message", "lb_goods 中无可抢购货品");
|
||||
result.put("successCount", 0);
|
||||
result.put("failCount", 0);
|
||||
result.put("details", List.of());
|
||||
return result;
|
||||
}
|
||||
|
||||
List<LbGoods> found = this.listByIds(distinctIds);
|
||||
Map<Long, LbGoods> goodsById = new LinkedHashMap<>();
|
||||
for (LbGoods goods : found) {
|
||||
if (goods.getId() != null) {
|
||||
goodsById.put(goods.getId(), goods);
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, Object>> details = new ArrayList<>();
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
boolean stoppedByMax = false;
|
||||
|
||||
for (Long goodsId : idList) {
|
||||
if (goodsId == null) {
|
||||
continue;
|
||||
}
|
||||
for (LbGoods goods : goodsList) {
|
||||
if (successCount >= maxBuyCount) {
|
||||
stoppedByMax = true;
|
||||
break;
|
||||
}
|
||||
if (goods.getId() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<String, Object> item = new LinkedHashMap<>();
|
||||
item.put("id", goodsId);
|
||||
|
||||
LbGoods goods = goodsById.get(goodsId);
|
||||
if (goods == null) {
|
||||
item.put("success", false);
|
||||
item.put("message", "lb_goods中未找到该货品");
|
||||
details.add(item);
|
||||
failCount++;
|
||||
continue;
|
||||
}
|
||||
if (goods.getSellerId() == null) {
|
||||
item.put("success", false);
|
||||
item.put("message", "seller_id为空,无法抢购");
|
||||
details.add(item);
|
||||
failCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
item.put("id", goods.getId());
|
||||
item.put("sellerId", goods.getSellerId());
|
||||
item.put("title", goods.getTitle());
|
||||
item.put("totalMoney", goods.getTotalMoney());
|
||||
|
||||
HxrAdminBuyService.BuyApiResult buyResult =
|
||||
hxrAdminBuyService.buy(goodsId, goods.getSellerId(), token);
|
||||
hxrAdminBuyService.buy(goods.getId(), goods.getSellerId(), token);
|
||||
item.put("apiCode", buyResult.apiCode());
|
||||
item.put("message", buyResult.apiMsg());
|
||||
item.put("success", buyResult.success());
|
||||
|
||||
Reference in New Issue
Block a user