快捷餐饮之店家后台订单管理实现

  • j3_liuliang
  • 上期写了餐桌及评论管理相关的功能,现在我们来实现一下订单管理相关内容

项目相关文章导航:

  1. 快捷点餐项目简介
  2. 餐饮系统设计概括
  3. 餐饮系统店家后端基础功能构建
  4. 快捷餐饮之店家后台OSS文件管理实现
  5. 快捷餐饮之店家后台厨艺秀实现
  6. 快捷餐饮之店家后台菜品分类及菜品管理实现
  7. 快捷餐饮之店家后台评论管理及餐桌管理实现
  8. 快捷餐饮之店家后台订单管理实现
  9. 下期实现店家员工管理相关功能

项目Git地址: 点这里哦!

一、订单管理

1.1 编写订单查询vo对象

OrderQueryConditionVO

在这里插入图片描述

/**
 * @Package: cn.liuliang.quickdinesysstore.entity.vo
 * @Author: liuliang
 * @CreateTime: 2020/10/30 - 8:40
 * @Description:
 */
@Data
@ApiModel(value = "订单查询vo", description = "")
public class OrderQueryConditionVO extends BaseVO {

    @ApiModelProperty(value = "桌号:关联餐桌表中的id")
    private String diningTableNumber;

    @ApiModelProperty(value = "是否结账:1:结账,2:未结账")
    private Integer isSettleAccounts;

    @ApiModelProperty(value = "下单人电话")
    private String orderDishesPeoplePhone;

    @ApiModelProperty(value = "金额")
    private BigDecimal money;

    @ApiModelProperty(value = "下单时间")
    private String orderTime;


}

1.2 编写订单信息DTO对象

OrderDTO

在这里插入图片描述

/**
 * @Package: cn.liuliang.quickdinesysstore.entity.dto
 * @Author: liuliang
 * @CreateTime: 2020/10/30 - 8:53
 * @Description:
 */
@Data
@ApiModel(value="订单信息DTO", description="")
public class OrderDTO implements Serializable {
    private static final long serialVersionUID=1L;

    @ApiModelProperty(value = "ID")
    private Long id;

    @ApiModelProperty(value = "店家名称:唯一")
    private String storeName;

    @ApiModelProperty(value = "桌号:关联餐桌表中的id")
    private String diningTableNumber;

    @ApiModelProperty(value = "下单人名称")
    private String orderDishesPeopleName;

    @ApiModelProperty(value = "下单人电话")
    private String orderDishesPeoplePhone;

    @ApiModelProperty(value = "已点菜品:生成id,关联已点菜表id")
    private Long foods;

    @ApiModelProperty(value = "金额")
    private BigDecimal money;

    @ApiModelProperty(value = "实付金额")
    private BigDecimal actualMoney;

    @ApiModelProperty(value = "金额来源描述(优惠率,积分抵扣)")
    private String description;

    @ApiModelProperty(value = "优惠率")
    private String discountRate;

    @ApiModelProperty(value = "积分抵扣")
    private String pointsDeduction;

    @ApiModelProperty(value = "积分:每十块抵一积分,积分可以在结账时抵扣,一积分抵扣一块钱(这个以后后台需要可设置话)")
    private Integer integral;

    @ApiModelProperty(value = "是否结账:1:结账,2:未结账")
    private Integer isSettleAccounts;

    @ApiModelProperty(value = "是否结账")
    private Date orderTime;

    @ApiModelProperty(value = "结账时间")
    private Date settleAccountsTime;
}

1.3 编写菜品信息DTO列表对象

AlreadyOrderDishesDTO

在这里插入图片描述

/**
 * @Package: cn.liuliang.quickdinesysstore.entity.dto
 * @Author: liuliang
 * @CreateTime: 2020/10/30 - 9:34
 * @Description:
 */
@Data
@ApiModel(value="所点菜品信息DTO", description="")
public class AlreadyOrderDishesDTO implements Serializable {

    @ApiModelProperty(value = "ID")
    private Long id;

    @ApiModelProperty(value = "菜Id:关联菜品表,根据这个菜品id可以查到菜品所有信息")
    private Long dishesId;

    @ApiModelProperty(value = "图片:存储图片的url访问地址")
    private String imageUrl;

    @ApiModelProperty(value = "菜名:唯一")
    private String dishesName;

    @ApiModelProperty(value = "价格")
    private BigDecimal price;

