飞书交互-发送问题知识库分类负责人名片。
This commit is contained in:
+88
-45
@@ -21,6 +21,7 @@ import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.jero.modules.system.util.HttpRequestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -565,69 +566,111 @@ public class FeishuServiceImpl implements IFeishuService {
|
||||
headerMap.put("Authorization", "Bearer " + token);
|
||||
headerMap.put("Content-Type", "application/json; charset=utf-8");
|
||||
|
||||
String sendJson = " {\n" +
|
||||
" \"config\": {\n" +
|
||||
" \"wide_screen_mode\": true\n" +
|
||||
" },\n" +
|
||||
//参考:https://open.feishu.cn/tool/cardbuilder?from=openplantform_mcb_entrance
|
||||
/*String sendJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"template\": \"green\",\n" +
|
||||
" \"title\": {\n" +
|
||||
" \"tag\": \"plain_text\",\n" +
|
||||
" \"content\": \"点击下方的分类查看常见问题\"\n" +
|
||||
" },\n" +
|
||||
" \"template\": \"green\"\n" +
|
||||
" \"content\": \"知识库分类负责人\",\n" +
|
||||
" \"tag\": \"plain_text\"\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"elements\": [\n" +
|
||||
" {\n" +
|
||||
" \"fields\": [\n" +
|
||||
" {\n" +
|
||||
" \"is_short\": true,\n" +
|
||||
" \"text\": {\n" +
|
||||
" \"content\": \"**\uD83D\uDC64 提交人:**\\n<at id=fag43ef3></at>\",\n" +
|
||||
" \"tag\": \"lark_md\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"tag\": \"div\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}";*/
|
||||
|
||||
String sendJson = "{\n" +
|
||||
" \"header\": {\n" +
|
||||
" \"template\": \"green\",\n" +
|
||||
" \"title\": {\n" +
|
||||
" \"content\": \"知识库分类负责人\",\n" +
|
||||
" \"tag\": \"plain_text\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
JSONObject jsonObject = JSONObject.parseObject(sendJson);
|
||||
JSONArray elements = new JSONArray();
|
||||
JSONObject element = new JSONObject();
|
||||
element.put("tag","action");
|
||||
element.put("layout","bisected");
|
||||
JSONArray fields = new JSONArray();
|
||||
|
||||
//获取分类
|
||||
List<ProblemKnowledgeBaseClassifyEO> problemKnowledgeBaseClassifyEOList = this.problemKnowledgeBaseClassifyEOService.list();
|
||||
this.problemKnowledgeBaseClassifyEOService.disposeData(problemKnowledgeBaseClassifyEOList);
|
||||
|
||||
JSONArray actions = new JSONArray();
|
||||
|
||||
//组装推送过去的点击按钮
|
||||
//获取所有分类下的负责人信息
|
||||
List<String> chargePersonUserIdList = new ArrayList<>();
|
||||
for (ProblemKnowledgeBaseClassifyEO problemKnowledgeBaseClassifyEO : problemKnowledgeBaseClassifyEOList) {
|
||||
JSONObject buttonObject = new JSONObject();
|
||||
JSONObject text = new JSONObject();
|
||||
JSONObject value = new JSONObject();
|
||||
buttonObject.put("tag","button");
|
||||
|
||||
text.put("tag","plain_text");
|
||||
text.put("content",problemKnowledgeBaseClassifyEO.getProblemLabel() + " [" + problemKnowledgeBaseClassifyEO.getChargePersonIdName() + "]");
|
||||
value.put("chosen",problemKnowledgeBaseClassifyEO.getChargePersonId());
|
||||
|
||||
buttonObject.put("text",text);
|
||||
buttonObject.put("type","primary");
|
||||
buttonObject.put("value",value);
|
||||
actions.add(buttonObject);
|
||||
if(StringUtils.isNotEmpty(problemKnowledgeBaseClassifyEO.getChargePersonId())){
|
||||
String chargePersonId = problemKnowledgeBaseClassifyEO.getChargePersonId();
|
||||
for (String chargePerson : chargePersonId.split(",")) {
|
||||
chargePersonUserIdList.add(chargePerson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
element.put("actions",actions);
|
||||
if(CollectionUtils.isNotEmpty(chargePersonUserIdList)){
|
||||
List<SysUser> chargePersonUserList = this.sysUserService.querySysUserListByIdList(chargePersonUserIdList);
|
||||
|
||||
//组装推送过去的知识库负责人信息
|
||||
for (ProblemKnowledgeBaseClassifyEO problemKnowledgeBaseClassifyEO : problemKnowledgeBaseClassifyEOList) {
|
||||
JSONObject field = new JSONObject();
|
||||
JSONObject text = new JSONObject();
|
||||
StringBuilder atUserSb = new StringBuilder();
|
||||
|
||||
elements.add(element);
|
||||
jsonObject.put("elements",elements);
|
||||
// 设置请求参数
|
||||
JSONObject paramsMap = new JSONObject();
|
||||
paramsMap.put("user_ids", userIds);
|
||||
paramsMap.put("msg_type", "interactive");
|
||||
paramsMap.put("card", jsonObject);
|
||||
if(StringUtils.isNotEmpty(problemKnowledgeBaseClassifyEO.getChargePersonId())){
|
||||
for (String chargePersonId : problemKnowledgeBaseClassifyEO.getChargePersonId().split(",")) {
|
||||
for (SysUser sysUser : chargePersonUserList) {
|
||||
if(StringUtils.equals(chargePersonId,sysUser.getId())){
|
||||
String thirdId = sysUser.getThirdId();
|
||||
atUserSb.append("<at id=" + thirdId + "></at>");
|
||||
atUserSb.append(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 发送请求给飞书
|
||||
String response = null;
|
||||
try {
|
||||
response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 获取返回结果
|
||||
JSONObject tokenJson = JSONObject.parseObject(response);
|
||||
if(!tokenJson.get("code").toString().equals("0")) {
|
||||
log.error("请求出现异常:" + tokenJson.get("msg") + " " + tokenJson);
|
||||
text.put("content","问题标签:" + problemKnowledgeBaseClassifyEO.getProblemLabel() + "\n" + "责任人:" + atUserSb.toString());
|
||||
text.put("tag","lark_md");
|
||||
|
||||
field.put("is_short",true);
|
||||
field.put("text",text);
|
||||
fields.add(field);
|
||||
}
|
||||
|
||||
element.put("tag","div");
|
||||
element.put("fields",fields);
|
||||
elements.add(element);
|
||||
jsonObject.put("elements",elements);
|
||||
// 设置请求参数
|
||||
JSONObject paramsMap = new JSONObject();
|
||||
paramsMap.put("user_ids", userIds);
|
||||
paramsMap.put("msg_type", "interactive");
|
||||
paramsMap.put("card", jsonObject);
|
||||
|
||||
// 发送请求给飞书
|
||||
String response = null;
|
||||
try {
|
||||
response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 获取返回结果
|
||||
JSONObject tokenJson = JSONObject.parseObject(response);
|
||||
if(!tokenJson.get("code").toString().equals("0")) {
|
||||
log.error("请求出现异常:" + tokenJson.get("msg") + " " + tokenJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user