package com.engine.recruit.conn;

import com.engine.recruit.util.WeaBrowserUtil;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.hrm.User;

/**
 * @author:dxfeng
 * @createTime: 2023/11/10
 * @version: 1.0
 */
public class ModeBrowserCommonInfo {
    /**
     * 性别
     */
    public static final String TYPE_GENDER = "1";
    /**
     * 简历来源
     */
    public static final String TYPE_RESUME_SOURCE = "2";
    /**
     * 招聘渠道
     */
    public static final String TYPE_RECRUITMENT_CHANNELS = "3";
    /**
     * 职位性质
     */
    public static final String TYPE_JOB_NATURE = "4";
    /**
     * 职位学历要求
     */
    public static final String TYPE_JOB_EDUCATION_REQUIREMENTS = "5";
    /**
     * 婚姻状况
     */
    public static final String TYPE_MARITAL_STATUS = "6";
    /**
     * 在职状态
     */
    public static final String TYPE_ON_THE_JOB_STATUS = "7";
    /**
     * 招聘原因
     */
    public static final String TYPE_RECRUITMENT_REASON = "8";
    /**
     * 工作年限
     */
    public static final String TYPE_YEARS_OF_WORK = "9";
    /**
     * 工作经验
     */
    public static final String TYPE_WORK_EXPERIENCE = "10";
    /**
     * 政治面貌
     */
    public static final String TYPE_POLITICAL_LANDSCAPE = "11";
    /**
     * 学位
     */
    public static final String TYPE_DEGREE = "12";

    /**
     * 根据名称，获取简历来源ID
     *
     * @param name
     * @return
     */
    public static String getResumeSource(String name) {
        return getBrowserId(TYPE_RESUME_SOURCE, name);
    }

    /**
     * 根据名称，获取工作经验ID
     *
     * @param name
     * @return
     */
    public static String getWorkExperience(String name) {
        return getBrowserId(TYPE_WORK_EXPERIENCE, name);
    }


    /**
     * 获取学位ID
     *
     * @param name
     * @return
     */
    public static String getDegreeId(String name) {
        return getBrowserId(TYPE_DEGREE, name);
    }

    /**
     * 获取学历ID
     *
     * @param name
     * @return
     */
    public static String getEducationLevelId(String name) {
        if (StringUtils.isBlank(name)) {
            return null;
        }
        String id = null;
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id from hrmeducationlevel where name like '%" + name + "%'");
        if (rs.next()) {
            id = rs.getString("id");
        }
        return id;
    }

    /**
     * 获取学历名称
     * @param id
     * @return
     */
    public static String getEducationLevelById(String id) {
        if (StringUtils.isBlank(id)) {
            return null;
        }
        String name = null;
        RecordSet rs = new RecordSet();
        rs.executeQuery("select name from hrmeducationlevel where id = ?", id);
        if (rs.next()) {
            name = rs.getString("name");
        }
        return name;
    }

    public static String getWorkPlaceShowName(User user, String id) {
        String placeName = "";
        if (StringUtils.isBlank(id)) {
            return placeName;
        }

        RecordSet rs = new RecordSet();
        rs.executeQuery("select ssq,xxdz from uf_zpgzdd where id = ?", id);
        if (rs.next()) {
            String ssq = rs.getString("ssq");
            String xxdz = rs.getString("xxdz");
            // 区县浏览按钮类型：263
            String areaName = WeaBrowserUtil.getBrowserShowNames(user, 263, ssq);
            rs.writeLog("areaName===" + areaName);
            if (StringUtils.isNotBlank(areaName) && StringUtils.isNotBlank(xxdz)) {
                String[] split = areaName.split("/");
                if (split.length == 4) {
                    areaName = split[1] + "-" + split[2] + "-" + split[3];
                    placeName = areaName + "-" + xxdz;
                } else if (split.length == 3) {
                    areaName = split[0] + "-" + split[1] + "-" + split[2];
                    placeName = areaName + "-" + xxdz;
                }
            } else {
                rs.writeLog("id=" + id + ",ssq=" + ssq + ",xxdz=" + xxdz);
            }
        }
        return placeName;
    }


    public static String getBrowserId(String zdlxmc, String xxnr) {
        if (StringUtils.isBlank(xxnr)) {
            return null;
        }
        String sourceId = null;
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id from uf_sjzd where zdlxmc = ? and xxnr = ? ", zdlxmc, xxnr);
        if (rs.next()) {
            sourceId = rs.getString("id");
        }
        return sourceId;
    }
}
