package com.customization.htsc.cus;

import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import com.engine.htsc.sfxzdj.service.impl.SfxzdjServiceImpl;
import com.engine.workflow.cmd.requestForm.RequestSubmitCmd;
import com.engine.workflow.entity.requestForm.RequestOperationResultBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * 触发流程
 */
@CommandDynamicProxy(target = RequestSubmitCmd.class, desc = "流程提交处理业务")
public class SfxzdjTriggerFlowCmd  extends AbstractCommandProxy<Map<String, Object>> {
    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> targetCommand) {
        RequestSubmitCmd requestSubmitCmd = (RequestSubmitCmd) targetCommand;
        HttpServletRequest request = requestSubmitCmd.getRequest();//从request中可以取到参数，不用以前的方法了
        String requestid = Util.null2String(request.getParameter("requestid"));
        String workflowid = Util.null2String(request.getParameter("workflowid"));
        String nodetype = Util.null2String(request.getParameter("nodetype"));
        String nodeid = Util.null2String(request.getParameter("nodeid"));
        String src = Util.null2String(request.getParameter("src"));
        String remark = Util.HTMLtoTxt(Util.null2String(request.getParameter("remark"))).trim();
        String operator = Util.null2String(request.getParameter("f_weaver_belongto_userid"));
        PropBean pb = new PropBean();
        String sfxzdj_workflowid = pb.getPropName("sfxzdj_workflowid");

        JAVATools.writelog("司法协助登记cmdsfxzdj_workflowid"+sfxzdj_workflowid);
        String sfxzdj_nodeid = pb.getPropName("sfxzdj_nodeid");
        JAVATools.writelog("司法协助登记cmdsfxzdj_nodeid"+sfxzdj_nodeid);
        //执行标准的业务处理
        Map<String, Object> result = nextExecute(targetCommand);
        RequestOperationResultBean resultBean = (RequestOperationResultBean) result.get("data");
        String executeResult = resultBean.getType().name();

        if ("SUCCESS".equals(executeResult) && "submit".equals(src)) {
            if(workflowid.equals(sfxzdj_workflowid)&&sfxzdj_nodeid.equals(nodeid) ){
                SfxzdjServiceImpl service = new SfxzdjServiceImpl();
                HashMap<String, Object> map = new HashMap<>();
                map.put("requestid",requestid);
                map.put("user",operator);
                JAVATools.writelog("司法协助登记cmd"+map.toString());
                service.triggerFlow(map);
            }

        }

        return result;
    }
}
