package com.gxwebsoft.pwl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.pwl.mapper.PwlProjectLibraryMapper;
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
import com.gxwebsoft.pwl.param.PwlProjectLibraryParam;
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 2025-09-28 09:38:17
 */
@Service
public class PwlProjectLibraryServiceImpl extends ServiceImpl<PwlProjectLibraryMapper, PwlProjectLibrary> implements PwlProjectLibraryService {

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

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

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

}
