
com.sondertara.notify.dingtalk.message.TextMessage Maven / Gradle / Ivy
package com.sondertara.notify.dingtalk.message;
import com.alibaba.fastjson.JSON;
import com.sondertara.common.exception.TaraException;
import com.sondertara.common.util.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author huangxiaohu
*/
public class TextMessage implements DingTalkMessage {
private String text;
private List atMobiles;
private boolean isAtAll;
public TextMessage(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public List getAtMobiles() {
return atMobiles;
}
public void setAtMobiles(List atMobiles) {
this.atMobiles = atMobiles;
}
public boolean isAtAll() {
return isAtAll;
}
public void setIsAtAll(boolean isAtAll) {
this.isAtAll = isAtAll;
}
@Override
public String toJsonString() {
Map items = new HashMap();
items.put("msgtype", "text");
Map textContent = new HashMap();
if (StringUtils.isBlank(text)) {
throw new TaraException("text should not be blank");
}
textContent.put("content", text);
items.put("text", textContent);
Map atItems = new HashMap();
if (atMobiles != null && !atMobiles.isEmpty()) {
atItems.put("atMobiles", atMobiles);
}
if (isAtAll) {
atItems.put("isAtAll", isAtAll);
}
if (CollectionUtils.isNotEmpty(atItems)) {
items.put("at", atItems);
}
return JSON.toJSONString(items);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy