package cc.smtweb.system.bpm.web.design.flow.define;

import cc.smtweb.system.bpm.web.design.flow.FlowConst;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Akmm at 2022/5/21 10:48
 * 流程定义信息
 */
@Data
public class ProcInfo {
    //默认表单定义
    private String page;
    //是否允许编辑非本人单据
    private boolean canEditOther;
    //1-驳回到制单 0-逐级驳回
    private boolean rejectToMake;
    //活动节点
    private List<Activity> activities;
    //连接线
    private List<Trans> trans;

    public Activity findActivity(String id) {
        if (StringUtils.isEmpty(id)) return null;
        for (Activity act : activities) {
            if (id.equalsIgnoreCase(act.getId())) {
                return act;
            }
        }
        return null;
    }

    //获取任务名称
    public String getActNameById(String id) {
        Activity act = findActivity(id);
        return act != null ? act.getLabel(): "";
    }

    //获取结束节点
    public List<Activity> findEndActivity() {
        List<Activity> list = new ArrayList<>();
        for (Activity act : activities) {
            if (act.getType() == FlowConst.ActivityType.END.value) {
                list.add(act);
            }
        }
        return list;
    }
}
