package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.SpecValueMapper;
import com.gxwebsoft.shop.service.SpecValueService;
import com.gxwebsoft.shop.entity.SpecValue;
import com.gxwebsoft.shop.param.SpecValueParam;
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-04-01 09:49:15
 */
@Service
public class SpecValueServiceImpl extends ServiceImpl<SpecValueMapper, SpecValue> implements SpecValueService {

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

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

    @Override
    public SpecValue getByIdRel(Integer specValueId) {
        SpecValueParam param = new SpecValueParam();
        param.setSpecValueId(specValueId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
