订单展示后端实现

一、业务分析

需要统计的是相同订单id的商品种类、商品数量和以及商品金额。

sql语句:
 

SELECT order_id,user_id,order_time,COUNT(product_id) product_num,SUM(product_num) order_num,SUM(product_price) order_price FROM orders GROUP BY order_id LIMIT 0,6;
LIMIT 0,6

表示显示1-6条数据

同:

LIMIT 6

上边那条sql执行有问题正常

1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'store_order.orders.user_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

详情见:http://t.csdnimg.cn/V5zic

执行下边的

SELECT order_id,user_id,order_time,COUNT(product_id) product_num,SUM(product_num) order_num,SUM(product_price) order_price
        FROM orders GROUP BY order_id,user_id,order_time,product_num LIMIT 0,6;

二、定义这个OrderVo实体类做返回的集合数据里的订单实体类

@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class AdminOrderVo {

    @JsonProperty("order_id")
    private Long orderId;
    @JsonProperty("user_id")
    private Integer userId;
    @JsonProperty("product_num")
    private Integer productNum; //商品种类
    @JsonProperty("order_num")
    private Integer orderNum; //订单中商品数量
    @JsonProperty("order_price")
    private Double  orderPrice; //订单金额
    @JsonProperty("order_time")
    private Long    orderTime; //订单时间
}

三、具体实现

常规套路:Admin服务调用order服务的订单展示接口,order先实现订单展示接口。

这里用自己封装的mapper方法。在resource目录下新建OrderMapper文件:

public interface OrderMapper extends BaseMapper<Order> {

    /**
     * 分页查询数据,返回order封装vo
     * @param offset
     * @param number
     * @return
     */
    List<AdminOrderVo> selectAdminOrders(@Param("offset") int offset, @Param("number")int number);
}


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.order.mapper.OrderMapper">

    <select id="selectAdminOrders" resultType="com.atguigu.vo.AdminOrderVo">
SELECT order_id,user_id,order_time,COUNT(product_id) product_num,SUM(product_num) order_num,SUM(product_price) order_price FROM orders GROUP BY order_id,user_id,order_time,product_num LIMIT #{offset} , #{number};
    </select>

</mapper>

实现类:

    @Override
    public R adminList(PageParam pageParam) {
        //分页数据计算
        int offset=(pageParam.getCurrentPage()-1)*pageParam.getPageSize();
        int pageSize=pageParam.getPageSize();
        List<AdminOrderVo> adminOrderVoList=orderMapper.selectAdminOrder(offset,pageSize);
        long total=adminOrderVoList.size();
        return R.ok("订单数据查询成功",adminOrderVoList,total);
    }
}

将该接口声明在client中,然后admin服务调用OrderClient中定义的接口即可。

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值