package com.customization.htsc.integration;

import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import com.engine.workflow.cmd.requestForm.ForwardSubmitCmd;
import weaver.general.Util;
import weaver.filter.WeaverRequest;
import weaver.workflow.request.WFAutoApproveThreadPoolUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Author:wanxq
 * Date:2021/3/25 16:53
 * Description: 集成门户统一已办
 * Copyright:上海泛微网络科技股份有限公司
 */
@CommandDynamicProxy(target = ForwardSubmitCmd.class, desc = "转办提交后将已办数据推送到门户")
public class PushFowardDoneDataCmd extends AbstractCommandProxy<Map<String, Object>> {
    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> targetCommand) {
        ForwardSubmitCmd forwardSubmitCmd = (ForwardSubmitCmd) targetCommand;
        HttpServletRequest request = forwardSubmitCmd.getRequest();//从request中可以取到参数，不用以前的方法了
        String forwardflag = Util.null2String(request.getParameter("forwardflag"));
        //System.out.println("PushFowardDoneDataCmd=====forwardflag==="+ forwardflag);
        //执行标准的业务处理
        Map<String, Object> result = nextExecute(targetCommand);
        //System.out.println("PushFowardDoneDataCmd====="+ JSON.toJSONString(result));
        boolean exeResult = (boolean) result.get("success");

        //3：转办   2：意见征询
        if(exeResult && ("2".equals(forwardflag) || "3".equals(forwardflag) || "5".equals(forwardflag) )){
            //创建线程处理已办数据推送
            WeaverRequest weaverRequest = new WeaverRequest(request);
            PushForwardDataThread pushForwardDataThread = new PushForwardDataThread(weaverRequest);
            WFAutoApproveThreadPoolUtil.getFixedThreadPool().execute(pushForwardDataThread);

        }

        return result;
    }


    public static void main(String[] args) {

    }
}
