package com.weaver.seconddev.interfaces.workflow.action;

import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.verupgrade.conn.CONN_TYPE;
import java.util.*;
import com.weaver.verupgrade.workflow.request.RequestManager;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.common.base.entity.result.WeaResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.weaver.verupgrade.soa.workflow.request.RequestInfo;
import java.util.Map;
import java.util.HashMap;
import com.weaver.verupgrade.conn.RecordSet;
import com.weaver.verupgrade.conn.RecordSetDataSource;
import com.weaver.verupgrade.general.TimeUtil;
import com.weaver.verupgrade.general.Util;
import com.weaver.verupgrade.interfaces.workflow.action.Action;
import com.weaver.verupgrade.soa.workflow.request.Property;
import com.weaver.verupgrade.soa.workflow.request.Cell;
import com.weaver.verupgrade.soa.workflow.request.DetailTable;
import com.weaver.verupgrade.soa.workflow.request.Row;


//废弃
@org.springframework.stereotype.Service("workflow_action_YongGongXuQiuAction")
public class YongGongXuQiuAction implements Action, EsbServerlessRpcRemoteInterface {

    // 对应E9的请求信息对象
    @Autowired
    private RequestInfo requestInfoTemp;

    private static final Logger logger_42aadd27 = LoggerFactory.getLogger(YongGongXuQiuAction.class);

    private Log log = LogFactory.getLog(YongGongXuQiuAction.class.getName());

    public Log getLog() {
        return log;
    }

    public void setLog(Log log) {
        this.log = log;
    }

