|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.google.gson.JsonObject;
|
|
|
+import com.management.platform.constant.Constant;
|
|
|
import com.management.platform.entity.FeishuInfo;
|
|
|
import com.management.platform.entity.FeishuSend;
|
|
|
import com.management.platform.entity.User;
|
|
@@ -286,9 +287,11 @@ public class FeishuInfoServiceImpl extends ServiceImpl<FeishuInfoMapper, FeishuI
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 批量发送卡片模板消息 需要配置模板获取模板上线后的模板id
|
|
|
+ * */
|
|
|
@Override
|
|
|
- public void batchSendCardMessage(FeishuInfo feishuInfo,List<String> userIds,String sendTypeName,List<String> templateVariableDetail) throws Exception {
|
|
|
+ public void batchSendCardTemplateMessage(FeishuInfo feishuInfo,List<String> userIds,String sendTypeName,List<String> templateVariableDetail) throws Exception {
|
|
|
if(feishuInfo.getExpireTime().isBefore(LocalDateTime.now())){
|
|
|
String tenantAccessToken = getTenantAccessToken(feishuInfo.getAppId());
|
|
|
feishuInfo.setAccessToken(tenantAccessToken);
|
|
@@ -330,4 +333,93 @@ public class FeishuInfoServiceImpl extends ServiceImpl<FeishuInfoMapper, FeishuI
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量发送卡片消息
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public void batchSendCardMessage(FeishuInfo feishuInfo, List<String> userIds,String sendTypeName, Map<String,String> templateVariableDetail,String pushUrl) throws Exception {
|
|
|
+ if(feishuInfo.getExpireTime().isBefore(LocalDateTime.now())){
|
|
|
+ String tenantAccessToken = getTenantAccessToken(feishuInfo.getAppId());
|
|
|
+ feishuInfo.setAccessToken(tenantAccessToken);
|
|
|
+ }
|
|
|
+ String[] cardDetail=new String[]{};
|
|
|
+ switch (sendTypeName){
|
|
|
+ case "项目报告审核通知":cardDetail= Constant.PROJECT_REPORT_CHECK;
|
|
|
+ break;
|
|
|
+ case "工作日报漏填提醒":cardDetail= Constant.WORK_REPORT_MISSING_FILLING;
|
|
|
+ break;
|
|
|
+ case "新任务通知":cardDetail= Constant.NEW_TASK;
|
|
|
+ break;
|
|
|
+ case "日报待审核提醒":cardDetail= Constant.REPORT_WAIT_CHECK;
|
|
|
+ break;
|
|
|
+ case "日报审核通过提醒(带评价)":cardDetail= Constant.REPORT_CHECK_PASS_WITH_APPRAISE;
|
|
|
+ break;
|
|
|
+ case "日报审核通过提醒":cardDetail= Constant.REPORT_CHECK_PASS;
|
|
|
+ break;
|
|
|
+ case "任务进展通知":cardDetail= Constant.TASK_EVOLVE;
|
|
|
+ break;
|
|
|
+ case "费用报销待审核提醒":cardDetail= Constant.EXPENSE_REIMBURSEMENT_WAIT_CHECK;
|
|
|
+ break;
|
|
|
+ case "员工请假待审核":cardDetail= Constant.LEAVE_WAIT_CHECK;
|
|
|
+ break;
|
|
|
+ case "请假审核通知":cardDetail= Constant.LEAVE_CHECK;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String url = BATCH_SEND_MESSAGE;
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+ headers.setContentType(type);
|
|
|
+ headers.add("Authorization","Bearer "+feishuInfo.getAccessToken());
|
|
|
+ JSONObject requestMap=new JSONObject();
|
|
|
+ JSONObject card=new JSONObject();
|
|
|
+ JSONObject config=new JSONObject();
|
|
|
+ JSONArray elements=new JSONArray();
|
|
|
+ config.put("wide_screen_mode",true);
|
|
|
+ card.put("config",config);
|
|
|
+ for (int i = 0; i < cardDetail.length; i++) {
|
|
|
+ JSONObject element=new JSONObject();
|
|
|
+ element.put("tag","div");
|
|
|
+ JSONObject text=new JSONObject();
|
|
|
+ text.put("content",cardDetail[i]+":"+templateVariableDetail.get(cardDetail[i]));
|
|
|
+ text.put("tag","plain_text");
|
|
|
+ element.put("text",text);
|
|
|
+ elements.add(element);
|
|
|
+ }
|
|
|
+ JSONObject element1=new JSONObject();
|
|
|
+ element1.put("tag","action");
|
|
|
+ JSONArray actions=new JSONArray();
|
|
|
+ JSONObject jb=new JSONObject();
|
|
|
+ jb.put("tag","button");
|
|
|
+ JSONObject text=new JSONObject();
|
|
|
+ text.put("tag","plain_text");
|
|
|
+ text.put("content","点击查看");
|
|
|
+ jb.put("text",text);
|
|
|
+ jb.put("type","primary");
|
|
|
+ JSONObject multiUrl=new JSONObject();
|
|
|
+ multiUrl.put("url",pushUrl);
|
|
|
+ jb.put("multi_url",multiUrl);
|
|
|
+ actions.add(jb);
|
|
|
+ element1.put("actions",actions);
|
|
|
+ elements.add(element1);
|
|
|
+ card.put("elements",elements);
|
|
|
+ JSONObject header=new JSONObject();
|
|
|
+ header.put("template","blue");
|
|
|
+ JSONObject title=new JSONObject();
|
|
|
+ title.put("content","工时管家 \n"+sendTypeName);
|
|
|
+ title.put("tag","plain_text");
|
|
|
+ header.put("title",title);
|
|
|
+ card.put("header",header);
|
|
|
+ requestMap.put("card",card);
|
|
|
+ requestMap.put("open_ids",userIds);
|
|
|
+ requestMap.put("msg_type","interactive");
|
|
|
+ HttpEntity<JSONObject> httpEntity = new HttpEntity<>(requestMap, headers);
|
|
|
+ ResponseEntity<String> ResponseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
|
|
|
+ if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = ResponseEntity.getBody();
|
|
|
+ System.out.println(resp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|