package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.DealerSettingMapper;
import com.gxwebsoft.shop.service.DealerSettingService;
import com.gxwebsoft.shop.entity.DealerSetting;
import com.gxwebsoft.shop.param.DealerSettingParam;
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 2024-07-28 11:57:41
 */
@Service
public class DealerSettingServiceImpl extends ServiceImpl<DealerSettingMapper, DealerSetting> implements DealerSettingService {

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

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

    @Override
    public DealerSetting getByIdRel(String key) {
        DealerSettingParam param = new DealerSettingParam();
        param.setKey(key);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
