|
@@ -9,12 +9,22 @@ import com.dgtly.common.utils.StringUtils;
|
|
import com.dgtly.common.utils.UserIdentityUtil;
|
|
import com.dgtly.common.utils.UserIdentityUtil;
|
|
import com.dgtly.system.domain.*;
|
|
import com.dgtly.system.domain.*;
|
|
import com.dgtly.system.mapper.*;
|
|
import com.dgtly.system.mapper.*;
|
|
|
|
+import com.dgtly.system.service.ISysDictDataService;
|
|
|
|
+import com.dgtly.system.util.MailUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import com.dgtly.system.service.ISysUserOrderAuthorService;
|
|
import com.dgtly.system.service.ISysUserOrderAuthorService;
|
|
import com.dgtly.common.core.text.Convert;
|
|
import com.dgtly.common.core.text.Convert;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import javax.mail.MessagingException;
|
|
|
|
+import javax.mail.NoSuchProviderException;
|
|
|
|
+import javax.mail.Session;
|
|
|
|
+import javax.mail.Transport;
|
|
|
|
+import javax.mail.internet.MimeMessage;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 权限Service业务层处理
|
|
* 权限Service业务层处理
|
|
*
|
|
*
|
|
@@ -22,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
* @date 2022-03-22
|
|
* @date 2022-03-22
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
|
|
+@Component
|
|
public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
{
|
|
{
|
|
@Autowired
|
|
@Autowired
|
|
@@ -32,15 +43,25 @@ public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private SysUserExtMapper userExtMapper;
|
|
private SysUserExtMapper userExtMapper;
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysDictDataService sysDictDataService;
|
|
@Autowired
|
|
@Autowired
|
|
private SysUserMapper userMapper;
|
|
private SysUserMapper userMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private SysUserQuitMapper userQuitMapper;
|
|
private SysUserQuitMapper userQuitMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private AssRelcustomerinfoMapper relcustomerinfoMapper;
|
|
private AssRelcustomerinfoMapper relcustomerinfoMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private MailUtils mailUtils;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private CustomerMapper customersMapper;
|
|
private CustomerMapper customersMapper;
|
|
|
|
+ @Value(value = "${spring.mail.username}")
|
|
|
|
+ private String myEmailAccount;
|
|
|
|
+ @Value(value = "${spring.mail.password}")
|
|
|
|
+ public String myEmailPassword;
|
|
|
|
+ @Value(value = "${spring.mail.host}")
|
|
|
|
+ public String myEmailSMTPHost;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 查询权限
|
|
* 查询权限
|
|
@@ -390,5 +411,83 @@ public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void sendmailUnionUser() {
|
|
|
|
+ List<UserVO> userList = userMapper.sendmailUnionUser();
|
|
|
|
+ // 1. 创建参数配置, 用于连接邮件服务器的参数配置
|
|
|
|
+ Properties props = new Properties(); // 参数配置
|
|
|
|
+ props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
|
|
|
|
+ props.setProperty("mail.smtp.host", myEmailSMTPHost); // 发件人的邮箱的 SMTP 服务器地址
|
|
|
|
+ props.setProperty("mail.smtp.port", "25");
|
|
|
|
+ props.setProperty("mail.smtp.auth", "true"); // 需要请求认证
|
|
|
|
+ props.setProperty("mail.smtp.starttls.enable", "false"); // 需要请求认证
|
|
|
|
+ props.setProperty("mail.smtp.ssl.enable", "false"); // 需要请求认证
|
|
|
|
+ Set<String> sendEmailUser = getConfigValueSet("sendmailUnionUser");
|
|
|
|
+ Session session = Session.getDefaultInstance(props);
|
|
|
|
+ session.setDebug(true);
|
|
|
|
+
|
|
|
|
+ for (String email : sendEmailUser
|
|
|
|
+ ) {
|
|
|
|
+ Mail mail = new Mail();
|
|
|
|
+ try {
|
|
|
|
+ mail.setFrom(myEmailSMTPHost);
|
|
|
|
+ mail.setTo(email);
|
|
|
|
+ mail.setSubject("用户账号重复");
|
|
|
|
+ mail.setContent(getHtmlUserContextList(userList));
|
|
|
|
+ //mailUtils.sendMailHtml(mailFromUsername, email, "用户账号重复通知", "您好,重复用户信息如下<br>" + userList);
|
|
|
|
+ MimeMessage message = mailUtils.createMimeMessage(session, myEmailAccount, email, mail);
|
|
|
|
+
|
|
|
|
+ // 4. 根据 Session 获取邮件传输对象
|
|
|
|
+ Transport transport = session.getTransport();
|
|
|
|
+
|
|
|
|
+ transport.connect(myEmailAccount, myEmailPassword);
|
|
|
|
+
|
|
|
|
+ // 6. 发送邮件, 发到所有的收件地址, message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人
|
|
|
|
+ transport.sendMessage(message, message.getAllRecipients());
|
|
|
|
+
|
|
|
|
+ // 7. 关闭连接
|
|
|
|
+ transport.close();
|
|
|
|
+ } catch (NoSuchProviderException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (MessagingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Set<String> getConfigValueSet(String dictType){
|
|
|
|
+ Set<String> res = new HashSet<>();
|
|
|
|
+ List<SysDictData> dictDatas = sysDictDataService.selectSimpleDictDataByType(dictType);
|
|
|
|
+ for(SysDictData d: dictDatas){
|
|
|
|
+ res.add(d.getDictValue());
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getHtmlUserContextList(List<UserVO> userList) {
|
|
|
|
+
|
|
|
|
+ String str = "";
|
|
|
|
+ for (UserVO u : userList) {
|
|
|
|
+ str += "<tr>" +
|
|
|
|
+ " <td>" + u.getUserName()
|
|
|
|
+ + " </td><td>" + u.getLoginName()
|
|
|
|
+ + " </td><td>" + u.getPhonenumber()
|
|
|
|
+ + " </td>" +
|
|
|
|
+ "</tr>";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String html = "<table border='1' Cellspacing='0'>" +
|
|
|
|
+ " <tr>" +
|
|
|
|
+ " <th>用户昵称</th>" +
|
|
|
|
+ " <th>用户登录名</th>" +
|
|
|
|
+ " <th>用户手机号</th>" +
|
|
|
|
+ " </tr>" +
|
|
|
|
+ str +
|
|
|
|
+ "</table>";
|
|
|
|
+
|
|
|
|
+ return html;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|