package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.CountMapper;
import com.gxwebsoft.shop.service.CountService;
import com.gxwebsoft.shop.entity.Count;
import com.gxwebsoft.shop.param.CountParam;
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-31 22:25:10
 */
@Service
public class CountServiceImpl extends ServiceImpl<CountMapper, Count> implements CountService {

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

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

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

}
