提交 70107539 authored 作者: hzh's avatar hzh

交易订单增加权限

上级 e1b617a9
......@@ -61,4 +61,7 @@ public class TradeOrderPageReqVO extends PageParam {
@InEnum(value = TerminalEnum.class, message = "订单来源 {value}")
private Integer terminal;
@Schema(description = "订单id集合")
private List<Long> orderIds;
}
package org.dromara.mall.mapper.product;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.commons.collections4.CollectionUtils;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlusPlus;
import org.dromara.common.mybatis.core.page.PageResult;
import org.dromara.common.mybatis.core.query.LambdaQueryWrapperX;
......@@ -13,6 +16,7 @@ import org.dromara.mall.domain.product.ProductSpuDO;
import org.dromara.mall.enums.product.ProductConstants;
import org.dromara.mall.enums.product.spu.ProductSpuStatusEnum;
import java.util.List;
import java.util.Objects;
import java.util.Set;
......@@ -173,4 +177,27 @@ public interface ProductSpuMapper extends BaseMapperPlusPlus<ProductSpuDO, Produ
update(null, updateWrapper);
}
/**
* 获取有权限的spuId集合
*
* @return spuId集合
*/
default List<Long> selectSpuIdsByDataPermission() {
// 设置权限
if (CustomerDataPermissionHelper.isNeedFilter()) {
LambdaQueryWrapper<ProductSpuDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(ProductSpuDO::getId);
if (CustomerDataPermissionHelper.isNeedFilterDeptId()) {
queryWrapper.in(ProductSpuDO::getDeptId, CustomerDataPermissionHelper.getDeptIds());
} else {
queryWrapper.eq(ProductSpuDO::getCreateBy, LoginHelper.getUserId());
}
List<ProductSpuDO> spuList = selectList(queryWrapper);
return CollectionUtils.isEmpty(spuList) ? List.of(-1L) : StreamUtils.toList(spuList, ProductSpuDO::getId);
} else {
return List.of();
}
}
}
......@@ -44,6 +44,7 @@ public interface TradeOrderMapper extends BaseMapperPlusPlus<TradeOrderDO, Trade
.eqIfPresent(TradeOrderDO::getLogisticsId, reqVO.getLogisticsId())
.inIfPresent(TradeOrderDO::getPickUpStoreId, reqVO.getPickUpStoreIds())
.likeIfPresent(TradeOrderDO::getPickUpVerifyCode, reqVO.getPickUpVerifyCode())
.inIfPresent(TradeOrderDO::getId, reqVO.getOrderIds())
.betweenIfPresent(TradeOrderDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(TradeOrderDO::getId));
}
......
......@@ -5,7 +5,10 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.mybatis.core.page.PageResult;
import org.dromara.mall.api.dto.member.MemberUserRespDTO;
import org.dromara.mall.api.service.member.MemberUserApi;
......@@ -21,6 +24,7 @@ import org.dromara.mall.enums.trade.order.TradeOrderStatusEnum;
import org.dromara.mall.framework.trade.delivery.core.client.ExpressClientFactory;
import org.dromara.mall.framework.trade.delivery.core.client.dto.ExpressTrackQueryReqDTO;
import org.dromara.mall.framework.trade.delivery.core.client.dto.ExpressTrackRespDTO;
import org.dromara.mall.mapper.product.ProductSpuMapper;
import org.dromara.mall.mapper.trade.TradeOrderItemMapper;
import org.dromara.mall.mapper.trade.TradeOrderMapper;
import org.dromara.mall.service.trade.delivery.DeliveryExpressService;
......@@ -29,7 +33,6 @@ import org.springframework.stereotype.Service;
import java.util.*;
import static org.dromara.common.mall.exception.util.ServiceExceptionUtil.exception;
import static org.dromara.common.mall.util.collection.CollectionUtils.convertSet;
import static org.dromara.mall.enums.trade.ErrorCodeConstants.EXPRESS_NOT_EXISTS;
......@@ -49,6 +52,8 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
@Resource
private TradeOrderMapper tradeOrderMapper;
@Resource
private ProductSpuMapper productSpuMapper;
@Resource
private TradeOrderItemMapper tradeOrderItemMapper;
@Resource
......@@ -94,6 +99,20 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
if (userIds == null) { // 没查询到用户,说明肯定也没他的订单
return PageResult.empty();
}
// 获取有权限的商品
List<Long> spuIds = productSpuMapper.selectSpuIdsByDataPermission();
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(spuIds)) {
List<TradeOrderItemDO> itemList = tradeOrderItemMapper.selectList(
new LambdaQueryWrapper<TradeOrderItemDO>()
.in(TradeOrderItemDO::getSpuId, spuIds)
.select(TradeOrderItemDO::getOrderId)
);
if (CollectionUtils.isEmpty(itemList)) {
return PageResult.empty();
}
reqVO.setOrderIds(StreamUtils.toList(itemList, TradeOrderItemDO::getOrderId));
}
// 分页查询
return tradeOrderMapper.selectPage(reqVO, userIds);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论