package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.OaAssetsCodeMapper;
import com.gxwebsoft.oa.service.OaAssetsCodeService;
import com.gxwebsoft.oa.entity.OaAssetsCode;
import com.gxwebsoft.oa.param.OaAssetsCodeParam;
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-10-18 18:27:01
 */
@Service
public class OaAssetsCodeServiceImpl extends ServiceImpl<OaAssetsCodeMapper, OaAssetsCode> implements OaAssetsCodeService {

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

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

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

}
