package com.engine.recruit.enums;

import com.engine.recruit.conn.ApplicantCommonInfo;
import com.engine.recruit.entity.record.ApplicantRecordPo;
import com.engine.recruit.entity.recruitflow.po.RecruitStepPo;
import weaver.conn.RecordSet;
import weaver.formmode.recruit.modeexpand.util.RecruitModeUtil;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2023/11/02
 * @version: 1.0
 */
public enum RecordOperateEnum implements RecordOperateAdapter {
    /**
     * 应聘过程操作类型
     */
    RESUME_SUBMISSION("resumeSubmission", "简历投递", "简历投递", recordPo -> {
        recordPo.setPcId(recordPo.getBillId());
        recordPo.setContent("");
    }),

    ELIMINATE("eliminate", "淘汰", "淘汰", recordPo -> {
        User user = recordPo.getUser();
        RecruitStepPo currentStep = ApplicantCommonInfo.getCurrentStep(recordPo.getBillId());
        String content = user.getLastname() + "淘汰，操作阶段：" + currentStep.getDescription();
        recordPo.setPcId(recordPo.getBillId());
        recordPo.setContent(content);
    }),

    TRANSFER_STAGE("transferStage", "转移阶段", "转移阶段", recordPo -> {
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String sourceStep = Util.null2String(otherParam.get("sourceStep"));
        String targetStep = Util.null2String(otherParam.get("targetStep"));
        User user = recordPo.getUser();
        String content = user.getLastname() + "转移阶段，应聘阶段：“" + sourceStep + "”变更为“" + targetStep + "”";
        recordPo.setPcId(recordPo.getBillId());
        recordPo.setContent(content);
    }),

    ARCHIVE_TALENT_POOL("archiveTalentPool", "归档人才库", "归档人才库", recordPo -> {
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String gdyy = Util.null2String(otherParam.get("gdyy"));
        String gdxxyy = Util.null2String(otherParam.get("gdxxyy"));
        int formId = ApplicantCommonInfo.getFormIdByTableName("uf_jcl_yppc");
        String selectName = ApplicantCommonInfo.getSelectName(String.valueOf(formId), "gdyy", gdyy);
        User user = recordPo.getUser();
        RecruitStepPo currentStep = ApplicantCommonInfo.getCurrentStep(recordPo.getBillId());
        String content = user.getLastname() + "归档人才库，操作阶段：" + currentStep.getDescription() + "，归档原因：" + selectName + "，归档详细原因：" + gdxxyy;
        recordPo.setPcId(recordPo.getBillId());
        recordPo.setContent(content);
    }),

    JOIN_BLACKLIST("joinBlacklist", "加入黑名单", "加入黑名单", recordPo -> {
        User user = recordPo.getUser();
        RecruitStepPo currentStep = ApplicantCommonInfo.getCurrentStep(recordPo.getBillId());
        String content = user.getLastname() + "加入黑名单，操作阶段：" + currentStep.getDescription();
        recordPo.setPcId(recordPo.getBillId());
        recordPo.setContent(content);
    }),

