|
@@ -12,6 +12,7 @@ import com.yonge.cooleshow.biz.dal.entity.SysUser;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.InOrOutEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.coupon.CouponInventoryEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.coupon.CouponUseStateEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.coupon.CouponValidTypeEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.CouponInfoMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.CouponInventoryMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.CouponIssueMapper;
|
|
@@ -25,6 +26,7 @@ import com.yonge.cooleshow.biz.dal.wrapper.coupon.CouponInventoryWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.coupon.CouponOrderWrapper;
|
|
|
import com.yonge.cooleshow.common.enums.EStatus;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
+import com.yonge.toolset.base.util.ThreadPool;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.joda.time.DateTime;
|
|
@@ -35,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -99,13 +102,39 @@ public class CouponInfoServiceImp extends ServiceImpl<CouponInfoMapper, CouponIn
|
|
|
return x.getRealName();
|
|
|
}, (o, n) -> n));
|
|
|
|
|
|
+ List<Long> updateIds = Lists.newArrayList();
|
|
|
for (CouponInfoWrapper item : wrappers) {
|
|
|
|
|
|
+ if (CouponValidTypeEnum.TIME_PERIOD == item.getValidType()
|
|
|
+ && Optional.ofNullable(item.getEndTime()).orElse(0L) > 0
|
|
|
+ && DateTime.now().getMillis() > item.getEndTime()) {
|
|
|
+
|
|
|
+ updateIds.add(item.getId());
|
|
|
+ // 更新显示状态为禁用
|
|
|
+ item.setStatus(EStatus.DISABLE.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
item.rewardNum(rewardNumMap.getOrDefault(item.getId(), 0))
|
|
|
.updatedUser(userNameMap.getOrDefault(item.getUpdatedBy(), ""))
|
|
|
.setIssueNum(issueNumMap.getOrDefault(item.getId(), 0));
|
|
|
}
|
|
|
|
|
|
+ // 增加优惠券时间过期处理流程
|
|
|
+ if (CollectionUtils.isNotEmpty(updateIds)) {
|
|
|
+
|
|
|
+ ThreadPool.getExecutor().submit(() -> {
|
|
|
+
|
|
|
+ CouponInfoWrapper wrapper = CouponInfoWrapper.builder()
|
|
|
+ .status(EStatus.DISABLE.getValue())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ getBaseMapper().update(JSON.parseObject(wrapper.jsonString(), CouponInfo.class),
|
|
|
+ Wrappers.<CouponInfo>lambdaQuery().in(CouponInfo::getId, updateIds));
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
return page.setRecords(wrappers);
|
|
|
}
|
|
|
|
|
@@ -162,6 +191,42 @@ public class CouponInfoServiceImp extends ServiceImpl<CouponInfoMapper, CouponIn
|
|
|
throw new BizException("无效的优惠券ID");
|
|
|
}
|
|
|
|
|
|
+ // 优惠券已过期
|
|
|
+ if (CouponValidTypeEnum.TIME_PERIOD == info.getValidType()
|
|
|
+ && Optional.ofNullable(info.getEndTime()).orElse(0L) > 0
|
|
|
+ && DateTime.now().getMillis() > info.getEndTime()) {
|
|
|
+
|
|
|
+ throw new BizException("已过期优惠券不允许修改");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 优惠券未过期,已发放不允许修复
|
|
|
+ List<Long> couponIds = Lists.newArrayList(couponInfo.getId());
|
|
|
+
|
|
|
+ int ret = 0;
|
|
|
+ // 查询优惠券发放人数
|
|
|
+ ret += getBaseMapper().selectCouponIssueStatInfo(couponIds,
|
|
|
+ CouponInfoQuery.IssueStatQuery.builder()
|
|
|
+ .excludeUseState(Lists.newArrayList(CouponUseStateEnum.WITHDRAW)).build()).stream()
|
|
|
+ .mapToInt(StatGroupWrapper::getTotal).sum();
|
|
|
+ if (ret > 0) {
|
|
|
+ throw new BizException("已发放优惠券不允许修改");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关联奖品数
|
|
|
+ ret += getBaseMapper().selectActivityCouponStatInfo(couponIds).stream()
|
|
|
+ .mapToInt(StatGroupWrapper::getTotal).sum();
|
|
|
+
|
|
|
+ if (ret > 0) {
|
|
|
+ throw new BizException("已关联奖品优惠券不允许修改");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 启用状态不允许修改
|
|
|
+ if (Objects.isNull(couponInfo.getStatus())
|
|
|
+ && EStatus.ENABLE.match(info.getStatus())) {
|
|
|
+
|
|
|
+ throw new BizException("已启用优惠券不允许修改");
|
|
|
+ }
|
|
|
+
|
|
|
// 更新优惠券
|
|
|
updateById(couponInfo);
|
|
|
}
|