Commit cbe72ece by 吕明尚

更新下单,开门

parent dce6e4f3
......@@ -53,6 +53,7 @@ public class SOrderController extends BaseController
public TableDataInfo list(SOrder sOrder)
{
startPage();
sOrder.setConsumerId(getUserId());
List<SOrder> list = sOrderService.selectSOrderList(sOrder);
return getDataTable(list);
}
......
......@@ -5,12 +5,14 @@ import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import share.common.core.redis.RedisUtil;
import share.common.enums.ReceiptRdeisEnum;
import share.system.service.ISConsumerCouponService;
import share.system.service.QPService;
import java.util.Date;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@Component("redisTask")
public class RedisTask {
......@@ -20,14 +22,16 @@ public class RedisTask {
private QPService qpService;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private RedisUtil redisUtil;
public void AuToReceiptCode() {
//获取redis中所有以tuangou.receipt.prepare开头的key
Set keys = redisTemplate.keys(ReceiptRdeisEnum.PREPARE.getValue() + "*");
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.PREPARE.getValue() + "*");
//遍历key
keys.stream().forEach(o -> {
//获取key对应的value
JSONObject jsonObject = (JSONObject) redisTemplate.opsForValue().get(o);
JSONObject jsonObject = redisUtil.get(o);
//获取过期时间
Date expirationTime = jsonObject.getDate("expirationTime");
//判断是否过期
......@@ -37,7 +41,7 @@ public class RedisTask {
//获取redis中的券码id
Long consumerCouponId = jsonObject.getLong("consumerCouponId");
//删除redis中的值
redisTemplate.delete(o);
redisUtil.delete(o);
//删除数据库中的值
isConsumerCouponService.deleteSConsumerCouponById(consumerCouponId);
});
......@@ -50,9 +54,8 @@ public class RedisTask {
String refreshToken = (String) o.get("refresh_token");
CustomerRefreshTokenResponse customerRefreshTokenResponse = qpService.refreshToken(refreshToken);
JSONObject jsonObject = new JSONObject(customerRefreshTokenResponse);
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), jsonObject.toString());
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), jsonObject.toString());
redisTemplate.expire(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), customerRefreshTokenResponse.getExpires_in() - 60 * 30, java.util.concurrent.TimeUnit.SECONDS);
redisUtil.set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), jsonObject.toString());
redisUtil.set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), jsonObject.toString(), customerRefreshTokenResponse.getExpires_in() - 60 * 30, TimeUnit.SECONDS);
}
}
}
......@@ -2,6 +2,7 @@ package share.system.domain.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import share.common.annotation.Excel;
import share.common.core.domain.BaseEntity;
import java.util.List;
......@@ -74,4 +75,7 @@ public class SStoreVo extends BaseEntity
@ApiModelProperty(value = "房间列表")
private List<SRoomVo> roomVoList;
@ApiModelProperty(name = "美团点评店铺id")
private String openShopUuid;
}
......@@ -77,7 +77,5 @@ public class CreateOrderRequest {
@NotNull(message = "实际支付金额不能为空")
private BigDecimal payFee;
@ApiModelProperty(value = "劵码")
private String code;
}
......@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.stereotype.Service;
import share.common.core.redis.RedisUtil;
import share.common.enums.*;
import share.common.utils.DateUtils;
import share.system.domain.SConsumer;
......@@ -39,6 +40,7 @@ import share.system.service.QPService;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Service
public class QPServiceImpl implements QPService {
......@@ -53,8 +55,9 @@ public class QPServiceImpl implements QPService {
@Autowired
private ISConsumerCouponService isConsumerCouponService;
@Autowired
private RedisTemplate redisTemplate;
private RedisUtil redisUtil;
/**
* 用户验卷接口
*/
......@@ -75,7 +78,7 @@ public class QPServiceImpl implements QPService {
//领取删除原来的
isConsumerCouponService.deleteSConsumerCouponById(one.getId());
//删除redis
redisTemplate.delete(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code());
redisUtil.delete(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code());
}
//根据优惠卷名称查询优惠劵配置
SCoupon sCoupon = isCouponService.selectSCouponByName(prepare.getDeal_title());
......@@ -135,7 +138,7 @@ public class QPServiceImpl implements QPService {
//设置30分钟后的时间
Date date = DateUtils.addMinutes(new Date(), 30);
map.put("expirationTime", String.valueOf(date));
redisTemplate.opsForValue().set(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code(), new JSONObject(map));
redisUtil.set(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code(), new JSONObject(map));
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String output1 = format2.format(prepare.getReceiptEndDate());
BeanUtils.copyProperties(prepare, response);
......@@ -172,7 +175,12 @@ public class QPServiceImpl implements QPService {
*/
@Override
public TuangouReceiptPrepareResponseEntity prepare(String code, String openShopUuid) {
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
Boolean b = redisUtil.exists(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
if (Boolean.FALSE.equals(b)) {
throw new RuntimeException("请联系管理员");
}
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, code, "", openShopUuid);
TuangouReceiptPrepare tuangouReceiptPrepare = new TuangouReceiptPrepare(request);
......@@ -190,13 +198,13 @@ public class QPServiceImpl implements QPService {
*/
@Override
public List<TuangouReceiptConsumeResponseEntity> consume(String code, int count, String openShopUuid) {
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
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, openShopUuid,
user.getAccount(), user.getNickName());
requestid, code, count, "", user.getAccount(), user.getNickName(), openShopUuid);
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptConsume tuangouReceiptConsume = new TuangouReceiptConsume(request);
TuangouReceiptConsumeResponse invoke = openAPIClient.invoke(tuangouReceiptConsume);
......@@ -212,12 +220,13 @@ public class QPServiceImpl implements QPService {
*/
@Override
public List<TuangouReceiptReverseConsumeResponseEntity> reverseconsume(String code, Long appDealId, String openShopUuid) {
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
String session = (String) sessionKey.get("access_token");
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
TuangouReceiptReverseConsumeRequest tuangouReceiptReverseConsumeRequest = new TuangouReceiptReverseConsumeRequest(APP_KEY, APP_SECRET, session,
String.valueOf(appDealId), code, openShopUuid,
user.getAccount(), user.getNickName());
String.valueOf(appDealId), code, "",
user.getAccount(), user.getNickName(), openShopUuid);
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptReverseConsume tuangouReceiptReverseConsume = new TuangouReceiptReverseConsume(tuangouReceiptReverseConsumeRequest);
TuangouReceiptReverseConsumeResponse response = openAPIClient.invoke(tuangouReceiptReverseConsume);
......@@ -233,11 +242,12 @@ public class QPServiceImpl implements QPService {
*/
@Override
public TuangouReceiptGetConsumedReponseEntity getconsumed(String code, String openShopUuid) {
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
String session = (String) sessionKey.get("access_token");
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
TuangouReceiptGetConsumedRequest request = new TuangouReceiptGetConsumedRequest(APP_KEY, APP_SECRET,
session, code, openShopUuid);
session, code, "", openShopUuid);
TuangouReceiptGetConsumed tuangouReceiptGetConsumed = new TuangouReceiptGetConsumed(request);
TuangouReceiptGetConsumedReponse response = openAPIClient.invoke(tuangouReceiptGetConsumed);
if (response.getCode() != 200) {
......@@ -255,9 +265,8 @@ public class QPServiceImpl implements QPService {
DynamicTokenResponse response = openAPIClient.invoke(dynamicToken);
//response转JSON
JSONObject jsonObject = new JSONObject(response);
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), jsonObject.toString());
redisTemplate.opsForValue().set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), jsonObject.toString());
redisTemplate.expire(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), response.getExpires_in() - 60 * 30, java.util.concurrent.TimeUnit.SECONDS);
redisUtil.set(ReceiptRdeisEnum.MT_SESSION_OBJECT_KEY.getValue(), jsonObject.toString());
redisUtil.set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), jsonObject.toString(), response.getExpires_in() - 60 * 30, TimeUnit.SECONDS);
return response.getAccess_token();
}
......@@ -270,7 +279,8 @@ public class QPServiceImpl implements QPService {
* @param app_shop_id
*/
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
String session = (String) sessionKey.get("access_token");
TuangouDealQueryShopDealRequest request = new TuangouDealQueryShopDealRequest(APP_KEY, APP_SECRET, session, "", 1, 100, openShopUuid);
TuangouDealQueryShopDeal tuangouDealQueryShopDeal = new TuangouDealQueryShopDeal(request);
......@@ -291,10 +301,11 @@ public class QPServiceImpl implements QPService {
@Override
public SessionVo queryKey() {
JSONObject o = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
//获取KEY过期时间
Long expire = redisTemplate.getExpire(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
Integer remainRefreshCount = (Integer) o.get("remain_refresh_count");
Long expire = redisUtil.getExpire(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
Integer remainRefreshCount = (Integer) sessionKey.get("remain_refresh_count");
SessionVo sessionVo = new SessionVo();
sessionVo.setExpiresIn(expire);
sessionVo.setRemainRefreshCount(remainRefreshCount);
......@@ -309,7 +320,8 @@ public class QPServiceImpl implements QPService {
@Override
public List<CustomerKeyShopScopeResponseEntity> scope() {
DefaultOpenAPIClient openAPIClient = new DefaultOpenAPIClient();
JSONObject sessionKey = new JSONObject(redisTemplate.opsForValue().get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()));
String o = redisUtil.get(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
JSONObject sessionKey = new JSONObject(o);
String session = (String) sessionKey.get("access_token");
String bid = (String) sessionKey.get("bid");
// CustomerKeyShopScopeRequest request = new CustomerKeyShopScopeRequest(APP_KEY, APP_SECRET, "13ff8a38219075fafbbdeea6839450ed6bea1b9b","f1fd23c1c413862137b895bdcfc10ef8");
......
......@@ -198,12 +198,15 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
redisUtil.lPush(Constants.ORDER_AUTO_CANCEL_KEY, sOrder.getOrderNo());
}
if (response.getStatus().equals(YesNoEnum.yes.getFlag())) {
if (Objects.nonNull(request.getCouponId()) && request.getCouponId() != 0) {
SConsumerCoupon byId = consumerCouponService.getById(request.getCouponId());
//验劵
qpService.consume(byId.getCouponCode(), 1, sStore.getOpenShopUuid());
SConsumerCoupon consumerCoupon = new SConsumerCoupon();
consumerCoupon.setId(request.getCouponId());
consumerCoupon.setUseStatus(UserStatusEnum.USED.getCode());
consumerCouponService.updateById(consumerCoupon);
//验劵
qpService.consume(request.getCode(), 1, sStore.getOpenShopUuid());
}
}
save(sOrder);
return response;
......@@ -512,6 +515,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
throw new BaseException("设备不存在!");
}
if (sOrder.getStatus().equals(OrderStatusEnum.UNUSED.getCode())) {
if (checkOrderOpenDoor()) {
throw new BaseException("房间当前时段已被占用不可开门!");
}
//更改订单状态,房间状态,开始时间,结束时间
sOrder.setStatus(1);
//计算预约开始和结束时间时长
......@@ -521,9 +527,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
sOrder.setEndDate(DateUtils.addHours(new Date(), bigDecimal.intValue()));
sOrderMapper.updateById(sOrder);
//查询非当前用户,预约时间或使用时间为当前时间的订单,如果存在,房间不可开门
if(checkOrderOpenDoor()){
throw new BaseException("房间当前时段已被占用不可开门!");
}
}
SConsumer user = FrontTokenComponent.getWxSConsumerEntry();
deviceOpService.openDoor(sRoomVo.getId(), user.getPhone());
......
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