Commit 5405ee1d by hayden

更换定时任务调用api

更换创建订单调用美团api
parent 36fc5af2
......@@ -10,6 +10,7 @@ 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.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;
......@@ -89,13 +90,12 @@ public class RedisTask {
final long FOUR_MINUTES = 60 * 4;
//3分钟的常量
final long THREE_MINUTES = 60 * 3;
@Value("${dianping.appKey}")
private String APP_KEY;
@Value("${dianping.appSecret}")
private String APP_SECRET;
public void AuToReceiptCode() {
/**
* 自动删除所有可用但已退款的优惠券
*/
public void AutoDelRefundedCoupon() {
//获取所有待使用的优惠卷
LambdaQueryWrapper<SConsumerCoupon> wrapper = Wrappers.lambdaQuery();
wrapper.eq(SConsumerCoupon::getUseStatus, CouponStatusEnum.NORMAL.getValue());
......@@ -107,18 +107,12 @@ public class RedisTask {
if (!CollectionUtils.isEmpty(coupons)) {
for (SConsumerCoupon coupon : coupons) {
//验券
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
String session = (String) sessionKey.get("access_token");
TuangouReceiptPrepareRequest request = new TuangouReceiptPrepareRequest(APP_KEY, APP_SECRET, session, coupon.getCouponCode(), "",
TuangouReceiptGetConsumedReponseEntity getconsumed = qpService.getconsumed(coupon.getCouponCode(),
stores.stream().filter(store -> store.getId().equals(coupon.getStoreId())).findFirst().get().getOpenShopUuid());
TuangouReceiptPrepare tuangouReceiptPrepare = new TuangouReceiptPrepare(request);
DefaultOpenAPIClient client = new DefaultOpenAPIClient();
TuangouReceiptPrepareResponse invoke = client.invoke(tuangouReceiptPrepare);
if (invoke.getCode() != 200) {
if (getconsumed == null) {
expiredCoupons.add(coupon.getId());
}
logger.info("券码:{}->查询结束:{}", coupon.getCouponCode(), invoke.getData());
logger.info("券码:{}->查询结束:{}", coupon.getCouponCode(), getconsumed);
}
//逻辑删除所有异常优惠券
isConsumerCouponService.removeByIds(expiredCoupons);
......
......@@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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;
......@@ -54,10 +55,6 @@ import share.system.service.*;
public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> implements ISOrderService {
private static final Logger logger = LoggerFactory.getLogger(SOrderServiceImpl.class);
@Value("${dianping.appKey}")
private String APP_KEY;
@Value("${dianping.appSecret}")
private String APP_SECRET;
@Value("${order.allow-refund-time}")
private Long allowRefundTime;
......@@ -331,20 +328,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (Objects.nonNull(byId)) {
if (byId.getUseStatus().equals(UserStatusEnum.UNUSED.getCode())) {
if (StringUtils.isNotEmpty(byId.getCouponCode())) {
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
String session = (String) sessionKey.get("access_token");
TuangouReceiptGetConsumedRequest getConsumedRequest = new TuangouReceiptGetConsumedRequest(APP_KEY, APP_SECRET, session, byId.getCouponCode(), "", sStore.getOpenShopUuid());
TuangouReceiptGetConsumed getConsumed = new TuangouReceiptGetConsumed(getConsumedRequest);
DefaultOpenAPIClient client = new DefaultOpenAPIClient();
TuangouReceiptGetConsumedReponse invoke = client.invoke(getConsumed);
if (invoke.getCode() == 200) {
if (invoke.getData() == null) {
logger.error("验卷准备失败:{}", invoke.getMsg());
TuangouReceiptGetConsumedReponseEntity getconsumed = qpService.getconsumed(byId.getCouponCode(), sStore.getOpenShopUuid());
if (getconsumed == null) {
throw new RuntimeException("优惠券异常,请稍后再试");
}
}
}
} else {
throw new BaseException("优惠券已使用!");
}
......
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