Commit 40ba1ab7 by 吕明尚

增加重新验卷的自动任务

parent 6a4878f3
......@@ -5,6 +5,8 @@ public enum ConsumerCouponStatusEnum {
WECHAT("2", "微信回调"),
SERVICE("3", "SERVICE回调"),
ORDER("4", "订单下单"),
//任务
TASK("5", "任务"),
;
ConsumerCouponStatusEnum() {
......
......@@ -39,6 +39,8 @@ public class QPServiceImplAspect {
@Autowired
private ISStoreService sStoreService;
private static final Integer TRY_NUMBER = 3;
/**
* 切点函数,用于标识需要记录操作日志的方法。
......@@ -127,7 +129,7 @@ public class QPServiceImplAspect {
JSONObject jsonObject = JSON.parseObject(params);
saveLog(couponLog, jsonObject);
couponLog.setStatus(YesNoEnum.no.getDisplay_3());
couponLog.setNumber(3);
couponLog.setNumber(TRY_NUMBER);
couponLog.setCreateTime(new Date());
couponLog.setMessage(stackTraceToString(e.getClass().getName(), e.getMessage(), e.getStackTrace()));
} catch (Exception e2) {
......
package share.quartz.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import share.common.enums.ConsumerCouponStatusEnum;
import share.common.enums.UserStatusEnum;
import share.common.enums.YesNoEnum;
import share.system.domain.CouponLog;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SStore;
import share.system.service.CouponLogService;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISStoreService;
import share.system.service.QPService;
import share.system.service.impl.QPServiceImpl;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component("couponRetryTask")
......@@ -22,27 +30,49 @@ public class CouponRetryTask {
private QPService qpService;
@Autowired
private ISStoreService sStoreService;
@Autowired
private ISConsumerCouponService sConsumerCouponService;
private static final Logger logger = LoggerFactory.getLogger(QPServiceImpl.class);
private static final Integer TRY_NUMBER = 3;
public void AuToRetryCoupon() {
//查询异常的优惠券日志
LambdaQueryWrapper<CouponLog> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CouponLog::getStatus, YesNoEnum.no.getDisplay_3());
//去重
queryWrapper.groupBy(CouponLog::getCode);
queryWrapper.eq(CouponLog::getNumber, TRY_NUMBER);
List<CouponLog> list = couponLogService.list(queryWrapper);
//根据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);
list.stream().forEach(couponLog -> {
//遍历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() > 0) {
for (int i = 0; i < 3; i++) {
qpService.consume(couponLog.getCode(), 1, sStore.getOpenShopUuid(), ConsumerCouponStatusEnum.WECHAT.getCode());
couponLog.setNumber(couponLog.getNumber() - 1);
couponLogService.updateById(couponLog);
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);
}
});
}
}
......@@ -81,6 +81,10 @@ public class QPServiceImpl implements QPService {
//默认门槛金额
private static final BigDecimal DEFAULT_MIN_PRICE = BigDecimal.valueOf(0.00);
private static final String ACCOUNT = "13888888888";
private static final String NAME = "管理人员";
/**
* 用户验卷接口
*/
......@@ -253,12 +257,19 @@ public class QPServiceImpl implements QPService {
String session = (String) sessionKey.get("access_token");
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
String requestid = UUID.randomUUID().toString();
TuangouReceiptConsumeRequest request = new TuangouReceiptConsumeRequest(APP_KEY, APP_SECRET, session,
requestid, code, count, "", user.getAccount(), user.getNickName(), openShopUuid);
TuangouReceiptConsumeRequest request = null;
if (ObjectUtils.isEmpty(user)) {
request = new TuangouReceiptConsumeRequest(APP_KEY, APP_SECRET, session,
requestid, code, count, "", ACCOUNT, NAME, openShopUuid);
} else {
request = new TuangouReceiptConsumeRequest(APP_KEY, APP_SECRET, session,
requestid, code, count, "", user.getAccount(), user.getNickName(), openShopUuid);
}
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptConsume tuangouReceiptConsume = new TuangouReceiptConsume(request);
TuangouReceiptConsumeResponse invoke = openAPIClient.invoke(tuangouReceiptConsume);
if (invoke.getCode() != 200) {
redisUtil.delete(ReceiptRdeisEnum.PREPARE.getValue() + code);
logger.error("验卷失败:{}", invoke.getMsg());
throw new RuntimeException(invoke.getMsg());
}
......
......@@ -101,7 +101,7 @@
<if test="startDate != null "> and start_date = #{startDate}</if>
<if test="endDate != null "> and end_date = #{endDate}</if>
<if test="useDate != null "> and use_date = #{useDate}</if>
<if test="useStatus != null and useStatus != ''"> and use_status = #{useStatus}</if>
<if test="useStatus != null and useStatus != '' or useStatus==0">and use_status = #{useStatus}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
<if test="deleteBy != null and deleteBy != ''"> and delete_by = #{deleteBy}</if>
<if test="deleteTime != null "> and delete_time = #{deleteTime}</if>
......
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