package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.AppMapper;
import com.gxwebsoft.oa.service.AppService;
import com.gxwebsoft.oa.entity.App;
import com.gxwebsoft.oa.param.AppParam;
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-10-26 22:06:23
 */
@Service
public class AppServiceImpl extends ServiceImpl<AppMapper, App> implements AppService {

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

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

    @Override
    public App getByIdRel(Integer appId) {
        AppParam param = new AppParam();
        param.setAppId(appId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