    @ApiModelProperty(value = "数量")
    private Integer number;

    @ApiModelProperty(value = "合计:价格 * 数量")
    private BigDecimal sumPrice;

}

1.4 编写订单详情信息DTO

OrderDetailDTO

在这里插入图片描述

/**
 * @Package: cn.liuliang.quickdinesysstore.entity.dto
 * @Author: liuliang
 * @CreateTime: 2020/10/30 - 9:31
 * @Description:
 */
@Data
@ApiModel(value="订单详情信息DTO", description="")
public class OrderDetailDTO implements Serializable {

    @ApiModelProperty(value = "订单基本信息DTO对象")
    private OrderDTO orderDTO;

    @ApiModelProperty(value = "所点菜品信息DTO列表")
    List<AlreadyOrderDishesDTO> alreadyOrderDishesDTOList;

}

1.5 编写订单控制类

在这里插入图片描述

@Api(value = "订单管理", tags = "订单管理")
@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "分页条件查询所有订单列表", notes = "分页条件查询所有订单列表")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功!", response = OrderDTO.class)})
    @GetMapping("/select-all")
    public ResultDTO selectAll(
            OrderQueryConditionVO orderQueryConditionVO,
            @ApiParam("当前页码") @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @ApiParam("每页显示条数") @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return orderService.selectAll(orderQueryConditionVO, pageNum, pageSize);
    }

    @ApiOperation(value = "根据id查询订单详情", notes = "根据id查询订单详情")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功!", response = OrderDetailDTO.class)})
    @GetMapping("/select-one")
    public ResultDTO selectOne(@ApiParam("订单id") @RequestParam(value = "id", required = true) Long id) {
        return orderService.selectOne(id);
    }

    @ApiOperation(value = "根据id删除订单", notes = "根据id删除订单")
    @GetMapping("/delete")
    public ResultDTO delete(@ApiParam("订单id") @RequestParam(value = "id", required = true) Long id){
        return orderService.delete(id);
    }

/*    @ApiOperation(value = "根据订单id进行结账", notes = "根据订单id进行结账")
    @GetMapping("/bill-please")
    public ResultDTO billPlease(@ApiParam("订单id") @RequestParam(value = "id", required = true) Long id){
        return orderService.billPlease(id);
    }*/
}

1.6 编写订单业务类

在这里插入图片描述

public interface OrderService extends IService<Order> {

    /**
     * 分页条件查询所有订单列表
     *
     * @param orderQueryConditionVO 订单查询条件对象
     * @param pageNum               当前页
     * @param pageSize              每页大小
     * @return
     */
    ResultDTO selectAll(OrderQueryConditionVO orderQueryConditionVO, Integer pageNum, Integer pageSize);

    /**
     * 根据订单 id 查询订单详情
     *
     * @param id 订单id
     * @return
     */
    ResultDTO selectOne(Long id);

    /**
     * 根据订单id删除订单
     *
     * @param id 订单id
     * @return
     */
    ResultDTO delete(Long id);

