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