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.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.common.base.entity.result.WeaResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.formmode.data.GetCubeBtnActionParam;
import com.weaver.verupgrade.conn.RecordSet;
import com.weaver.verupgrade.general.Util;
import com.weaver.verupgrade.hrm.User;
import com.weaver.verupgrade.hrm.resource.ResourceComInfo;
import com.weaver.verupgrade.soa.workflow.request.RequestInfo;

/**
 * 说明
 * 修改时
 * 类名要与文件名保持一致
 * class文件存放位置与路径保持一致。
 * 请把编译后的class文件，放在对应的目录中才能生效
 * 注意 同一路径下java名不能相同。
 * @author Administrator
 */
@org.springframework.stereotype.Service("htjt_mode_UpdateSecLevelAndLockStatus")
public class UpdateSecLevelAndLockStatus implements EsbServerlessRpcRemoteInterface {

    public static final org.slf4j.Logger logger_b15f4fa5 = LoggerFactory.getLogger(UpdateSecLevelAndLockStatus.class);

    /**
     * 执行模块扩展动作
     * @param param
     *  param包含(但不限于)以下数据
     *  user 当前用户
     *  importtype 导入方式(仅在批量导入的接口动作会传输) 1 追加，2覆盖,3更新，获取方式(int)param.get("importtype")
     *  导入链接中拼接的特殊参数(仅在批量导入的接口动作会传输)，比如a=1，可通过param.get("a")获取参数值
     *  页面链接拼接的参数，比如b=2,可以通过param.get("b")来获取参数
     * @return
     */
    public WeaResult<Map<String, Object>> execute(Map<String, Object> param) {

        logger_b15f4fa5.error("htjt_mode_UpdateSecLevelAndLockStatus start param == " + param);

        // 构建E9 requestInfo对象参数
        I18nContextUtil.getBean(GetCubeBtnActionParam.class).getCubeBtnActionParam(param);

        Long billid = Long.parseLong(String.valueOf(param.getOrDefault("billid", -1)));
        logger_b15f4fa5.error("billid == "+ billid );

        Map<String, String> result = new HashMap<String, String>();
        try {


            if (billid != null) {

                if (billid > 0 ) {
                    RecordSet rs = I18nContextUtil.getBean(RecordSet.class);
                    String sql = "select * from e10_common.dbo.uf_sellevellock_chg where id=" + billid;
                    String ry = "";
                    String aqjb = "";
                    String zhsd = "";
                    rs.execute(sql);
                    if (rs.next()) {
                        ry = Util.null2String(rs.getString("ry"));
                        aqjb = Util.null2String(rs.getString("aqjb"));
                        zhsd = Util.null2String(rs.getString("zhsd"));
                    }
                    if ("".equals(zhsd)) {
                        zhsd = "0";
                    }
                    sql = "update eteams.dbo.employee as  hrmresource set seclevel=" + aqjb + ",passwordlock=" + zhsd + " where id=" + ry + "";
                    boolean execute = rs.execute(sql);
                    logger_b15f4fa5.error("execute == "+ execute );
                    ResourceComInfo rci = I18nContextUtil.getBean(ResourceComInfo.class);
                    rci.updateResourceInfoCache(ry);
                }
            }
        } catch (Exception e) {
            result.put("errmsg", "自定义出错信息");
            result.put("flag", "false");
            return  WeaResult.fail(500, "UpdateSecLevelAndLockStatus e {}"+ e);

        }
        logger_b15f4fa5.error("htjt_mode_UpdateSecLevelAndLockStatus stop result == " + result);
        return WeaResult.success(new HashMap<>(result));
    }
}
