package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.DealerOrderMapper;
import com.gxwebsoft.shop.service.DealerOrderService;
import com.gxwebsoft.shop.entity.DealerOrder;
import com.gxwebsoft.shop.param.DealerOrderParam;
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 DealerOrderServiceImpl extends ServiceImpl<DealerOrderMapper, DealerOrder> implements DealerOrderService {

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

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

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

}
