package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.FormRecordMapper;
import com.gxwebsoft.cms.service.FormRecordService;
import com.gxwebsoft.cms.entity.FormRecord;
import com.gxwebsoft.cms.param.FormRecordParam;
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 FormRecordServiceImpl extends ServiceImpl<FormRecordMapper, FormRecord> implements FormRecordService {

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

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

    @Override
    public FormRecord getByIdRel(Integer formRecordId) {
        FormRecordParam param = new FormRecordParam();
        param.setFormRecordId(formRecordId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
