Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
SongZhang 2024-10-22 09:32:08 +08:00
commit c7f68b363e
2 changed files with 40 additions and 4 deletions

View File

@ -1,14 +1,28 @@
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;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
@ -17,7 +31,9 @@ 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
@RequestMapping("/api/place")
public class TbPlaceController {
@ -25,7 +41,16 @@ 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
private RedisUtils redisUtils;
@GetMapping("/activate")
@ApiOperation("查询/product")
@ -145,7 +170,17 @@ public class TbPlaceController {
@ApiOperation("代客下单 支付订单")
public ResponseEntity<Object> pay(HttpServletRequest request, @Validated @RequestBody PayDTO payDTO) {
String token = tokenProvider.getToken(request);
payDTO.setToken(token);
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));
}

View File

@ -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;
@ -26,4 +25,6 @@ public interface TbTokenRepository extends JpaRepository<TbToken, Integer>, JpaS
"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("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);
}