From 2005b31ae98b0e58285e942db2c7fd61989b5fdc Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Fri, 31 Jul 2020 23:44:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=82=AE=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/startup/SocketClientStartUp.java | 13 +- .../properties/SocketServerProperties.java | 8 +- .../dao/projectleader/IProjectLeaderDao.java | 31 +++-- .../control/manager/SocketServerManager.java | 7 +- .../pojo/bos/ClientOffLineNoticeBO.java | 44 ++++++ .../control/pojo/bos/SocketClientBO.java | 27 +++- .../projectleader/ClientProjectLeaderDTO.java | 60 ++++++++ .../service/client/IClientService.java | 6 - .../client/impl/ClientServiceImpl.java | 5 - .../projectleader/IProjectLeaderService.java | 14 +- .../impl/ProjectLeaderServiceImpl.java | 6 + .../socket/offline/IOffLineService.java | 23 +++ .../offline/impl/OffLineServiceImpl.java | 131 ++++++++++++++++++ .../control/startup/SocketServerStartUp.java | 18 ++- .../projectleader/projectleader-mapper.xml | 36 +++++ .../utils/email/SimpleMailSenderUtil.java | 2 +- .../sms/service/impl/EmailServiceImpl.java | 3 + 17 files changed, 397 insertions(+), 37 deletions(-) create mode 100644 cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/ClientOffLineNoticeBO.java create mode 100644 cloud-central-control/src/main/java/com/cm/central/control/pojo/dtos/projectleader/ClientProjectLeaderDTO.java create mode 100644 cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/IOffLineService.java create mode 100644 cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/impl/OffLineServiceImpl.java diff --git a/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/startup/SocketClientStartUp.java b/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/startup/SocketClientStartUp.java index 1f05182..e9a64b3 100644 --- a/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/startup/SocketClientStartUp.java +++ b/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/startup/SocketClientStartUp.java @@ -2,7 +2,10 @@ package com.cm.central.control.client.socket.startup; import com.cm.central.control.client.socket.socket.SocketClientRunnable; import com.cm.socket.pojo.SocketClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; @@ -20,11 +23,19 @@ import org.springframework.stereotype.Component; @Component public class SocketClientStartUp implements ApplicationRunner { + private static final Logger LOG = LoggerFactory.getLogger(SocketClientStartUp.class); + @Value("${socket.central-control.active:false}") + private Boolean socketServerActive; + @Autowired private SocketClientRunnable socketClientRunnable; @Override public void run(ApplicationArguments args) throws Exception { - new Thread(socketClientRunnable).start(); + if (socketServerActive != null && socketServerActive) { + new Thread(socketClientRunnable).start(); + } else { + LOG.debug("Socket监控未激活"); + } } } diff --git a/cloud-central-control/src/main/java/com/cm/central/control/config/properties/SocketServerProperties.java b/cloud-central-control/src/main/java/com/cm/central/control/config/properties/SocketServerProperties.java index 35ca560..81e6435 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/config/properties/SocketServerProperties.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/config/properties/SocketServerProperties.java @@ -21,7 +21,7 @@ public class SocketServerProperties { private Integer port = 9999; private Integer soBacklog = 1024; - private Integer readIdleTimeSecond = 10; + private Integer readIdleTimeSecond = 5; private Integer offlineNoticeMinute = 10; private String offlineNoticeType = "email"; private Integer offlineNoticeCount = 3; @@ -43,7 +43,7 @@ public class SocketServerProperties { } public Integer getReadIdleTimeSecond() { - return readIdleTimeSecond < 0 ? 5 : readIdleTimeSecond; + return readIdleTimeSecond < 5 ? 5 : readIdleTimeSecond; } public void setReadIdleTimeSecond(Integer readIdleTimeSecond) { @@ -51,7 +51,7 @@ public class SocketServerProperties { } public Integer getOfflineNoticeMinute() { - return offlineNoticeMinute == null || offlineNoticeMinute < 0 ? 10 : offlineNoticeMinute; + return offlineNoticeMinute == null || offlineNoticeMinute < 1 ? 10 : offlineNoticeMinute; } public void setOfflineNoticeMinute(Integer offlineNoticeMinute) { @@ -67,7 +67,7 @@ public class SocketServerProperties { } public Integer getOfflineNoticeCount() { - return offlineNoticeCount == null || offlineNoticeCount < 0 ? 3 : offlineNoticeCount; + return offlineNoticeCount == null || offlineNoticeCount < 3 ? 3 : offlineNoticeCount; } public void setOfflineNoticeCount(Integer offlineNoticeCount) { diff --git a/cloud-central-control/src/main/java/com/cm/central/control/dao/projectleader/IProjectLeaderDao.java b/cloud-central-control/src/main/java/com/cm/central/control/dao/projectleader/IProjectLeaderDao.java index 21a1026..1fd2d09 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/dao/projectleader/IProjectLeaderDao.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/dao/projectleader/IProjectLeaderDao.java @@ -1,5 +1,6 @@ package com.cm.central.control.dao.projectleader; +import com.cm.central.control.pojo.dtos.projectleader.ClientProjectLeaderDTO; import com.cm.common.exception.RemoveException; import com.cm.common.exception.SaveException; import com.cm.common.exception.SearchException; @@ -38,11 +39,11 @@ public interface IProjectLeaderDao { void removeProjectLeader(Map params) throws RemoveException; /** - * 删除项目负责人(物理) - * - * @param params - * @throws RemoveException - */ + * 删除项目负责人(物理) + * + * @param params + * @throws RemoveException + */ void deleteProjectLeader(Map params) throws RemoveException; /** @@ -72,12 +73,20 @@ public interface IProjectLeaderDao { List listProjectLeader(Map params) throws SearchException; /** - * 项目负责人统计 - * - * @param params - * @return - * @throws SearchException - */ + * 项目负责人统计 + * + * @param params + * @return + * @throws SearchException + */ Integer countProjectLeader(Map params) throws SearchException; + /** + * 获取项目负责人(通过客户端ID) + * + * @param clientId + * @return + * @throws SearchException + */ + ClientProjectLeaderDTO getProjectLeaderByClientId(String clientId) throws SearchException; } \ No newline at end of file diff --git a/cloud-central-control/src/main/java/com/cm/central/control/manager/SocketServerManager.java b/cloud-central-control/src/main/java/com/cm/central/control/manager/SocketServerManager.java index 4dfea48..e70311b 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/manager/SocketServerManager.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/manager/SocketServerManager.java @@ -90,7 +90,7 @@ public class SocketServerManager { public void removeOnlineClient(String token) { SocketClientBO socketClientBO = getOnlineClientByToken(token); if (socketClientBO != null) { - // 加入离线队列 + // 加入离线队列,清空通知队列 offLineClientMap.put(socketClientBO.getClientId(), socketClientBO); } onLineClientMap.remove(token); @@ -125,6 +125,11 @@ public class SocketServerManager { return false; } + /** + * 离线客户端列表 + * + * @return + */ public List listOffLineClient() { List socketClientBOs = new ArrayList<>(); for (Map.Entry kv : offLineClientMap.entrySet()) { diff --git a/cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/ClientOffLineNoticeBO.java b/cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/ClientOffLineNoticeBO.java new file mode 100644 index 0000000..2cbabdd --- /dev/null +++ b/cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/ClientOffLineNoticeBO.java @@ -0,0 +1,44 @@ +package com.cm.central.control.pojo.bos; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: ClientOffLineNoticeBO + * @Description: 客户端离线 + * @Author: WangGeng + * @Date: 2020/7/31 8:37 下午 + * @Version: 1.0 + **/ +public class ClientOffLineNoticeBO { + + private String emailId; + private long sendTime; + + public String getEmailId() { + return emailId == null ? "" : emailId.trim(); + } + + public void setEmailId(String emailId) { + this.emailId = emailId; + } + + public long getSendTime() { + return sendTime; + } + + public void setSendTime(long sendTime) { + this.sendTime = sendTime; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"emailId\":") + .append("\"").append(emailId).append("\""); + sb.append(",\"sendTime\":") + .append(sendTime); + sb.append('}'); + return sb.toString(); + } +} diff --git a/cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/SocketClientBO.java b/cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/SocketClientBO.java index 8555a9e..b6e80fc 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/SocketClientBO.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/pojo/bos/SocketClientBO.java @@ -3,6 +3,8 @@ package com.cm.central.control.pojo.bos; import io.netty.channel.Channel; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; /** * When you feel like quitting. Think about why you started @@ -20,7 +22,7 @@ public class SocketClientBO implements Serializable { private String clientId; private Long lastTime; private Channel channel; - + private Integer emailNoticeCount = 0; public String getClientId() { return clientId == null ? "" : clientId.trim(); @@ -45,4 +47,27 @@ public class SocketClientBO implements Serializable { public void setChannel(Channel channel) { this.channel = channel; } + + public Integer getEmailNoticeCount() { + return emailNoticeCount == null || emailNoticeCount < 0 ? 0 : emailNoticeCount; + } + + public void setEmailNoticeCount(Integer emailNoticeCount) { + this.emailNoticeCount = emailNoticeCount; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"clientId\":") + .append("\"").append(clientId).append("\""); + sb.append(",\"lastTime\":") + .append(lastTime); + sb.append(",\"channel\":") + .append(channel); + sb.append(",\"emailNoticeCount\":") + .append(emailNoticeCount); + sb.append('}'); + return sb.toString(); + } } diff --git a/cloud-central-control/src/main/java/com/cm/central/control/pojo/dtos/projectleader/ClientProjectLeaderDTO.java b/cloud-central-control/src/main/java/com/cm/central/control/pojo/dtos/projectleader/ClientProjectLeaderDTO.java new file mode 100644 index 0000000..64f8c5a --- /dev/null +++ b/cloud-central-control/src/main/java/com/cm/central/control/pojo/dtos/projectleader/ClientProjectLeaderDTO.java @@ -0,0 +1,60 @@ +package com.cm.central.control.pojo.dtos.projectleader; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * + * @ClassName: ProjectLeaderDTO + * @Description: 项目负责人 + * @Author: WenG + * @Date: 2020-07-30 19:04 + * @Version: 1.0 + **/ +@ApiModel +public class ClientProjectLeaderDTO extends ProjectLeaderDTO { + + @ApiModelProperty(name = "clientName", value = "名称") + private String clientName; + @ApiModelProperty(name = "customerName", value = "客户名称") + private String customerName; + @ApiModelProperty(name = "serverIp", value = "服务器地址") + private String serverIp; + + public String getClientName() { + return clientName == null ? "" : clientName.trim(); + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + public String getCustomerName() { + return customerName == null ? "" : customerName.trim(); + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getServerIp() { + return serverIp == null ? "" : serverIp.trim(); + } + + public void setServerIp(String serverIp) { + this.serverIp = serverIp; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"clientName\":") + .append("\"").append(clientName).append("\""); + sb.append(",\"customerName\":") + .append("\"").append(customerName).append("\""); + sb.append(",\"serverIp\":") + .append("\"").append(serverIp).append("\""); + sb.append('}'); + return sb.toString(); + } +} diff --git a/cloud-central-control/src/main/java/com/cm/central/control/service/client/IClientService.java b/cloud-central-control/src/main/java/com/cm/central/control/service/client/IClientService.java index f3091c0..5ed9cb8 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/service/client/IClientService.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/service/client/IClientService.java @@ -218,10 +218,4 @@ public interface IClientService { */ ClientBO getClientBOByClientId(String clientId) throws SearchException; - /** - * 检查离线客户端并发送邮件 - * - * @throws Exception - */ - void checkOfflineClientAndSendEmail() throws Exception; } \ No newline at end of file diff --git a/cloud-central-control/src/main/java/com/cm/central/control/service/client/impl/ClientServiceImpl.java b/cloud-central-control/src/main/java/com/cm/central/control/service/client/impl/ClientServiceImpl.java index 8f26b19..9a23567 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/service/client/impl/ClientServiceImpl.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/service/client/impl/ClientServiceImpl.java @@ -270,9 +270,4 @@ public class ClientServiceImpl extends AbstractService implements IClientService return clientDao.getClientBO(params); } - @Override - public void checkOfflineClientAndSendEmail() throws Exception { - - } - } \ No newline at end of file diff --git a/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/IProjectLeaderService.java b/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/IProjectLeaderService.java index b108a45..8faa0a1 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/IProjectLeaderService.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/IProjectLeaderService.java @@ -1,14 +1,14 @@ package com.cm.central.control.service.projectleader; +import com.cm.central.control.pojo.dtos.projectleader.ClientProjectLeaderDTO; +import com.cm.central.control.pojo.dtos.projectleader.ProjectLeaderDTO; +import com.cm.central.control.pojo.vos.projectleader.ProjectLeaderVO; import com.cm.common.exception.RemoveException; -import com.cm.common.exception.SaveException; import com.cm.common.exception.SearchException; import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultData; import com.cm.common.result.SuccessResultList; -import com.cm.central.control.pojo.dtos.projectleader.ProjectLeaderDTO; -import com.cm.central.control.pojo.vos.projectleader.ProjectLeaderVO; import java.util.List; import java.util.Map; @@ -153,4 +153,12 @@ public interface IProjectLeaderService { */ SuccessResultData countProjectLeader(Map params) throws SearchException; + /** + * 获取项目负责人 + * + * @param clientId + * @return + * @throws SearchException + */ + ClientProjectLeaderDTO getProjectLeaderByClientId(String clientId) throws SearchException; } \ No newline at end of file diff --git a/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/impl/ProjectLeaderServiceImpl.java b/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/impl/ProjectLeaderServiceImpl.java index a4ff9f0..3986722 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/impl/ProjectLeaderServiceImpl.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/service/projectleader/impl/ProjectLeaderServiceImpl.java @@ -1,5 +1,6 @@ package com.cm.central.control.service.projectleader.impl; +import com.cm.central.control.pojo.dtos.projectleader.ClientProjectLeaderDTO; import com.cm.common.base.AbstractService; import com.cm.common.exception.RemoveException; import com.cm.common.exception.SaveException; @@ -185,4 +186,9 @@ public class ProjectLeaderServiceImpl extends AbstractService implements IProjec return new SuccessResultData<>(countNumberProjectLeader(params)); } + @Override + public ClientProjectLeaderDTO getProjectLeaderByClientId(String clientId) throws SearchException { + return projectLeaderDao.getProjectLeaderByClientId(clientId); + } + } \ No newline at end of file diff --git a/cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/IOffLineService.java b/cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/IOffLineService.java new file mode 100644 index 0000000..a4445eb --- /dev/null +++ b/cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/IOffLineService.java @@ -0,0 +1,23 @@ +package com.cm.central.control.service.socket.offline; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IOffLineService + * @Description: 离线业务 + * @Author: WangGeng + * @Date: 2020/7/31 8:51 下午 + * @Version: 1.0 + **/ +public interface IOffLineService { + + String NOTICE_TYPE_EMAIL = "email"; + String NOTICE_TYPE_SMS = "sms"; + + /** + * 检查离线客户端并发送邮件 + * @throws Exception + */ + void checkOfflineClientAndSendEmail() throws Exception; +} diff --git a/cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/impl/OffLineServiceImpl.java b/cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/impl/OffLineServiceImpl.java new file mode 100644 index 0000000..18fd9e6 --- /dev/null +++ b/cloud-central-control/src/main/java/com/cm/central/control/service/socket/offline/impl/OffLineServiceImpl.java @@ -0,0 +1,131 @@ +package com.cm.central.control.service.socket.offline.impl; + +import com.alibaba.druid.util.StringUtils; +import com.cm.central.control.config.properties.SocketServerProperties; +import com.cm.central.control.manager.SocketServerManager; +import com.cm.central.control.pojo.bos.ClientOffLineNoticeBO; +import com.cm.central.control.pojo.bos.SocketClientBO; +import com.cm.central.control.pojo.dtos.projectleader.ClientProjectLeaderDTO; +import com.cm.central.control.service.BaseService; +import com.cm.central.control.service.client.IClientService; +import com.cm.central.control.service.projectleader.IProjectLeaderService; +import com.cm.central.control.service.socket.offline.IOffLineService; +import com.cm.common.constants.ISystemConstant; +import com.cm.manager.sms.pojo.vos.email.EmailVO; +import com.cm.manager.sms.service.IEmailService; +import com.cm.manager.sms.service.ISmsService; +import org.joda.time.DateTime; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: OffLineServiceImpl + * @Description: 离线业务 + * @Author: WangGeng + * @Date: 2020/7/31 8:51 下午 + * @Version: 1.0 + **/ +@Service +public class OffLineServiceImpl extends BaseService implements IOffLineService { + + @Autowired + private SocketServerProperties socketServerProperties; + @Autowired + private IClientService clientService; + @Autowired + private IProjectLeaderService projectLeaderService; + @Autowired + private IEmailService emailService; + @Autowired + private ISmsService smsService; + + @Override + public void checkOfflineClientAndSendEmail() throws Exception { + // 获取当前离线的客户端 + List socketClientBOs = SocketServerManager.getInstance().listOffLineClient(); + if (socketClientBOs.isEmpty()) { + LOG.debug("当前无离线客户端"); + return; + } + boolean canNotice = StringUtils.equalsIgnoreCase(NOTICE_TYPE_EMAIL, socketServerProperties.getOfflineNoticeType()); + if (!canNotice) { + LOG.debug("通知类型设置错误,目前只支持email"); + return; + } + Map> noticeMap = new HashMap<>(16); + // 构建通知通知内容 + for (SocketClientBO socketClientBO : socketClientBOs) { + int emailNoticeCount = socketClientBO.getEmailNoticeCount(); + if (emailNoticeCount >= socketServerProperties.getOfflineNoticeCount()) { + // 超过通知次数的不再通知 + continue; + } + if (System.currentTimeMillis() - socketClientBO.getLastTime() <= socketServerProperties.getOfflineNoticeMinute() * 60000) { + // 没有超过提醒时间的不通知 + continue; + } + // 查询客户端负责人 + ClientProjectLeaderDTO clientProjectLeaderDTO = projectLeaderService.getProjectLeaderByClientId(socketClientBO.getClientId()); + if (clientProjectLeaderDTO == null) { + LOG.debug("ClientId: {},没有设置项目负责人"); + continue; + } + String emailKey = clientProjectLeaderDTO.getLeaderEmail(); + StringBuilder noticeContentSB = new StringBuilder(); + noticeContentSB.append("").append(clientProjectLeaderDTO.getClientName()).append("") + .append(clientProjectLeaderDTO.getCustomerName()).append("").append(clientProjectLeaderDTO.getServerIp()) + .append("").append(new DateTime(socketClientBO.getLastTime()).toString(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)) + .append(""); + List noticeList = noticeMap.get(emailKey); + if (noticeList == null) { + noticeList = new ArrayList<>(); + noticeMap.put(emailKey, noticeList); + } + noticeList.add(noticeContentSB.toString()); + socketClientBO.setEmailNoticeCount(emailNoticeCount + 1); + } + sendNoticeEmail(noticeMap); + } + + /** + * 发送邮件 + * + * @param noticeMap + * @throws Exception + */ + private void sendNoticeEmail(Map> noticeMap) throws Exception { + if (noticeMap.isEmpty()) { + LOG.debug("无离线通知邮件发送"); + return; + } + for (Map.Entry> notice : noticeMap.entrySet()) { + String receiverEmail = notice.getKey(); + StringBuilder noticeContentTable = new StringBuilder(); + noticeContentTable.append("
您好,您所负责的项目出现异常离线情况,请及时处理,如果是主动离线请忽略

"); + noticeContentTable.append("
详细情况见下表:

"); + noticeContentTable.append(""); + noticeContentTable.append(""); + noticeContentTable.append(""); + for (String tbodyTr : notice.getValue()) { + noticeContentTable.append(tbodyTr); + } + noticeContentTable.append(""); + noticeContentTable.append("
系统所属客户服务器IP离线时间
"); + EmailVO emailVO = new EmailVO(); + emailVO.setEmailReceiver(receiverEmail); + emailVO.setEmailSubject("项目离线通知"); + emailVO.setEmailContent(noticeContentTable.toString()); + emailVO.setEmailType("2"); + emailService.saveAndSendSystemEmail(emailVO); + } + } + +} diff --git a/cloud-central-control/src/main/java/com/cm/central/control/startup/SocketServerStartUp.java b/cloud-central-control/src/main/java/com/cm/central/control/startup/SocketServerStartUp.java index 2de2111..d967e23 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/startup/SocketServerStartUp.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/startup/SocketServerStartUp.java @@ -1,9 +1,13 @@ package com.cm.central.control.startup; import com.cm.central.control.service.client.IClientService; +import com.cm.central.control.service.socket.offline.IOffLineService; import com.cm.central.control.socket.SocketServerRunnable; import com.cm.common.token.app.AppTokenManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.scheduling.annotation.EnableScheduling; @@ -24,19 +28,25 @@ import org.springframework.stereotype.Component; @EnableScheduling public class SocketServerStartUp implements ApplicationRunner { + private static final Logger LOG = LoggerFactory.getLogger(SocketServerStartUp.class); @Autowired - private IClientService clientService; - + private IOffLineService offLineService; @Autowired private SocketServerRunnable socketServerRunnable; + @Value("${socket.central-control.active:false}") + private Boolean socketServerActive; @Override public void run(ApplicationArguments args) throws Exception { - new Thread(socketServerRunnable).start(); + if (socketServerActive != null && socketServerActive) { + new Thread(socketServerRunnable).start(); + } else { + LOG.debug("Socket监控未激活"); + } } @Scheduled(cron = "0 0/1 * * * ?") public void checkOfflineClientEmail() throws Exception { - clientService.checkOfflineClientAndSendEmail(); + offLineService.checkOfflineClientAndSendEmail(); } } diff --git a/cloud-central-control/src/main/resources/mybatis/mapper/projectleader/projectleader-mapper.xml b/cloud-central-control/src/main/resources/mybatis/mapper/projectleader/projectleader-mapper.xml index f45a126..fee7dc4 100644 --- a/cloud-central-control/src/main/resources/mybatis/mapper/projectleader/projectleader-mapper.xml +++ b/cloud-central-control/src/main/resources/mybatis/mapper/projectleader/projectleader-mapper.xml @@ -9,6 +9,12 @@ + + + + + + INSERT INTO central_project_leader( @@ -143,4 +149,34 @@ t1.is_delete = 0 + + + \ No newline at end of file diff --git a/cloud-common/src/main/java/com/cm/common/utils/email/SimpleMailSenderUtil.java b/cloud-common/src/main/java/com/cm/common/utils/email/SimpleMailSenderUtil.java index a6ec6f3..1603ef1 100644 --- a/cloud-common/src/main/java/com/cm/common/utils/email/SimpleMailSenderUtil.java +++ b/cloud-common/src/main/java/com/cm/common/utils/email/SimpleMailSenderUtil.java @@ -126,7 +126,7 @@ public class SimpleMailSenderUtil { mailInfo.setUserName("dpdbd001@163.com"); mailInfo.setPassword("WAASUQNNVITVXDJS"); mailInfo.setFromAddress("dpdbd001@163.com"); - mailInfo.setToAddress("450292408@qq.com "); + mailInfo.setToAddress("450292408@qq.com"); mailInfo.setSubject("123"); mailInfo.setContent("123"); SimpleMailSenderUtil simpleMailSenderUtil = new SimpleMailSenderUtil(); diff --git a/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/EmailServiceImpl.java b/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/EmailServiceImpl.java index ce03a08..d927ae8 100644 --- a/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/EmailServiceImpl.java +++ b/cloud-manager-sms/src/main/java/com/cm/manager/sms/service/impl/EmailServiceImpl.java @@ -9,6 +9,7 @@ import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultList; import com.cm.common.utils.HashMapUtil; +import com.cm.common.utils.UUIDUtil; import com.cm.common.utils.email.SimpleMailSenderUtil; import com.cm.manager.sms.config.properties.EmailProperties; import com.cm.manager.sms.dao.email.IEmailDao; @@ -64,8 +65,10 @@ public class EmailServiceImpl extends AbstractService implements IEmailService { if (!sendSuccess) { LOG.error("邮件发送失败"); } + emailVO.setEmailSender(emailProperties.getSenderEmail()); emailVO.setSendingStatus(sendSuccess ? 1 : 0); Map params = HashMapUtil.beanToMap(emailVO); + params.put("emailId", UUIDUtil.getUUID()); setSaveInfoByUserId(params, "1"); emailDao.saveEmail(params); return new SuccessResult();