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 23aee837
authored
Oct 16, 2022
by
liushuangwu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
111
1 parent
3d68f4e2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
215 additions
and
78 deletions
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
src/main/java/com/pipihelper/project/feishu/service/EmployeeService.java
src/main/java/com/pipihelper/project/feishu/service/PainService.java
src/main/java/com/pipihelper/project/scheduled/MassageNoticeScheduleService.java
src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
View file @
23aee83
package
com
.
pipihelper
.
project
.
feishu
.
controller
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Lists
;
...
...
@@ -194,85 +195,90 @@ public class FeiShuEventController {
@PostMapping
(
"/employee-list"
)
public
Object
event
()
{
employeeService
.
uprsetAllEmployee
();
LastMaxPain
maxPain
=
lastMaxPainService
.
findByFloor
(
14
);
int
startEmployeeId
=
0
;
if
(
maxPain
!=
null
)
{
startEmployeeId
=
maxPain
.
getEmployeeId
();
}
int
countByFloor
=
employeeService
.
findCountByFloor
(
14
);
int
limit
=
30
;
if
(
countByFloor
<
30
){
limit
=
countByFloor
;
}
List
<
Employee
>
employeeList
=
employeeService
.
findStartList
(
startEmployeeId
,
14
,
limit
);
Integer
maxEmploeeId
=
0
;
if
(
employeeList
.
size
()
==
limit
)
{
maxEmploeeId
=
employeeList
.
stream
().
map
(
Employee:
:
getId
).
max
(
Comparator
.
comparing
(
x
->
x
)).
orElse
(
0
);
}
else
{
List
<
Employee
>
employees
=
employeeService
.
findStartList
(
0
,
14
,
limit
-
employeeList
.
size
());
maxEmploeeId
=
employees
.
stream
().
map
(
Employee:
:
getId
).
max
(
Comparator
.
comparing
(
x
->
x
)).
orElse
(
0
);
employeeList
.
addAll
(
employees
);
}
System
.
out
.
println
(
maxEmploeeId
);
Map
<
String
,
FeiShuDepartmentDTO
>
departmentMap
=
new
HashMap
<>();
List
<
String
>
departmentIdList
=
employeeList
.
stream
().
map
(
Employee:
:
getDepartmentId
).
distinct
().
collect
(
Collectors
.
toList
());
departmentIdList
.
forEach
(
it
->
{
FeiShuDepartmentDTO
department
=
feiShuApiService
.
getDepartment
(
it
);
departmentMap
.
put
(
it
,
department
);
});
painService
.
deleteAllByFloor
(
14
);
System
.
out
.
println
(
employeeList
);
List
<
PushPainBO
>
pushPainBOList
=
new
ArrayList
<>();
String
[]
userIdList
=
new
String
[
employeeList
.
size
()];
AtomicInteger
i
=
new
AtomicInteger
(
1
);
employeeList
.
forEach
(
it
->
{
Pain
pain
=
new
Pain
();
pain
.
setOpenId
(
it
.
getOpenId
());
pain
.
setStatus
(
0
);
pain
.
setFloor
(
Optional
.
ofNullable
(
it
.
getFloor
()).
orElse
(
14
));
int
increment
=
i
.
getAndIncrement
();
pain
.
setPindex
(
increment
);
pain
.
setName
(
it
.
getName
());
String
departMentName
=
departmentMap
.
getOrDefault
(
it
.
getDepartmentId
(),
new
FeiShuDepartmentDTO
()).
getName
();
pain
.
setDepartMentName
(
departMentName
);
painService
.
create
(
pain
);
PushPainBO
pushPainBO
=
new
PushPainBO
();
pushPainBO
.
setIndex
(
increment
);
pushPainBO
.
setName
(
it
.
getName
());
pushPainBO
.
setDepartMentName
(
departMentName
);
pushPainBO
.
setOpenId
(
it
.
getOpenId
());
pushPainBO
.
setTimeRange
(
"15:00-16:00"
);
pushPainBOList
.
add
(
pushPainBO
);
userIdList
[
increment
-
1
]
=
it
.
getOpenId
();
});
System
.
out
.
println
(
pushPainBOList
);
FeiShuChatDTO
feiShuChatDTO
=
new
FeiShuChatDTO
();
feiShuChatDTO
.
setName
(
"etgh "
);
feiShuChatDTO
.
setOwnerId
(
pushPainBOList
.
get
(
0
).
getOpenId
());
feiShuChatDTO
.
setUserIdList
(
userIdList
);
String
chatId
=
feiShuApiService
.
createChatList
(
feiShuChatDTO
);
massageService
.
sendMassageMsgCardToPiPiChat
(
pushPainBOList
,
chatId
);
massageService
.
sendMassageMsgCardToPiPiChat
(
pushPainBOList
,
feiShuConfig
.
getChatId
());
if
(
maxPain
!=
null
)
{
maxPain
.
setEmployeeId
(
maxEmploeeId
);
lastMaxPainService
.
update
(
maxPain
);
}
else
{
maxPain
=
new
LastMaxPain
();
maxPain
.
setEmployeeId
(
maxEmploeeId
);
maxPain
.
setFloor
(
14
);
lastMaxPainService
.
create
(
maxPain
);
for
(
Integer
floor
:
Lists
.
newArrayList
(
14
))
{
LastMaxPain
maxPain
=
lastMaxPainService
.
findByFloor
(
floor
);
int
startEmployeeId
=
0
;
if
(
maxPain
!=
null
)
{
startEmployeeId
=
maxPain
.
getEmployeeId
();
}
int
countByFloor
=
employeeService
.
findCountByFloor
(
floor
);
int
limit
=
2
;
if
(
countByFloor
<
2
)
{
limit
=
countByFloor
;
}
List
<
Employee
>
employeeList
=
employeeService
.
findStartList
(
startEmployeeId
,
floor
,
limit
);
Integer
maxEmploeeId
=
0
;
if
(
employeeList
.
size
()
==
limit
)
{
maxEmploeeId
=
employeeList
.
stream
().
map
(
Employee:
:
getId
).
max
(
Comparator
.
comparing
(
x
->
x
)).
orElse
(
0
);
}
else
{
List
<
Employee
>
employees
=
employeeService
.
findStartList
(
0
,
floor
,
limit
-
employeeList
.
size
());
maxEmploeeId
=
employees
.
stream
().
map
(
Employee:
:
getId
).
max
(
Comparator
.
comparing
(
x
->
x
)).
orElse
(
0
);
employeeList
.
addAll
(
employees
);
}
Map
<
String
,
FeiShuDepartmentDTO
>
departmentMap
=
new
HashMap
<>();
List
<
String
>
departmentIdList
=
employeeList
.
stream
().
map
(
Employee:
:
getDepartmentId
).
distinct
().
collect
(
Collectors
.
toList
());
departmentIdList
.
forEach
(
it
->
{
FeiShuDepartmentDTO
department
=
feiShuApiService
.
getDepartment
(
it
);
departmentMap
.
put
(
it
,
department
);
});
painService
.
deleteAllByFloor
(
floor
);
List
<
PushPainBO
>
pushPainBOList
=
new
ArrayList
<>();
String
[]
userIdList
=
new
String
[
employeeList
.
size
()];
AtomicInteger
i
=
new
AtomicInteger
(
1
);
employeeList
.
forEach
(
it
->
{
Pain
pain
=
new
Pain
();
pain
.
setOpenId
(
it
.
getOpenId
());
pain
.
setStatus
(
0
);
pain
.
setFloor
(
Optional
.
ofNullable
(
it
.
getFloor
()).
orElse
(
floor
));
int
increment
=
i
.
getAndIncrement
();
pain
.
setPindex
(
increment
);
pain
.
setName
(
it
.
getName
());
String
departMentName
=
departmentMap
.
getOrDefault
(
it
.
getDepartmentId
(),
new
FeiShuDepartmentDTO
()).
getName
();
pain
.
setDepartMentName
(
departMentName
);
painService
.
create
(
pain
);
PushPainBO
pushPainBO
=
new
PushPainBO
();
pushPainBO
.
setIndex
(
increment
);
pushPainBO
.
setName
(
it
.
getName
());
pushPainBO
.
setDepartMentName
(
departMentName
);
pushPainBO
.
setOpenId
(
it
.
getOpenId
());
pushPainBO
.
setTimeRange
(
painService
.
getTimeRange
(
increment
,
floor
));
pushPainBOList
.
add
(
pushPainBO
);
userIdList
[
increment
-
1
]
=
it
.
getOpenId
();
});
FeiShuChatDTO
feiShuChatDTO
=
new
FeiShuChatDTO
();
feiShuChatDTO
.
setName
(
"按摩群 "
+
DateUtil
.
today
());
feiShuChatDTO
.
setOwnerId
(
pushPainBOList
.
get
(
0
).
getOpenId
());
feiShuChatDTO
.
setUserIdList
(
userIdList
);
String
chatId
=
feiShuApiService
.
createChatList
(
feiShuChatDTO
);
massageService
.
sendMassageMsgCardToPiPiChat
(
pushPainBOList
,
chatId
);
massageService
.
sendMassageMsgCardToPiPiChat
(
pushPainBOList
,
feiShuConfig
.
getChatId
());
if
(
maxPain
!=
null
)
{
maxPain
.
setEmployeeId
(
maxEmploeeId
);
lastMaxPainService
.
update
(
maxPain
);
}
else
{
maxPain
=
new
LastMaxPain
();
maxPain
.
setEmployeeId
(
maxEmploeeId
);
maxPain
.
setFloor
(
floor
);
lastMaxPainService
.
create
(
maxPain
);
}
}
List
<
FeiShuEmployeeDTO
>
dtos
=
feiShuApiService
.
getEmployeeList
();
return
dtos
;
}
@PostMapping
(
"/department-user"
)
public
Object
departmentUser
(
String
department
)
{
return
feiShuApiService
.
getUser
(
department
);
}
@PostMapping
(
"/department"
)
public
Object
department
(
String
department
)
{
...
...
src/main/java/com/pipihelper/project/feishu/service/EmployeeService.java
View file @
23aee83
...
...
@@ -7,6 +7,7 @@ import com.pipihelper.project.feishu.entity.Employee;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
...
...
@@ -18,6 +19,21 @@ public class EmployeeService {
@Autowired
private
EmployeeDao
employeeDao
;
private
static
final
List
<
String
>
eightFloorEightdepartmentIdList
=
new
ArrayList
<>();
static
{
eightFloorEightdepartmentIdList
.
add
(
"od-3890573b4cd286f437d8e935e10f79bd"
);
eightFloorEightdepartmentIdList
.
add
(
"od-80c6807080faabbb1c4db7bd4d9bd3fd"
);
eightFloorEightdepartmentIdList
.
add
(
"od-257f04c282e11a4dbb40bbce905dc288"
);
eightFloorEightdepartmentIdList
.
add
(
"od-4ff65217e64292e3ff5726258ddb2bd8"
);
eightFloorEightdepartmentIdList
.
add
(
"od-5493776cfddf24c28e1c4620b9ee3406"
);
eightFloorEightdepartmentIdList
.
add
(
"od-133305bbba80fa87b979453a1ffc689a"
);
eightFloorEightdepartmentIdList
.
add
(
"od-2a43207cc2d92d781cb1cdfdcf33dc28"
);
eightFloorEightdepartmentIdList
.
add
(
"od-f2a40e56473fbdfbdcca9efb4302cbca"
);
eightFloorEightdepartmentIdList
.
add
(
"od-d7ddf7e8b966b0886319ff93f4dac95b"
);
eightFloorEightdepartmentIdList
.
add
(
"od-ab7c4b49f80d53ca54f60bb47661bad3"
);
}
@Autowired
private
FeiShuApiService
feiShuApiService
;
...
...
@@ -76,7 +92,7 @@ public class EmployeeService {
employee
.
setName
(
systemFieldsDTO
.
getName
());
employee
.
setMobile
(
systemFieldsDTO
.
getMobile
());
}
employee
.
setFloor
(
14
);
employee
.
setFloor
(
eightFloorEightdepartmentIdList
.
contains
(
employee
.
getDepartmentId
())
?
8
:
14
);
this
.
create
(
employee
);
});
}
...
...
src/main/java/com/pipihelper/project/feishu/service/PainService.java
View file @
23aee83
...
...
@@ -52,6 +52,11 @@ public class PainService {
return
painDao
.
findAll
();
}
public
String
getTimeRange
(
int
pindex
,
int
floor
)
{
String
timeRange
=
pindexFloors
.
stream
().
filter
(
it
->
it
.
floor
!=
null
&&
it
.
floor
==
floor
)
.
filter
(
it
->
pindex
<=
it
.
getEndIndex
()
&&
pindex
>=
it
.
getStartIndex
()).
findFirst
().
get
().
timeRange
;
return
timeRange
;
}
public
List
<
Pain
>
findAllReorderByFloor
(
int
floor
)
{
List
<
Pain
>
painList
=
painDao
.
findAllByFloor
(
floor
);
...
...
@@ -64,7 +69,7 @@ public class PainService {
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
;
.
filter
(
it
->
increment
<=
it
.
getEndIndex
()
&&
increment
>=
it
.
getStartIndex
()).
findFirst
().
get
().
timeRange
;
pain
.
setTimeRange
(
timeRange
);
});
return
painList
;
...
...
src/main/java/com/pipihelper/project/scheduled/MassageNoticeScheduleService.java
View file @
23aee83
package
com
.
pipihelper
.
project
.
scheduled
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Lists
;
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.department.FeiShuDepartmentDTO
;
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.EmployeeService
;
import
com.pipihelper.project.feishu.service.FeiShuApiService
;
import
com.pipihelper.project.feishu.service.LastMaxPainService
;
import
com.pipihelper.project.feishu.service.PainService
;
import
com.pipihelper.project.feishu.service.massage.MassageService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -11,8 +22,16 @@ import org.springframework.scheduling.annotation.Async;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.stream.Collectors
;
/**
* @Description: TODO
...
...
@@ -32,13 +51,104 @@ public class MassageNoticeScheduleService {
@Autowired
private
FeiShuApiService
feiShuApiService
;
@Autowired
private
EmployeeService
employeeService
;
@Autowired
private
LastMaxPainService
lastMaxPainService
;
@Resource
private
FeiShuConfig
feiShuConfig
;
private
final
static
Map
<
Integer
,
Integer
>
floorCountMap
=
new
HashMap
<>();
static
{
floorCountMap
.
put
(
8
,
10
);
floorCountMap
.
put
(
14
,
30
);
}
/**
* 每周四定时生成要按摩的人员名单,并发送大群和单人消息
*/
@Async
@Scheduled
(
cron
=
"0 0 10 * * ?"
)
public
void
sendMsgCardToPipiChat
(){
public
void
sendMsgCardToPipiChat
()
{
employeeService
.
uprsetAllEmployee
();
for
(
Integer
floor
:
Lists
.
newArrayList
(
14
))
{
LastMaxPain
maxPain
=
lastMaxPainService
.
findByFloor
(
floor
);
int
startEmployeeId
=
0
;
if
(
maxPain
!=
null
)
{
startEmployeeId
=
maxPain
.
getEmployeeId
();
}
int
countByFloor
=
employeeService
.
findCountByFloor
(
floor
);
int
limit
=
floorCountMap
.
get
(
floor
);
if
(
countByFloor
<
limit
)
{
limit
=
countByFloor
;
}
List
<
Employee
>
employeeList
=
employeeService
.
findStartList
(
startEmployeeId
,
floor
,
limit
);
Integer
maxEmploeeId
;
if
(
employeeList
.
size
()
==
limit
)
{
maxEmploeeId
=
employeeList
.
stream
().
map
(
Employee:
:
getId
).
max
(
Comparator
.
comparing
(
x
->
x
)).
orElse
(
0
);
}
else
{
List
<
Employee
>
employees
=
employeeService
.
findStartList
(
0
,
floor
,
limit
-
employeeList
.
size
());
maxEmploeeId
=
employees
.
stream
().
map
(
Employee:
:
getId
).
max
(
Comparator
.
comparing
(
x
->
x
)).
orElse
(
0
);
employeeList
.
addAll
(
employees
);
}
Map
<
String
,
FeiShuDepartmentDTO
>
departmentMap
=
new
HashMap
<>();
List
<
String
>
departmentIdList
=
employeeList
.
stream
().
map
(
Employee:
:
getDepartmentId
).
distinct
().
collect
(
Collectors
.
toList
());
departmentIdList
.
forEach
(
it
->
{
FeiShuDepartmentDTO
department
=
feiShuApiService
.
getDepartment
(
it
);
departmentMap
.
put
(
it
,
department
);
});
painService
.
deleteAllByFloor
(
floor
);
if
(
CollectionUtil
.
isEmpty
(
employeeList
))
{
return
;
}
List
<
PushPainBO
>
pushPainBOList
=
new
ArrayList
<>();
String
[]
userIdList
=
new
String
[
employeeList
.
size
()];
AtomicInteger
i
=
new
AtomicInteger
(
1
);
employeeList
.
forEach
(
it
->
{
Pain
pain
=
new
Pain
();
pain
.
setOpenId
(
it
.
getOpenId
());
pain
.
setStatus
(
0
);
pain
.
setFloor
(
Optional
.
ofNullable
(
it
.
getFloor
()).
orElse
(
floor
));
int
increment
=
i
.
getAndIncrement
();
pain
.
setPindex
(
increment
);
pain
.
setName
(
it
.
getName
());
String
departMentName
=
departmentMap
.
getOrDefault
(
it
.
getDepartmentId
(),
new
FeiShuDepartmentDTO
()).
getName
();
pain
.
setDepartMentName
(
departMentName
);
painService
.
create
(
pain
);
PushPainBO
pushPainBO
=
new
PushPainBO
();
pushPainBO
.
setIndex
(
increment
);
pushPainBO
.
setName
(
it
.
getName
());
pushPainBO
.
setDepartMentName
(
departMentName
);
pushPainBO
.
setOpenId
(
it
.
getOpenId
());
pushPainBO
.
setTimeRange
(
painService
.
getTimeRange
(
increment
,
floor
));
pushPainBOList
.
add
(
pushPainBO
);
userIdList
[
increment
-
1
]
=
it
.
getOpenId
();
});
FeiShuChatDTO
feiShuChatDTO
=
new
FeiShuChatDTO
();
feiShuChatDTO
.
setName
(
"按摩群 "
+
DateUtil
.
today
());
feiShuChatDTO
.
setOwnerId
(
pushPainBOList
.
get
(
0
).
getOpenId
());
feiShuChatDTO
.
setUserIdList
(
userIdList
);
String
chatId
=
feiShuApiService
.
createChatList
(
feiShuChatDTO
);
massageService
.
sendMassageMsgCardToPiPiChat
(
pushPainBOList
,
chatId
);
massageService
.
sendMassageMsgCardToPiPiChat
(
pushPainBOList
,
feiShuConfig
.
getChatId
());
if
(
maxPain
!=
null
)
{
maxPain
.
setEmployeeId
(
maxEmploeeId
);
lastMaxPainService
.
update
(
maxPain
);
}
else
{
maxPain
=
new
LastMaxPain
();
maxPain
.
setEmployeeId
(
maxEmploeeId
);
maxPain
.
setFloor
(
floor
);
lastMaxPainService
.
create
(
maxPain
);
}
}
}
...
...
@@ -47,9 +157,9 @@ public class MassageNoticeScheduleService {
*/
// @Async
// @Scheduled(cron = "0 0 10 * * ?")
public
void
massageStart
(){
public
void
massageStart
()
{
List
<
Pain
>
pains
=
painService
.
findListAsc
(
3
);
for
(
Pain
pain:
pains
)
{
for
(
Pain
pain
:
pains
)
{
String
messageId
=
pain
.
getMessageId
();
massageService
.
updateSingleMassageMsgCardWhenBegin
(
messageId
);
//1代表正在按
...
...
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