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.MqMessageDto;
import com.mall.order.domain.entity.MqMessage;
import com.mall.order.domain.vo.MqMessageVo;
import com.mall.order.mapper.MqMessageMapper;
import com.mall.order.service.MqMessageService;
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 MqMessageServiceImpl extends ServiceImpl<MqMessageMapper, MqMessage> implements MqMessageService {

    /**
     * *  服务实现类
     *
     * @param pageParams 分页查询page对象
     * @param dto        分页查询对象
     * @return 查询分页返回对象
     */
    @Override
    public PageResult<MqMessageVo> getMqMessagePage(Page<MqMessage> pageParams, MqMessageDto dto) {
        IPage<MqMessageVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加
     *
     * @param dto 添加
     */
    @Override
    public void addMqMessage(MqMessageDto dto) {
        MqMessage mqMessage = new MqMessage();
        BeanUtils.copyProperties(dto, mqMessage);
        save(mqMessage);
    }

    /**
     * 更新
     *
     * @param dto 更新
     */
    @Override
    public void updateMqMessage(MqMessageDto dto) {
        MqMessage mqMessage = new MqMessage();
        BeanUtils.copyProperties(dto, mqMessage);
        updateById(mqMessage);
    }

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