package com.engine.recruit.service.impl;

import com.engine.core.impl.Service;
import com.engine.recruit.conn.RecruitRecordSet;
import com.engine.recruit.entity.position.PositionSdkInstance;
import com.engine.recruit.exception.CustomizeRunTimeException;
import com.engine.recruit.service.RpaJclService;
import com.weaver.rpa.sdk.clients.application.resume.ERPAResumeSDKClient;
import com.weaver.rpa.sdk.clients.application.resume.entity.ResumeEmailSetting;
import weaver.conn.RecordSet;
import weaver.general.Util;

import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2023/10/27
 * @version: 1.0
 */
public class RpaJclServiceImpl extends Service implements RpaJclService {
    @Override
    public Map<String, Object> setEmailSetting(Map<String, Object> param) {
            boolean enableSdkClient = PositionSdkInstance.enableSdkClient();
            if (!enableSdkClient) {
                throw new CustomizeRunTimeException("千里聆SDK校验失败，无法执行邮箱操作，请检查千里聆非标配置");
            }
            String billId = Util.null2String(param.get("billId"));
            RecordSet rs = new RecordSet();
            rs.executeQuery("select * from uf_jcl_qllyxpz where id = ? ", billId);
            Map<String, Object> dataMap = RecruitRecordSet.getSingleRecordMap(rs);

            ERPAResumeSDKClient resumeSDKClient = PositionSdkInstance.getPositionSdkInstance().getResumeSDKClient();
            String userId = Util.null2String(dataMap.get("szr"));
            String status = Util.null2String(dataMap.get("zt"));
            String server = Util.null2String(dataMap.get("yjjsfwq"));
            String port = Util.null2String(dataMap.get("jsdk"));
            String protocol = Util.null2String(dataMap.get("csxy"));
            String site = Util.null2String(dataMap.get("yxdz"));
            String login = Util.null2String(dataMap.get("yxzh"));
            String password = Util.null2String(dataMap.get("yxsqmmm"));

            ResumeEmailSetting emailSetting = new ResumeEmailSetting();

            // 配置启用邮箱功能
            emailSetting.setSEMAILSTATUS(status);
            emailSetting.setSEMAILSERVER(server);
            emailSetting.setSEMAILPORT(port);
            emailSetting.setSEMAILPROTOCOL(protocol);
            //emailSetting.setSISSEND(isSend);
            emailSetting.setSEMAILSITE(site);
            emailSetting.setSEMAILLOGIN(login);
            emailSetting.setSEMAILPASSWORD(password);

            // 禁用邮箱功能(只需要传递Status为0)
            // emailSetting.setSEMAILSTATUS("0");

            // 调用方法更新简历机器人采集设置（在千里聆中会更新目标用户机器人配置）
            resumeSDKClient.setEmailSetting(userId, emailSetting);
        return null;
    }
}
