Commit e9a9e943 by zhaolianjie

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
2 parents 8e499e62 3caf3402
......@@ -135,15 +135,14 @@ public class FeiShuEventController {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String waitUserId = feiShuMsgCardEventDTO.getOpen_id();
painService.waitPain(waitUserId);
//更新大群
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
//没有按摩群的id
// massageService.updateMassageMsgCardToPiPiChat();
//更新按摩群
massageService.updateMassageMsgCardToPiPiChat((String) CacheUtil.get("chatId"));
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "已为你推迟到最后");
} else if ("rob".equals(actionTypeSecond)) {
// 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
return rob(feiShuMsgCardEventDTO);
} else if ("next".equals(actionTypeSecond)) {
// 当前按完,有请下一位
......@@ -157,6 +156,15 @@ public class FeiShuEventController {
noticePain.setStatus(1);
painService.update(noticePain);
massageService.updateSingleMassageMsgCardWhenBegin(noticePain.getMessageId());
//按摩群中同步发送按摩进度信息
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
String msg = "当前按摩进度:" + String.format("<at user_id=\\\"%s\\\">%s</at>", noticePain.getOpenId(), noticePain.getName());
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setReceiveId((String) CacheUtil.get("chatId"));
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
}
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "欢迎下次光临~");
......@@ -179,6 +187,12 @@ public class FeiShuEventController {
feiShuChatDTO.setChatId((String) CacheUtil.get("chatId"));
feiShuChatDTO.setIdList(new String[]{feiShuMsgCardEventDTO.getOpen_id()});
feiShuApiService.joinChatList(feiShuChatDTO);
// 更新大群和按摩群的大卡片,异步
// 大群
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
//按摩群
massageService.updateMassageMsgCardToPiPiChat((String) CacheUtil.get("chatId"));
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json");
return getInteractiveCardStr(fileName1, "已经被" + user.getString("name") + "抢啦,啦啦~");
}
......@@ -318,9 +332,13 @@ public class FeiShuEventController {
@PostMapping("/start")
public Result start() {
List<Pain> pains = painService.findListAsc(3);
StringBuilder userString = new StringBuilder();
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()));
//1代表正在按
pain.setStatus(1);
painService.update(pain);
......@@ -330,6 +348,27 @@ public class FeiShuEventController {
log.info("发送应用内容消息提醒");
feiShuApiService.patchUrgentApp(messageId, noticeMsg);
}
//按摩群中同步发送按摩进度信息
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
String msg = "当前按摩进度:" + userString;
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setReceiveId((String) CacheUtil.get("chatId"));
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
return ResultGenerator.genSuccessResult();
}
@PostMapping("/send-msg")
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());
feiShuMsgDTO.setReceiveId(receiveId);
feiShuApiService.sendMsg(feiShuMsgDTO, receiveIdType);
return ResultGenerator.genSuccessResult();
}
......
......@@ -25,9 +25,9 @@ public interface PainDao {
List<Pain> findListAsc(int limit);
List<Pain> findBackIndex(@Param(value = "index") Integer index, @Param(value = "limit") int limit);
List<Pain> findBackIndex(@Param(value = "pindex") Integer pindex, @Param(value = "limit") int limit);
void deleteAllByFloor(int floor);
List<Pain> findAllByFloor(int floor);
List<Pain> findAllByFloor(@Param(value = "floor") int floor);
}
......@@ -156,7 +156,7 @@ public class FeiShuApiService {
@Async
public JSONObject patchUrgentApp(String message_id, JSONObject content) {
String api = "/im/v1/messages/" + message_id + "/urgent_sms?user_id_type=user_id";
String api = "/im/v1/messages/" + message_id + "/urgent_app?user_id_type=open_id";
OkHttpClient client = new OkHttpClient();
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
RequestBody requestBody = RequestBody.create(content.toString(), MediaType.parse("application/json"));
......@@ -180,7 +180,7 @@ public class FeiShuApiService {
@Async
public JSONObject patchUrgentSms(String message_id, JSONObject content) {
String api = "/im/v1/messages/" + message_id + "/urgent_app?user_id_type=open_id";
String api = "/im/v1/messages/" + message_id + "/urgent_sms?user_id_type=user_id";
OkHttpClient client = new OkHttpClient();
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
RequestBody requestBody = RequestBody.create(content.toString(), MediaType.parse("application/json"));
......
......@@ -3,12 +3,16 @@ package com.pipihelper.project.feishu.service;
import cn.hutool.core.collection.CollectionUtil;
import com.pipihelper.project.feishu.dao.PainDao;
import com.pipihelper.project.feishu.entity.Pain;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
public class PainService {
......@@ -16,6 +20,14 @@ public class PainService {
@Autowired
private PainDao painDao;
private final static List<PindexFloor> pindexFloors = new ArrayList<>();
static {
pindexFloors.add(new PindexFloor().setStartIndex(1).setEndIndex(12).setTimeRange("15:00-16:00").setFloor(14));
pindexFloors.add(new PindexFloor().setStartIndex(13).setEndIndex(24).setTimeRange("16:00-17:00").setFloor(14));
pindexFloors.add(new PindexFloor().setStartIndex(25).setEndIndex(30).setTimeRange("17:00-17:30").setFloor(14));
}
public void create(Pain pain) {
painDao.create(pain);
}
......@@ -40,13 +52,22 @@ public class PainService {
return painDao.findAll();
}
public List<Pain> findAllReorderByFloor(int floor) {
List<Pain> painList = painDao.findAllByFloor(floor);
if (CollectionUtil.isEmpty(painList)) {
return new ArrayList<>();
}
painList.stream().sorted(Comparator.comparing(Pain::getPindex));
return new ArrayList<>();
painList = painList.stream().sorted(Comparator.comparing(Pain::getPindex)).collect(Collectors.toList());
AtomicInteger atomicInteger = new AtomicInteger(1);
painList.forEach(pain -> {
int increment = atomicInteger.getAndIncrement();
pain.setPindex(increment);
String timeRange = pindexFloors.stream().filter(it -> it.floor != null && it.floor == floor)
.filter(it -> floor <= it.getEndIndex() && floor >= it.getStartIndex()).findFirst().get().timeRange;
pain.setTimeRange(timeRange);
});
return painList;
}
public void waitPain(String openId) {
......@@ -61,11 +82,20 @@ public class PainService {
return painDao.findListAsc(limit);
}
public List<Pain> findBackIndex(Integer index, int limit) {
return painDao.findBackIndex(index, limit);
public List<Pain> findBackIndex(Integer pindex, int limit) {
return painDao.findBackIndex(pindex, limit);
}
public void deleteAllByFloor(int floor) {
painDao.deleteAllByFloor(floor);
}
@Data
@Accessors(chain = true)
public static class PindexFloor {
private Integer startIndex;
private Integer endIndex;
private String timeRange;
private Integer floor;
}
}
......@@ -43,13 +43,14 @@ public class MassageService {
private ChatMessageService chatMessageService;
//给群里发送消息
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList, String chatId){
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList, String chatId) {
List<List<String>> pushUser = new ArrayList<>();
for(PushPainBO pushPainBO:pushPainBOList){
for (PushPainBO pushPainBO : pushPainBOList) {
List<String> user = new ArrayList<>();
if(chatId.equals(feiShuConfig.getChatId())){
//给单个用户发送
String singleContent = massageMsgCardSerivce.genMassageMsgCardForSingle();
log.info("给单个用户发送按摩消息:{}",singleContent);
log.info("给单个用户发送按摩消息:{}", singleContent);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(singleContent);
......@@ -61,6 +62,7 @@ public class MassageService {
Pain pain = painService.findByOpenId(pushPainBO.getOpenId());
pain.setMessageId(messageId);
painService.update(pain);
}
//构建给大群发送的名单
user.add(pushPainBO.getIndex().toString());
user.add(pushPainBO.getName());
......@@ -71,7 +73,7 @@ public class MassageService {
}
//给大群发送消息
String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
log.info("给大群发送按摩消息:{}",content);
log.info("给大群发送按摩消息:{}", content);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(content);
......@@ -88,7 +90,7 @@ public class MassageService {
}
public void updateSingleMassageMsgCardWhenBegin(String messageId){
public void updateSingleMassageMsgCardWhenBegin(String messageId) {
JSONObject patchMsg = new JSONObject();
String msgCardContent = massageMsgCardSerivce.genMassageMsgCardForSingleStart();
patchMsg.put("content", msgCardContent);
......@@ -97,29 +99,28 @@ public class MassageService {
//更新群消息
@Async
public void updateMassageMsgCardToPiPiChat(String chatId){
List<Pain> pains = painService.findAll();
public void updateMassageMsgCardToPiPiChat(String chatId) {
List<Pain> pains = painService.findAllReorderByFloor(14);
System.out.println(pains);
String messageId = chatMessageService.findListChatAndType(chatId, 1).get(0).getMessageId();
List<List<String>> pushUser = new ArrayList<>();
for(Pain pain:pains){
for (Pain pain : pains) {
List<String> user = new ArrayList<>();
//构建给大群发送的名单
user.add(pain.getPindex().toString());
user.add(pain.getName());
user.add(pain.getDepartMentName());
user.add("15:00-18:00");
user.add(pain.getTimeRange());
user.add("");
pushUser.add(user);
}
//给大群更新发送消息
String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
log.info("给大群发送按摩消息:{}",content);
log.info("给大群发送按摩消息:{}", content);
JSONObject patchMsg = new JSONObject();
patchMsg.put("content", content);
feiShuApiService.patchMsg(messageId, patchMsg);
}
}
package com.pipihelper.project.scheduled;
import com.alibaba.fastjson.JSONObject;
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.PainService;
import com.pipihelper.project.feishu.service.massage.MassageService;
import com.pipihelper.project.utils.CacheUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
......@@ -33,7 +35,7 @@ public class MassageNoticeScheduleService {
@Autowired
private FeiShuApiService feiShuApiService;
/**
* 每周四定时生成要按摩的人员名单,并发送大群和单人消息
* TODO 每周四定时生成要按摩的人员名单,并发送大群和单人消息
*/
@Async
@Scheduled(cron = "0 0 10 * * ?")
......@@ -49,41 +51,32 @@ public class MassageNoticeScheduleService {
// @Scheduled(cron = "0 0 10 * * ?")
public void massageStart(){
List<Pain> pains = painService.findListAsc(3);
// String msg = "{\"text\":\"当前按摩进度:<at user_id=\\\"%s\\\">%s</at> <at user_id=\\\"%s\\\">%s</at> <at user_id=\\\"%s\\\">%s</at>\"}";
StringBuilder userString = new StringBuilder();
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()));
//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);
}
}
//按摩群中同步发送按摩进度信息
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
String msg = "当前按摩进度:" + userString;
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setReceiveId((String) CacheUtil.get("chatId"));
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
}
// /**
// * 当天时间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);
// }
//
// }
}
......@@ -33,6 +33,15 @@
</where>
</select>
<select id="findAllByFloor" parameterType="java.lang.Integer" resultMap="PainResultMap">
select
<include refid="Base_Column_List"/>
from t_pain
<where>
floor = #{floor}
</where>
</select>
<select id="findBackIndex" resultMap="PainResultMap">
select
<include refid="Base_Column_List"/>
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "已经被抢啦啦啦~",
"content": "已抢完~",
"tag": "lark_md"
}
}
......@@ -15,7 +15,7 @@
"header": {
"template": "turquoise",
"title": {
"content": "👻 按摩提醒请查收!",
"content": "👻 有按摩名额空余啦!",
"tag": "plain_text"
}
}
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "当前空余一个名额",
"content": "有人怕疼放弃了,快来抢吧!",
"tag": "lark_md"
}
},
......@@ -16,7 +16,7 @@
{
"tag": "button",
"text": {
"content": "😁 我",
"content": "😁 我不怕",
"tag": "plain_text"
},
"type": "default",
......@@ -31,7 +31,7 @@
"header": {
"template": "turquoise",
"title": {
"content": "👻 按摩提醒请查收!",
"content": "👻 有按摩名额空余啦!",
"tag": "plain_text"
}
}
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "欢呼吧,你排到了按摩哦!",
"content": "欢呼吧,你本周有按摩名额哦!",
"tag": "lark_md"
}
},
......@@ -38,7 +38,7 @@
{
"tag": "button",
"text": {
"content": "😢 等一下",
"content": "😢 我最后来",
"tag": "plain_text"
},
"type": "default",
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "欢呼吧,你排到了按摩哦!",
"content": "按摩到你了哦!",
"tag": "lark_md"
}
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!