package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerProjectMapper;
import com.gxwebsoft.tower.service.TowerProjectService;
import com.gxwebsoft.tower.entity.TowerProject;
import com.gxwebsoft.tower.param.TowerProjectParam;
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 2023-05-22 13:30:39
 */
@Service
public class TowerProjectServiceImpl extends ServiceImpl<TowerProjectMapper, TowerProject> implements TowerProjectService {

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

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

    @Override
    public TowerProject getByIdRel(Integer projectId) {
        TowerProjectParam param = new TowerProjectParam();
        param.setProjectId(projectId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
