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.RequestSubmitCmd;
import com.engine.workflow.entity.requestForm.RequestOperationResultBean;
import weaver.filter.WeaverRequest;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.workflow.request.WFAutoApproveThreadPoolUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Author:wanxq
 * Date:2021/3/17 14:53
 * Description: 集成门户统一已办
 * Copyright:上海泛微网络科技股份有限公司
 */
@CommandDynamicProxy(target = RequestSubmitCmd.class, desc = "集成门户统一已办")
public class PushWorflowDoneDataCmd extends AbstractCommandProxy<Map<String, Object>> {
    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> targetCommand) {
        BaseBean bb = new BaseBean();
        RequestSubmitCmd requestSubmitCmd = (RequestSubmitCmd) targetCommand;
        HttpServletRequest request = requestSubmitCmd.getRequest();//从request中可以取到参数，不用以前的方法了
        String src = Util.null2String(request.getParameter("src"));
        String isremark = Util.null2String(request.getParameter("isremark"));
        String takisremark = Util.null2String(request.getParameter("takisremark"));

        //执行标准的业务处理
        Map<String, Object> result = nextExecute(targetCommand);
        RequestOperationResultBean resultBean = (RequestOperationResultBean) result.get("data");
        String executeResult = resultBean.getType().name();

        bb.writeLog("PushWorflowDoneDataCmd ======executeResult:"+executeResult+" src=="+src+" ===isremark:"+isremark+" ====takisremark:"+takisremark);


        if("SUCCESS".equals(executeResult)){
            //submit：正常提交  save： isremark 1、8、9转发、抄送  takisremark 2 意见征询
            if("submit".equals(src) || "reject".equals(src)
                    || ( "save".equals(src) && ("1".equals(isremark) || "8".equals(isremark)
                    || "9".equals(isremark) || "2".equals(takisremark)) )){
                //创建线程处理已办数据推送
                WeaverRequest weaverRequest = new WeaverRequest(request);
                PushDataThread pushDataThread = new PushDataThread(weaverRequest);
                WFAutoApproveThreadPoolUtil.getFixedThreadPool().execute(pushDataThread);
            }

        }

        return result;
    }


    public static void main(String[] args) {

    }
}
