package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.MerchantAccountMapper;
import com.gxwebsoft.shop.service.MerchantAccountService;
import com.gxwebsoft.shop.entity.MerchantAccount;
import com.gxwebsoft.shop.param.MerchantAccountParam;
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-04-19 12:02:24
 */
@Service
public class MerchantAccountServiceImpl extends ServiceImpl<MerchantAccountMapper, MerchantAccount> implements MerchantAccountService {

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

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

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

}
