weaver-hrm-recruit/src/weaver/formmode/yaq/modeexpand/email/EmailUpdateExpand.java

133 lines
7.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package weaver.formmode.yaq.modeexpand.email;
import com.engine.email.entity.EmailFlockSendAccountComInfo;
import com.engine.email.entity.EmailFlockSendSyncSetComInfo;
import com.engine.recruit.conn.RecruitDataMap;
import com.engine.recruit.exception.CustomizeRunTimeException;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.email.EmailEncoder;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import java.util.HashMap;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/26
* @version: 1.0
*/
public class EmailUpdateExpand extends AbstractModeExpandJavaCodeNew {
@Override
public Map<String, String> doModeExpand(Map<String, Object> param) {
Map<String, String> result = new HashMap<>();
try {
RequestInfo requestInfo = (RequestInfo) param.get("RequestInfo");
if (requestInfo != null) {
String billId = Util.null2String(param.get("billid"));
String src = Util.null2String(param.get("src"));
if (StringUtils.isBlank(billId)) {
throw new CustomizeRunTimeException("数据ID获取失败");
}
MainTableInfo mainTableInfo = requestInfo.getMainTableInfo();
Property[] properties = mainTableInfo.getProperty();
RecruitDataMap<String> mainDataMap = new RecruitDataMap<>();
for (Property property : properties) {
mainDataMap.put(property.getName(), property.getValue());
}
String qydqpz = mainDataMap.get("qydqpz");
// 如果是编辑操作、且当前配置未启用,不进行以下操作
if("save".equals(src) && "0".equals(qydqpz)){
return result;
}
String sendProtocol = mainDataMap.get("send_protocol");
String sendProtocolStr = "";
if (StringUtils.isNotBlank(sendProtocol)) {
switch (sendProtocol) {
case "0":
sendProtocolStr = "SMTP";
break;
case "1":
sendProtocolStr = "EXCHANGE";
break;
case "2":
sendProtocolStr = "Microsoft Graph";
break;
default:
break;
}
}
if (StringUtils.isBlank(sendProtocolStr)) {
throw new CustomizeRunTimeException("发送协议转换失败,请检查配置");
}
String smtpServer = mainDataMap.get("smtp_server");
String sendNeedssl = mainDataMap.get("send_needssl");
String smtpServerPort = mainDataMap.get("smtp_serverport");
String isstarttls = mainDataMap.get("isstarttls");
String needCheck = mainDataMap.get("needcheck");
String accountName = mainDataMap.get("accountname");
String accountMailAddress = mainDataMap.get("accountmailaddress");
String accountId = mainDataMap.get("accountid");
String accountPassword = mainDataMap.get("accountpassword");
// 密码加密转换
String accountPasswordStr = EmailEncoder.EncoderPassword(accountPassword);
if (StringUtils.isBlank(accountPasswordStr)) {
throw new CustomizeRunTimeException("邮箱密码设置失败");
}
String ewsServiceUrl = mainDataMap.get("ews_service_url");
String ewsDomain = mainDataMap.get("ews_domain");
String ewsVersion = mainDataMap.get("ews_version");
String subcompanyid = mainDataMap.get("subcompanyid");
RecordSet rs = new RecordSet();
// 更新email_flocksendaccount表指定subcompanyid的数据
//String sql = "insert into email_flocksendaccount (send_protocol, smtp_server, send_needssl, smtp_serverport, isstarttls, needcheck, accountname, accountmailaddress," +
// " accountid, accountpassword, ews_service_url, ews_domain, ews_version,subcompanyid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
//boolean flag = rs.executeUpdate(sql, sendProtocol, smtpServer, sendNeedssl, smtpServerPort, isstarttls, needCheck, accountName, accountMailAddress, accountId, accountPasswordStr, ewsServiceUrl, ewsDomain, ewsVersion, subcompanyid);
boolean flag;
rs.executeQuery("select * from email_flocksendaccount where subcompanyid = ?", subcompanyid);
String sql = "";
if (rs.next()) {
sql = "update email_flocksendaccount set send_protocol = ?,smtp_server = ?,send_needssl = ? , smtp_serverport = ? , isstarttls = ?, needcheck = ?, accountname = ?, accountmailaddress = ?," +
" accountid = ? , accountpassword = ? , ews_service_url = ? , ews_domain = ? , ews_version = ? where subcompanyid = ?";
flag = rs.executeUpdate(sql, sendProtocolStr, smtpServer, sendNeedssl, smtpServerPort, isstarttls, needCheck, accountName, accountMailAddress, accountId, accountPasswordStr, ewsServiceUrl, ewsDomain, ewsVersion, subcompanyid);
} else {
sql = "insert into email_flocksendaccount (send_protocol, smtp_server, send_needssl, smtp_serverport, isstarttls, needcheck, accountname, accountmailaddress," +
" accountid, accountpassword, ews_service_url, ews_domain, ews_version,subcompanyid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
flag = rs.executeUpdate(sql, sendProtocolStr, smtpServer, sendNeedssl, smtpServerPort, isstarttls, needCheck, accountName, accountMailAddress, accountId, accountPasswordStr, ewsServiceUrl, ewsDomain, ewsVersion, subcompanyid);
}
// 刷新缓存
EmailFlockSendAccountComInfo emailFlockSendAccountComInfo = new EmailFlockSendAccountComInfo();
emailFlockSendAccountComInfo.updateCache(subcompanyid);
EmailFlockSendSyncSetComInfo efsssci = new EmailFlockSendSyncSetComInfo();
efsssci.updateCache(subcompanyid);
if (flag) {
// 更新其他数据为不启用
rs.executeUpdate("update uf_recruit_email set qydqpz = 0 where id != ? ", billId);
rs.executeUpdate("update uf_recruit_email set qydqpz = 1 where id = ? ", billId);
}
}
return result;
} catch (Exception e) {
new BaseBean().writeLog("招聘邮箱设置异常", e);
result.put("errmsg", e.getMessage());
result.put("flag", "false");
return result;
}
}
}