    /**
     * 根据订单id进行结账
     *
     * @param id  订单id
     * @return
     */
    ResultDTO billPlease(Long id);
}
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private DiningTableMapper diningTableMapper;

    @Autowired
    private QueryUtils queryUtils;

    @Override
    public ResultDTO selectAll(OrderQueryConditionVO orderQueryConditionVO, Integer pageNum, Integer pageSize) {
        // 构造分页
        Page<Order> orderPage = new Page<>(pageNum, pageSize);
        // 设置查询店家名称条件
        orderQueryConditionVO.setStoreName(queryUtils.getStoreName());
        // 执行查询
        List<Order> orderList = orderMapper.selectAll(orderPage, orderQueryConditionVO);
        // 构造数据
        List<OrderDTO> orderDTOList = new ArrayList<>(orderList.size());
        orderList.forEach(order -> {
            OrderDTO orderDTO = new OrderDTO();
            BeanUtils.copyProperties(order, orderDTO);
            orderDTOList.add(orderDTO);
        });
        return ResultDTO.success().data("total", Math.toIntExact(orderPage.getTotal())).data("rows", orderDTOList);
    }

    @Override
    public ResultDTO selectOne(Long id) {
        // 查询订单基本信息
        Order order = orderMapper.selectById(id);
        // 根据订单中的点菜id,查询点菜列表
        List<AlreadyOrderDishesDTO> alreadyOrderDishesDTOList = orderMapper.selectAlreadyOrderDishesByFoods(order.getFoods());
        // 计算点菜条目中的合计字段
        alreadyOrderDishesDTOList.forEach(alreadyOrderDishesDTO -> {
            alreadyOrderDishesDTO.setSumPrice(alreadyOrderDishesDTO.getPrice().multiply(new BigDecimal(alreadyOrderDishesDTO.getNumber())));
        });
        // 组装数据
        OrderDetailDTO orderDetailDTO = new OrderDetailDTO();
        // 组装订单基本数据
        OrderDTO orderDTO = new OrderDTO();
        BeanUtils.copyProperties(order, orderDTO);
        orderDTO.setDiscountRate(orderDTO.getDescription().split(";")[0]);
        orderDTO.setPointsDeduction(orderDTO.getDescription().split(";")[1]);
        // 设置订单菜品信息
        orderDetailDTO.setOrderDTO(orderDTO);
        orderDetailDTO.setAlreadyOrderDishesDTOList(alreadyOrderDishesDTOList);
        return ResultDTO.success().data("data", orderDetailDTO);
    }

    @Override
    public ResultDTO delete(Long id) {
        // 根据订单id , 查询其下面的所有一点菜品id(foods)
        // 构造查询条件对象
        QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.select("foods").eq("id", id);
        Order order = orderMapper.selectOne(orderQueryWrapper);
        // 开始删除订单基本信息
        orderMapper.deleteById(id);
        // 开始删除订单下的以点菜品信息
        orderMapper.deleteAlreadyOrderDishes(order.getFoods());
        return ResultDTO.success();
    }

    @Transactional
    @Override
    public ResultDTO billPlease(Long id) {
        // 获取订单的餐桌号
        QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.select("dining_table_number").eq("id", id);
        Order order = orderMapper.selectOne(orderQueryWrapper);
        // 修改餐桌状态为空闲和下单状态为未下单
        UpdateWrapper<DiningTable> diningTableUpdateWrapper = new UpdateWrapper<>();
        DiningTable diningTable = new DiningTable();
        //diningTable.setIsLeisure(1);
        //diningTable.setIsOrder(2);
        diningTableUpdateWrapper.eq("dining_table_number", order.getDiningTableNumber());
        diningTableMapper.update(diningTable, diningTableUpdateWrapper);
        // 修改订单的结账状态为结账
        UpdateWrapper<Order> orderUpdateWrapper = new UpdateWrapper<>();
        Order order1 = new Order();
        order1.setIsSettleAccounts(1);
        diningTableUpdateWrapper.eq("id", id);
        orderMapper.update(order1, orderUpdateWrapper);
        // 结账成功 ,返回结果
        return ResultDTO.success();
    }
}

QueryUtils工具类

内置店家名称的一个配置类

在这里插入图片描述

在这里插入图片描述

/**
 * @Package: cn.liuliang.quickdinesysstore.utils
 * @Author: liuliang
 * @CreateTime: 2020/10/31 - 15:30
 * @Description: 系统相关属性工具类
 */
@Data
@Component
@ConfigurationProperties(prefix = "quick")
public class QueryUtils {
    /**
     * 当前系统的店家名称
     */
    private String storeName;
}

1.7 编写订单mapper

在这里插入图片描述

public interface OrderMapper extends BaseMapper<Order> {

    /**
     * 分页条件查询所有订单列表
     *
     * @param orderPage             分页对象
     * @param orderQueryConditionVO 查询条件对象
     * @return
     */
    List<Order> selectAll(@Param("orderPage") Page<Order> orderPage, @Param("orderQueryConditionVO") OrderQueryConditionVO orderQueryConditionVO);

    /**
     * 根据订单中已点菜foods字段查询订单的所有菜品
     *
     * @param foods 已点菜字段
     * @return
     */
    List<AlreadyOrderDishesDTO> selectAlreadyOrderDishesByFoods(@Param("foods") Long foods);

