package com.weaver.seconddev.njwebservice;

import com.weaver.seconddev.njwebservice.entity.SubmitWorkflowReq;
import com.weaver.seconddev.njwebservice.entity.SubmitWorkflowRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.regex.Pattern;


/**
 * 自动创建流程 webService
 */
@Service("autoCreateWorkflowEncService")
public class AutoCreateWorkflowEncService {

    private final static Logger log = LoggerFactory.getLogger(AutoCreateWorkflowEncService.class);

    @Autowired
    private AutoCreateWorkflowService autoCreateWorkflowService;

//    @Autowired
//    private SubmitWorkflowRes var12;

    public SubmitWorkflowRes createWorkflow(SubmitWorkflowReq var1) {
        log.error("AutoCreateWorkflowEncService createWorkflow start ");
        log.error("SubmitWorkflowReq ：  " + var1);
        String var2 = var1.getDATAS().getLoginname();
        log.error("var2 ：  " + var2);

        String var3 = var1.getDATAS().getPassword();
        String var4 = var1.getDATAS().getWorkflowId();
        String var5 = var1.getDATAS().getCreator();
        String var6 = var1.getDATAS().getRequestLevel();
        String var7 = var1.getDATAS().getMainTable();
        String[] var8 = var1.getDATAS().getDetailTables();
        log.error("var8 ：  " + var8);

        String var9 = var1.getSYSID();
        log.error("var9 ：  " + var9);


        String var10 = var1.getSENDID();
        log.error("var10 ：  " + var10);

        String var11 = var1.getITFID();
        log.error("var11 ：  " + var11);


        SubmitWorkflowRes var12 = SubmitWorkflowRes.builder().build();

        var12.setITFID(var11);
        var12.setSYSID(var9);
        var12.setSENDID(var10);

        log.error("createWorkflow start ：  " + var12.toString());
        String var14 = autoCreateWorkflowService.createWorkflow(var2, var3, var4, var5, var6, var7, var8);
        if (isInteger(var14)) {
            var12.setISTAT("S");
            log.error(var5 + "创建流程id为" + var4 + "的流程成功!");
        } else {
            var12.setISTAT("F");
            log.error(var5 + "创建流程id为" + var4 + "的流程失败：" + var14);
        }

        var12.setMESSAGE(var14);
        return var12;
    }


    private  static boolean isInteger(String var0) {
        Pattern var1 = Pattern.compile("^\\+?[1-9][0-9]*$");
        return var1.matcher(var0).matches();
    }



}