package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.WebsiteFieldMapper;
import com.gxwebsoft.cms.service.WebsiteFieldService;
import com.gxwebsoft.cms.entity.WebsiteField;
import com.gxwebsoft.cms.param.WebsiteFieldParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * 应用参数Service实现
 *
 * @author 科技小王子
 * @since 2024-03-05 15:53:44
 */
@Service
public class WebsiteFieldServiceImpl extends ServiceImpl<WebsiteFieldMapper, WebsiteField> implements WebsiteFieldService {

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

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

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

}
