package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.AssetsMapper;
import com.gxwebsoft.oa.service.AssetsService;
import com.gxwebsoft.oa.entity.Assets;
import com.gxwebsoft.oa.param.AssetsParam;
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 WebSoft
 * @since 2022-11-16 11:13:16
 */
@Service
public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets> implements AssetsService {

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

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

    @Override
    public Assets getByIdRel(Integer assetsId) {
        AssetsParam param = new AssetsParam();
        param.setAssetsId(assetsId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
