Commit 1880ee07 by liushuangwu

Merge remote-tracking branch 'origin/master'

2 parents ca0c0e9d b5602aff
......@@ -85,10 +85,10 @@ public class FeiShuEventController {
@PostMapping("/event")
public JSONObject event(@RequestBody String s) throws Exception {
JSONObject reqJsonObject = JSON.parseObject(s);
System.out.println(s);
log.info("接收到事件,密文:{}", s);
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getEncryptKey());
JSONObject encryptJsonObject = JSON.parseObject(d.decrypt(reqJsonObject.getString("encrypt")));
System.out.println(encryptJsonObject);
log.info("接收到事件,明文:{}", encryptJsonObject);
if (encryptJsonObject.containsKey("challenge")) {
return encryptJsonObject;
}
......@@ -97,9 +97,8 @@ public class FeiShuEventController {
return null;
}
if ("im.message.receive_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
} else if ("im.message.message_read_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageMessageReadV1(feiShuEventDTO);
log.info("处理单聊事件:{}",feiShuEventDTO);
feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
}
return null;
}
......@@ -122,7 +121,7 @@ public class FeiShuEventController {
// 接受按摩
String fileName = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName, "感谢支持");
return getInteractiveCardStr(fileName, "您已接受啦~");
} else if ("giveUp".equals(actionTypeSecond)) {
// 放弃 - 往大群中发送抢按摩机会卡片
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
......@@ -134,7 +133,7 @@ public class FeiShuEventController {
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "遗憾放弃");
return getInteractiveCardStr(fileName1, "怕疼的家伙~");
} else if ("wait".equals(actionTypeSecond)) {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String waitUserId = feiShuMsgCardEventDTO.getOpen_id();
......@@ -144,7 +143,7 @@ public class FeiShuEventController {
//更新按摩群
massageService.updateMassageMsgCardToPiPiChat((String) CacheUtil.get("chatId"));
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "已为你推迟到最后");
return getInteractiveCardStr(fileName1, "已为你推迟到队尾");
} else if ("rob".equals(actionTypeSecond)) {
// 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
return rob(feiShuMsgCardEventDTO);
......@@ -171,7 +170,7 @@ public class FeiShuEventController {
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
}
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "欢迎下次光临~");
return getInteractiveCardStr(fileName1, "您本次的massage之旅已结束~");
}
default:
}
......@@ -181,16 +180,20 @@ public class FeiShuEventController {
public synchronized JSONObject rob(FeiShuMsgCardEventDTO feiShuMsgCardEventDTO) {
String oldUserId = feiShuMsgCardEventDTO.getAction().getValue().getKey().split("\\.")[2];
String robUserId = feiShuMsgCardEventDTO.getOpen_id();
JSONObject user = feiShuApiService.getUserInfo(robUserId);
Employee employee = employeeService.findByOpenId(robUserId);
Pain oldPain = painService.findByOpenId(oldUserId);
if (oldPain == null) {
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json");
return getInteractiveCardStr(fileName1, "已经被" + employee.getName() + "抢啦,啦啦~");
}
oldPain.setOpenId(robUserId);
oldPain.setName(user.getString("name"));
oldPain.setName(employee.getName());
painService.update(oldPain);
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setChatId((String) CacheUtil.get("chatId"));
feiShuChatDTO.setIdList(new String[]{feiShuMsgCardEventDTO.getOpen_id()});
feiShuApiService.joinChatList(feiShuChatDTO);
sendSingle(robUserId);
// 更新大群和按摩群的大卡片,异步
// 大群
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
......@@ -198,9 +201,25 @@ public class FeiShuEventController {
massageService.updateMassageMsgCardToPiPiChat((String) CacheUtil.get("chatId"));
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json");
return getInteractiveCardStr(fileName1, "已经被" + user.getString("name") + "抢啦,啦啦~");
return getInteractiveCardStr(fileName1, "已经被" + employee.getName() + "抢啦,啦啦~");
}
private void sendSingle(String openId){
//给单个用户发送
String singleContent = massageMsgCardSerivce.genMassageMsgCardForSingle();
log.info("给单个用户发送按摩消息:{}", singleContent);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(singleContent);
feiShuMsgDTO.setReceiveId(openId);
log.info(feiShuMsgDTO.toString());
JSONObject sendMsgResponse = feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
String messageId = sendMsgResponse.getJSONObject("data").getString("message_id");
//更新按摩记录表中的messageId
Pain pain = painService.findByOpenId(openId);
pain.setMessageId(messageId);
painService.update(pain);
}
/**
* 读取模板文件
*
......@@ -220,6 +239,13 @@ public class FeiShuEventController {
return null;
}
@PostMapping("/delete-chat-list")
public Object deleteChat() {
String chatId = (String) CacheUtil.get("chatId");
log.info("删除群组id:{}", chatId);
feiShuApiService.deleteChatList(chatId);
return null;
}
@PostMapping("/employee-list")
public Object event() {
......@@ -348,7 +374,7 @@ public class FeiShuEventController {
for (Pain pain : pains) {
String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId);
userString.append(String.format("<at user_id=\\\"%s\\\">%s</at>", pain.getOpenId(), pain.getName()));
userString.append(String.format("<at user_id=\"%s\">%s</at>", pain.getOpenId(), pain.getName()));
//1代表正在按
pain.setStatus(1);
......@@ -372,16 +398,17 @@ public class FeiShuEventController {
}
@PostMapping("/send-msg")
public Result sendMsg(String receiveId, String msg, String receiveIdType){
public Result sendMsg(String receiveId, String msg, String receiveIdType) {
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
if(receiveId.equals("-1")){
if (receiveId.equals("-1")) {
receiveId = (String) CacheUtil.get("chatId");
}
feiShuMsgDTO.setReceiveId(receiveId);
log.info("已机器人身份发送消息:{}", feiShuMsgDTO.toString());
feiShuApiService.sendMsg(feiShuMsgDTO, receiveIdType);
return ResultGenerator.genSuccessResult();
}
......
......@@ -25,7 +25,6 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
......@@ -454,6 +453,26 @@ public class FeiShuApiService {
}
}
public String deleteChatList(String chatId) {
String api = "/im/v1/chats/:{chat_id}";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + getTenantToken());
headers.set("Content-Type", "application/json; charset=utf-8");
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
try {
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, String.class, chatId);
System.out.println(responseEntity.getBody());
Type type = new TypeReference<FeiShuResultDTO>() {
}.getType();
FeiShuResultDTO feiShuResultDTO = JSONObject.parseObject(responseEntity.getBody(), type);
return feiShuResultDTO.getData().getChatId();
} catch (Exception e) {
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
}
}
/**
* 群发消息
* https://open.feishu.cn/document/ukTMukTMukTM/ucDO1EjL3gTNx4yN4UTM
......
package com.pipihelper.project.feishu.service;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventHeaderDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventReceiveMessageDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.tx.dto.TxConfig;
import com.pipihelper.project.tx.service.TxApiService;
import com.tencentcloudapi.tbp.v20190627.models.Group;
import com.tencentcloudapi.tbp.v20190627.models.TextProcessResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.regex.Pattern;
/**
* @Description: TODO
......@@ -41,22 +48,37 @@ public class FeiShuEventService {
@Async
public void imMessageReceiveV1(FeiShuEventDTO feiShuEventDTO){
FeiShuEventHeaderDTO feiShuEventHeaderDTO = feiShuEventDTO.getHeader();
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
//单独处理群消息
if (message.getChat_id().equals(feiShuConfig.getChatId())
|| message.getChat_id().equals(feiShuConfig.getChatId())) { //判断是否为指定群消息
return;
if(message.getChat_type().equals("p2p")) {
robotTalk(feiShuEventDTO);
}
else {
//如果是单聊
if(message.getChat_type().equals("p2p")) {
// robotTalk(feiShuEventDTO);
}
public void robotTalk(FeiShuEventDTO feiShuEventDTO){
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setReceiveId(sender.getSender_id().getOpen_id());
if(message.getMessage_type().equals("text")){
JSONObject jsonObjectText = JSON.parseObject(message.getContent());
String inputText = jsonObjectText.getString("text");
String uuid = IdUtil.randomUUID();
TextProcessResponse textProcessResponse = txApiService.txTextProcessRequest(uuid, inputText);
for (Group group : textProcessResponse.getResponseMessage().getGroupList()) {
JSONObject content = new JSONObject();
content.put("text", group.getContent());
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setMsgType("text");
feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
}
}
}
}
}
......@@ -70,11 +70,11 @@ public class MassageNoticeScheduleService {
floorCountMap.put(14, 30);
}
/**
* 每周四定时生成要按摩的人员名单,并发送大群和单人消息
*/
@Async
@Scheduled(cron = "0 0 10 * * ?")
// /**
// * 每周四定时生成要按摩的人员名单,并发送大群和单人消息
// */
// @Async
// @Scheduled(cron = "0 0 10 * * ?")
public void sendMsgCardToPipiChat() {
employeeService.uprsetAllEmployee();
chatMessageService.deleteAll();
......@@ -156,7 +156,16 @@ public class MassageNoticeScheduleService {
}
}
}
/**
* 每周四18:00删除当天的群聊
*/
// @Async
// @Scheduled(cron = "0 0 18 * * ?")
public void deleteChatList() {
String chatId = (String) CacheUtil.get("chatId");
feiShuApiService.deleteChatList(chatId);
}
/**
* 当天时间2:55,给第一波三个人更新卡片,并发送应用内提醒
......@@ -170,7 +179,7 @@ public class MassageNoticeScheduleService {
for (Pain pain : pains) {
String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId);
userString.append(String.format("<at user_id=\\\"%s\\\">%s</at>", pain.getOpenId(), pain.getName()));
userString.append(String.format("<at user_id=\"%s\">%s</at>", pain.getOpenId(), pain.getName()));
//1代表正在按
pain.setStatus(1);
painService.update(pain);
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "已抢完~",
"content": "%s",
"tag": "lark_md"
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!