package com.mall.order.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.order.domain.dto.OrderDto;
import com.mall.order.domain.entity.Order;
import com.mall.order.domain.vo.OrderVo;
import com.mall.order.mapper.OrderMapper;
import com.mall.order.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 18:54:06
 */
@Service
@Transactional
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    /**
     * * 订单 服务实现类
     *
     * @param pageParams 订单分页查询page对象
     * @param dto        订单分页查询对象
     * @return 查询分页订单返回对象
     */
    @Override
    public PageResult<OrderVo> getOrderPage(Page<Order> pageParams, OrderDto dto) {
        IPage<OrderVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<OrderVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 添加订单
     *
     * @param dto 订单添加
     */
    @Override
    public void addOrder(OrderDto dto) {
        Order order = new Order();
        BeanUtils.copyProperties(dto, order);
        save(order);
    }

    /**
     * 更新订单
     *
     * @param dto 订单更新
     */
    @Override
    public void updateOrder(OrderDto dto) {
        Order order = new Order();
        BeanUtils.copyProperties(dto, order);
        updateById(order);
    }

    /**
     * 删除|批量删除订单
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteOrder(List<Long> ids) {
        removeByIds(ids);
    }
}