package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.SpecMapper;
import com.gxwebsoft.shop.service.SpecService;
import com.gxwebsoft.shop.entity.Spec;
import com.gxwebsoft.shop.param.SpecParam;
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 2024-07-25 03:00:41
 */
@Service
public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements SpecService {

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

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

    @Override
    public Spec getByIdRel(Integer specId) {
        SpecParam param = new SpecParam();
        param.setSpecId(specId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
