package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.FormMapper;
import com.gxwebsoft.cms.service.FormService;
import com.gxwebsoft.cms.entity.Form;
import com.gxwebsoft.cms.param.FormParam;
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-03-14 08:59:33
 */
@Service
public class FormServiceImpl extends ServiceImpl<FormMapper, Form> implements FormService {

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

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

    @Override
    public Form getByIdRel(Integer formId) {
        FormParam param = new FormParam();
        param.setFormId(formId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