    /**
     * 删除订单下的以点菜品信息
     *
     * @param foods id
     */
    void deleteAlreadyOrderDishes(@Param("foods") Long foods);

}
<?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="cn.liuliang.quickdinesysstore.mapper.OrderMapper">


    <resultMap id="order" type="cn.liuliang.quickdinesysstore.entity.Order">
        <result property="id" javaType="long" column="id"/>
        <result property="storeName" javaType="string" column="store_name"/>
        <result property="diningTableNumber" javaType="string" column="dining_table_number"/>
        <result property="orderDishesPeopleName" javaType="string" column="order_dishes_people_name"/>
        <result property="orderDishesPeoplePhone" javaType="string" column="order_dishes_people_phone"/>
        <result property="foods" javaType="long" column="foods"/>
        <result property="money" javaType="java.math.BigDecimal" column="money"/>
        <result property="integral" javaType="integer" column="integral"/>
        <result property="isSettleAccounts" javaType="integer" column="is_settle_accounts"/>
        <result property="orderTime" javaType="date" column="order_time"/>
        <result property="settleAccountsTime" javaType="date" column="settle_accounts_time"/>
    </resultMap>
    <select id="selectAll" resultMap="order">
        SELECT
            t_order.`id`,
            t_order.`store_name`,
            t_order.`dining_table_number`,
            t_order.`order_dishes_people_name`,
            t_order.`order_dishes_people_phone`,
            t_order.`foods`,
            t_order.`money`,
            t_order.`integral`,
            t_order.`is_settle_accounts`,
            t_order.`order_time`,
            t_order.`settle_accounts_time`
        FROM t_order
        <where>
                AND t_order.`store_name` = #{orderQueryConditionVO.storeName}
            <if test="orderQueryConditionVO.diningTableNumber != null and orderQueryConditionVO.diningTableNumber != ''">
                AND t_order.`dining_table_number` = #{orderQueryConditionVO.diningTableNumber}
            </if>
            <if test="orderQueryConditionVO.isSettleAccounts != null">
                AND t_order.`is_settle_accounts` = #{orderQueryConditionVO.isSettleAccounts}
            </if>
            <if test="orderQueryConditionVO.orderDishesPeoplePhone != null and orderQueryConditionVO.orderDishesPeoplePhone != ''">
                AND t_order.`order_dishes_people_phone` = #{orderQueryConditionVO.orderDishesPeoplePhone}
            </if>
            <if test="orderQueryConditionVO.money != null">
                AND t_order.`money` = #{orderQueryConditionVO.money}
            </if>
            <if test="orderQueryConditionVO.orderTime != null and orderQueryConditionVO.orderTime != ''">
                AND DATE_FORMAT(t_order.`order_time`, '%Y-%m-%d') = DATE_FORMAT(#{orderQueryConditionVO.orderTime}, '%Y-%m-%d')
            </if>
        </where>
        ORDER BY t_order.`update_time` DESC
    </select>

    <resultMap id="alreadyOrderDishesDTO" type="cn.liuliang.quickdinesysstore.entity.dto.AlreadyOrderDishesDTO">
        <result property="id" javaType="long" column="id"/>
        <result property="dishesId" javaType="long" column="dishes_id"/>
        <result property="imageUrl" javaType="string" column="image_url"/>
        <result property="dishesName" javaType="string" column="dishes_name"/>
        <result property="price" javaType="java.math.BigDecimal" column="price"/>
        <result property="number" javaType="integer" column="number"/>
    </resultMap>
    <select id="selectAlreadyOrderDishesByFoods" resultMap="alreadyOrderDishesDTO">
        SELECT
            t_already_order_dishes.`id`,
            t_already_order_dishes.`dishes_id`,
            t_dishes.`image_url`,
            t_dishes.`dishes_name`,
            t_dishes.`price`,
            t_already_order_dishes.`number`
        FROM
        t_already_order_dishes
        LEFT JOIN t_dishes ON t_dishes.`id` = t_already_order_dishes.`dishes_id`
        WHERE t_already_order_dishes.`id` = #{foods}
    </select>

    <delete id="deleteAlreadyOrderDishes">
        DELETE FROM t_already_order_dishes WHERE id = #{foods}
    </delete>
</mapper>

1.8 启动项目swagger测试

http://localhost:9110/swagger-ui.html#/

在这里插入图片描述

结束语

  • 由于博主才疏学浅,难免会有纰漏,假如你发现了错误或偏见的地方,还望留言给我指出来,我会对其加以修正。
  • 如果你觉得文章还不错,你的转发、分享、点赞、留言就是对我最大的鼓励。
  • 感谢您的阅读,十分欢迎并感谢您的关注。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

J3code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值