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

import java.util.HashMap;
import java.util.Map;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.verupgrade.conn.CONN_TYPE;
import java.lang.*;
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 com.weaver.verupgrade.conn.RecordSet;
import com.weaver.verupgrade.general.BaseBean;
import com.weaver.verupgrade.general.Util;
import com.weaver.verupgrade.soa.workflow.request.Cell;
import com.weaver.verupgrade.soa.workflow.request.DetailTable;
import com.weaver.verupgrade.soa.workflow.request.Row;
import com.weaver.verupgrade.interfaces.workflow.action.Action;



//不启用
@org.springframework.stereotype.Service("workflow_action_UpdateSeclevelAndpasswordlock")
public class UpdateSeclevelAndpasswordlock extends BaseBean implements Action, EsbServerlessRpcRemoteInterface {

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

    private static final Logger logger_54eacf62 = LoggerFactory.getLogger(UpdateSeclevelAndpasswordlock.class);

    public WeaResult<Map<String, Object>> execute(Map<String, Object> requestInfoMap) {
        logger_54eacf62.error("UpdateSeclevelAndpasswordlock 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);
        try {
            String requestid = request.getRequestid();
            logger_54eacf62.error(String.valueOf(requestid + "修改安全级别和密码解锁开始"));
            DetailTable[] detailtable = request.getDetailTableInfo().getDetailTable();
            DetailTable dtq = detailtable[0];
            Row[] sq = dtq.getRow();
            RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
            //TODO custom 不启用
//            try {
//                for (int j = 0; j < sq.length; j++) {
//                    // 指定行
//                    Row rq = sq[j];
//                    // 每行数据再按列存储
//                    Cell[] cq = rq.getCell();
//                    Map<String, String> map = new HashMap<String, String>();
//                    for (int k = 0; k < cq.length; k++) {
//                        // 指定列
//                        Cell cq1 = cq[k];
//                        // 明细字段名称
//                        String nameq = cq1.getName().toLowerCase();
//                        String valueq = Util.null2String(cq1.getValue());
//                        map.put(nameq, valueq);
//                    }
//                    if (map.get("xglx").equals("0")) {
//                        String userid = map.get("xgyhxm");
//                        String seclevel = map.get("xaqjb");
//                        String sql = "update eteams.dbo.employee as  hrmresource set seclevel=" + seclevel + " where id=" + userid;
//                        logger_54eacf62.error(String.valueOf("修改安全级别和密码解锁sql:" + sql));
//                        String poolname = CONN_TYPE.workflow.getType();
//                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                        rs.executeSql(sql, poolname);
//                    }
//                    if (map.get("xglx").equals("1")) {
//                        String userid = map.get("xgyhxm");
//                        String sql = "update employee as  hrmresource set passwordlock=0 where id=" + userid;
//                        logger_54eacf62.error(String.valueOf("修改安全级别和密码解锁sql:" + sql));
//                        String poolname_ow = CONN_TYPE.workflow.getType();
//                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                        rs.executeSql(sql, poolname_ow);
//                    }
//                    if (map.get("xglx").equals("2")) {
//                        String userid = map.get("xgyhxm");
//                        String seclevel = map.get("xaqjb");
//                        String sql = "update eteams.dbo.employee as  hrmresource set passwordlock=0,seclevel=" + seclevel + " where id=" + userid;
//                        logger_54eacf62.error(String.valueOf("修改安全级别和密码解锁sql:" + sql));
//                        String poolname_fw = CONN_TYPE.workflow.getType();
//                        // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
//                        rs.executeSql(sql, poolname_fw);
//                    }
//                }
//                logger_54eacf62.error(String.valueOf(requestid + "修改安全级别和密码解锁结束"));
//            } catch (Exception e) {
//                logger_54eacf62.error(String.valueOf("修改安全级别和密码解锁出错：" + e.toString()));
//                return WeaResult.fail(500, "出错啦", getResultMapForAction(weaverResultMap, "result", "", request.getRequestManager()));
//            }
            return WeaResult.success(getResultMapForAction(weaverResultMap, "result", Action.SUCCESS, request.getRequestManager()));
        } catch (Exception e) {
            e.printStackTrace();
            logger_54eacf62.error("UpdateSeclevelAndpasswordlock e: {}", e.getMessage());
            return  WeaResult.fail(500, "UpdateSeclevelAndpasswordlock 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;
    }
}
