package com.hz.pm.api.sys.project;

import cn.hutool.core.date.StopWatch;
import com.alibaba.fastjson.JSON;
import com.hz.pm.api.AppTests;
import com.hz.pm.api.common.statemachine.util.StateMachineUtil;
import com.hz.pm.api.projectlib.model.enumeration.ProjectStatusEnum;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.hz.pm.api.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 StateMachineUtil stateMachineUtil;

    @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());
        //调用状态机 进入下一个通过状态
        stateMachineUtil.pass(project);

        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));
    }
}
