【新增】消息服务
This commit is contained in:
parent
44576d5b2b
commit
5a3b9be923
|
|
@ -206,6 +206,12 @@
|
|||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.5.17</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.nflg.qms.admin.controller;
|
||||
|
||||
import com.nflg.qms.admin.service.BasdeSerialNumberControllerService;
|
||||
import com.nflg.qms.admin.service.ISendMessageService;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.repository.entity.QmsTodoItem;
|
||||
import com.nflg.wms.starter.BaseController;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class TestController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private List<ISendMessageService> sendMessageServices;
|
||||
|
||||
@Resource
|
||||
private BasdeSerialNumberControllerService basdeSerialNumberControllerService;
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
@GetMapping("/sendMessage")
|
||||
public ApiResult<Void> sendMessage() {
|
||||
QmsTodoItem qmsTodoItem = new QmsTodoItem()
|
||||
.setCode(basdeSerialNumberControllerService.generateSerialNumber(32))
|
||||
.setIsRead(false)
|
||||
.setSourceTypeId(2046157760401182721L)
|
||||
.setSourceId(0L)
|
||||
.setCreateUserId(UserUtil.getUserId())
|
||||
.setCreateUserName(UserUtil.getUserName())
|
||||
.setCreateTime(java.time.LocalDateTime.now());
|
||||
sendMessageServices.forEach(service -> service.sendSystemMessage(qmsTodoItem));
|
||||
return ApiResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.nflg.qms.admin.service;
|
||||
|
||||
import com.nflg.wms.repository.entity.QmsTodoItem;
|
||||
|
||||
public interface ISendMessageService {
|
||||
|
||||
/**
|
||||
* 发送待办消息
|
||||
* @param item 待办事项
|
||||
*/
|
||||
void sendSystemMessage(QmsTodoItem item);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.nflg.qms.admin.service.impl;
|
||||
|
||||
import com.nflg.qms.admin.service.ISendMessageService;
|
||||
import com.nflg.wms.repository.entity.QmsTodoItem;
|
||||
import com.nflg.wms.starter.service.EmailService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 邮件消息实现类
|
||||
*/
|
||||
@Service
|
||||
public class EmailMessageImpl implements ISendMessageService {
|
||||
|
||||
@Resource
|
||||
private EmailService emailService;
|
||||
|
||||
@Override
|
||||
public void sendSystemMessage(QmsTodoItem item) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.nflg.qms.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.qms.admin.service.ISendMessageService;
|
||||
import com.nflg.qms.admin.service.RtxSendService;
|
||||
import com.nflg.wms.common.pojo.vo.DictionaryItemTranslateVO;
|
||||
import com.nflg.wms.common.util.MultilingualUtil;
|
||||
import com.nflg.wms.repository.entity.QmsTodoItem;
|
||||
import com.nflg.wms.repository.entity.UserInterior;
|
||||
import com.nflg.wms.repository.service.IDictionaryItemTranslateService;
|
||||
import com.nflg.wms.repository.service.IUserInteriorService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 腾讯RTX消息实现类
|
||||
*/
|
||||
@Service
|
||||
public class RtxMessageImpl implements ISendMessageService {
|
||||
|
||||
@Resource
|
||||
private RtxSendService rtxSendService;
|
||||
|
||||
@Resource
|
||||
private IUserInteriorService userInteriorService;
|
||||
|
||||
@Resource
|
||||
private IDictionaryItemTranslateService dictionaryItemTranslateService;
|
||||
|
||||
@Override
|
||||
public void sendSystemMessage(QmsTodoItem item) {
|
||||
UserInterior userInterior = userInteriorService.lambdaQuery()
|
||||
.eq(UserInterior::getUserId, item.getCreateUserId())
|
||||
.one();
|
||||
if (Objects.nonNull(userInterior) && StrUtil.isNotBlank(userInterior.getRtxCode())) {
|
||||
DictionaryItemTranslateVO dictionaryItemTranslateVO = dictionaryItemTranslateService.getByDictionaryItemId(item.getSourceTypeId(), MultilingualUtil.getLanguage());
|
||||
if (Objects.nonNull(dictionaryItemTranslateVO)) {
|
||||
rtxSendService.sendNotify(List.of(userInterior.getRtxCode()),
|
||||
dictionaryItemTranslateVO.getValue(),
|
||||
switch (dictionaryItemTranslateVO.getDictionaryItemCode()) {
|
||||
default -> "未定义的待办事项:" + dictionaryItemTranslateVO.getDictionaryItemCode();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.nflg.qms.admin.service.impl;
|
||||
|
||||
import com.nflg.qms.admin.service.ISendMessageService;
|
||||
import com.nflg.wms.repository.entity.QmsTodoItem;
|
||||
import com.nflg.wms.repository.service.IQmsTodoItemService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 待办事项消息实现类
|
||||
*/
|
||||
@Service
|
||||
public class TodoItemMessageImpl implements ISendMessageService {
|
||||
|
||||
@Resource
|
||||
private IQmsTodoItemService todoItemService;
|
||||
|
||||
@Override
|
||||
public void sendSystemMessage(QmsTodoItem item) {
|
||||
todoItemService.save(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.nflg.wms.common.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class EmailConfig {
|
||||
|
||||
//SMTP 服务器地址
|
||||
private String host;
|
||||
|
||||
//SMTP 服务器端口
|
||||
private Integer port;
|
||||
|
||||
//发件人用户名
|
||||
private String username;
|
||||
|
||||
//发件人密码
|
||||
private String password;
|
||||
}
|
||||
|
|
@ -31,11 +31,6 @@ public class QmsTodoItem implements Serializable {
|
|||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 来源类型ID,关联dictionary_item表(字典编码MessageType)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -44,4 +44,9 @@ public class UserInterior implements Serializable {
|
|||
* 职位id
|
||||
*/
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* rtx账号
|
||||
*/
|
||||
private String rtxCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,6 @@ public interface DictionaryItemTranslateMapper extends BaseMapper<DictionaryItem
|
|||
String getValueByCode(String dictionaryCode, String dictionaryItemCode, String language);
|
||||
|
||||
List<DictionaryItemTranslate> getByDictionaryCode(String dictionaryCode);
|
||||
|
||||
DictionaryItemTranslateVO getByDictionaryItemId(Long id, String language);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ public interface IDictionaryItemTranslateService extends IService<DictionaryItem
|
|||
|
||||
List<DictionaryItemTranslateVO> getListByDictionaryItemId(Long id);
|
||||
|
||||
DictionaryItemTranslateVO getByDictionaryItemId(Long id, String language);
|
||||
|
||||
Long getId(Long dictionaryItemId, String code);
|
||||
|
||||
List<DictionaryItemTranslateVO> getAllByDictionaryCode(String code, String language);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,11 @@ public class DictionaryItemTranslateServiceImpl extends ServiceImpl<DictionaryIt
|
|||
return datas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DictionaryItemTranslateVO getByDictionaryItemId(Long id, String language) {
|
||||
return baseMapper.getByDictionaryItemId(id, language);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId(Long dictionaryItemId, String code) {
|
||||
DictionaryItemTranslate translate = lambdaQuery()
|
||||
|
|
|
|||
|
|
@ -37,4 +37,12 @@
|
|||
WHERE d.code=#{dictionaryCode}
|
||||
ORDER BY dit.id
|
||||
</select>
|
||||
|
||||
<select id="getByDictionaryItemId" resultType="com.nflg.wms.common.pojo.vo.DictionaryItemTranslateVO">
|
||||
SELECT t.id,l.code,l.name,t.value,t.dictionary_item_id,di.name as "dictionaryItemName",di.code as "dictionaryItemCode"
|
||||
FROM dictionary_item_translate t
|
||||
LEFT JOIN dictionary_item di ON di.id=t.dictionary_item_id
|
||||
LEFT JOIN language l ON t.language_code=l.code
|
||||
WHERE t.dictionary_item_id=#{id} AND t.language_code=#{language}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -117,6 +117,15 @@
|
|||
<artifactId>s3</artifactId>
|
||||
<version>2.39.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
package com.nflg.wms.starter.service;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.nflg.wms.common.pojo.dto.EmailConfig;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.ParamConfig;
|
||||
import com.nflg.wms.repository.service.IParamConfigService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EmailService {
|
||||
|
||||
@Resource
|
||||
private IParamConfigService paramConfigService;
|
||||
|
||||
public void sendEmail(String to,String subject, String content) throws MessagingException {
|
||||
log.info("准备发送邮件,to:{},subject:{},content:{}",to,subject,content);
|
||||
ParamConfig config = paramConfigService.lambdaQuery().eq(ParamConfig::getCode, "EmailSet").one();
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(config)).throwMessage("未配置邮件参数");
|
||||
EmailConfig emailConfig= JSONUtil.toBean(config.getValue(), EmailConfig.class);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(emailConfig)).throwMessage("邮件参数解析失败");
|
||||
Properties properties = new Properties();
|
||||
properties.put("mail.smtp.host", emailConfig.getHost());
|
||||
properties.put("mail.smtp.port", emailConfig.getPort().toString());
|
||||
properties.put("mail.smtp.auth", "true");
|
||||
properties.put("mail.smtp.ssl.enable", "true");
|
||||
// 设置超时时间(单位:毫秒)
|
||||
properties.put("mail.smtp.connectiontimeout", "5000"); // 连接超时
|
||||
properties.put("mail.smtp.timeout", "5000"); // 读取超时
|
||||
properties.put("mail.smtp.writetimeout", "5000"); // 写入超时
|
||||
Session session = Session.getInstance(properties, new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(emailConfig.getUsername(), emailConfig.getPassword());
|
||||
}
|
||||
});
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(emailConfig.getUsername()));
|
||||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
|
||||
message.setSubject(subject);
|
||||
message.setContent(content, "text/html; charset=UTF-8");
|
||||
Transport.send(message);
|
||||
log.info("发送邮件完成,to:{},subject:{},content:{}",to,subject,content);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue