package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.BcFoodMapper;
import com.gxwebsoft.apps.service.BcFoodService;
import com.gxwebsoft.apps.entity.BcFood;
import com.gxwebsoft.apps.param.BcFoodParam;
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-04-27 17:59:40
 */
@Service
public class BcFoodServiceImpl extends ServiceImpl<BcFoodMapper, BcFood> implements BcFoodService {

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

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

    @Override
    public BcFood getByIdRel(Integer bcFoodId) {
        BcFoodParam param = new BcFoodParam();
        param.setBcFoodId(bcFoodId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
