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 2956b2a2
authored
Oct 25, 2022
by
zhaolianjie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
卡片流程 - 删除群组
1 parent
4e8fa188
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
11 deletions
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
src/main/java/com/pipihelper/project/scheduled/MassageNoticeScheduleService.java
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
View file @
2956b2a
...
...
@@ -150,7 +150,8 @@ public class FeiShuEventController {
//更新大群
massageService
.
updateMassageMsgCardToPiPiChat
(
feiShuConfig
.
getChatId
());
//更新按摩群
massageService
.
updateMassageMsgCardToPiPiChat
((
String
)
CacheUtil
.
get
(
"chatId"
));
String
chatId
=
feiShuApiService
.
queryChatId
();
massageService
.
updateMassageMsgCardToPiPiChat
(
chatId
);
String
fileName1
=
String
.
format
(
"/templates/massage-singel-msg-card-end.json"
);
return
getInteractiveCardStr
(
fileName1
,
"已为你推迟到队尾"
);
}
else
if
(
"rob"
.
equals
(
actionTypeSecond
))
{
...
...
@@ -175,7 +176,9 @@ public class FeiShuEventController {
content
.
put
(
"text"
,
msg
);
feiShuMsgDTO
.
setMsgType
(
"text"
);
feiShuMsgDTO
.
setContent
(
content
.
toString
());
feiShuMsgDTO
.
setReceiveId
((
String
)
CacheUtil
.
get
(
"chatId"
));
String
chatId
=
feiShuApiService
.
queryChatId
();
feiShuMsgDTO
.
setReceiveId
(
chatId
);
feiShuApiService
.
sendMsg
(
feiShuMsgDTO
,
"chat_id"
);
}
String
fileName1
=
String
.
format
(
"/templates/massage-singel-msg-card-end.json"
);
...
...
@@ -227,7 +230,7 @@ public class FeiShuEventController {
@PostMapping
(
"/delete-chat-list"
)
public
Object
deleteChat
(
String
chatId
)
{
if
(
StringUtils
.
isBlank
(
chatId
))
{
chatId
=
(
String
)
CacheUtil
.
get
(
"chatId"
);
chatId
=
feiShuApiService
.
queryChatId
(
);
}
log
.
info
(
"删除群组id:{}"
,
chatId
);
feiShuApiService
.
deleteChatList
(
chatId
);
...
...
@@ -390,7 +393,8 @@ public class FeiShuEventController {
content
.
put
(
"text"
,
msg
);
feiShuMsgDTO
.
setMsgType
(
"text"
);
feiShuMsgDTO
.
setContent
(
content
.
toString
());
feiShuMsgDTO
.
setReceiveId
((
String
)
CacheUtil
.
get
(
"chatId"
));
String
chatId
=
feiShuApiService
.
queryChatId
();
feiShuMsgDTO
.
setReceiveId
(
chatId
);
feiShuApiService
.
sendMsg
(
feiShuMsgDTO
,
"chat_id"
);
return
ResultGenerator
.
genSuccessResult
();
}
...
...
@@ -403,7 +407,7 @@ public class FeiShuEventController {
feiShuMsgDTO
.
setMsgType
(
"text"
);
feiShuMsgDTO
.
setContent
(
content
.
toString
());
if
(
receiveId
.
equals
(
"-1"
))
{
receiveId
=
(
String
)
CacheUtil
.
get
(
"chatId"
);
receiveId
=
feiShuApiService
.
queryChatId
(
);
}
feiShuMsgDTO
.
setReceiveId
(
receiveId
);
log
.
info
(
"已机器人身份发送消息:{}"
,
feiShuMsgDTO
.
toString
());
...
...
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
View file @
2956b2a
package
com
.
pipihelper
.
project
.
feishu
.
service
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
...
...
@@ -17,7 +19,7 @@ import com.pipihelper.project.feishu.dto.doc.FieldsDTO;
import
com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuBatchMsgDTO
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO
;
import
com.pipihelper.project.
utils.CacheUtil
;
import
com.pipihelper.project.
feishu.entity.ChatMessage
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
...
...
@@ -25,6 +27,7 @@ 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
;
...
...
@@ -41,6 +44,7 @@ import java.lang.reflect.Type;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* @Description: TODO
...
...
@@ -54,6 +58,8 @@ public class FeiShuApiService {
@Resource
private
FeiShuConfig
feiShuConfig
;
@Autowired
private
ChatMessageService
chatMessageService
;
private
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
...
...
@@ -426,12 +432,32 @@ public class FeiShuApiService {
Type
type
=
new
TypeReference
<
FeiShuResultDTO
>()
{
}.
getType
();
FeiShuResultDTO
feiShuResultDTO
=
JSONObject
.
parseObject
(
responseEntity
.
getBody
(),
type
);
CacheUtil
.
put
(
"chatId"
,
feiShuResultDTO
.
getData
().
getChatId
());
saveChatId
(
feiShuResultDTO
.
getData
().
getChatId
());
return
feiShuResultDTO
.
getData
().
getChatId
();
}
catch
(
Exception
e
)
{
throw
new
ServiceException
(
"飞书:"
+
api
+
"接口调用失败"
+
"\n"
+
e
);
}
}
public
void
saveChatId
(
String
chatId
)
{
ChatMessage
chatMessage
=
new
ChatMessage
();
chatMessage
.
setChatId
(
chatId
);
chatMessage
.
setType
(
11
);
chatMessageService
.
create
(
chatMessage
);
}
public
String
queryChatId
()
{
List
<
ChatMessage
>
list
=
chatMessageService
.
findAll
();
if
(
CollectionUtil
.
isEmpty
(
list
)
||
list
.
size
()
>
1
)
{
return
null
;
}
List
<
ChatMessage
>
remainList
=
list
.
stream
().
filter
(
chatMessage1
->
ObjectUtil
.
equal
(
chatMessage1
.
getType
(),
11
)
&&
chatMessage1
.
getMessageId
()
==
null
).
collect
(
Collectors
.
toList
());
return
CollectionUtil
.
getFirst
(
remainList
).
getChatId
();
}
@Async
public
String
joinChatList
(
FeiShuChatDTO
feiShuChatDTO
)
{
String
api
=
"/im/v1/chats/{chat_id}/members"
;
...
...
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
View file @
2956b2a
...
...
@@ -128,7 +128,9 @@ public class MassageService {
@Async
public
void
robSingle
(
String
robOpenId
,
String
robDepartmentId
,
Integer
givUpPainId
)
{
FeiShuChatDTO
feiShuChatDTO
=
new
FeiShuChatDTO
();
feiShuChatDTO
.
setChatId
((
String
)
CacheUtil
.
get
(
"chatId"
));
String
chatId
=
feiShuApiService
.
queryChatId
();
feiShuChatDTO
.
setChatId
(
chatId
);
feiShuChatDTO
.
setIdList
(
new
String
[]{
robOpenId
});
feiShuApiService
.
joinChatList
(
feiShuChatDTO
);
...
...
@@ -146,7 +148,7 @@ public class MassageService {
// 大群
updateMassageMsgCardToPiPiChat
(
feiShuConfig
.
getChatId
());
//按摩群
updateMassageMsgCardToPiPiChat
(
(
String
)
CacheUtil
.
get
(
"chatId"
)
);
updateMassageMsgCardToPiPiChat
(
chatId
);
}
public
void
sendSingle
(
String
openId
)
{
...
...
src/main/java/com/pipihelper/project/scheduled/MassageNoticeScheduleService.java
View file @
2956b2a
...
...
@@ -163,7 +163,7 @@ public class MassageNoticeScheduleService {
// @Async
@Scheduled
(
cron
=
"0 0 19 * * ?"
)
public
void
deleteChatList
()
{
String
chatId
=
(
String
)
CacheUtil
.
get
(
"chatId"
);
String
chatId
=
feiShuApiService
.
queryChatId
(
);
if
(
StringUtils
.
isEmpty
(
chatId
))
{
return
;
}
...
...
@@ -201,7 +201,8 @@ public class MassageNoticeScheduleService {
content
.
put
(
"text"
,
msg
);
feiShuMsgDTO
.
setMsgType
(
"text"
);
feiShuMsgDTO
.
setContent
(
content
.
toString
());
feiShuMsgDTO
.
setReceiveId
((
String
)
CacheUtil
.
get
(
"chatId"
));
String
chatId
=
feiShuApiService
.
queryChatId
();
feiShuMsgDTO
.
setReceiveId
(
chatId
);
feiShuApiService
.
sendMsg
(
feiShuMsgDTO
,
"chat_id"
);
}
...
...
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