package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.oa.entity.App;
import com.gxwebsoft.oa.mapper.AppMapper;
import com.gxwebsoft.oa.param.AppParam;
import com.gxwebsoft.oa.service.AppService;
import com.gxwebsoft.oa.service.AppUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 应用管理记录表Service实现
 *
 * @author 科技小王子
 * @since 2023-03-28 10:45:39
 */
@Service
public class AppServiceImpl extends ServiceImpl<AppMapper, App> implements AppService {
    @Resource
    private AppUserService appUserService;

    @Override
    public PageResult<App> pageRel(AppParam param) {
      PageParam<App, AppParam> page = new PageParam<>(param);
        page.setDefaultOrder("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("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));
    }

}
