REQ-3345: 向群里发卡片消息
This commit is contained in:
parent
14e1d3add2
commit
fc62645227
@ -81,7 +81,9 @@ public class CardManager {
|
||||
public CardSendResponse send(CardSendRequest request) {
|
||||
// 校验参数
|
||||
BizAssertions.assertNotNull(request.getSender(), "发送人不能为空");
|
||||
BizAssertions.assertNotEmpty(request.getReceivers(), "接收人不能为空");
|
||||
BizAssertions.assertFalse(
|
||||
request.getReceivers().isEmpty()
|
||||
&& request.getImReceiveAccounts().isEmpty(), "接收人不能为空");
|
||||
RequestInfo requestInfo = new RequestInfo();
|
||||
requestInfo.setTemplateCode(request.getTemplateCode());
|
||||
requestInfo.setBizCode(request.getBizCode());
|
||||
|
||||
@ -98,8 +98,7 @@ public class CardSupport {
|
||||
GeneralMessagePushVO cardContent = cardParser.parseCardContent(
|
||||
sendModel.getCardTemplate(), sendModel.getRequest());
|
||||
sendModel.setCardContent(cardContent);
|
||||
for (PeerPerson person : sendModel.getRequest().getReceivers()) {
|
||||
for (AppTypeEnum appType : sendModel.getCardTemplate().ensureAppTypesPresent()) {
|
||||
Supplier<Card> cardFactory = () -> {
|
||||
Card card = new Card();
|
||||
sendModel.addCard(card);
|
||||
card.setBatchNo(sendModel.getRequestContext().getBatchNo());
|
||||
@ -119,18 +118,32 @@ public class CardSupport {
|
||||
card.setRouterParam(sendModel.getRequest().getRouterParam());
|
||||
card.setSenderAppType(AppTypeEnum.SYSTEM);
|
||||
card.setIsSenderRobot(YesOrNo.YES);
|
||||
card.setReceiverAppType(appType);
|
||||
card.setSenderPersonId(sendModel.getRequest().getSender().getPersonIdOrDefault());
|
||||
card.setSenderOuId(sendModel.getRequest().getSender().getOuIdOrDefault());
|
||||
card.setSenderWorkspaceId(sendModel.getRequest().getSender().getWorkspaceIdOrDefault());
|
||||
card.setReceiverPersonId(person.getPersonIdOrDefault());
|
||||
card.setReceiverOuId(person.getOuIdOrDefault());
|
||||
card.setReceiverWorkspaceId(person.getWorkspaceIdOrDefault());
|
||||
card.setSubtitle(sendModel.getRequest().getSubtitle());
|
||||
card.setButtonStates(Collections.emptyList());
|
||||
card.setUpdatable(sendModel.getCardTemplate().isUpdatable() ? YesOrNo.YES : YesOrNo.NO);
|
||||
return card;
|
||||
};
|
||||
for (PeerPerson person : sendModel.getRequest().receiversOrEmpty()) {
|
||||
for (AppTypeEnum appType : sendModel.getCardTemplate().ensureAppTypesPresent()) {
|
||||
Card card = cardFactory.get();
|
||||
card.setReceiverAppType(appType);
|
||||
card.setReceiverPersonId(person.getPersonIdOrDefault());
|
||||
card.setReceiverOuId(person.getOuIdOrDefault());
|
||||
card.setReceiverWorkspaceId(person.getWorkspaceIdOrDefault());
|
||||
card.setImReceiveAccount("");
|
||||
}
|
||||
}
|
||||
for (String imAccount : sendModel.getRequest().imReceiveAccountsOrEmpty()) {
|
||||
Card card = cardFactory.get();
|
||||
card.setReceiverAppType(AppTypeEnum.NONE);
|
||||
card.setReceiverPersonId(-1L);
|
||||
card.setReceiverOuId(-1L);
|
||||
card.setReceiverWorkspaceId(-1L);
|
||||
card.setImReceiveAccount(imAccount);
|
||||
}
|
||||
}
|
||||
|
||||
SendTemplateMessageParam buildImSendRequest(CardSendModel sendModel,
|
||||
@ -168,6 +181,7 @@ public class CardSupport {
|
||||
.append(subBizCode)
|
||||
.build());
|
||||
imRequest.setReceivePersons(group.buildReceiverAccounts());
|
||||
imRequest.setImReceiveAccounts(group.collectImReceiveAccounts());
|
||||
imRequest.setExt(extBuilder.get());
|
||||
imRequest.setUpdatable(sendModel.getCardTemplate().isUpdatable());
|
||||
if (pushData.determinePushable(log, template.getCode())) {
|
||||
|
||||
@ -10,12 +10,15 @@ import cn.axzo.msg.center.nimpush.device.PushDeviceSnapshots;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
@ -31,15 +34,18 @@ public class CardGroup {
|
||||
cards.add(card);
|
||||
}
|
||||
|
||||
public List<PersonAccountAttribute> buildReceiverAccounts() {
|
||||
return getCards().stream().map(card -> {
|
||||
public Set<PersonAccountAttribute> buildReceiverAccounts() {
|
||||
return getCards().stream()
|
||||
.filter(card -> card.getReceiverAppType() != AppTypeEnum.NONE)
|
||||
.map(card -> {
|
||||
PersonAccountAttribute account = new PersonAccountAttribute();
|
||||
account.setPersonId(card.getReceiverPersonId() + "");
|
||||
account.setOuId(card.getReceiverOuId());
|
||||
account.setWorkspaceId(card.getReceiverWorkspaceId());
|
||||
account.setAppType(groupKey.getAppType());
|
||||
return account;
|
||||
}).collect(toList());
|
||||
})
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
public List<ExcludePushPayload> buildNimPushExcludes(PushDeviceSnapshots deviceSnapshots) {
|
||||
@ -58,6 +64,13 @@ public class CardGroup {
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
public Set<String> collectImReceiveAccounts() {
|
||||
return getCards().stream()
|
||||
.map(Card::getImReceiveAccount)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
|
||||
@ -60,6 +60,7 @@ public class CardLoggers {
|
||||
log.setReceiverOuId(card.getReceiverOuId());
|
||||
log.setReceiverWorkspaceId(card.getReceiverWorkspaceId());
|
||||
log.setReceiverAppType(card.getReceiverAppType());
|
||||
log.setImReceiveAccount(card.getImReceiveAccount());
|
||||
log.setBizState(card.getBizState());
|
||||
log.setCardState(card.getCardState());
|
||||
log.setIdentityCode(card.getIdentityCode());
|
||||
|
||||
@ -73,6 +73,11 @@ public class CardSendRequest implements CardContent {
|
||||
@NotEmpty(message = "接收人不能为空")
|
||||
private Set<PeerPerson> receivers = new HashSet<>();
|
||||
|
||||
/**
|
||||
* 消息接收IM账号或群id
|
||||
*/
|
||||
private Set<String> imReceiveAccounts;
|
||||
|
||||
/**
|
||||
* 业务参数
|
||||
*/
|
||||
@ -93,6 +98,14 @@ public class CardSendRequest implements CardContent {
|
||||
*/
|
||||
private boolean returnCards = false;
|
||||
|
||||
public Set<PeerPerson> receiversOrEmpty() {
|
||||
return receivers == null ? Collections.emptySet() : receivers;
|
||||
}
|
||||
|
||||
public Set<String> imReceiveAccountsOrEmpty() {
|
||||
return imReceiveAccounts == null ? Collections.emptySet() : imReceiveAccounts;
|
||||
}
|
||||
|
||||
@Override @JsonIgnore @JSONField(serialize = false, defaultValue = "false")
|
||||
public CardStateInfo getStateInfo() {
|
||||
return CardStateInfo.create(CardState.CREATED, CardBizState.PENDING);
|
||||
|
||||
@ -152,6 +152,11 @@ public class Card extends BaseEntityExt<Card> implements CardContent {
|
||||
*/
|
||||
private Long receiverWorkspaceId;
|
||||
|
||||
/**
|
||||
* 接收账号
|
||||
*/
|
||||
private String imReceiveAccount;
|
||||
|
||||
/**
|
||||
* 按钮状态
|
||||
*/
|
||||
|
||||
@ -61,6 +61,11 @@ public class CardLog extends BaseEntityExt<CardLog> {
|
||||
*/
|
||||
private AppTypeEnum receiverAppType;
|
||||
|
||||
/**
|
||||
* 接收账号
|
||||
*/
|
||||
private String imReceiveAccount;
|
||||
|
||||
/**
|
||||
* 异常
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user