refactor: 飞书显示@其他用户

This commit is contained in:
Captain.B 2021-08-21 16:15:05 +08:00 committed by 刘瑞斌
parent 3c303e97e0
commit 14abc1a82e
4 changed files with 26 additions and 5 deletions

View File

@ -57,7 +57,7 @@
</select> </select>
<select id="queryTypeByIds" parameterType="java.lang.String" resultType="io.metersphere.notice.domain.UserDetail"> <select id="queryTypeByIds" parameterType="java.lang.String" resultType="io.metersphere.notice.domain.UserDetail">
SELECT SELECT
email,phone email,phone,name
from user from user
WHERE id IN WHERE id IN
<foreach collection="list" item="id" index="index" <foreach collection="list" item="id" index="index"

View File

@ -4,6 +4,7 @@ import lombok.Data;
@Data @Data
public class UserDetail { public class UserDetail {
private String email; private String name;
private String phone; private String email;
private String phone;
} }

View File

@ -112,6 +112,10 @@ public abstract class AbstractNoticeSender implements NoticeSender {
return phoneList.stream().distinct().collect(Collectors.toList()); return phoneList.stream().distinct().collect(Collectors.toList());
} }
protected List<UserDetail> getUserDetails(NoticeModel noticeModel, List<String> userIds) {
return userService.queryTypeByIds(userIds);
}
private List<Receiver> getRealUserIds(List<String> userIds, NoticeModel noticeModel, String event) { private List<Receiver> getRealUserIds(List<String> userIds, NoticeModel noticeModel, String event) {
List<Receiver> toUsers = new ArrayList<>(); List<Receiver> toUsers = new ArrayList<>();
Map<String, Object> paramMap = noticeModel.getParamMap(); Map<String, Object> paramMap = noticeModel.getParamMap();

View File

@ -1,22 +1,38 @@
package io.metersphere.notice.sender.impl; package io.metersphere.notice.sender.impl;
import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.notice.domain.Receiver;
import io.metersphere.notice.domain.UserDetail;
import io.metersphere.notice.sender.AbstractNoticeSender; import io.metersphere.notice.sender.AbstractNoticeSender;
import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.util.LarkClient; import io.metersphere.notice.util.LarkClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
@Component @Component
public class LarkNoticeSender extends AbstractNoticeSender { public class LarkNoticeSender extends AbstractNoticeSender {
public void sendLark(MessageDetail messageDetail, String context) { public void sendLark(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
//TextMessage message = new TextMessage(context); //TextMessage message = new TextMessage(context);
List<String> userIds = noticeModel.getReceivers().stream()
.map(Receiver::getUserId)
.distinct()
.collect(Collectors.toList());
List<UserDetail> userDetails = super.getUserDetails(noticeModel, userIds);
List<String> collect = userDetails.stream()
.map(ud -> "<at email=\"" + ud.getEmail() + "\">" + ud.getName() + "</at>")
.collect(Collectors.toList());
context += StringUtils.join(collect, " ");
LarkClient.send(messageDetail.getWebhook(), context); LarkClient.send(messageDetail.getWebhook(), context);
} }
@Override @Override
public void send(MessageDetail messageDetail, NoticeModel noticeModel) { public void send(MessageDetail messageDetail, NoticeModel noticeModel) {
String context = super.getContext(messageDetail, noticeModel); String context = super.getContext(messageDetail, noticeModel);
sendLark(messageDetail, context); sendLark(messageDetail, noticeModel, context);
} }
} }