Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
zhangshaowu
/
pipi-helper
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 50ffc2f8
authored
Oct 16, 2022
by
liushuangwu
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
2 parents
ab2b4c5e
79d0a06f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
44 deletions
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
src/main/java/com/pipihelper/project/feishu/controller/SendMsgUseFeiShu.java
src/main/java/com/pipihelper/project/feishu/service/massage/MassageMsgCardSerivce.java
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
src/main/java/com/pipihelper/project/scheduled/MassageNoticeScheduleService.java
src/main/resources/templates/massage-single-msg-card-start.json → src/main/resources/templates/massage-single-msg-card-next.json
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
View file @
50ffc2f
...
...
@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
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.FeiShuEventDTO
;
import
com.pipihelper.project.feishu.dto.FeiShuMsgCardEventDTO
;
...
...
@@ -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.MassageService
;
import
com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -33,6 +36,7 @@ import java.io.BufferedReader;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -46,6 +50,7 @@ import java.util.stream.Stream;
* @author: charles
* @date: 2022年03月30日 17:39
*/
@Slf4j
@RestController
@RequestMapping
(
"/pipitest/feishu"
)
public
class
FeiShuEventController
{
...
...
@@ -127,7 +132,10 @@ public class FeiShuEventController {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String
waitUserId
=
feiShuMsgCardEventDTO
.
getOpen_id
();
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"
);
return
getInteractiveCardStr
(
fileName1
,
"已为你推迟到最后"
);
}
else
if
(
"rob"
.
equals
(
actionTypeSecond
))
{
...
...
@@ -137,7 +145,10 @@ public class FeiShuEventController {
Pain
oldPain
=
painService
.
findByOpenId
(
oldUserId
);
oldPain
.
setOpenId
(
robUserId
);
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"
);
return
getInteractiveCardStr
(
fileName1
,
"已经被抢啦啦啦~"
);
}
else
if
(
"next"
.
equals
(
actionTypeSecond
))
{
...
...
@@ -266,4 +277,23 @@ public class FeiShuEventController {
feiShuChatDTO
.
setIdList
(
new
String
[]{
openId
});
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
();
}
}
src/main/java/com/pipihelper/project/feishu/controller/SendMsgUseFeiShu.java
View file @
50ffc2f
...
...
@@ -58,7 +58,7 @@ public class SendMsgUseFeiShu {
userList
.
add
(
pushPainBO
);
userList
.
add
(
pushPainBO1
);
userList
.
add
(
pushPainBO2
);
massageService
.
sendMassageMsgCardToPiPiChat
(
userList
);
massageService
.
sendMassageMsgCardToPiPiChat
(
userList
,
feiShuConfig
.
getChatId
()
);
return
ResultGenerator
.
genSuccessResult
();
}
}
src/main/java/com/pipihelper/project/feishu/service/massage/MassageMsgCardSerivce.java
View file @
50ffc2f
...
...
@@ -39,7 +39,7 @@ public class MassageMsgCardSerivce {
public
String
genMassageMsgCardForSingleStart
(){
String
fileName
=
String
.
format
(
"/templates/massage-single-msg-card-
star
t.json"
);
String
fileName
=
String
.
format
(
"/templates/massage-single-msg-card-
nex
t.json"
);
String
msgCardContent
=
String
.
format
(
getInteractiveCardStr
(
fileName
));
return
msgCardContent
;
}
...
...
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
View file @
50ffc2f
...
...
@@ -5,10 +5,12 @@ import com.pipihelper.project.feishu.bo.PushPainBO;
import
com.pipihelper.project.feishu.dto.FeiShuConfig
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO
;
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.PainService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -36,7 +38,11 @@ public class MassageService {
@Autowired
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
<>();
for
(
PushPainBO
pushPainBO:
pushPainBOList
){
List
<
String
>
user
=
new
ArrayList
<>();
...
...
@@ -68,7 +74,7 @@ public class MassageService {
FeiShuMsgDTO
feiShuMsgDTO
=
new
FeiShuMsgDTO
();
feiShuMsgDTO
.
setMsgType
(
"interactive"
);
feiShuMsgDTO
.
setContent
(
content
);
feiShuMsgDTO
.
setReceiveId
(
feiShuConfig
.
getChatId
()
);
feiShuMsgDTO
.
setReceiveId
(
chatId
);
log
.
info
(
feiShuMsgDTO
.
toString
());
feiShuApiService
.
sendMsg
(
feiShuMsgDTO
,
"chat_id"
);
}
...
...
@@ -80,44 +86,30 @@ public class MassageService {
patchMsg
.
put
(
"content"
,
msgCardContent
);
feiShuApiService
.
patchMsg
(
messageId
,
patchMsg
);
}
//
// public void updateMassageMsgCardToPiPiChat(){
// List<PushPainBO> pushPainBOList =
// List<List<String>> pushUser = new ArrayList<>();
// for(PushPainBO pushPainBO:pushPainBOList){
// 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.getName());
// 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");
// }
//更新群消息
@Async
public
void
updateMassageMsgCardToPiPiChat
(
String
chatId
){
List
<
Pain
>
pains
=
painService
.
findAll
();
String
messageId
=
chatMessageService
.
findListChatAndType
(
chatId
,
1
).
get
(
0
).
getMessageId
();
List
<
List
<
String
>>
pushUser
=
new
ArrayList
<>();
for
(
Pain
pain:
pains
){
List
<
String
>
user
=
new
ArrayList
<>();
//构建给大群发送的名单
user
.
add
(
pain
.
getIndex
().
toString
());
user
.
add
(
pain
.
getName
());
user
.
add
(
pain
.
getDepartMentName
());
user
.
add
(
pain
.
getTimeRange
());
user
.
add
(
""
);
pushUser
.
add
(
user
);
}
//给大群更新发送消息
String
content
=
massageMsgCardSerivce
.
genMassageMsgCardForCompany
(
pushUser
);
log
.
info
(
"给大群发送按摩消息:{}"
,
content
);
JSONObject
patchMsg
=
new
JSONObject
();
patchMsg
.
put
(
"content"
,
content
);
feiShuApiService
.
patchMsg
(
messageId
,
patchMsg
);
}
...
...
src/main/java/com/pipihelper/project/scheduled/MassageNoticeScheduleService.java
View file @
50ffc2f
...
...
@@ -52,6 +52,9 @@ public class MassageNoticeScheduleService {
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
()));
//发送应用内提醒
...
...
@@ -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);
// }
//
// }
}
src/main/resources/templates/massage-single-msg-card-
star
t.json
→
src/main/resources/templates/massage-single-msg-card-
nex
t.json
View file @
50ffc2f
File moved
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment