发送订阅消息增加token
This commit is contained in:
parent
0d79a23ad7
commit
6b4397dec5
|
|
@ -1,15 +1,24 @@
|
|||
package cn.ysk.cashier.controller.product;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.ysk.cashier.annotation.AnonymousAccess;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.config.security.security.TokenProvider;
|
||||
import cn.ysk.cashier.dto.shoptable.*;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbMerchantAccountMapper;
|
||||
import cn.ysk.cashier.pojo.TbToken;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
||||
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
|
||||
import cn.ysk.cashier.repository.TbTokenRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbPlussShopStaffRepository;
|
||||
import cn.ysk.cashier.service.product.TbProductService;
|
||||
import cn.ysk.cashier.service.shop.TbShopTableService;
|
||||
import cn.ysk.cashier.utils.RabbitMsgUtils;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -22,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
|
@ -31,6 +41,12 @@ public class TbPlaceController {
|
|||
private final TbProductService tbProductService;
|
||||
private final RabbitMsgUtils rabbitMsgUtils;
|
||||
@Resource
|
||||
private TbPlussShopStaffRepository staffRepository;
|
||||
@Resource
|
||||
private TbMerchantAccountMapper tbMerchantAccountMapper;
|
||||
@Resource
|
||||
private TbTokenRepository tbTokenRepository;
|
||||
@Resource
|
||||
private TokenProvider tokenProvider;
|
||||
@Lazy
|
||||
@Autowired
|
||||
|
|
@ -154,10 +170,17 @@ public class TbPlaceController {
|
|||
@ApiOperation("代客下单 支付订单")
|
||||
public ResponseEntity<Object> pay(HttpServletRequest request, @Validated @RequestBody PayDTO payDTO) {
|
||||
String token = tokenProvider.getToken(request);
|
||||
payDTO.setToken(token);
|
||||
Object o = redisUtils.get("online-token-"+token);
|
||||
String jsonString = JSON.toJSONString(o);
|
||||
log.error(">>>>>>>>>>>>>>>>>>>>>>>>>>>>jsonString:{}", jsonString);
|
||||
JSONObject userInfo = JSON.parseObject(JSON.toJSONString(redisUtils.get("online-token-"+token)));
|
||||
String userName = userInfo.getString("userName");
|
||||
String shopId = userInfo.getString("shopId");
|
||||
TbPlussShopStaff shopStaff = staffRepository.queryByAccount(userName, shopId);
|
||||
TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(Wrappers.<TbMerchantAccount>lambdaQuery().eq(TbMerchantAccount::getAccount, shopStaff.getAccount()));
|
||||
Integer accountId = merchantAccount.getId();
|
||||
Integer staffId = shopStaff.getId();
|
||||
List<TbToken> onlineUserList = tbTokenRepository.findListByAccountIdAndStaffId(accountId, staffId);
|
||||
if (CollUtil.isNotEmpty(onlineUserList)) {
|
||||
payDTO.setToken(onlineUserList.get(0).getToken());
|
||||
}
|
||||
return ResponseEntity.ok(tbShopTableService.pay(payDTO));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package cn.ysk.cashier.repository;
|
||||
|
||||
import javax.persistence.Tuple;
|
||||
import cn.ysk.cashier.pojo.TbShopPayType;
|
||||
import cn.ysk.cashier.pojo.TbToken;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import javax.persistence.Tuple;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -23,7 +22,9 @@ public interface TbTokenRepository extends JpaRepository<TbToken, Integer>, JpaS
|
|||
Tuple countByAccountId(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query(value = "select count(0),DATE_FORMAT(create_time,'%Y-%m-%d')from tb_token where account_id=:shopId " +
|
||||
"and create_time BETWEEN :startTime and :endTime group by DATE_FORMAT( create_time, '%Y-%m-%d') ",nativeQuery = true)
|
||||
"and create_time BETWEEN :startTime and :endTime group by DATE_FORMAT( create_time, '%Y-%m-%d') ", nativeQuery = true)
|
||||
List<Object[]> countByMonth(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query("select x.token from TbToken x where x.accountId=:accountId and x.staffId=:staffId and x.status=1 order by x.id desc")
|
||||
List<TbToken> findListByAccountIdAndStaffId(@Param("accountId") Integer accountId, @Param("staffId") Integer staffId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue