|
@@ -1,30 +1,52 @@
|
|
package com.fjhx.service.impl;
|
|
package com.fjhx.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.lang.Assert;
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.fjhx.config.http.EmailEngineUtil;
|
|
import com.fjhx.config.http.EmailEngineUtil;
|
|
|
|
+import com.fjhx.entity.EmailInfo;
|
|
import com.fjhx.service.IAccountService;
|
|
import com.fjhx.service.IAccountService;
|
|
-import com.fjhx.vo.BindingVo;
|
|
|
|
-import com.fjhx.vo.VerifyResult;
|
|
|
|
-import com.fjhx.vo.VerifyVo;
|
|
|
|
|
|
+import com.fjhx.service.IEmailInfoService;
|
|
|
|
+import com.fjhx.vo.*;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class AccountServiceImpl implements IAccountService {
|
|
public class AccountServiceImpl implements IAccountService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IEmailInfoService emailInfoService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public void binding(BindingVo bindingVo) {
|
|
|
|
|
|
+ public EmailInfo binding(BindingVo bindingVo) {
|
|
|
|
+
|
|
|
|
+ EmailInfo emailInfo = emailInfoService.getOne(Wrappers.<EmailInfo>lambdaQuery()
|
|
|
|
+ .eq(EmailInfo::getEmail, bindingVo.getEmail()));
|
|
|
|
+ // 如果存在,直接返回邮箱信息
|
|
|
|
+ if (emailInfo != null) {
|
|
|
|
+ return emailInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
// 验证邮件配置参数
|
|
// 验证邮件配置参数
|
|
VerifyVo verifyVo = createVerifyVo(bindingVo);
|
|
VerifyVo verifyVo = createVerifyVo(bindingVo);
|
|
// 验证邮件配置是否正确
|
|
// 验证邮件配置是否正确
|
|
VerifyResult verifyResult = EmailEngineUtil.post("v1/verifyAccount", verifyVo, VerifyResult.class);
|
|
VerifyResult verifyResult = EmailEngineUtil.post("v1/verifyAccount", verifyVo, VerifyResult.class);
|
|
// 解析验证结果
|
|
// 解析验证结果
|
|
parsingVerifyResult(verifyResult);
|
|
parsingVerifyResult(verifyResult);
|
|
|
|
+ // 生成添加账号入参
|
|
|
|
+ AddAccountVo addAccountVo = createAddAccountVo(verifyVo, bindingVo.getEmail());
|
|
|
|
+ // 添加邮箱
|
|
|
|
+ AddAccountResult addAccountResult = EmailEngineUtil.post("v1/account", addAccountVo, AddAccountResult.class);
|
|
|
|
+ // 验证邮箱添加状态
|
|
|
|
+ parsingAddAccountResult(addAccountResult);
|
|
|
|
+ // mysql添加邮箱
|
|
|
|
+ emailInfo = addEmailInfo(bindingVo);
|
|
|
|
|
|
|
|
|
|
- System.err.println(JSONObject.toJSONString(verifyResult));
|
|
|
|
|
|
+ return emailInfo;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private VerifyVo createVerifyVo(BindingVo bindingVo) {
|
|
private VerifyVo createVerifyVo(BindingVo bindingVo) {
|
|
VerifyVo verifyVo = new VerifyVo();
|
|
VerifyVo verifyVo = new VerifyVo();
|
|
|
|
|
|
@@ -69,4 +91,36 @@ public class AccountServiceImpl implements IAccountService {
|
|
Assert.isTrue(smtp.getSuccess(), "smtp解析失败:error:{} ;code:{};", smtp.getError(), smtp.getCode());
|
|
Assert.isTrue(smtp.getSuccess(), "smtp解析失败:error:{} ;code:{};", smtp.getError(), smtp.getCode());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 生成添加账号入参
|
|
|
|
+ */
|
|
|
|
+ private AddAccountVo createAddAccountVo(VerifyVo verifyVo, String email) {
|
|
|
|
+ AddAccountVo addAccountVo = BeanUtil.copyProperties(verifyVo, AddAccountVo.class);
|
|
|
|
+ addAccountVo.setAccount(email);
|
|
|
|
+ addAccountVo.setName(email);
|
|
|
|
+ addAccountVo.setEmail(email);
|
|
|
|
+ addAccountVo.setPath("*");
|
|
|
|
+ return addAccountVo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 验证添加状态
|
|
|
|
+ */
|
|
|
|
+ private void parsingAddAccountResult(AddAccountResult addAccountResult) {
|
|
|
|
+ String state = addAccountResult.getState();
|
|
|
|
+
|
|
|
|
+ Assert.isTrue("new".equals(state),
|
|
|
|
+ "邮箱添加失败,account:{},state:{}",
|
|
|
|
+ addAccountResult.getAccount(), addAccountResult.getState());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 添加邮件信息
|
|
|
|
+ */
|
|
|
|
+ private EmailInfo addEmailInfo(BindingVo bindingVo) {
|
|
|
|
+ EmailInfo emailInfo = BeanUtil.copyProperties(bindingVo, EmailInfo.class);
|
|
|
|
+ emailInfoService.save(emailInfo);
|
|
|
|
+ return emailInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|