package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.BcPlanMapper;
import com.gxwebsoft.apps.service.BcPlanService;
import com.gxwebsoft.apps.entity.BcPlan;
import com.gxwebsoft.apps.param.BcPlanParam;
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 BcPlanServiceImpl extends ServiceImpl<BcPlanMapper, BcPlan> implements BcPlanService {

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

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

    @Override
    public BcPlan getByIdRel(Integer bcPlanId) {
        BcPlanParam param = new BcPlanParam();
        param.setBcPlanId(bcPlanId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
