虚拟清单发布和撤回--发送飞书消息

This commit is contained in:
zhn
2022-10-26 16:46:32 +08:00
parent d15254b4d9
commit cf17a1a7a9
3 changed files with 156 additions and 2 deletions
@@ -29,6 +29,7 @@ import com.jero.modules.dummy.service.IDummyInventoryInfoEOService;
import com.jero.modules.dummy.service.IDummyReadEOService;
import com.jero.modules.dummy.vo.VirtualCreaterVo;
import com.jero.modules.feishu.service.IFeishuService;
import com.jero.modules.feishu.vo.FeishuMsgVo;
import com.jero.modules.oss.entity.OSSFile;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.system.entity.SysAnnouncement;
@@ -366,6 +367,7 @@ public class DummyInventoryBaseEOServiceImpl extends ServiceImpl<DummyInventoryB
List<DummyInventoryInfoEO> dummyInventoryInfoEOList = iDummyInventoryInfoEOService.list(lambdaQueryWrapper);
String contentLog = "The "+ baseEO.getName()+" virtual list you subscribed to has been updated as follows" + "</br>";
String contentLogFeishu = "The "+ baseEO.getName()+" virtual list you subscribed to has been updated as follows" + " ";
String contentLogFeishuTemp = "The "+ baseEO.getName()+" virtual list you subscribed to has been updated as follows" + " ";
if(dummyContentChangeEOList.size() == 0){
//没有添加过需要进行第一次添加
@@ -449,7 +451,15 @@ public class DummyInventoryBaseEOServiceImpl extends ServiceImpl<DummyInventoryB
if(thirdIdList.size() != 0){
String href = backUrl + "/virtualListDetails?name=" + baseEO.getName() + "&useExplain=" + baseEO.getUseExplain() +"&id=" + baseEO.getId() +"&title=维护虚拟清单";
try {
iFeishuService.batchSendMessage(thirdIdList.toArray(new String[]{}), contentLogFeishu, MessageTypeEnum.PUSH.getName(), href);
String contentInfoFeiCn = "您所订阅的"+baseEO.getName()+"虚拟清单已更新,更新内容如下:";
FeishuMsgVo feishuMsgVo = new FeishuMsgVo();
feishuMsgVo.setTitle(MessageTypeEnum.READ.getName());
feishuMsgVo.setUrl(href);
feishuMsgVo.setContentEn(contentLogFeishuTemp);
feishuMsgVo.setContent(contentInfoFeiCn);
iFeishuService.sendCardMsgVirtua(thirdIdList.toArray(new String[]{}),feishuMsgVo,serialNumberAddList,serialNumberDeleteList);
// iFeishuService.batchSendMessage(thirdIdList.toArray(new String[]{}), contentLogFeishu, MessageTypeEnum.PUSH.getName(), href);
} catch (IOException e) {
e.printStackTrace();
}
@@ -490,8 +500,15 @@ public class DummyInventoryBaseEOServiceImpl extends ServiceImpl<DummyInventoryB
//飞书
if(thirdIdList.size() != 0){
String contentInfoTemp = "Please note that the "+ baseEO.getName()+" virtual list you subscribed to has been withdrawn.";
String contentInfoFeiCn = "您订阅的虚拟清单"+ baseEO.getName()+"已被撤回.";
String href = backUrl + "/virtualListDetails?name=" + baseEO.getName() + "&useExplain=" + baseEO.getUseExplain() +"&id=" + baseEO.getId() +"&title=维护虚拟清单";
iFeishuService.batchSendMessage(thirdIdList.toArray(new String[]{}), contentInfoTemp, MessageTypeEnum.PUSH.getName(), href);
FeishuMsgVo feishuMsgVo = new FeishuMsgVo();
feishuMsgVo.setTitle(MessageTypeEnum.READ.getName());
feishuMsgVo.setUrl(href);
feishuMsgVo.setContentEn(contentInfoTemp);
feishuMsgVo.setContent(contentInfoFeiCn);
iFeishuService.sendCardMsgVirtua(thirdIdList.toArray(new String[]{}), feishuMsgVo,null,null);
// iFeishuService.batchSendMessage(thirdIdList.toArray(new String[]{}), contentInfoTemp, MessageTypeEnum.PUSH.getName(), href);
}
}catch (Exception e){
e.printStackTrace();
@@ -5,6 +5,7 @@ import com.jero.modules.feishu.vo.FeishuMsg2Vo;
import com.jero.modules.feishu.vo.FeishuMsgVo;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
@@ -57,6 +58,15 @@ public interface IFeishuService {
*/
String sendCardMsgTerritory(String[] userIds, FeishuMsgVo feishuMsgVo) throws IOException;
/**
* 虚拟清单(飞书消息)
* @param userIds
* @param feishuMsgVo
* @return
* @throws IOException
*/
String sendCardMsgVirtua(String[] userIds, FeishuMsgVo feishuMsgVo, List<String> serialNumberAddList,List<String> serialNumberDeleteList) throws IOException;
/**
* 翻译文本
* @param params
@@ -453,6 +453,133 @@ public class FeishuServiceImpl implements IFeishuService {
contentSb.append("\"header\": {");
contentSb.append("\"template\": \"green\",");
contentSb.append("\"title\": {");
contentSb.append("\"content\": \" " + feishuMsgVo.getTitle() + " \",");
contentSb.append("\"tag\": \"plain_text\"");
contentSb.append("}");
contentSb.append("}");
contentSb.append("}");
JSONObject jsonObject = JSONObject.parseObject(contentSb.toString());
// 设置请求参数
JSONObject paramsMap = new JSONObject();
paramsMap.put("user_ids", userIds);
paramsMap.put("msg_type", "interactive");
paramsMap.put("card", jsonObject);
// 发送请求给飞书
String response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString());
// 获取返回结果
JSONObject tokenJson = JSONObject.parseObject(response);
if(!tokenJson.get("code").toString().equals("0")) {
log.error("请求出现异常:" + tokenJson.get("msg") + " " + tokenJson);
}
return tokenJson.get("msg").toString();
}
/**
* 虚拟清单发布(飞书消息)
* @param userIds
* @param feishuMsgVo
* @return
* @throws IOException
*/
public String sendCardMsgVirtua(String[] userIds, FeishuMsgVo feishuMsgVo,
List<String> serialNumberAddList,List<String> serialNumberDeleteList) throws IOException {
String token = getTenantAccessToken();
// 设置请求头
Map<String, String> headerMap = new HashMap<>();
headerMap.put("Authorization", "Bearer " + token);
headerMap.put("Content-Type", "application/json; charset=utf-8");
// 示例
StringBuilder contentSb = new StringBuilder();
contentSb.append("{");
contentSb.append("\"elements\": [");
// 内容中文
if (StrUtil.isNotEmpty(feishuMsgVo.getContent())){
contentSb.append("{");
contentSb.append("\"tag\": \"div\",");
contentSb.append("\"text\": {");
contentSb.append("\"content\": \"" + feishuMsgVo.getContent() + "\"\n,");
contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}");
contentSb.append("},");
};
if(ObjectUtils.isNotEmpty(serialNumberAddList)){
int count = 1;
contentSb.append("{");
contentSb.append("\"tag\": \"div\",");
contentSb.append("\"text\": {");
contentSb.append("\"content\": \"" + count + ". 新增文档: " + StringUtils.join(serialNumberAddList,",") + "\"\n,");
contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}");
contentSb.append("},");
}
if(ObjectUtils.isNotEmpty(serialNumberDeleteList)){
int count = 2;
contentSb.append("{");
contentSb.append("\"tag\": \"div\",");
contentSb.append("\"text\": {");
contentSb.append("\"content\": \"" + count + ". 删除文档: " + StringUtils.join(serialNumberDeleteList,",") + "\"\n,");
contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}");
contentSb.append("},");
}
contentSb.append("{\"tag\": \"hr\"},");
//内容英文
if (StrUtil.isNotEmpty(feishuMsgVo.getContentEn())){
contentSb.append("{");
contentSb.append("\"tag\": \"div\",");
contentSb.append("\"text\": {");
contentSb.append("\"content\": \"" + feishuMsgVo.getContentEn() + "\"\n,");
contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}");
contentSb.append("},");
};
if (ObjectUtils.isNotEmpty(serialNumberAddList)) {
int count = 1;
contentSb.append("{");
contentSb.append("\"tag\": \"div\",");
contentSb.append("\"text\": {");
contentSb.append("\"content\": \"" + count + ". New regulations: " + StringUtils.join(serialNumberAddList,",") + "\"\n,");
contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}");
contentSb.append("},");
}
if (ObjectUtils.isNotEmpty(serialNumberDeleteList)) {
int count = 2;
contentSb.append("{");
contentSb.append("\"tag\": \"div\",");
contentSb.append("\"text\": {");
contentSb.append("\"content\": \"" + count + ". Remove regulations: " + StringUtils.join(serialNumberDeleteList,",") + "\"\n,");
contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}");
contentSb.append("},");
}
contentSb.append("{");
contentSb.append("\"actions\": [");
contentSb.append("{");
contentSb.append("\"tag\": \"button\",");
contentSb.append("\"text\": {");
contentSb.append("\"content\": \"view\",");
contentSb.append("\"tag\": \"plain_text\"");
contentSb.append("},");
contentSb.append("\"type\": \"primary\",");
contentSb.append("\"url\": \" "+ feishuMsgVo.getUrl() +" \"");
contentSb.append("}");
contentSb.append("],");
contentSb.append("\"tag\": \"action\"");
contentSb.append("}");
contentSb.append("],");
contentSb.append("\"header\": {");
contentSb.append("\"template\": \"green\",");
contentSb.append("\"title\": {");