package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.BcCookbookMapper;
import com.gxwebsoft.apps.service.BcCookbookService;
import com.gxwebsoft.apps.entity.BcCookbook;
import com.gxwebsoft.apps.param.BcCookbookParam;
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-05-05 14:56:54
 */
@Service
public class BcCookbookServiceImpl extends ServiceImpl<BcCookbookMapper, BcCookbook> implements BcCookbookService {

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

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

    @Override
    public BcCookbook getByIdRel(Integer cookbookId) {
        BcCookbookParam param = new BcCookbookParam();
        param.setCookbookId(cookbookId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
