package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.MerchantVoiceDeviceMapper;
import com.gxwebsoft.shop.service.MerchantVoiceDeviceService;
import com.gxwebsoft.shop.entity.MerchantVoiceDevice;
import com.gxwebsoft.shop.param.MerchantVoiceDeviceParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商铺播报设备Service实现
 *
 * @author 科技小王子
 * @since 2025-05-28 21:07:20
 */
@Service
public class MerchantVoiceDeviceServiceImpl extends ServiceImpl<MerchantVoiceDeviceMapper, MerchantVoiceDevice> implements MerchantVoiceDeviceService {

    @Override
    public PageResult<MerchantVoiceDevice> pageRel(MerchantVoiceDeviceParam param) {
        PageParam<MerchantVoiceDevice, MerchantVoiceDeviceParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<MerchantVoiceDevice> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<MerchantVoiceDevice> listRel(MerchantVoiceDeviceParam param) {
        List<MerchantVoiceDevice> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<MerchantVoiceDevice, MerchantVoiceDeviceParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public MerchantVoiceDevice getByIdRel(Integer id) {
        MerchantVoiceDeviceParam param = new MerchantVoiceDeviceParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public List<MerchantVoiceDevice> listInMerchant(Integer merchantId) {
        return list(
                new LambdaQueryWrapper<MerchantVoiceDevice>()
                        .eq(MerchantVoiceDevice::getMerchantId, merchantId)
        );
    }

}
