package com.customization.htsc.jgxtlc;

import com.engine.common.util.ParamUtil;
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.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;

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


@CommandDynamicProxy(target = RequestSubmitCmd.class, desc = "监管协同流程流程提交更新主表附件")
public class JgxtlcRequestSubmitUpdateFjCmd extends AbstractCommandProxy<Map<String, Object>> {
    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> command) {

        BaseBean bb = new BaseBean();
        bb.writeLog("JgxtlcRequestSubmitUpdateFjCmd");
        RecordSet rs = new RecordSet();
        RequestSubmitCmd requestSubmitCmd = (RequestSubmitCmd) command;
        HttpServletRequest request = requestSubmitCmd.getRequest(); //从request中可以取到参数，不用以前的方法了
        //Map<String,Object> param = ParamUtil.request2Map(request);

        String requestid = Util.null2String(request.getParameter("requestid"));
        String workflowid = Util.null2String(request.getParameter("workflowid"));
        String nodeid = Util.null2String(request.getParameter("nodeid"));
        String formid = Util.null2String(request.getParameter("formid")) ;

        String src = Util.null2String(request.getParameter("src"));
        bb.writeLog("requestid:"+requestid);
        bb.writeLog("workflowid:"+workflowid );
        bb.writeLog("src:"+src);
        Map<String, Object> result  = nextExecute(command);;
        try{
//            RequestOperationResultBean resultBean = (RequestOperationResultBean) result.get("data");
//            Map<String, Object> messagemap = resultBean.getMessageInfo();
//
//            String isSuccess = Util.null2String(messagemap.get("isSuccess"));
//            bb.writeLog("JgxtlcRequestSubmitUpdateFjCmd---isSuccess:"+isSuccess);

            if(!"".equals(nodeid))
            {
                int current_nodeid = Util.getIntValue(nodeid);
                if(("submit".equals(src) || "reject".equals(src)) && current_nodeid < 0)
                {
                    bb.writeLog("3333333");
                    if(!"".equals(workflowid)){
                        String unnumber = "" ;
                        String sql = " select unnumber from workflow_base where id="+workflowid;
                        rs.execute(sql);
                        if(rs.next()){
                            unnumber = Util.null2String(rs.getString("unnumber"));
                        }
                        bb.writeLog("unnumber："+unnumber);
                        if("jgxtsq".equals(unnumber)){
                            sql = " update formtable_main_"+Math.abs(Util.getIntValue(formid))+" set fkfj='' where requestid="+requestid;
                            boolean flag = rs.execute(sql);
                            bb.writeLog("JgxtlcRequestSubmitUpdateFjCmd---flag:"+flag);
                        }
                    }
                }else{
                    bb.writeLog("4444444：");
                }
            }
        }catch (Exception e){
            bb.writeLog("JgxtlcRequestSubmitUpdateFjCmd："+e);
        }
        return result;
    }







}
