package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.HualalaFoodMapper;
import com.gxwebsoft.apps.service.HualalaFoodService;
import com.gxwebsoft.apps.entity.HualalaFood;
import com.gxwebsoft.apps.param.HualalaFoodParam;
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-01-12 15:34:55
 */
@Service
public class HualalaFoodServiceImpl extends ServiceImpl<HualalaFoodMapper, HualalaFood> implements HualalaFoodService {

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

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

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

    @Override
    public HualalaFood getByFoodId(Integer foodId) {
      return query().like("foodId", foodId).one();
    }

}
