feat(订单): 增加根据企业微信用户ID和AB98用户ID查询订单功能
新增通过企业微信用户ID直接查询订单的接口 扩展原有openid查询接口支持关联AB98用户和企业微信用户 添加用户信息关联查询逻辑,完善订单查询场景覆盖
This commit is contained in:
parent
39f4e421d3
commit
0ac7911ea5
|
@ -84,8 +84,18 @@ public class OrderController extends BaseController {
|
|||
* @return 包含订单列表的响应
|
||||
*/
|
||||
@GetMapping("/user/{openid}")
|
||||
public ResponseDTO<GetOrdersByOpenIdDTO> getOrdersByOpenId(@PathVariable String openid) {
|
||||
GetOrdersByOpenIdDTO result = orderApplicationService.getOrdersByOpenId(openid);
|
||||
public ResponseDTO<GetOrdersByOpenIdDTO> getOrdersByOpenId(@PathVariable String openid, @RequestParam(required = false) String corpid) {
|
||||
GetOrdersByOpenIdDTO result = orderApplicationService.getOrdersByOpenId(openid, corpid);
|
||||
return ResponseDTO.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户openid获取订单列表
|
||||
* @return 包含订单列表的响应
|
||||
*/
|
||||
@GetMapping("/user/qy/{qyUserId}")
|
||||
public ResponseDTO<GetOrdersByOpenIdDTO> getOrdersByOpenId(@PathVariable Long qyUserId) {
|
||||
GetOrdersByOpenIdDTO result = orderApplicationService.getOrdersByQyUserId(qyUserId);
|
||||
return ResponseDTO.ok(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -255,6 +255,16 @@ public class PaymentController {
|
|||
return ResponseDTO.fail(new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "无效的openid参数"));
|
||||
}
|
||||
|
||||
try {
|
||||
if (qyUser.getAb98UserId()!= null) {
|
||||
Ab98UserEntity ab98User = ab98UserApplicationService.getByAb98UserId(qyUser.getAb98UserId());
|
||||
ab98User.setOpenid(openid);
|
||||
ab98User.updateById();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新汇邦云绑定的微信openid失败", e);
|
||||
}
|
||||
|
||||
// 创建响应对象(假设GetBalanceResponse包含balance字段)
|
||||
GetBalanceResponse response = new GetBalanceResponse(
|
||||
qyUser.getUserid(),
|
||||
|
|
|
@ -30,4 +30,6 @@ public interface QyUserService extends IService<QyUserEntity> {
|
|||
List<String> selectAdminUserIds(String corpid);
|
||||
|
||||
QyUserStatsDTO selectTotalBalance(String corpid);
|
||||
|
||||
QyUserEntity getUserByAb98UserId(Long ab98UserId, String corpid);
|
||||
}
|
||||
|
|
|
@ -68,4 +68,14 @@ public class QyUserServiceImpl extends ServiceImpl<QyUserMapper, QyUserEntity> i
|
|||
return baseMapper.selectTotalBalanceByCorpid(corpid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QyUserEntity getUserByAb98UserId(Long ab98UserId, String corpid) {
|
||||
LambdaQueryWrapper<QyUserEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(QyUserEntity::getAb98UserId, ab98UserId)
|
||||
.eq(QyUserEntity::getCorpid, corpid)
|
||||
.eq(QyUserEntity::getDeleted, false)
|
||||
.last("LIMIT 1");
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import com.agileboot.common.constant.PayApiConstants;
|
|||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.ab98.user.db.Ab98UserEntity;
|
||||
import com.agileboot.domain.ab98.user.db.Ab98UserService;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellEntity;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellService;
|
||||
import com.agileboot.domain.cabinet.mainboard.db.CabinetMainboardEntity;
|
||||
|
@ -62,6 +64,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -88,6 +91,7 @@ public class OrderApplicationService {
|
|||
private final AuthCorpInfoApplicationService authCorpInfoApplicationService;
|
||||
private final AccessTokenApplicationService accessTokenApplicationService;
|
||||
private final QyUserService qyUserService;
|
||||
private final Ab98UserService ab98UserService;
|
||||
|
||||
public PageDTO<OrderWithGoodsDTO> getOrderList(SearchShopOrderQuery<OrderWithGoodsDTO> query) {
|
||||
Page<OrderWithGoodsDTO> page = orderService.getOrderList(query);
|
||||
|
@ -395,11 +399,106 @@ public class OrderApplicationService {
|
|||
}
|
||||
}
|
||||
|
||||
public GetOrdersByOpenIdDTO getOrdersByOpenId(String openid) {
|
||||
/**
|
||||
* 根据 openid 和 corpid 获取订单相关信息
|
||||
*
|
||||
* @param openid 开放用户 ID
|
||||
* @param corpid 企业微信 ID
|
||||
* @return 包含订单列表、订单商品列表和商品列表的 DTO 对象
|
||||
*/
|
||||
public GetOrdersByOpenIdDTO getOrdersByOpenId(String openid, String corpid) {
|
||||
// 根据 openid 获取 Ab98 用户信息
|
||||
Ab98UserEntity ab98User = ab98UserService.getByOpenid(openid);
|
||||
|
||||
// 构建订单查询条件
|
||||
QueryWrapper<ShopOrderEntity> orderQueryWrapper = new QueryWrapper<>();
|
||||
// 添加 openid 作为查询条件
|
||||
orderQueryWrapper.eq("openid", openid);
|
||||
// 如果 Ab98 用户信息存在
|
||||
if (ab98User != null) {
|
||||
// 添加 or 条件,根据 Ab98 用户的 userid 查询订单
|
||||
orderQueryWrapper.or()
|
||||
.eq("userid", ab98User.getUserid());
|
||||
|
||||
// 如果 corpid 不为空
|
||||
if (StringUtils.isNotBlank(corpid)) {
|
||||
// 根据 Ab98 用户的 ab98UserId 和 corpid 获取企业微信用户信息
|
||||
QyUserEntity qyUser = qyUserService.getUserByAb98UserId(ab98User.getAb98UserId(), corpid);
|
||||
// 如果企业微信用户信息存在
|
||||
if (qyUser!= null) {
|
||||
// 添加 or 条件,根据企业微信用户的 userid 查询订单
|
||||
orderQueryWrapper.or()
|
||||
.eq("userid", qyUser.getUserid());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 根据查询条件获取订单列表
|
||||
List<ShopOrderEntity> orderList = orderService.list(orderQueryWrapper);
|
||||
|
||||
// 构建订单商品查询条件
|
||||
QueryWrapper<ShopOrderGoodsEntity> orderGoodsQueryWrapper = new QueryWrapper<>();
|
||||
// 添加订单 ID 作为查询条件,查询属于这些订单的商品
|
||||
orderGoodsQueryWrapper.in("order_id", orderList.stream().map(ShopOrderEntity::getOrderId).collect(Collectors.toList()));
|
||||
// 根据查询条件获取订单商品列表
|
||||
List<ShopOrderGoodsEntity> orderGoods = orderGoodsService.list(orderGoodsQueryWrapper);
|
||||
|
||||
// 构建商品查询条件
|
||||
QueryWrapper<ShopGoodsEntity> goodsQueryWrapper = new QueryWrapper<>();
|
||||
// 添加商品 ID 作为查询条件,查询这些商品信息
|
||||
goodsQueryWrapper.in("goods_id", orderGoods.stream().map(ShopOrderGoodsEntity::getGoodsId).collect(Collectors.toList()));
|
||||
// 根据查询条件获取商品列表
|
||||
List<ShopGoodsEntity> goods = goodsService.list(goodsQueryWrapper);
|
||||
|
||||
// 返回包含订单列表、订单商品列表和商品列表的 DTO 对象
|
||||
return new GetOrdersByOpenIdDTO(orderList, orderGoods, goods);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据企业微信用户 ID 获取订单相关信息
|
||||
*
|
||||
* @param qyUserId 企业微信用户 ID
|
||||
* @return 包含订单列表、订单商品列表和商品列表的 DTO 对象
|
||||
*/
|
||||
public GetOrdersByOpenIdDTO getOrdersByQyUserId(Long qyUserId) {
|
||||
// 校验 qyUserId 是否为空,为空则抛出异常
|
||||
if (qyUserId == null) {
|
||||
throw new ApiException(ErrorCode.Client.COMMON_REQUEST_PARAMETERS_INVALID, "qyUserId不能为空");
|
||||
}
|
||||
// 根据企业微信用户 ID 获取企业微信用户信息
|
||||
QyUserEntity qyUser = qyUserService.getById(qyUserId);
|
||||
|
||||
// 构建订单查询条件
|
||||
QueryWrapper<ShopOrderEntity> orderQueryWrapper = new QueryWrapper<>();
|
||||
// 添加企业微信用户的 userid 作为查询条件
|
||||
orderQueryWrapper.eq("userid", qyUser.getUserid());
|
||||
// 如果企业微信用户的 ab98UserId 不为空
|
||||
if (qyUser.getAb98UserId() != null) {
|
||||
// 根据 ab98UserId 获取 Ab98 用户信息
|
||||
Ab98UserEntity ab98User = ab98UserService.getById(qyUser.getAb98UserId());
|
||||
// 如果 Ab98 用户信息存在
|
||||
if (ab98User!= null) {
|
||||
// 添加 or 条件,根据 Ab98 用户的 userid 查询订单
|
||||
orderQueryWrapper.or()
|
||||
.eq("userid", ab98User.getUserid());
|
||||
|
||||
// 如果 Ab98 用户的 openid 不为空
|
||||
if (StringUtils.isNotBlank(ab98User.getOpenid())) {
|
||||
// 添加 or 条件,根据 Ab98 用户的 openid 查询订单
|
||||
orderQueryWrapper.or()
|
||||
.eq("openid", ab98User.getOpenid());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 根据查询条件获取订单列表
|
||||
List<ShopOrderEntity> orderList = orderService.list(orderQueryWrapper);
|
||||
|
||||
// 构建订单商品查询条件
|
||||
// 返回包含订单列表、订单商品列表和商品列表的 DTO 对象
|
||||
// 根据查询条件获取商品列表
|
||||
// 添加商品 ID 作为查询条件,查询这些商品信息
|
||||
// 构建商品查询条件
|
||||
// 根据查询条件获取订单商品列表
|
||||
// 添加订单 ID 作为查询条件,查询属于这些订单的商品
|
||||
QueryWrapper<ShopOrderGoodsEntity> orderGoodsQueryWrapper = new QueryWrapper<>();
|
||||
orderGoodsQueryWrapper.in("order_id", orderList.stream().map(ShopOrderEntity::getOrderId).collect(Collectors.toList()));
|
||||
List<ShopOrderGoodsEntity> orderGoods = orderGoodsService.list(orderGoodsQueryWrapper);
|
||||
|
|
Loading…
Reference in New Issue