package com.ningdatech.pmapi.projectlib.handle;

import com.ningdatech.pmapi.common.constant.CommonConst;
import com.ningdatech.pmapi.projectlib.enumeration.StepStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.model.vo.ProcessDetailVO;
import com.ningdatech.pmapi.projectlib.service.IProjectService;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 项目申报处理
 *
 * @author CMM
 * @since 2023/02/24 14:35
 */

@Order(1)
@Component
public class ProjectDeclareHandle extends AbstractProcessBusinessHandle {

    private final IProjectService projectService;

    public ProjectDeclareHandle(IProjectService projectService){
        this.projectService = projectService;
    }

    @Override
    void businessHandle(Long projectId, List<ProcessDetailVO> processSchedule) {
        // 因为此时在项目库中的项目，都是已经申报过的项目，所以直接设置环节状态为已完成
        ProcessDetailVO processDetailVO = new ProcessDetailVO();
        processDetailVO.setStepStatus(StepStatusEnum.COMPLETED);
        // 项目库中查出申报完成时间
        Project project = projectService.getById(projectId);
        LocalDateTime createOn = project.getCreateOn();
        processDetailVO.setFinishTime(createOn);
        processDetailVO.setProcessName(CommonConst.PROJECT_DECLARE);
        processSchedule.add(processDetailVO);
    }
}
