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 f3ecc075
authored
Oct 16, 2022
by
weiss
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
2 parents
f62d6617
efe136d0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
205 additions
and
36 deletions
src/main/java/com/pipihelper/project/controller/LoveChatController.java
src/main/java/com/pipihelper/project/feishu/bo/LoveChatVO.java
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
src/main/java/com/pipihelper/project/feishu/dao/LoveChatDao.java
src/main/java/com/pipihelper/project/feishu/entity/LoveChat.java
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
src/main/java/com/pipihelper/project/feishu/service/LoveChatService.java
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
src/main/resources/mybatis/LoveChatMapper.xml
src/main/java/com/pipihelper/project/controller/LoveChatController.java
0 → 100644
View file @
f3ecc07
package
com
.
pipihelper
.
project
.
controller
;
import
com.pipihelper.project.core.Result
;
import
com.pipihelper.project.core.ResultGenerator
;
import
com.pipihelper.project.feishu.service.LoveChatService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/api/v1/love-chat"
)
public
class
LoveChatController
{
@Autowired
private
LoveChatService
loveChatService
;
@PostMapping
(
value
=
"list"
)
public
Result
list
(
@RequestParam
(
value
=
"title"
,
required
=
false
)
String
title
,
@RequestParam
(
"pageNum"
)
Integer
pageNum
,
@RequestParam
(
"pageSize"
)
Integer
pageSize
)
{
return
ResultGenerator
.
genSuccessResult
(
loveChatService
.
list
(
title
,
pageNum
,
pageSize
));
}
}
src/main/java/com/pipihelper/project/feishu/bo/LoveChatVO.java
0 → 100644
View file @
f3ecc07
package
com
.
pipihelper
.
project
.
feishu
.
bo
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
LoveChatVO
{
private
Integer
id
;
private
String
title
;
private
List
<
LoveChatDetail
>
loveChatDetails
;
@Data
public
static
class
LoveChatDetail
{
private
Integer
type
;
private
String
text
;
}
}
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
View file @
f3ecc07
...
...
@@ -18,6 +18,7 @@ import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import
com.pipihelper.project.feishu.entity.Employee
;
import
com.pipihelper.project.feishu.entity.LastMaxPain
;
import
com.pipihelper.project.feishu.entity.Pain
;
import
com.pipihelper.project.feishu.service.ChatMessageService
;
import
com.pipihelper.project.feishu.service.EmployeeService
;
import
com.pipihelper.project.feishu.service.FeiShuApiService
;
import
com.pipihelper.project.feishu.service.FeiShuEventService
;
...
...
@@ -72,6 +73,8 @@ public class FeiShuEventController {
@Autowired
private
EmployeeService
employeeService
;
@Autowired
private
ChatMessageService
chatMessageService
;
@Autowired
private
LastMaxPainService
lastMaxPainService
;
@Autowired
private
PainService
painService
;
...
...
@@ -178,45 +181,13 @@ public class FeiShuEventController {
String
oldUserId
=
feiShuMsgCardEventDTO
.
getAction
().
getValue
().
getKey
().
split
(
"\\."
)[
2
];
String
robUserId
=
feiShuMsgCardEventDTO
.
getOpen_id
();
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
(
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
());
//按摩群
massageService
.
updateMassageMsgCardToPiPiChat
((
String
)
CacheUtil
.
get
(
"chatId"
));
massageService
.
robSingle
(
robUserId
,
oldUserId
,
employee
.
getName
());
String
fileName1
=
String
.
format
(
"/templates/massage-msg-card-rob-end.json"
);
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
);
}
/**
* 读取模板文件
*
...
...
@@ -247,6 +218,8 @@ public class FeiShuEventController {
@PostMapping
(
"/employee-list"
)
public
Object
event
()
{
employeeService
.
uprsetAllEmployee
();
chatMessageService
.
deleteAll
();
for
(
Integer
floor
:
Lists
.
newArrayList
(
14
))
{
LastMaxPain
maxPain
=
lastMaxPainService
.
findByFloor
(
floor
);
int
startEmployeeId
=
0
;
...
...
src/main/java/com/pipihelper/project/feishu/dao/LoveChatDao.java
0 → 100644
View file @
f3ecc07
package
com
.
pipihelper
.
project
.
feishu
.
dao
;
import
com.pipihelper.project.feishu.entity.LoveChat
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
@Mapper
public
interface
LoveChatDao
{
List
<
LoveChat
>
findList
(
@Param
(
value
=
"title"
)
String
title
);
}
src/main/java/com/pipihelper/project/feishu/entity/LoveChat.java
0 → 100644
View file @
f3ecc07
package
com
.
pipihelper
.
project
.
feishu
.
entity
;
import
lombok.Data
;
@Data
public
class
LoveChat
{
private
Integer
id
;
private
String
title
;
private
String
content
;
private
Integer
isDelete
;
}
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
View file @
f3ecc07
...
...
@@ -432,7 +432,7 @@ public class FeiShuApiService {
throw
new
ServiceException
(
"飞书:"
+
api
+
"接口调用失败"
+
"\n"
+
e
);
}
}
@Async
public
String
joinChatList
(
FeiShuChatDTO
feiShuChatDTO
)
{
String
api
=
"/im/v1/chats/{chat_id}/members"
;
RestTemplate
restTemplate
=
new
RestTemplate
();
...
...
src/main/java/com/pipihelper/project/feishu/service/LoveChatService.java
0 → 100644
View file @
f3ecc07
package
com
.
pipihelper
.
project
.
feishu
.
service
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.github.pagehelper.PageHelper
;
import
com.pipihelper.project.feishu.bo.LoveChatVO
;
import
com.pipihelper.project.feishu.dao.LoveChatDao
;
import
com.pipihelper.project.feishu.entity.LoveChat
;
import
lombok.Data
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
public
class
LoveChatService
{
@Autowired
private
LoveChatDao
loveChatDao
;
public
List
<
LoveChatVO
>
list
(
String
title
,
Integer
pageNum
,
Integer
pageSize
)
{
if
(
StringUtils
.
isBlank
(
title
)){
title
=
null
;
}
PageHelper
.
startPage
(
pageNum
,
pageSize
);
List
<
LoveChat
>
chatList
=
loveChatDao
.
findList
(
title
);
if
(
CollectionUtil
.
isEmpty
(
chatList
))
{
return
new
ArrayList
<>();
}
return
chatList
.
stream
().
map
(
it
->
{
LoveChatVO
loveChatVO
=
new
LoveChatVO
();
loveChatVO
.
setTitle
(
it
.
getTitle
());
loveChatVO
.
setId
(
it
.
getId
());
List
<
SpeedContent
>
speedContentList
=
JSON
.
parseArray
(
it
.
getContent
(),
SpeedContent
.
class
);
loveChatVO
.
setLoveChatDetails
(
speedContentList
.
stream
().
map
(
speedContent
->
{
LoveChatVO
.
LoveChatDetail
chatDetail
=
new
LoveChatVO
.
LoveChatDetail
();
chatDetail
.
setType
(
"me"
.
equals
(
speedContent
.
getObject
())
?
1
:
2
);
chatDetail
.
setText
(
speedContent
.
getPlan
());
return
chatDetail
;
}).
collect
(
Collectors
.
toList
()));
return
loveChatVO
;
}).
collect
(
Collectors
.
toList
());
}
@Data
private
static
class
SpeedContent
{
private
String
object
;
private
String
plan
;
}
}
src/main/java/com/pipihelper/project/feishu/service/massage/MassageService.java
View file @
f3ecc07
...
...
@@ -3,12 +3,14 @@ package com.pipihelper.project.feishu.service.massage;
import
com.alibaba.fastjson.JSONObject
;
import
com.pipihelper.project.feishu.bo.PushPainBO
;
import
com.pipihelper.project.feishu.dto.FeiShuConfig
;
import
com.pipihelper.project.feishu.dto.chat.FeiShuChatDTO
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO
;
import
com.pipihelper.project.feishu.entity.ChatMessage
;
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
com.pipihelper.project.utils.CacheUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
...
...
@@ -47,7 +49,7 @@ public class MassageService {
List
<
List
<
String
>>
pushUser
=
new
ArrayList
<>();
for
(
PushPainBO
pushPainBO
:
pushPainBOList
)
{
List
<
String
>
user
=
new
ArrayList
<>();
if
(
chatId
.
equals
(
feiShuConfig
.
getChatId
()))
{
if
(
chatId
.
equals
(
feiShuConfig
.
getChatId
()))
{
//给单个用户发送
String
singleContent
=
massageMsgCardSerivce
.
genMassageMsgCardForSingle
();
log
.
info
(
"给单个用户发送按摩消息:{}"
,
singleContent
);
...
...
@@ -122,5 +124,42 @@ public class MassageService {
feiShuApiService
.
patchMsg
(
messageId
,
patchMsg
);
}
@Async
public
void
robSingle
(
String
robUserId
,
String
oldUserId
,
String
name
)
{
Pain
oldPain
=
painService
.
findByOpenId
(
oldUserId
);
oldPain
.
setOpenId
(
robUserId
);
oldPain
.
setName
(
name
);
painService
.
update
(
oldPain
);
FeiShuChatDTO
feiShuChatDTO
=
new
FeiShuChatDTO
();
feiShuChatDTO
.
setChatId
((
String
)
CacheUtil
.
get
(
"chatId"
));
feiShuChatDTO
.
setIdList
(
new
String
[]{
robUserId
});
feiShuApiService
.
joinChatList
(
feiShuChatDTO
);
sendSingle
(
robUserId
);
// 更新大群和按摩群的大卡片,异步
// 大群
updateMassageMsgCardToPiPiChat
(
feiShuConfig
.
getChatId
());
//按摩群
updateMassageMsgCardToPiPiChat
((
String
)
CacheUtil
.
get
(
"chatId"
));
}
public
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
);
}
}
src/main/resources/mybatis/LoveChatMapper.xml
0 → 100644
View file @
f3ecc07
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.pipihelper.project.feishu.dao.LoveChatDao"
>
<resultMap
id=
"ChatMessageResultMap"
type=
"com.pipihelper.project.feishu.entity.LoveChat"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"title"
property=
"title"
/>
<result
column=
"content"
property=
"content"
/>
<result
column=
"is_delete"
property=
"isDelete"
/>
</resultMap>
<!-- <resultMap id="BuffConfigResultBOMap" type="com.pipihelper.project.feishu.entity.Deployee"
extends="ChatMessageResultMap">
</resultMap>-->
<sql
id=
"Base_Column_List"
>
id,title,content,is_delete
</sql>
<select
id=
"findList"
resultMap=
"ChatMessageResultMap"
>
SELECT
<include
refid=
"Base_Column_List"
/>
FROM t_love_chat
<where>
is_delete = 0
<if
test=
"title != null"
>
and title like '%${title}%'
</if>
</where>
</select>
</mapper>
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