    ADD_SCREEN("addScreen", "部门筛选反馈", "部门筛选反馈", recordPo -> {
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String jg = Util.null2String(otherParam.get("jg"));
        String pj = Util.null2String(otherParam.get("pj"));
        String ypz = Util.null2String(otherParam.get("ypz"));
        String fkr = Util.null2String(otherParam.get("fkr"));
        String createName = Util.null2String(otherParam.get("createName"));
        String resourceNames = RecruitModeUtil.getResourceNames(fkr);
        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "jg", jg);

        String content = "创建人：" + createName + "，反馈人：" + resourceNames + "，结果：" + selectName + "，评价：" + pj;

        recordPo.setContent(content);
        recordPo.setPcId(ypz);
        recordPo.autoCreateLink();
    }),

    UPDATE_SCREEN("updateScreen", "修改筛选反馈", "部门筛选反馈", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String jg = Util.null2String(otherParam.get("jg"));
        String pj = Util.null2String(otherParam.get("pj"));
        String ypz = Util.null2String(otherParam.get("ypz"));
        String fkr = Util.null2String(otherParam.get("fkr"));
        String resourceNames = RecruitModeUtil.getResourceNames(fkr);
        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "jg", jg);

        String content = "更新关联数据，最近修改人:" + user.getLastname() + "，反馈人:" + resourceNames + "，结果:" + selectName + "，评价:" + pj;
        recordPo.setContent(content);

        recordPo.autoCreateLink();
        recordPo.setPcId(ypz);
    }),

    DELETE_SCREEN("deleteScreen", "删除筛选反馈", "部门筛选反馈", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String ypz = Util.null2String(otherParam.get("ypz"));
        String content = user.getLastname() + "删除/隐藏关联记录数据";
        recordPo.setContent(content);
        recordPo.setPcId(ypz);
    }),

    ADD_INTERVIEW_RESULT("addInterviewResult", "面试评价反馈", "面试评价反馈", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String msrq = Util.null2String(otherParam.get("msrq"));
        String jg = Util.null2String(otherParam.get("jg"));
        String pj = Util.null2String(otherParam.get("pj"));
        String ypz = Util.null2String(otherParam.get("ypz"));

        String msg = Util.null2String(otherParam.get("msg"));
        String createName = Util.null2String(otherParam.get("createName"));
        String msgNames = RecruitModeUtil.getResourceNames(msg);
        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "jg", jg);

        String content = "创建人：" + createName + "，面试官：" + msgNames + "  ，面试时间：" + msrq + "，反馈人：" + user.getLastname() + " ， 结果：" + selectName + "  ，评价：" + pj;

        recordPo.setContent(content);
        recordPo.setPcId(ypz);
        recordPo.autoCreateLink();
    }),

    UPDATE_INTERVIEW_RESULT("updateInterviewResult", "修改面试评价反馈", "面试评价反馈", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String msrq = Util.null2String(otherParam.get("msrq"));
        String jg = Util.null2String(otherParam.get("jg"));
        String pj = Util.null2String(otherParam.get("pj"));
        String ypz = Util.null2String(otherParam.get("ypz"));

        String msg = Util.null2String(otherParam.get("msg"));
        String fkr = Util.null2String(otherParam.get("fkr"));
        String fkrNames = RecruitModeUtil.getResourceNames(fkr);
        String msgNames = RecruitModeUtil.getResourceNames(msg);
        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "jg", jg);

        String content = "更新关联数据，最近修改人:" + user.getLastname() + "面试官:" + msgNames + "，面试时间:" + msrq + "，反馈人:" + fkrNames + "， 结果：" + selectName + "，评价：" + pj;
        recordPo.setContent(content);

        recordPo.autoCreateLink();
        recordPo.setPcId(ypz);
    }),

    DELETE_INTERVIEW("deleteInterview", "删除面试", "面试评价反馈", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String ypz = Util.null2String(otherParam.get("ypz"));
        String content = user.getLastname() + "删除/隐藏关联记录数据";
        recordPo.setContent(content);
        recordPo.setPcId(ypz);
    }),

    ADD_WRITTEN_RESULT("addWrittenResult", "笔试结果录入", "笔试", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String bsmc = Util.null2String(otherParam.get("bsmc"));
        String bsjg = Util.null2String(otherParam.get("bsjg"));
        String bscj = Util.null2String(otherParam.get("bscj"));
        String ypz = Util.null2String(otherParam.get("ypz"));

        String createName = Util.null2String(otherParam.get("createName"));
        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "bsjg", bsjg);

        String content = "创建人：" + createName + "，笔试名称：" + bsmc + " ，笔试结果：" + selectName + "  ，笔试成绩：" + bscj;

        recordPo.setContent(content);
        recordPo.setPcId(ypz);
        recordPo.autoCreateLink();

    }),

    UPDATE_WRITTEN_RESULT("updateWrittenResult", "编辑笔试结果", "笔试", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String bsmc = Util.null2String(otherParam.get("bsmc"));
        String bsjg = Util.null2String(otherParam.get("bsjg"));
        String bscj = Util.null2String(otherParam.get("bscj"));
        String ypz = Util.null2String(otherParam.get("ypz"));

        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "bsjg", bsjg);

        String content = "更新关联数据：最近修改人：" + user.getLastname() + "，笔试名称:" + bsmc + "，笔试结果:" + selectName + " ，笔试成绩" + bscj;
        recordPo.setContent(content);

        recordPo.autoCreateLink();
        recordPo.setPcId(ypz);
    }),

    DELETE_WRITTEN_RESULT("deleteWrittenResult", "删除笔试结果", "笔试", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String ypz = Util.null2String(otherParam.get("ypz"));
        String content = user.getLastname() + "删除/隐藏关联记录数据";
        recordPo.setContent(content);
        recordPo.setPcId(ypz);
    }),

    ADD_SALARY_NEGOTIATION("addSalaryNegotiation", "薪酬谈判录入", "薪酬谈判", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String tpjg = Util.null2String(otherParam.get("tpjg"));
        String ypz = Util.null2String(otherParam.get("ypz"));

        String createName = Util.null2String(otherParam.get("createName"));
        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "tpjg", tpjg);

        String content = "创建人：" + createName + "，谈判结果：" + selectName;

        recordPo.setContent(content);
        recordPo.setPcId(ypz);
        recordPo.autoCreateLink();
    }),

    UPDATE_SALARY_NEGOTIATION("updateSalaryNegotiation", "修改薪酬谈判记录", "薪酬谈判", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String tpjg = Util.null2String(otherParam.get("tpjg"));
        String ypz = Util.null2String(otherParam.get("ypz"));

        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "tpjg", tpjg);

        String content = "更新关联数据：最近修改人:" + user.getLastname() + "，谈判结果:" + selectName;
        recordPo.setContent(content);

        recordPo.autoCreateLink();
        recordPo.setPcId(ypz);
    }),

    DELETE_SALARY_NEGOTIATION("deleteSalaryNegotiation", "删除薪酬谈判记录", "薪酬谈判", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String ypz = Util.null2String(otherParam.get("ypz"));
        String content = user.getLastname() + "删除/隐藏关联记录数据";
        recordPo.setContent(content);
        recordPo.setPcId(ypz);
    }),

    ADD_BACK_TONE("addBackTone", "背调录入", "背调", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String dcjg = Util.null2String(otherParam.get("dcjg"));
        String ypz = Util.null2String(otherParam.get("ypz"));
        String dcdw = Util.null2String(otherParam.get("dcdw"));

        String createName = Util.null2String(otherParam.get("createName"));
        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "dcjg", dcjg);

        String content = "创建人：" + createName + "，调查结果：" + selectName + "  ，调查单位：" + dcdw;

        recordPo.setContent(content);
        recordPo.setPcId(ypz);
        recordPo.autoCreateLink();
    }),

    UPDATE_BACK_TONE("updateBackTone", "修改背调记录", "背调", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String dcjg = Util.null2String(otherParam.get("dcjg"));
        String ypz = Util.null2String(otherParam.get("ypz"));
        String dcdw = Util.null2String(otherParam.get("dcdw"));

        String selectName = ApplicantCommonInfo.getSelectName(recordPo.getFormId(), "dcjg", dcjg);

        String content = "更新关联数据：最近修改人:" + user.getLastname() + "，调查结果:" + selectName + " ，调查单位" + dcdw;
        recordPo.setContent(content);

        recordPo.autoCreateLink();
        recordPo.setPcId(ypz);
    }),

    DELETE_BACK_TONE("deleteBackTone", "删除背调记录", "背调", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String ypz = Util.null2String(otherParam.get("ypz"));
        String content = user.getLastname() + "删除/隐藏关联记录数据";
        recordPo.setContent(content);
        recordPo.setPcId(ypz);
    }),

    CREATE_OFFER("createOffer", "创建offer", "创建offer", recordPo -> {
        Map<String, Object> otherParam = recordPo.getOtherParam();


        String createName = Util.null2String(otherParam.get("createName"));
        String requestName = Util.null2String(otherParam.get("requestName"));
        String xm = Util.null2String(otherParam.get("xm"));
        String content = "创建人：" + createName + "，offer流程：" + requestName;

        recordPo.setContent(content);
        recordPo.setPcId(xm);
    }),

    SEND_OFFER("sendOffer", "发送offer", "发送offer", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String xm = Util.null2String(otherParam.get("xm"));
        String content = user.getLastname() + "发送offer";
        recordPo.setContent(content);
        recordPo.setPcId(xm);
    }),

    OFFER_FEEDBACK("offerFeedback", "offer反馈", "offer反馈", recordPo -> {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select xm,zt from uf_jcl_offer where id = ?", recordPo.getBillId());
        String xm = "";
        String zt = "";
        if (rs.next()) {
            xm = rs.getString("xm");
            zt = rs.getString("zt");
        }
        int formId = ApplicantCommonInfo.getFormIdByTableName("uf_jcl_offer");
        String selectName = ApplicantCommonInfo.getSelectName(String.valueOf(formId), "zt", zt);

        String content = "offer反馈：" + selectName;
        recordPo.setContent(content);
        recordPo.setPcId(xm);
    }),

    PENDING_EMPLOYMENT("pendingEmployment", "进入待入职", "进入待入职", recordPo -> {
        Map<String, Object> otherParam = recordPo.getOtherParam();


        String createName = Util.null2String(otherParam.get("createName"));
        String pcid = Util.null2String(otherParam.get("pcid"));
        String content = createName + "操作进入待入职";

        recordPo.setContent(content);
        recordPo.setPcId(pcid);
    }),

    ENTRY_PROCESS("entryProcess", "入职流程", "入职流程", recordPo -> {
        Map<String, Object> otherParam = recordPo.getOtherParam();


        String createName = Util.null2String(otherParam.get("createName"));
        String requestName = Util.null2String(otherParam.get("requestName"));
        String content = "创建人：" + createName + "，offer流程：" + requestName;

        recordPo.setContent(content);
        RecordSet rs = new RecordSet();
        rs.executeQuery("select pcid from uf_jcl_rzgl where rzlc = ?", recordPo.getBillId());
        if (rs.next()) {
            String pcid = rs.getString("pcid");
            recordPo.setPcId(pcid);
        }
    }),

    INFO_COLLECT("infoCollect", "信息采集", "信息采集", recordPo -> {
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String createName = Util.null2String(otherParam.get("createName"));
        String pcid = Util.null2String(otherParam.get("pcid"));
        String content = createName + "发送信息采集";

        recordPo.setContent(content);
        recordPo.setPcId(pcid);

        recordPo.autoCreateLink();
    }),

    CANCEL_ENTRY("cancelEntry", "取消入职", "取消入职", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String qxyy = Util.null2String(otherParam.get("qxyy"));
        String pcid = Util.null2String(otherParam.get("pcid"));
        String content = user.getLastname() + "操作取消入职，取消原因：" + qxyy;

        recordPo.setContent(content);
        recordPo.setPcId(pcid);
    }),

    HANDLE_ENTRY("handleEntry", "办理入职", "办理入职", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String rzrq = Util.null2String(otherParam.get("rzrq"));
        String pcid = Util.null2String(otherParam.get("pcid"));
        String content = user.getLastname() + "操作办理入职，入职日期：" + rzrq;

        recordPo.setContent(content);
        recordPo.setPcId(pcid);
    }),

    ADD_REMARK("addRemark", "新建备注", "备注", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String bznr = Util.null2String(otherParam.get("bznr"));
        String pcid = Util.null2String(otherParam.get("pcid"));
        String createName = Util.null2String(otherParam.get("createName"));

        String content = createName + "添加备注，备注内容：" + bznr;

        recordPo.setContent(content);
        recordPo.setPcId(pcid);
    }),

    UPDATE_REMARK("updateRemark", "编辑备注", "备注", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();

        String bznr = Util.null2String(otherParam.get("bznr"));
        String pcid = Util.null2String(otherParam.get("pcid"));

        String content = "更新关联数据：最近修改人:" + user.getLastname() + "，备注内容:" + bznr;

        recordPo.setContent(content);
        recordPo.setPcId(pcid);
    }),

    DELETE_REMARK("deleteRemark", "删除备注", "备注", recordPo -> {
        User user = recordPo.getUser();
        Map<String, Object> otherParam = recordPo.getOtherParam();
        String pcid = Util.null2String(otherParam.get("pcid"));
        String content = user.getLastname() + "删除/隐藏关联记录数据";
        recordPo.setContent(content);
        recordPo.setPcId(pcid);
    });

    RecordOperateEnum(String operateType, String operateName, String showName, RecordOperateAdapter adapter) {
        this.operateName = operateName;
        this.operateType = operateType;
        this.showName = showName;
        this.adapter = adapter;
    }

    public static RecordOperateEnum getOperateEnum(String operateType) {
        for (RecordOperateEnum item : RecordOperateEnum.values()) {
            if (item.operateType.equalsIgnoreCase(operateType)) {
                return item;
            }
        }
        return null;
    }


    private String operateName;
    private String operateType;
    private String showName;
    private RecordOperateAdapter adapter;


    public String getOperateName() {
        return operateName;
    }

    public String getOperateType() {
        return operateType;
    }

    public String getShowName() {
        return showName;
    }

    public void setOperateName(String operateName) {
        this.operateName = operateName;
    }

    public void setOperateType(String operateType) {
        this.operateType = operateType;
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }


    @Override
    public void createOperateRecord(ApplicantRecordPo recordPo) {
        adapter.createOperateRecord(recordPo);
    }
}
