feat(新增): 获取订单分页列表

Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
bunny 2024-03-29 10:03:57 +08:00
parent a191aa60f2
commit 89cc176e90
7 changed files with 79 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import com.atguigu.spzx.model.dto.h5.OrderInfoDto;
import com.atguigu.spzx.model.entity.order.OrderInfo; import com.atguigu.spzx.model.entity.order.OrderInfo;
import com.atguigu.spzx.model.vo.h5.TradeVo; import com.atguigu.spzx.model.vo.h5.TradeVo;
import com.atguigu.spzx.model.vo.result.Result; import com.atguigu.spzx.model.vo.result.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -45,4 +46,17 @@ public class OrderInfoController {
TradeVo tradeVo = orderInfoService.buy(skuId); TradeVo tradeVo = orderInfoService.buy(skuId);
return Result.success(tradeVo); return Result.success(tradeVo);
} }
@Operation(summary = "获取订单分页列表")
@GetMapping("auth/{page}/{limit}")
public Result<PageInfo<OrderInfo>> list(
@Parameter(name = "page", description = "当前页码", required = true)
@PathVariable Integer page,
@Parameter(name = "limit", description = "每页记录数", required = true)
@PathVariable Integer limit,
@Parameter(name = "orderStatus", description = "订单状态", required = false)
@RequestParam(required = false, defaultValue = "") Integer orderStatus) {
PageInfo<OrderInfo> pageInfo = orderInfoService.findUserPage(page, limit, orderStatus);
return Result.success(pageInfo);
}
} }

View File

@ -3,6 +3,8 @@ package com.atguigu.order.mapper;
import com.atguigu.spzx.model.entity.order.OrderInfo; import com.atguigu.spzx.model.entity.order.OrderInfo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper @Mapper
public interface OrderInfoMapper { public interface OrderInfoMapper {
/** /**
@ -19,4 +21,6 @@ public interface OrderInfoMapper {
* @return OrderInfo * @return OrderInfo
*/ */
OrderInfo getById(Long orderId); OrderInfo getById(Long orderId);
List<OrderInfo> findUserPage(Long userId, Integer orderStatus);
} }

View File

@ -3,6 +3,8 @@ package com.atguigu.order.mapper;
import com.atguigu.spzx.model.entity.order.OrderItem; import com.atguigu.spzx.model.entity.order.OrderItem;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper @Mapper
public interface OrderItemMapper { public interface OrderItemMapper {
/** /**
@ -11,4 +13,6 @@ public interface OrderItemMapper {
* @param orderItem orderItem * @param orderItem orderItem
*/ */
void save(OrderItem orderItem); void save(OrderItem orderItem);
List<OrderItem> findByOrderId(Long id);
} }

View File

@ -3,6 +3,7 @@ package com.atguigu.order.service;
import com.atguigu.spzx.model.dto.h5.OrderInfoDto; import com.atguigu.spzx.model.dto.h5.OrderInfoDto;
import com.atguigu.spzx.model.entity.order.OrderInfo; import com.atguigu.spzx.model.entity.order.OrderInfo;
import com.atguigu.spzx.model.vo.h5.TradeVo; import com.atguigu.spzx.model.vo.h5.TradeVo;
import com.github.pagehelper.PageInfo;
public interface OrderInfoService { public interface OrderInfoService {
/** /**
@ -35,4 +36,14 @@ public interface OrderInfoService {
* @return 结算实体类 * @return 结算实体类
*/ */
TradeVo buy(Long skuId); TradeVo buy(Long skuId);
/**
* 获取订单分页列表
*
* @param page page
* @param limit limit
* @param orderStatus orderStatus
* @return PageInfo<OrderInfo>
*/
PageInfo<OrderInfo> findUserPage(Integer page, Integer limit, Integer orderStatus);
} }

View File

@ -22,6 +22,7 @@ import com.atguigu.spzx.model.entity.user.UserInfo;
import com.atguigu.spzx.model.vo.h5.TradeVo; import com.atguigu.spzx.model.vo.h5.TradeVo;
import com.atguigu.spzx.model.vo.result.ResultCodeEnum; import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
import com.atguigu.utils.EmptyUtil; import com.atguigu.utils.EmptyUtil;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -189,4 +190,25 @@ public class OrderInfoServiceImpl implements OrderInfoService {
// 返回 // 返回
return tradeVo; return tradeVo;
} }
/**
* 获取订单分页列表
*
* @param page page
* @param limit limit
* @param orderStatus orderStatus
* @return PageInfo<OrderInfo>
*/
@Override
public PageInfo<OrderInfo> findUserPage(Integer page, Integer limit, Integer orderStatus) {
Long userId = BaseContext.getUserInfo().getId();
List<OrderInfo> orderInfoList = orderInfoMapper.findUserPage(userId, orderStatus);
orderInfoList.forEach(orderInfo -> {
List<OrderItem> orderItem = orderItemMapper.findByOrderId(orderInfo.getId());
orderInfo.setOrderItemList(orderItem);
});
return new PageInfo<>(orderInfoList);
}
} }

View File

@ -66,4 +66,19 @@
where where
id = #{id} id = #{id}
</select> </select>
<select id="findUserPage" resultType="com.atguigu.spzx.model.entity.order.OrderInfo">
select
<include refid="columns"/>
from order_info
<where>
<if test="userId != null">
and user_id = #{userId}
</if>
<if test="orderStatus != null">
and order_status = #{orderStatus}
</if>
and is_deleted = 0
</where>
order by id desc
</select>
</mapper> </mapper>

View File

@ -23,4 +23,13 @@
#{skuPrice}, #{skuPrice},
#{skuNum}) #{skuNum})
</insert> </insert>
<select id="findByOrderId" resultType="com.atguigu.spzx.model.entity.order.OrderItem">
select
<include refid="columns"/>
from order_item
where
order_id = #{orderId}
and is_deleted = 0
order by id desc
</select>
</mapper> </mapper>