package com.weaver.seconddev.interfaces.htjt.workflow.hr;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import com.weaver.verupgrade.conn.CONN_TYPE;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.conn.RecordSet;
import com.weaver.verupgrade.conn.RecordSetDataSource;
import com.weaver.verupgrade.general.Util;

/**
 * ClassName hrUtil
 * Author
 * Date 2023/9/18 9:57
 * Description hrUtil
 * Version 1.0
 */
public class HrUtil {

    private static final org.slf4j.Logger logger_3cf7b2d9 = LoggerFactory.getLogger(HrUtil.class);

    public String getExpiredDate() {
        Calendar cd = Calendar.getInstance();
        cd.add(Calendar.MINUTE, 5);
        Date date = cd.getTime();
        SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String expiredDate = sdft.format(date);
        return expiredDate;
    }

//    public String getQjlbGuid(String qjlb) {
//        String guid = "";
//        if (!"".equals(qjlb)) {
//            // TODO 有参构造 :new RecordSetDataSource("hr") 实例化方式改变,请检查是否有对应有参实现
////            RecordSetDataSource rsd = I18nContextUtil.getBean(RecordSetDataSource.class).setPoolname("hr");
//            RecordSet rsd = I18nContextUtil.getBean(RecordSet.class);
//            String sql = "select classGUID from ht_ATDATTENDANCECLASS where id=" + qjlb;
//            String poolname = "";
//            // TODO E10必须指定poolname数据源
//            rsd.executeSql(sql, "hr");
//            if (rsd.next()) {
//                guid = Util.null2String(rsd.getString("classGUID"));
//            }
//        }
//        return guid;
//    }

    /**
     * 获取hr系统配置
     * @param gh
     * @return
     */
    public Map<String, String> getHrurl(String gh, RecordSet rs) {
        Map<String, String> xtpz = new HashMap<>();
        try {
            String field3 = "";
            String sql = "select a.id,b.field3 from eteams.dbo.employee a,eteams.dbo.hrmemployeedefined b where a.formdata = b.FORM_DATA_ID and a.job_num='" + gh + "'";
            logger_3cf7b2d9.error("sql--" + sql);
            String poolname_2v = CONN_TYPE.workflow.getType();
            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
            rs.executeSql(sql, poolname_2v);
            if (rs.next()) {
                field3 = Util.null2String(rs.getString("field3"));
            }
            if ("".equals(field3)) {
                field3 = "jt";
            }

            sql = "select * from e10_common.dbo.uf_hrxt_mt where xtbs='" + field3 + "'";
            logger_3cf7b2d9.error("sql--" + sql);
            String poolname_9n = "E10JTZH";
            // TODO E10执行sql方法第二参数必须指定源，默认使用流程源，单体客户无需修改，微服务/组合客户需根据查询表所属服务切换源，或使用外部数据源
            rs.executeSql(sql, poolname_9n);
            if (rs.next()) {
                xtpz.put("hrapiurl", Util.null2String(rs.getString("hrapiurl")));
                xtpz.put("hrtoken", Util.null2String(rs.getString("hrtoken")));
                xtpz.put("hrloginname", Util.null2String(rs.getString("hrloginname")));
                xtpz.put("hrygwcid", Util.null2String(rs.getString("hrygwcid")));
                xtpz.put("hrbkjqid", Util.null2String(rs.getString("hrbkjqid")));
            }
            logger_3cf7b2d9.error("xtpz--"+xtpz);
        }catch (Exception e){
            logger_3cf7b2d9.error("获取hr系统配置失败", e);
        }
        return xtpz;
    }
}
