Commit 50ffc2f8 by liushuangwu

Merge remote-tracking branch 'origin/master'

2 parents ab2b4c5e 79d0a06f
...@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil; ...@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.pipihelper.project.core.Result;
import com.pipihelper.project.core.ResultGenerator;
import com.pipihelper.project.feishu.dto.FeiShuConfig; import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO; import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuMsgCardEventDTO; import com.pipihelper.project.feishu.dto.FeiShuMsgCardEventDTO;
...@@ -22,6 +24,7 @@ import com.pipihelper.project.feishu.service.PainService; ...@@ -22,6 +24,7 @@ import com.pipihelper.project.feishu.service.PainService;
import com.pipihelper.project.feishu.service.massage.MassageMsgCardSerivce; import com.pipihelper.project.feishu.service.massage.MassageMsgCardSerivce;
import com.pipihelper.project.feishu.service.massage.MassageService; import com.pipihelper.project.feishu.service.massage.MassageService;
import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter; import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -33,6 +36,7 @@ import java.io.BufferedReader; ...@@ -33,6 +36,7 @@ import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -46,6 +50,7 @@ import java.util.stream.Stream; ...@@ -46,6 +50,7 @@ import java.util.stream.Stream;
* @author: charles * @author: charles
* @date: 2022年03月30日 17:39 * @date: 2022年03月30日 17:39
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/pipitest/feishu") @RequestMapping("/pipitest/feishu")
public class FeiShuEventController { public class FeiShuEventController {
...@@ -127,7 +132,10 @@ public class FeiShuEventController { ...@@ -127,7 +132,10 @@ public class FeiShuEventController {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片 // 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String waitUserId = feiShuMsgCardEventDTO.getOpen_id(); String waitUserId = feiShuMsgCardEventDTO.getOpen_id();
painService.waitPain(waitUserId); painService.waitPain(waitUserId);
//ToDo 更新大群和按摩群的大卡片,异步 //ToDo 没有按摩群的id
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
//没有按摩群的id
// massageService.updateMassageMsgCardToPiPiChat();
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)) {
...@@ -137,7 +145,10 @@ public class FeiShuEventController { ...@@ -137,7 +145,10 @@ public class FeiShuEventController {
Pain oldPain = painService.findByOpenId(oldUserId); Pain oldPain = painService.findByOpenId(oldUserId);
oldPain.setOpenId(robUserId); oldPain.setOpenId(robUserId);
painService.update(oldPain); painService.update(oldPain);
//ToDo 更新大群和按摩群的大卡片,异步 //ToDo 没有按摩群的id
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
//没有按摩群的id
// massageService.updateMassageMsgCardToPiPiChat();
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, "已经被抢啦啦啦~");
} else if ("next".equals(actionTypeSecond)) { } else if ("next".equals(actionTypeSecond)) {
...@@ -266,4 +277,23 @@ public class FeiShuEventController { ...@@ -266,4 +277,23 @@ public class FeiShuEventController {
feiShuChatDTO.setIdList(new String[]{openId}); feiShuChatDTO.setIdList(new String[]{openId});
return feiShuApiService.joinChatList(feiShuChatDTO); return feiShuApiService.joinChatList(feiShuChatDTO);
} }
@PostMapping("/start")
public Result start() {
List<Pain> pains = painService.findListAsc(3);
for(Pain pain:pains){
String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId);
//1代表正在按
pain.setStatus(1);
painService.update(pain);
JSONObject noticeMsg = new JSONObject();
noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId()));
//发送应用内提醒
log.info("发送应用内容消息提醒");
feiShuApiService.patchUrgentApp(messageId, noticeMsg);
}
return ResultGenerator.genSuccessResult();
}
} }
...@@ -58,7 +58,7 @@ public class SendMsgUseFeiShu { ...@@ -58,7 +58,7 @@ public class SendMsgUseFeiShu {
userList.add(pushPainBO); userList.add(pushPainBO);
userList.add(pushPainBO1); userList.add(pushPainBO1);
userList.add(pushPainBO2); userList.add(pushPainBO2);
massageService.sendMassageMsgCardToPiPiChat(userList); massageService.sendMassageMsgCardToPiPiChat(userList,feiShuConfig.getChatId());
return ResultGenerator.genSuccessResult(); return ResultGenerator.genSuccessResult();
} }
} }
...@@ -39,7 +39,7 @@ public class MassageMsgCardSerivce { ...@@ -39,7 +39,7 @@ public class MassageMsgCardSerivce {
public String genMassageMsgCardForSingleStart(){ public String genMassageMsgCardForSingleStart(){
String fileName = String.format("/templates/massage-single-msg-card-start.json"); String fileName = String.format("/templates/massage-single-msg-card-next.json");
String msgCardContent = String.format(getInteractiveCardStr(fileName)); String msgCardContent = String.format(getInteractiveCardStr(fileName));
return msgCardContent; return msgCardContent;
} }
......
...@@ -5,10 +5,12 @@ import com.pipihelper.project.feishu.bo.PushPainBO; ...@@ -5,10 +5,12 @@ 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.entity.Pain;
import com.pipihelper.project.feishu.service.ChatMessageService;
import com.pipihelper.project.feishu.service.FeiShuApiService; import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.PainService; 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.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -36,7 +38,11 @@ public class MassageService { ...@@ -36,7 +38,11 @@ public class MassageService {
@Autowired @Autowired
private PainService painService; private PainService painService;
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList){ @Autowired
private ChatMessageService chatMessageService;
//给群里发送消息
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList, String chatId){
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<>();
...@@ -68,7 +74,7 @@ public class MassageService { ...@@ -68,7 +74,7 @@ public class MassageService {
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO(); FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive"); feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(content); feiShuMsgDTO.setContent(content);
feiShuMsgDTO.setReceiveId(feiShuConfig.getChatId()); feiShuMsgDTO.setReceiveId(chatId);
log.info(feiShuMsgDTO.toString()); log.info(feiShuMsgDTO.toString());
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id"); feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
} }
...@@ -80,44 +86,30 @@ public class MassageService { ...@@ -80,44 +86,30 @@ public class MassageService {
patchMsg.put("content", msgCardContent); patchMsg.put("content", msgCardContent);
feiShuApiService.patchMsg(messageId, patchMsg); feiShuApiService.patchMsg(messageId, patchMsg);
} }
//
// public void updateMassageMsgCardToPiPiChat(){ //更新群消息
// List<PushPainBO> pushPainBOList = @Async
// List<List<String>> pushUser = new ArrayList<>(); public void updateMassageMsgCardToPiPiChat(String chatId){
// for(PushPainBO pushPainBO:pushPainBOList){ List<Pain> pains = painService.findAll();
// List<String> user = new ArrayList<>(); String messageId = chatMessageService.findListChatAndType(chatId, 1).get(0).getMessageId();
// //给单个用户发送 List<List<String>> pushUser = new ArrayList<>();
// String singleContent = massageMsgCardSerivce.genMassageMsgCardForSingle(); for(Pain pain:pains){
// log.info("给单个用户发送按摩消息:{}",singleContent); List<String> user = new ArrayList<>();
// FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO(); //构建给大群发送的名单
// feiShuMsgDTO.setMsgType("interactive"); user.add(pain.getIndex().toString());
// feiShuMsgDTO.setContent(singleContent); user.add(pain.getName());
// feiShuMsgDTO.setReceiveId(pushPainBO.getOpenId()); user.add(pain.getDepartMentName());
// log.info(feiShuMsgDTO.toString()); user.add(pain.getTimeRange());
// JSONObject sendMsgResponse = feiShuApiService.sendMsg(feiShuMsgDTO, "open_id"); user.add("");
// String messageId = sendMsgResponse.getJSONObject("data").getString("message_id"); pushUser.add(user);
// //更新按摩记录表中的messageId }
// Pain pain = painService.findByOpenId(pushPainBO.getOpenId()); //给大群更新发送消息
// pain.setMessageId(messageId); String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
// painService.update(pain); log.info("给大群发送按摩消息:{}",content);
// //构建给大群发送的名单 JSONObject patchMsg = new JSONObject();
// user.add(pushPainBO.getIndex().toString()); patchMsg.put("content", content);
// user.add(pushPainBO.getName()); feiShuApiService.patchMsg(messageId, patchMsg);
// user.add(pushPainBO.getDepartMentName()); }
// user.add(pushPainBO.getTimeRange());
// user.add("");
// pushUser.add(user);
// }
// //给大群发送消息
// String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
// log.info("给大群发送按摩消息:{}",content);
// FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
// feiShuMsgDTO.setMsgType("interactive");
// feiShuMsgDTO.setContent(content);
// feiShuMsgDTO.setReceiveId(feiShuConfig.getChatId());
// log.info(feiShuMsgDTO.toString());
// feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
// }
......
...@@ -52,6 +52,9 @@ public class MassageNoticeScheduleService { ...@@ -52,6 +52,9 @@ public class MassageNoticeScheduleService {
for(Pain pain:pains){ for(Pain pain:pains){
String messageId = pain.getMessageId(); String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId); massageService.updateSingleMassageMsgCardWhenBegin(messageId);
//1代表正在按
pain.setStatus(1);
painService.update(pain);
JSONObject noticeMsg = new JSONObject(); JSONObject noticeMsg = new JSONObject();
noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId())); noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId()));
//发送应用内提醒 //发送应用内提醒
...@@ -60,4 +63,27 @@ public class MassageNoticeScheduleService { ...@@ -60,4 +63,27 @@ public class MassageNoticeScheduleService {
} }
} }
// /**
// * 当天时间2:55,给第一波三个人更新卡片,并发送应用内提醒
// */
// @Async
// @Scheduled(cron = "0 0 10 * * ?")
// public void massageStart(){
// List<Pain> pains = painService.findListAsc(3);
// for(Pain pain:pains){
// String messageId = pain.getMessageId();
// massageService.updateSingleMassageMsgCardWhenBegin(messageId);
// //1代表正在按
// pain.setStatus(1);
// painService.update(pain);
// JSONObject noticeMsg = new JSONObject();
// noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId()));
// //发送应用内提醒
// log.info("发送应用内容消息提醒");
// feiShuApiService.patchUrgentApp(messageId, noticeMsg);
// }
//
// }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!