Commit de22fd43 by hayden

Merge branch 'dev_lch' into dev

parents ef7991f7 5405ee1d
package share.quartz.task; package share.quartz.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import share.common.enums.ConsumerCouponStatusEnum;
import share.common.enums.UserStatusEnum; import share.common.enums.UserStatusEnum;
import share.common.enums.YesNoEnum;
import share.system.domain.CouponLog;
import share.system.domain.SConsumerCoupon; import share.system.domain.SConsumerCoupon;
import share.system.domain.SStore;
import share.system.service.CouponLogService;
import share.system.service.ISConsumerCouponService; import share.system.service.ISConsumerCouponService;
import share.system.service.ISStoreService;
import share.system.service.QPService;
import share.system.service.impl.QPServiceImpl; import share.system.service.impl.QPServiceImpl;
import java.util.*; import java.util.*;
...@@ -25,17 +17,9 @@ import java.util.stream.Collectors; ...@@ -25,17 +17,9 @@ import java.util.stream.Collectors;
@Component("couponRetryTask") @Component("couponRetryTask")
public class CouponRetryTask { public class CouponRetryTask {
@Autowired @Autowired
private CouponLogService couponLogService;
@Autowired
private QPService qpService;
@Autowired
private ISStoreService sStoreService;
@Autowired
private ISConsumerCouponService sConsumerCouponService; private ISConsumerCouponService sConsumerCouponService;
private static final Logger logger = LoggerFactory.getLogger(QPServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(QPServiceImpl.class);
private static final Integer TRY_NUMBER = 3;
public void AuToRetryCoupon() { public void AuToRetryCoupon() {
LambdaQueryWrapper<SConsumerCoupon> consumerCouponWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SConsumerCoupon> consumerCouponWrapper = new LambdaQueryWrapper<>();
consumerCouponWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode()); consumerCouponWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode());
...@@ -50,46 +34,5 @@ public class CouponRetryTask { ...@@ -50,46 +34,5 @@ public class CouponRetryTask {
if (!CollectionUtils.isEmpty(expiredSConsumerCounpons)) { if (!CollectionUtils.isEmpty(expiredSConsumerCounpons)) {
sConsumerCouponService.updateBatchById(expiredSConsumerCounpons); sConsumerCouponService.updateBatchById(expiredSConsumerCounpons);
} }
LambdaQueryWrapper<CouponLog> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CouponLog::getStatus, YesNoEnum.no.getDisplay_3());
queryWrapper.eq(CouponLog::getNumber, TRY_NUMBER);
List<CouponLog> list = couponLogService.list(queryWrapper);
if (CollectionUtils.isEmpty(list)) {
return;
}
//根据code分组
Map<String, List<CouponLog>> collect = list.stream().collect(Collectors.groupingBy(CouponLog::getCode));
//门店id集合
List<Long> storeIds = list.stream().map(CouponLog::getStoreId).distinct().collect(Collectors.toList());
List<SStore> sStoreList = sStoreService.listByIds(storeIds);
//遍历Map
collect.forEach((k, v) -> {
CouponLog couponLog = v.get(0);
SStore sStore = sStoreList.stream().filter(s -> s.getId().equals(couponLog.getStoreId())).findFirst().get();
if (couponLog.getNumber().equals(TRY_NUMBER)) {
for (int i = 0; i < TRY_NUMBER; i++) {
try {
qpService.consume(couponLog.getCode(), 1, sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.TASK.getCode());
} catch (Exception e) {
logger.error("验卷失败:{}", e.getMessage());
} finally {
couponLog.setNumber(couponLog.getNumber() - 1);
couponLogService.updateById(couponLog);
}
}
//根据code批量更新状态
LambdaUpdateWrapper<CouponLog> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(CouponLog::getCode, k);
//设置number为0
updateWrapper.set(CouponLog::getNumber, 0);
couponLogService.update(updateWrapper);
//更新优惠卷领取状态
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
sConsumerCoupon.setId(couponLog.getCouponId());
sConsumerCoupon.setUseStatus(UserStatusEnum.EXPIRED.getCode());
sConsumerCouponService.updateById(sConsumerCoupon);
}
});
} }
} }
...@@ -7,11 +7,18 @@ import cn.hutool.json.JSONException; ...@@ -7,11 +7,18 @@ import cn.hutool.json.JSONException;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse; import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse;
import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptPrepare;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptGetConsumedReponseEntity;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptPrepareRequest;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptPrepareResponse;
import com.dianping.openapi.sdk.httpclient.DefaultOpenAPIClient;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -85,45 +92,31 @@ public class RedisTask { ...@@ -85,45 +92,31 @@ public class RedisTask {
final long THREE_MINUTES = 60 * 3; final long THREE_MINUTES = 60 * 3;
public void AuToReceiptCode() { /**
//获取redis中所有以tuangou.receipt.prepare开头的key * 自动删除所有可用但已退款的优惠券
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.PREPARE.getValue() + "*"); */
if (keys.size() == 0) { public void AutoDelRefundedCoupon() {
return;
}
//获取所有待使用的优惠卷 //获取所有待使用的优惠卷
LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SConsumerCoupon> wrapper = Wrappers.lambdaQuery();
queryWrapper.eq(SConsumerCoupon::getUseStatus, CouponStatusEnum.NORMAL.getValue()); wrapper.eq(SConsumerCoupon::getUseStatus, CouponStatusEnum.NORMAL.getValue());
List<SConsumerCoupon> list = isConsumerCouponService.list(queryWrapper); wrapper.isNotNull(SConsumerCoupon::getCouponCode);
//遍历key List<SConsumerCoupon> coupons = isConsumerCouponService.list(wrapper);
keys.stream().forEach(o -> { List<SStore> stores = storeService.list();
//获取key对应的value
String value = redisUtil.get(String.valueOf(o)); List<Long> expiredCoupons = new ArrayList<>();
JSONObject jsonObject = new JSONObject(value); if (!CollectionUtils.isEmpty(coupons)) {
Date expirationTime = jsonObject.getDate("expirationTime"); for (SConsumerCoupon coupon : coupons) {
//判断是否过期 //验券
if (expirationTime.getTime() < new Date().getTime()) { TuangouReceiptGetConsumedReponseEntity getconsumed = qpService.getconsumed(coupon.getCouponCode(),
//获取redis中的券码id stores.stream().filter(store -> store.getId().equals(coupon.getStoreId())).findFirst().get().getOpenShopUuid());
Long consumerCouponId = jsonObject.getLong("consumerCouponId"); if (getconsumed == null) {
if (CollectionUtils.isEmpty(list)) { expiredCoupons.add(coupon.getId());
//删除redis中的值
redisUtil.delete(o);
//删除数据库中的值
isConsumerCouponService.deleteSConsumerCouponById(consumerCouponId);
//跳过循环
return;
} }
if (ObjectUtil.isEmpty(list.stream().filter(item -> item.getId().equals(consumerCouponId)).findFirst().orElse(null))) { logger.info("券码:{}->查询结束:{}", coupon.getCouponCode(), getconsumed);
//删除redis中的值
redisUtil.delete(o);
//删除数据库中的值
isConsumerCouponService.deleteSConsumerCouponById(consumerCouponId);
} else {
//删除redis中的值
redisUtil.delete(o);
} }
//逻辑删除所有异常优惠券
isConsumerCouponService.removeByIds(expiredCoupons);
} }
});
} }
public void processAutoReceiptCode() { public void processAutoReceiptCode() {
......
package share.system.service.impl; package share.system.service.impl;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dianping.openapi.sdk.api.customerauth.session.CustomerKeyShopScopeQuery; import com.dianping.openapi.sdk.api.customerauth.session.CustomerKeyShopScopeQuery;
...@@ -90,35 +92,24 @@ public class QPServiceImpl implements QPService { ...@@ -90,35 +92,24 @@ public class QPServiceImpl implements QPService {
*/ */
@Override @Override
public TuangouReceiptPrepareResponseEntityVo consumeByUser(String code, String openShopUuid, String status) { public TuangouReceiptPrepareResponseEntityVo consumeByUser(String code, String openShopUuid, String status) {
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
sStoreLambdaQueryWrapper.eq(SStore::getOpenShopUuid, openShopUuid);
SStore sStore = storeService.getOne(sStoreLambdaQueryWrapper);
if (ObjectUtils.isEmpty(sStore) || StoreStatusEnum.STOP.getIndex().equals(sStore.getStatus())) {
throw new RuntimeException("门店状态异常,请联系管理员");
}
//验券准备 //验券准备
TuangouReceiptPrepareResponseEntity prepare = prepare(code.trim(), openShopUuid, status); TuangouReceiptPrepareResponseEntity prepare = prepare(code.trim(), openShopUuid, status);
//获取用户信息 //获取用户信息
SConsumer user = FrontTokenComponent.getWxSConsumerEntry(); SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
//查询领取记录表 //查询领取记录表
LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SConsumerCoupon::getDealId, prepare.getDeal_id());
queryWrapper.eq(SConsumerCoupon::getCouponCode, code); queryWrapper.eq(SConsumerCoupon::getCouponCode, code);
queryWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode()); queryWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode());
SConsumerCoupon couponTwo = isConsumerCouponService.getOne(queryWrapper); SConsumerCoupon unUsedCoupon = isConsumerCouponService.getOne(queryWrapper);
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>(); if (ObjectUtils.isNotEmpty(unUsedCoupon)) {
sStoreLambdaQueryWrapper.eq(SStore::getOpenShopUuid, openShopUuid); throw new RuntimeException("该券已被领取");
SStore sStore = storeService.getOne(sStoreLambdaQueryWrapper);
if (ObjectUtils.isEmpty(sStore)) {
throw new RuntimeException("门店不存在");
}
if (sStore.getStatus().equals(StoreStatusEnum.STOP.getIndex())) {
throw new RuntimeException("门店已停止");
}
if (ObjectUtils.isNotEmpty(couponTwo)) {
//判断是否本人领取过
if (couponTwo.getConsumerId().equals(user.getId())) {
//领取删除原来的
isConsumerCouponService.deleteSConsumerCouponById(couponTwo.getId());
//删除redis
redisUtil.delete(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code());
} else {
return null;
}
} }
//根据优惠卷名称查询优惠劵配置 查询list,取第一个 //根据优惠卷名称查询优惠劵配置 查询list,取第一个
TuangouReceiptPrepareResponseEntityVo response = new TuangouReceiptPrepareResponseEntityVo(); TuangouReceiptPrepareResponseEntityVo response = new TuangouReceiptPrepareResponseEntityVo();
...@@ -134,20 +125,15 @@ public class QPServiceImpl implements QPService { ...@@ -134,20 +125,15 @@ public class QPServiceImpl implements QPService {
sConsumerCoupon.setCreateBy(String.valueOf(user.getId())); sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setCreateTime(new Date()); sConsumerCoupon.setCreateTime(new Date());
sConsumerCoupon.setSubPrice(BigDecimal.valueOf(prepare.getDeal_marketprice())); sConsumerCoupon.setSubPrice(BigDecimal.valueOf(prepare.getDeal_marketprice()));
//根据门店id查询门店信息 //查询美团团购信息
List<TuangouDealQueryShopDealResponseEntity> queryshopdeal = queryshopdeal(openShopUuid); List<TuangouDealQueryShopDealResponseEntity> groupActivities = queryshopdeal(openShopUuid);
queryshopdeal.stream().forEach(o -> { groupActivities.forEach(o -> {
//套餐名称相同并且在售卖中 //套餐名称相同并且在售卖中
if (prepare.getDeal_title().equals(o.getTitle()) && o.getSale_status().equals(saleStatusEnum.SELLING.getCode())) { if (prepare.getDeal_title().equals(o.getTitle()) && saleStatusEnum.SELLING.getCode().equals(o.getSale_status())) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date receiptEndDate = DateUtil.parse(o.getReceipt_end_date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN);
try { Date receiptBeginDate = DateUtil.parse(o.getReceipt_begin_date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN);
Date receiptEndDate = sdf.parse(o.getReceipt_end_date());
Date receiptBeginDate = sdf.parse(o.getReceipt_begin_date());
sConsumerCoupon.setStartDate(receiptBeginDate); sConsumerCoupon.setStartDate(receiptBeginDate);
sConsumerCoupon.setEndDate(receiptEndDate); sConsumerCoupon.setEndDate(receiptEndDate);
} catch (Exception e) {
e.printStackTrace();
}
} }
}); });
...@@ -187,19 +173,12 @@ public class QPServiceImpl implements QPService { ...@@ -187,19 +173,12 @@ public class QPServiceImpl implements QPService {
} }
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon); isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon);
response.setConsumerCouponId(sConsumerCoupon.getId()); response.setConsumerCouponId(sConsumerCoupon.getId());
//设置过期时间30分钟 String output1 = DateUtil.format(prepare.getReceiptEndDate(), DatePattern.NORM_DATETIME_PATTERN);
Map<String, String> map = new HashMap<>();
map.put("receipt_code", prepare.getReceipt_code());
map.put("consumerCouponId", String.valueOf(response.getConsumerCouponId()));
//设置30分钟后的时间
Date date = DateUtils.addMinutes(new Date(), 30);
map.put("expirationTime", String.valueOf(date));
JSONObject jsonObject = new JSONObject(map);
redisUtil.set(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code(), jsonObject.toString());
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String output1 = format2.format(prepare.getReceiptEndDate());
BeanUtils.copyProperties(prepare, response); BeanUtils.copyProperties(prepare, response);
response.setExpirationTime(output1); response.setExpirationTime(output1);
//核销美团券
consume(code.trim(), 1, openShopUuid, ConsumerCouponStatusEnum.ORDER.getCode());
return response; return response;
} }
......
...@@ -14,6 +14,11 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional; ...@@ -14,6 +14,11 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dianping.openapi.sdk.api.tuangou.TuangouReceiptGetConsumed;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptGetConsumedReponse;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptGetConsumedReponseEntity;
import com.dianping.openapi.sdk.api.tuangou.entity.TuangouReceiptGetConsumedRequest;
import com.dianping.openapi.sdk.httpclient.DefaultOpenAPIClient;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -323,7 +328,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -323,7 +328,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (Objects.nonNull(byId)) { if (Objects.nonNull(byId)) {
if (byId.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) { if (byId.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) {
if (StringUtils.isNotEmpty(byId.getCouponCode())) { if (StringUtils.isNotEmpty(byId.getCouponCode())) {
qpService.prepare(byId.getCouponCode(), sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.ORDER.getCode()); TuangouReceiptGetConsumedReponseEntity getconsumed = qpService.getconsumed(byId.getCouponCode(), sStore.getOpenShopUuid());
if (getconsumed == null) {
throw new RuntimeException("优惠券异常,请稍后再试");
}
} }
} else { } else {
throw new BaseException("优惠券已使用!"); throw new BaseException("优惠券已使用!");
...@@ -349,10 +357,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -349,10 +357,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
save(sOrder); save(sOrder);
if (response.getStatus().equals(YesNoEnum.yes.getFlag())) { if (response.getStatus().equals(YesNoEnum.yes.getFlag())) {
if (Objects.nonNull(byId)) { if (Objects.nonNull(byId)) {
if (StringUtils.isNotEmpty(byId.getCouponCode())) {
//验劵
qpService.consume(byId.getCouponCode(), 1, sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.ORDER.getCode());
}
SConsumerCoupon consumerCoupon = new SConsumerCoupon(); SConsumerCoupon consumerCoupon = new SConsumerCoupon();
consumerCoupon.setId(request.getCouponId()); consumerCoupon.setId(request.getCouponId());
consumerCoupon.setUseDate(new Date()); consumerCoupon.setUseDate(new Date());
...@@ -795,10 +799,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -795,10 +799,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
SConsumerCoupon consumerCoupon = consumerCouponService.getById(couponId); SConsumerCoupon consumerCoupon = consumerCouponService.getById(couponId);
if (ObjectUtil.isNotEmpty(consumerCoupon)) { if (ObjectUtil.isNotEmpty(consumerCoupon)) {
if (consumerCoupon.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) { if (consumerCoupon.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) {
if (StringUtils.isNotEmpty(consumerCoupon.getCouponCode())) {
//验劵
qpService.consume(consumerCoupon.getCouponCode(), 1, sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.WECHAT.getCode());
}
consumerCoupon.setUseDate(new Date()); consumerCoupon.setUseDate(new Date());
consumerCoupon.setUseStatus(UserStatusEnum.USED.getCode()); consumerCoupon.setUseStatus(UserStatusEnum.USED.getCode());
consumerCouponService.updateById(consumerCoupon); consumerCouponService.updateById(consumerCoupon);
......
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