package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.HualalaCartFoodMapper;
import com.gxwebsoft.apps.service.HualalaCartFoodService;
import com.gxwebsoft.apps.entity.HualalaCartFood;
import com.gxwebsoft.apps.param.HualalaCartFoodParam;
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-14 14:46:44
 */
@Service
public class HualalaCartFoodServiceImpl extends ServiceImpl<HualalaCartFoodMapper, HualalaCartFood> implements HualalaCartFoodService {

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

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

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

}
