Commit 7c49d1d7 by liushuangwu

Merge remote-tracking branch 'origin/master'

2 parents e1210d96 9a658cb0
...@@ -116,14 +116,21 @@ public class FeiShuEventController { ...@@ -116,14 +116,21 @@ public class FeiShuEventController {
return getInteractiveCardStr(fileName1, "遗憾放弃"); return getInteractiveCardStr(fileName1, "遗憾放弃");
} else if ("wait".equals(actionTypeSecond)) { } else if ("wait".equals(actionTypeSecond)) {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片 // 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String waitUserId = feiShuMsgCardEventDTO.getOpen_id();
JSONObject waitObj = feiShuApiService.getUserInfo(waitUserId);
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json.json"); String fileName1 = String.format("/templates/massage-singel-msg-card-end.json.json");
return getInteractiveCardStr(fileName1, "已为你推迟到最后"); return getInteractiveCardStr(fileName1, "已为你推迟到最后");
} else if ("rob".equals(actionTypeSecond)) { } else if ("rob".equals(actionTypeSecond)) {
// 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片 // 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String oldUserId = feiShuMsgCardEventDTO.getAction().getValue().getKey().split("\\.")[2];
String robUserId = feiShuMsgCardEventDTO.getOpen_id();
JSONObject oldObj = feiShuApiService.getUserInfo(oldUserId);
JSONObject robObj = feiShuApiService.getUserInfo(robUserId);
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json.json.json"); String fileName1 = String.format("/templates/massage-msg-card-rob-end.json.json.json");
return getInteractiveCardStr(fileName1, ""); return getInteractiveCardStr(fileName1, "已经被抢啦啦啦~");
} }
default: default:
} }
......
...@@ -282,6 +282,23 @@ public class FeiShuApiService { ...@@ -282,6 +282,23 @@ public class FeiShuApiService {
} }
} }
public JSONObject getUserInfo(String openId) {
String api = "/contact/v3/users/:{userId}?department_id_type=open_department_id&user_id_type=open_id";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + getTenantToken());
headers.set("Content-Type", "application/json; charset=utf-8");
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
try {
ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, JSONObject.class, openId);
JSONObject user = responseEntity.getBody().getJSONObject("user");
return user;
} catch (Exception e) {
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
}
}
//下载文件 //下载文件
public byte[] downloadFile(String filePath) { public byte[] downloadFile(String filePath) {
String api = "/im/v1/files/{filePath}"; String api = "/im/v1/files/{filePath}";
...@@ -322,7 +339,7 @@ public class FeiShuApiService { ...@@ -322,7 +339,7 @@ public class FeiShuApiService {
//上传图片 //上传图片
public String uploadImage(String image_type,byte[] file) { public String uploadImage(String image_type, byte[] file) {
String api = "/im/v1/images"; String api = "/im/v1/images";
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
...@@ -417,6 +434,7 @@ public class FeiShuApiService { ...@@ -417,6 +434,7 @@ public class FeiShuApiService {
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e); throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
} }
} }
public String joinChatList(FeiShuChatDTO feiShuChatDTO) { public String joinChatList(FeiShuChatDTO feiShuChatDTO) {
String api = "/im/v1/chats/{chat_id}/members"; String api = "/im/v1/chats/{chat_id}/members";
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
...@@ -426,7 +444,7 @@ public class FeiShuApiService { ...@@ -426,7 +444,7 @@ public class FeiShuApiService {
String url = feiShuConfig.getFeiShuOpenApiHost() + api; String url = feiShuConfig.getFeiShuOpenApiHost() + api;
try { try {
HttpEntity<String> requestEntity = new HttpEntity<>(objectMapper.writeValueAsString(feiShuChatDTO), headers); HttpEntity<String> requestEntity = new HttpEntity<>(objectMapper.writeValueAsString(feiShuChatDTO), headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class,feiShuChatDTO.getChatId()); ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class, feiShuChatDTO.getChatId());
System.out.println(responseEntity.getBody()); System.out.println(responseEntity.getBody());
Type type = new TypeReference<FeiShuResultDTO>() { Type type = new TypeReference<FeiShuResultDTO>() {
}.getType(); }.getType();
...@@ -436,6 +454,7 @@ public class FeiShuApiService { ...@@ -436,6 +454,7 @@ public class FeiShuApiService {
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e); throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
} }
} }
/** /**
* 群发消息 * 群发消息
* https://open.feishu.cn/document/ukTMukTMukTM/ucDO1EjL3gTNx4yN4UTM * https://open.feishu.cn/document/ukTMukTMukTM/ucDO1EjL3gTNx4yN4UTM
...@@ -463,7 +482,7 @@ public class FeiShuApiService { ...@@ -463,7 +482,7 @@ public class FeiShuApiService {
* *
* @param feiShuMsgDTO * @param feiShuMsgDTO
*/ */
public void sendMsg(FeiShuMsgDTO feiShuMsgDTO, String receiveIdType) { public JSONObject sendMsg(FeiShuMsgDTO feiShuMsgDTO, String receiveIdType) {
String api = "/im/v1/messages?receive_id_type={receiveIdType}"; String api = "/im/v1/messages?receive_id_type={receiveIdType}";
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
try { try {
...@@ -474,10 +493,14 @@ public class FeiShuApiService { ...@@ -474,10 +493,14 @@ public class FeiShuApiService {
String url = feiShuConfig.getFeiShuOpenApiHost() + api; String url = feiShuConfig.getFeiShuOpenApiHost() + api;
log.info(requestEntity.toString()); log.info(requestEntity.toString());
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, requestEntity, JSONObject.class, receiveIdType); ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, requestEntity, JSONObject.class, receiveIdType);
// ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class, receiveIdType); if (responseEntity.getBody().getJSONObject("data") == null) {
log.info("单发消息成功, req:{}, resp: {}", feiShuMsgDTO, responseEntity); return null;
}
log.info("消息发送成功,接收人: {}", feiShuMsgDTO.getReceiveId());
return responseEntity.getBody();
} catch (Exception e) { } catch (Exception e) {
log.error("单发消息失败", e); log.error("单发消息失败", e);
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
} }
} }
......
...@@ -31,6 +31,12 @@ public class MassageMsgCardSerivce { ...@@ -31,6 +31,12 @@ public class MassageMsgCardSerivce {
@Autowired @Autowired
private FeiShuApiService feiShuApiService; private FeiShuApiService feiShuApiService;
public String genMassageMsgCardForSingle(){
String fileName = String.format("/templates/massage-singel-msg-card.json");
String msgCardContent = String.format(getInteractiveCardStr(fileName));
return msgCardContent;
}
public String genMassageMsgCardForCompany(List<List<String>> pushUser){ public String genMassageMsgCardForCompany(List<List<String>> pushUser){
try { try {
......
package com.pipihelper.project.feishu.service.massage; package com.pipihelper.project.feishu.service.massage;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.bo.PushPainBO; import com.pipihelper.project.feishu.bo.PushPainBO;
import com.pipihelper.project.feishu.dto.FeiShuConfig; import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO; import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.entity.Pain;
import com.pipihelper.project.feishu.service.FeiShuApiService; import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.PainService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -30,12 +33,27 @@ public class MassageService { ...@@ -30,12 +33,27 @@ public class MassageService {
@Autowired @Autowired
private FeiShuConfig feiShuConfig; private FeiShuConfig feiShuConfig;
@Autowired
private PainService painService;
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList){ public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList){
List<List<String>> pushUser = new ArrayList<>(); List<List<String>> pushUser = new ArrayList<>();
for(PushPainBO pushPainBO:pushPainBOList){ for(PushPainBO pushPainBO:pushPainBOList){
List<String> user = new ArrayList<>(); List<String> user = new ArrayList<>();
//给单个用户发送 //给单个用户发送
String singleContent = massageMsgCardSerivce.genMassageMsgCardForSingle();
log.info("给单个用户发送按摩消息:{}",singleContent);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(singleContent);
feiShuMsgDTO.setReceiveId(pushPainBO.getOpenId());
log.info(feiShuMsgDTO.toString());
JSONObject sendMsgResponse = feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
String messageId = sendMsgResponse.getJSONObject("data").getString("message_id");
//更新按摩记录表中的messageId
Pain pain = painService.findByOpenId(pushPainBO.getOpenId());
pain.setMessageId(messageId);
painService.update(pain);
//构建给大群发送的名单 //构建给大群发送的名单
user.add(pushPainBO.getIndex().toString()); user.add(pushPainBO.getIndex().toString());
user.add(pushPainBO.getName()); user.add(pushPainBO.getName());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!