package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.TestDataMapper;
import com.gxwebsoft.apps.service.TestDataService;
import com.gxwebsoft.apps.entity.TestData;
import com.gxwebsoft.apps.param.TestDataParam;
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 2023-02-01 12:13:46
 */
@Service
public class TestDataServiceImpl extends ServiceImpl<TestDataMapper, TestData> implements TestDataService {

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

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

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

}
