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

Commit fa4e0656 authored by 张国柄's avatar 张国柄

~API:商铺活动:优惠券+领取使用统计;

+优惠券库存为0不做库存判断逻辑;
parent f076911a
......@@ -40,7 +40,7 @@ public class GoblinStoreMgtCouponListVo implements Serializable, Cloneable {
@ApiModelProperty(position = 20, value = "已领取库存")
private Integer receiveStock;
private int receiveStock;
@ApiModelProperty(position = 21, value = "已使用库存")
private Integer usedStock;
private int usedStock;
}
......@@ -83,7 +83,7 @@ public class GoblinCouponController {
return ResponseDto.failure(ErrorMapping.get("140052"));
}
}
if (goblinRedisUtils.getStoreCouponStock(storeCouponId) > 0) {
if (storeCouponVo.getStock().equals(0) || goblinRedisUtils.getStoreCouponStock(storeCouponId) > 0) {
Boolean resultFlg = goblinCouponService.receiveCoupon(currentUid, userCouponVos, storeCouponVo);
return resultFlg ? ResponseDto.success() : ResponseDto.failure();
}
......
......@@ -72,16 +72,16 @@ public class GoblinCouponImpl implements GoblinCouponService {
@Override
public Boolean receiveCoupon(String uid, List<GoblinUserCouponVo> userCouponVoList, GoblinStoreCouponVo storeCouponVo) {
String storeCouponId = storeCouponVo.getStoreCouponId();
LocalDateTime now = LocalDateTime.now();
if (storeCouponVo.getStock().equals(0) || goblinRedisUtils.decrStoreCouponStock(storeCouponId, 1) >= 0) {
LocalDateTime now = LocalDateTime.now();
GoblinUserCouponBasicVo receiveUserCouponBasicVo = GoblinUserCouponBasicVo.getNew().initByStoreCouponVo(storeCouponVo);
receiveUserCouponBasicVo.setUid(uid);
receiveUserCouponBasicVo.setBindAt(now);
receiveUserCouponBasicVo.setOperator(uid);
receiveUserCouponBasicVo.setCreatedAt(now);
GoblinUserCouponBasicVo receiveUserCouponBasicVo = GoblinUserCouponBasicVo.getNew().initByStoreCouponVo(storeCouponVo);
receiveUserCouponBasicVo.setUid(uid);
receiveUserCouponBasicVo.setBindAt(now);
receiveUserCouponBasicVo.setOperator(uid);
receiveUserCouponBasicVo.setCreatedAt(now);
userCouponVoList.add(GoblinUserCouponVo.getNew().copy(receiveUserCouponBasicVo));
userCouponVoList.add(GoblinUserCouponVo.getNew().copy(receiveUserCouponBasicVo));
if (goblinRedisUtils.decrStoreCouponStock(storeCouponId, 1) >= 0) {
goblinMongoUtils.insertUserCouponVo(receiveUserCouponBasicVo);
goblinRedisUtils.setUserCouponVos(uid, userCouponVoList);
......@@ -95,7 +95,9 @@ public class GoblinCouponImpl implements GoblinCouponService {
SqlMapping.get("goblin_user_coupon.insert", initUserCouponObjs));
return true;
}
goblinRedisUtils.incrStoreCouponStock(storeCouponId, 1);
if (!storeCouponVo.getStock().equals(0)) {
goblinRedisUtils.incrStoreCouponStock(storeCouponId, 1);
}
return false;
}
......
......@@ -12,9 +12,7 @@ import com.liquidnet.service.goblin.dto.manage.GoblinStoreMgtCouponFilterParam;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponInfoVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtCouponSpuListVo;
import com.liquidnet.service.goblin.dto.manage.vo.GoblinStoreMgtGoodsListVo;
import com.liquidnet.service.goblin.dto.vo.GoblinGoodsInfoVo;
import com.liquidnet.service.goblin.dto.vo.GoblinSelfGoodsCategoryVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponBasicVo;
import com.liquidnet.service.goblin.dto.vo.GoblinStoreCouponVo;
import com.liquidnet.service.goblin.service.manage.IGoblinStoreMgtExtraService;
......@@ -24,15 +22,13 @@ import com.liquidnet.service.goblin.util.GoblinRedisUtils;
import com.liquidnet.service.goblin.util.ObjectUtil;
import com.liquidnet.service.goblin.util.QueueUtils;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
......@@ -52,7 +48,31 @@ public class GoblinStoreMgtCouponServiceImpl implements IGoblinstoreMgtCouponSer
PagedResult<GoblinStoreMgtCouponListVo> mgtCouponListVoPagedResult = goblinMongoUtils.getMgtStoreCouponListVos(filterParam);
if (mgtCouponListVoPagedResult.getTotal() > 0) {
List<GoblinStoreMgtCouponListVo> volist = mgtCouponListVoPagedResult.getList();
List<String> storeCouponIdList = volist.stream().map(GoblinStoreMgtCouponListVo::getStoreCouponId).collect(Collectors.toList());
List<Document> aggregateUserCouponResults = goblinMongoUtils.aggregateMgtUserCoupon(storeCouponIdList);
if (!CollectionUtils.isEmpty(aggregateUserCouponResults)) {
volist.forEach(vo -> {
List<Document> aggregateUserCouponResult = aggregateUserCouponResults.stream()
.filter(r -> r.getString("storeCouponId").equals(vo.getStoreCouponId())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(aggregateUserCouponResult)) {
int receiveStock = 0, usedStock = 0;
for (Document aggregateDoc : aggregateUserCouponResult) {
Integer totalCount = aggregateDoc.getInteger("totalCount");
switch (aggregateDoc.getInteger("state")) {// 用户券状态[1-可用|2-无效|3-已过期|5-已使用]
case 5:
usedStock += totalCount;
default:
receiveStock += totalCount;
}
}
vo.setReceiveStock(receiveStock);
vo.setUsedStock(usedStock);
}
});
} else {
}
}
return mgtCouponListVoPagedResult;
}
......@@ -122,7 +142,10 @@ public class GoblinStoreMgtCouponServiceImpl implements IGoblinstoreMgtCouponSer
storeCouponBasicVo.setCreatedBy(uid);
goblinMongoUtils.setMgtStoreCouponBasicVo(storeCouponBasicVo);
Integer stock = storeCouponBasicVo.getStock();
if (!stock.equals(0)) {
goblinRedisUtils.setStoreCouponStock(storeCouponId, stock);
}
LinkedList<String> toMqSqls = CollectionUtil.linkedListString();
toMqSqls.add(SqlMapping.get("goblin_store_coupon.insert"));
......@@ -130,7 +153,7 @@ public class GoblinStoreMgtCouponServiceImpl implements IGoblinstoreMgtCouponSer
initStoreCouponObjs.add(new Object[]{
storeCouponId, storeCouponBasicVo.getStoreCouponNo(), storeCouponBasicVo.getStoreId(),
storeCouponBasicVo.getTitle(), storeCouponBasicVo.getLabel(), storeCouponBasicVo.getNotice(),
storeCouponBasicVo.getType(), storeCouponBasicVo.getStock(), storeCouponBasicVo.getTriggers(),
storeCouponBasicVo.getType(), stock, storeCouponBasicVo.getTriggers(),
storeCouponBasicVo.getValFace(), storeCouponBasicVo.getDiscount(), storeCouponBasicVo.getValOver(),
storeCouponBasicVo.getValMinus(), storeCouponBasicVo.getDeduction(), storeCouponBasicVo.getReceiveLimit(),
storeCouponBasicVo.getReceiveCurb(), storeCouponBasicVo.getUseScope(), storeCouponBasicVo.getState(),
......@@ -210,7 +233,8 @@ public class GoblinStoreMgtCouponServiceImpl implements IGoblinstoreMgtCouponSer
@Override
public boolean couponEditStock(GoblinStoreCouponVo storeCouponVo, String uid, int operStock) {
String storeCouponId = storeCouponVo.getStoreCouponId();
int stock = storeCouponVo.getStock(), surplusStock, operStockVal = Math.abs(operStock);
Integer stock = storeCouponVo.getStock();
int surplusStock, operStockVal = Math.abs(operStock);
if (operStock < 0) {
surplusStock = goblinRedisUtils.decrStoreCouponStock(storeCouponId, operStockVal);
if (surplusStock < 0) {
......@@ -227,6 +251,9 @@ public class GoblinStoreMgtCouponServiceImpl implements IGoblinstoreMgtCouponSer
LocalDateTime now = LocalDateTime.now();
goblinMongoUtils.updateMgtStoreCouponStock(storeCouponId, stock, uid, now);
if (stock.equals(0)) {
goblinRedisUtils.delStoreCouponStock(storeCouponId);
}
goblinRedisUtils.del(GoblinRedisConst.STORE_COUPON.concat(storeCouponId));// 删除REDIS缓存
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
......
......@@ -1096,6 +1096,16 @@ public class GoblinMongoUtils {
return pagedResult.setList(mgtCouponListVos).setTotal(count, filterParam.getPageSize());
}
public List<Document> aggregateMgtUserCoupon(List<String> storeCouponIds) {
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.project("storeCouponId", "state", "receiveStock"),
Aggregation.match(Criteria.where("storeCouponId").in(storeCouponIds).and("state").ne(2)),
Aggregation.group("storeCouponId", "state").count().as("totalCount")
);
AggregationResults<Document> aggregationResults = mongoTemplate.aggregate(aggregation, GoblinUserCouponBasicVo.class.getSimpleName(), Document.class);
return aggregationResults.getMappedResults();
}
//根据艺人标签和演出查询商品
public List<GoblinGoodsInfoVo> getMusicTagPGoods(String musicTag, String performanceId) {
return mongoTemplate.find(
......
......@@ -986,6 +986,10 @@ public class GoblinRedisUtils {
return redisUtil.set(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId), stock);
}
public void delStoreCouponStock(String storeCouponId) {
redisUtil.del(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId));
}
public int getStoreCouponStock(String storeCouponId) {
Object valObj = redisUtil.get(GoblinRedisConst.STORE_COUPON_STOCK.concat(storeCouponId));
return null == valObj ? 0 : (int) valObj;
......
......@@ -29,6 +29,9 @@ public class GoblinRedisUtils {
public void del(String... keys) {
getRedis().del(keys);
}
public boolean set(String key, Object val) {
return getRedis().set(key, val);
}
// 获取 订单相关vo
public GoblinStoreOrderVo getGoblinOrder(String orderId) {
......@@ -139,8 +142,14 @@ public class GoblinRedisUtils {
public boolean addStoreMarketDto(String storeId, GoblinStoreMarketDto dto) {
List<GoblinStoreMarketDto> dtos = this.getStoreMarketDtos(storeId);
dtos.removeIf(r -> r.getType().equals(dto.getType()) && r.getId().equals(dto.getId()));
dtos.add(dto);
return getRedis().set(GoblinRedisConst.STORE_MARKETS.concat(storeId), JsonUtils.toJson(dtos));
// if (dtos.stream().noneMatch(r -> (r.getType().equals(dto.getType()) && r.getId().equals(dto.getId())))) {
// dtos.add(dto);
// return getRedis().set(GoblinRedisConst.STORE_MARKETS.concat(storeId), JsonUtils.toJson(dtos));
// }
// return false;
}
public void delStoreMarketDto(String storeId, GoblinStoreMarketDto dto) {
......
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