package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsAppFieldMapper;
import com.gxwebsoft.cms.service.CmsAppFieldService;
import com.gxwebsoft.cms.entity.CmsAppField;
import com.gxwebsoft.cms.param.CmsAppFieldParam;
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-09-10 20:36:14
 */
@Service
public class CmsAppFieldServiceImpl extends ServiceImpl<CmsAppFieldMapper, CmsAppField> implements CmsAppFieldService {

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

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

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

    @Override
    public CmsAppField getByCodeRel(String code) {
      CmsAppFieldParam param = new CmsAppFieldParam();
      param.setName(code);
      return param.getOne(baseMapper.selectListRel(param));
    }

}
