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.OrderOperateHistoryDto;
import com.mall.order.domain.entity.OrderOperateHistory;
import com.mall.order.domain.vo.OrderOperateHistoryVo;
import com.mall.order.mapper.OrderOperateHistoryMapper;
import com.mall.order.service.OrderOperateHistoryService;
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 OrderOperateHistoryServiceImpl extends ServiceImpl<OrderOperateHistoryMapper, OrderOperateHistory> implements OrderOperateHistoryService {

    /**
     * * 订单操作历史记录 服务实现类
     *
     * @param pageParams 订单操作历史记录分页查询page对象
     * @param dto        订单操作历史记录分页查询对象
     * @return 查询分页订单操作历史记录返回对象
     */
    @Override
    public PageResult<OrderOperateHistoryVo> getOrderOperateHistoryPage(Page<OrderOperateHistory> pageParams, OrderOperateHistoryDto dto) {
        IPage<OrderOperateHistoryVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加订单操作历史记录
     *
     * @param dto 订单操作历史记录添加
     */
    @Override
    public void addOrderOperateHistory(OrderOperateHistoryDto dto) {
        OrderOperateHistory orderOperateHistory = new OrderOperateHistory();
        BeanUtils.copyProperties(dto, orderOperateHistory);
        save(orderOperateHistory);
    }

    /**
     * 更新订单操作历史记录
     *
     * @param dto 订单操作历史记录更新
     */
    @Override
    public void updateOrderOperateHistory(OrderOperateHistoryDto dto) {
        OrderOperateHistory orderOperateHistory = new OrderOperateHistory();
        BeanUtils.copyProperties(dto, orderOperateHistory);
        updateById(orderOperateHistory);
    }

    /**
     * 删除|批量删除订单操作历史记录
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteOrderOperateHistory(List<Long> ids) {
        removeByIds(ids);
    }
}