package com.ningdatech.pmapi.sys.project;

import cn.hutool.core.date.StopWatch;
import com.alibaba.fastjson.JSON;
import com.ningdatech.pmapi.AppTests;
import com.ningdatech.pmapi.common.statemachine.event.ProjectStatusChangeEvent;
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils;
import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.service.IProjectService;
import org.junit.Test;

import javax.annotation.Resource;

/**
 * @Classname ProjectStateTest
 * @Description
 * @Date 2023/2/8 11:12
 * @Author PoffyZhang
 */
public class ProjectStateTest extends AppTests {

    @Resource
    private StateMachineUtils stateMachineUtils;

    @Resource
    private IProjectService projectService;

    @Test
    public void execute() throws Exception {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        System.out.println("调用状态机开始");

        Project project = new Project();
        project.setInstCode("1");
        project.setId(1L);
        project.setStage(ProjectStatusEnum.NOT_APPROVED.getCode());
        project.setStatus(ProjectStatusEnum.PENDING_PREQUALIFICATION.getCode());
        //调用状态机 进入下一个通过状态
        stateMachineUtils.execute(project,stateMachineUtils.getProjectStatusPassEvent(project.getStatus()));

        stopWatch.stop();
        System.out.println("调用状态机结束 :" + stopWatch.getTotalTimeSeconds());
    }

    @Test
    public void getProject() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        Project project = projectService.getById(1);

        stopWatch.stop();
        System.out.println("project :" + JSON.toJSONString(project));
    }
}
