package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.GoodsServiceMapper;
import com.gxwebsoft.shop.service.GoodsServiceService;
import com.gxwebsoft.shop.entity.GoodsService;
import com.gxwebsoft.shop.param.GoodsServiceParam;
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 2022-11-23 21:57:50
 */
@Service
public class GoodsServiceServiceImpl extends ServiceImpl<GoodsServiceMapper, GoodsService> implements GoodsServiceService {

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

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

    @Override
    public GoodsService getByIdRel(Integer serviceId) {
        GoodsServiceParam param = new GoodsServiceParam();
        param.setServiceId(serviceId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
