package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.OaAppMapper;
import com.gxwebsoft.oa.service.OaAppService;
import com.gxwebsoft.oa.entity.OaApp;
import com.gxwebsoft.oa.param.OaAppParam;
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-09-10 20:57:41
 */
@Service
public class OaAppServiceImpl extends ServiceImpl<OaAppMapper, OaApp> implements OaAppService {

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

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

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

}
