package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.MpFieldMapper;
import com.gxwebsoft.cms.service.MpFieldService;
import com.gxwebsoft.cms.entity.MpField;
import com.gxwebsoft.cms.param.MpFieldParam;
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-22 12:54:13
 */
@Service
public class MpFieldServiceImpl extends ServiceImpl<MpFieldMapper, MpField> implements MpFieldService {

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

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

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

}