    public WeaResult<Map<String, Object>> execute(Map<String, Object> requestInfoMap) {
        return null ;
//        logger_42aadd27.error("YongGongXuQiuAction start");
//        Map<String, Object> weaverResultMap = new HashMap<>();
//        Long requestIdTemp = Long.parseLong(String.valueOf(requestInfoMap.getOrDefault("requestid", -1)));
//        Long userIdTemp = Long.parseLong(String.valueOf(requestInfoMap.getOrDefault("userid", -1)));
//        RequestInfo request = requestInfoTemp.getRequestInfo(requestIdTemp, userIdTemp);
//        // int departmentId = Util.getIntValue(rs2.getString("id"));
//        // String GWXL = "";//岗位序列
//        // String GWLX = "";//岗位类型
//        // String PositionStatus = "0"; //是否新增岗位
//        // RecordSet rs3 = new RecordSet();
//        // rs3.executeSql("select * from HrmJobTitles where id="+XQGW);
//        // if (!rs3.next()){
//        // PositionStatus = "1";
//        // }
//        try {
//            log.error("do action on request:" + request.getRequestid());
//            String requestid = request.getRequestid();
////            String lastoperator = request.getLastoperator();
////            String creater = request.getCreatorid();
//            RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
////            RecordSet rs2 = I18nContextUtil.getBean(RecordSet.class);
////            String workflowid = request.getWorkflowid();
////            String maintable = "";
////            String sql = "select b.tablename from e10_common.dbo.wfp_base a,e10_common.dbo.form b where a.formid = b.id and a.id = " + workflowid;
////            logger_42aadd27.error("getMainTableInfo sql = " + sql);
////            String createsqlString = "select id  from eteams.dbo.employee as  hrmresource where lastname ='" + creater + "'";
////            String poolname = CONN_TYPE.workflow.getType();
//            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
////            boolean b = rs2.executeSql(createsqlString, poolname);
////            logger_42aadd27.error("getMainTableInfo rs2.executeSql = " + b);
////            rs2.next();
////            String createrId = rs2.getString("id");
////            String poolname_hy = CONN_TYPE.workflow.getType();
//            // int departmentId = Util.getIntValue(rs2.getString("id"));
//            /*        String creater = rs2.getString("departmentmark") + "_" + rs2.getString("lastname");
// TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源*/
////            boolean b1 = rs.executeSql(sql, poolname_hy);
////            logger_42aadd27.error("getMainTableInfo rs.executeSql = " + b1);
////            while (rs.next()) {
////                maintable = rs.getString("tablename");
////            }
//            // 需求部门
//            String XQBM = "";
//            // String GWXL = "";//岗位序列
//            // String GWLX = "";//岗位类型
//            // 需求岗位
//            String XQGW = "";
//            // 申请日期
//            String SQRQ = "";
//            // 需求人数
//            String XQRS = "";
//            // 希望报到期限
//            String XWBDQX = "";
//            // 增补方式
//            String ZBFS = "";
//            // 需求原因
//            String XQYY = "";
//            String DeptID = "";
//            String positionID = "";
//            // 离职补员
//            String LZBY = "";
//            // 人员调动替补
//            String RYDD = "";
//            // 新增岗位或人员
//            String XZGWRY = "";
//            // 人才储备
//            String RCCB = "";
//            // String PositionStatus = "0"; //是否新增岗位
//            // 获取表单主字段信息
//            Property[] properties = request.getMainTableInfo().getProperty();
//            for (int i = 0; i < properties.length; i++) {
//                // 主表数据
//                // 字段名
//                String name = properties[i].getName().toUpperCase();
//                // 值
//                String value = Util.null2String(properties[i].getValue());
//                if (name.equals("XQBM")) {
//                    XQBM = value;
//                    String poolname_rh = CONN_TYPE.workflow.getType();
//                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                    String sql1 = "select code from eteams.dbo.department as  HrmDepartment where id =" + XQBM;
//                    logger_42aadd27.error("getMainTableInfo sql = " + sql1);
//                    rs.executeSql(sql1, poolname_rh);
//                    rs.next();
//                    DeptID = Util.null2String(rs.getString("departmentcode"));
//                } else if (name.equals("XQGW")) {
//                    XQGW = value;
//                    String poolname_qe = CONN_TYPE.workflow.getType();
//                    // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                    String sql1 = "select code from position as  HrmJobTitles where id =" + XQGW;
//                    logger_42aadd27.error("getMainTableInfo sql = " + sql1);
//                    rs.executeSql(sql1, poolname_qe);
//                    rs.next();
//                    positionID = Util.null2String(rs.getString("jobtitlecode"));
//                } else if (name.equals("SQRQ")) {
//                    SQRQ = value;
//                    SQRQ = SQRQ.substring(0, 10);
//                } else if (name.equals("XWBDQX")) {
//                    XWBDQX = value;
//                    XWBDQX = XWBDQX.substring(0, 10);
//                } else if (name.equals("LZBY")) {
//                    LZBY = value;
//                } else if (name.equals("RYDD")) {
//                    RYDD = value;
//                } else if (name.equals("XZGWRY")) {
//                    XZGWRY = value;
//                } else if (name.equals("RCCB")) {
//                    RCCB = value;
//                } else if (name.equals("XQRS")) {
//                    XQRS = value;
//                } else if (name.equals("ZBFS")) {
//                    ZBFS = value;
//                }
//                logger_42aadd27.error(" YongGongXuQiuAction main:" + requestid + "	" + name + "	" + value);
//            }
//            if (!"".equals(LZBY)) {
//                XQYY = LZBY;
//            }
//            if (!"".equals(RYDD)) {
//                XQYY = RYDD;
//            }
//            if (!"".equals(XZGWRY)) {
//                XQYY = XZGWRY;
//            }
//            if (!"".equals(RCCB)) {
//                XQYY = RCCB;
//            }
//            String ZBFS2 = "";
//            if (ZBFS.equals("2")) {
//                ZBFS2 = "1";
//            } else {
//                ZBFS2 = "0";
//            }
//            // RecordSet rs3 = new RecordSet();
//            // rs3.executeSql("select * from HrmJobTitles where id="+XQGW);
//            // if (!rs3.next()){
//            // PositionStatus = "1";
//            // }
//            try {
//                logger_42aadd27.error("YongGongXuQiuAction  endPoint" );
//                // ApplyPositionFormWS(XQBM,XQGW,SQRQ,Integer.parseInt(XQRS),XWBDRQ,ZBFS2,XQYY1);
//                // JobCodeToDeptFormWS(XQBM,XQGW,createrId,SQRQ);
//                String endPoint = "http://10.6.2.12/hengtongws/HengtongWebService.asmx";
//                String soapaction = "http://tempuri.org/";
//                Service service = new Service();
//                Call call1 = (Call) service.createCall();
//                call1.setTargetEndpointAddress(new java.net.URL(endPoint));
//                call1.setOperationName(new QName(soapaction, "ApplyPositionFormWS"));
//                call1.addParameter(new QName(soapaction, "DeptID"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.INOUT);
//                call1.addParameter(new QName(soapaction, "positionID"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.INOUT);
//                call1.addParameter(new QName(soapaction, "ApplyDate"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.INOUT);
//                call1.addParameter(new QName(soapaction, "PositionCount"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.INOUT);
//                call1.addParameter(new QName(soapaction, "ONDUTYDATE"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.INOUT);
//                call1.addParameter(new QName(soapaction, "INTERIOR"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.INOUT);
//                call1.addParameter(new QName(soapaction, "ReasonID"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.INOUT);
//                call1.setReturnType(new QName(soapaction, "ApplyPositionFormWS"), String.class);
//                call1.setUseSOAPAction(true);
//                call1.setSOAPActionURI(soapaction + "ApplyPositionFormWS");
//                logger_42aadd27.error("DeptID:" + DeptID + "positionID" + positionID);
//                String str = (String) call1.invoke(new Object[] { DeptID, positionID, SQRQ, XQRS, XWBDQX, ZBFS2, XQYY });
//                logger_42aadd27.error("str:" + str);
//                if (!str.equals("SUCCESS")) {
//                    request.getRequestManager().setMessageid("100002");
//                    request.getRequestManager().setMessagecontent(str);
//                    return  WeaResult.fail(500, "YongGongXuQiuActionstr"+ str, getResultMapForAction(weaverResultMap, "result",str, request.getRequestManager()));
//
//                }
//            } catch (Exception e) {
//                logger_42aadd27.error("YongGongXuQiuAction catchErr:" + e.toString());
//                return  WeaResult.fail(500, "YongGongXuQiuAction err"+ e, getResultMapForAction(weaverResultMap, "result",e.getMessage(), request.getRequestManager()));
//
//            }
//            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", Action.SUCCESS, request.getRequestManager()));
//        } catch (Exception e) {
//            e.printStackTrace();
//            logger_42aadd27.error("YongGongXuQiuAction e: {}", e.getMessage());
//            return  WeaResult.fail(500, "YongGongXuQiuAction e {}"+ e, getResultMapForAction(weaverResultMap, "result",e.getMessage(), request.getRequestManager()));
//        }
    }

    Map<String, Object> getResultMapForAction(Map<String, Object> map, String key, Object value, RequestManager requestManager) {
        if (key != null && !key.isEmpty()) {
            map.put(key, value);
        }
        String msgContent = requestManager.getMessagecontent();
        if (msgContent != null && !msgContent.isEmpty()) {
            map.put("msgContent", msgContent);
        }
        String msgId = requestManager.getMessageid();
        if (msgId != null && !msgId.isEmpty()) {
            map.put("msgId", msgId);
        }
        return map;
    }
}
