package com.hz.pm.api.projectlib.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hz.pm.api.projectlib.model.po.ProjectPO;
import com.hz.pm.api.projectlib.model.req.ProjectListReq;

import java.util.List;

/**
 * <p>
 * 服务类
 * </p>
 *
 * @author WendyYang
 * @since 2023-02-03
 */
public interface IProjectService extends IService<Project> {

    public List<Long> getAllVersionProjectId(Project project);

    public List<Long> getAllVersionProjectId(Long projectId);

    Project getNewProject(Long projectId);

    Project getNewConstructProject(Long projectId);

    Project getProjectByCode(String projectCode);

    Page<ProjectPO> pageAllWithPermission(Page<ProjectPO> page, ProjectListReq req);

    Page<ProjectPO> pageLibWithPermission(Page<ProjectPO> page, ProjectListReq req);

    default void reverseNewest(String projectCode, Long projectId) {
        LambdaUpdateWrapper<Project> wrapper = Wrappers.lambdaUpdate(Project.class)
                .set(Project::getNewest, Boolean.FALSE)
                .eq(Project::getNewest, Boolean.TRUE)
                .eq(Project::getProjectCode, projectCode)
                .ne(Project::getId, projectId);
        update(wrapper);
    }

}
