package com.gxwebsoft.love.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.love.mapper.ProfitMapper;
import com.gxwebsoft.love.service.ProfitService;
import com.gxwebsoft.love.entity.Profit;
import com.gxwebsoft.love.param.ProfitParam;
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 2023-06-28 20:49:17
 */
@Service
public class ProfitServiceImpl extends ServiceImpl<ProfitMapper, Profit> implements ProfitService {

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

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

    @Override
    public Profit getByIdRel(Integer profitId) {
        ProfitParam param = new ProfitParam();
        param.setProfitId(profitId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
