Commit 43dd5c75 by zhaolianjie

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
2 parents 4c9208d0 331a5a2a
...@@ -4,10 +4,13 @@ import cn.hutool.core.collection.CollectionUtil; ...@@ -4,10 +4,13 @@ import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; 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.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO; import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuMsgCardEventDTO; import com.pipihelper.project.feishu.dto.FeiShuMsgCardEventDTO;
import com.pipihelper.project.feishu.dto.chat.FeiShuChatDTO; import com.pipihelper.project.feishu.dto.chat.FeiShuChatDTO;
import com.pipihelper.project.feishu.dto.department.FeiShuDepartmentDTO;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO; import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO; import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.entity.Employee; import com.pipihelper.project.feishu.entity.Employee;
...@@ -23,6 +26,7 @@ import com.pipihelper.project.feishu.service.massage.MassageService; ...@@ -23,6 +26,7 @@ import com.pipihelper.project.feishu.service.massage.MassageService;
import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter; import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter;
import com.pipihelper.project.utils.CacheUtil; import com.pipihelper.project.utils.CacheUtil;
import jdk.nashorn.internal.ir.CatchNode; import jdk.nashorn.internal.ir.CatchNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -34,8 +38,11 @@ import java.io.BufferedReader; ...@@ -34,8 +38,11 @@ import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -45,6 +52,7 @@ import java.util.stream.Stream; ...@@ -45,6 +52,7 @@ import java.util.stream.Stream;
* @author: charles * @author: charles
* @date: 2022年03月30日 17:39 * @date: 2022年03月30日 17:39
*/ */
@Slf4j
@RestController @RestController
@RequestMapping("/pipitest/feishu") @RequestMapping("/pipitest/feishu")
public class FeiShuEventController { public class FeiShuEventController {
...@@ -126,12 +134,15 @@ public class FeiShuEventController { ...@@ -126,12 +134,15 @@ public class FeiShuEventController {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片 // 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String waitUserId = feiShuMsgCardEventDTO.getOpen_id(); String waitUserId = feiShuMsgCardEventDTO.getOpen_id();
painService.waitPain(waitUserId); 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"); String fileName1 = String.format("/templates/massage-singel-msg-card-end.json.json");
return getInteractiveCardStr(fileName1, "已为你推迟到最后"); return getInteractiveCardStr(fileName1, "已为你推迟到最后");
} else if ("rob".equals(actionTypeSecond)) { } else if ("rob".equals(actionTypeSecond)) {
// 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片 // 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
rob(feiShuMsgCardEventDTO); return rob(feiShuMsgCardEventDTO);
} else if ("next".equals(actionTypeSecond)) { } else if ("next".equals(actionTypeSecond)) {
// 当前按完,有请下一位 // 当前按完,有请下一位
String endUserId = feiShuMsgCardEventDTO.getOpen_id(); String endUserId = feiShuMsgCardEventDTO.getOpen_id();
...@@ -195,7 +206,7 @@ public class FeiShuEventController { ...@@ -195,7 +206,7 @@ public class FeiShuEventController {
LastMaxPain maxPain = lastMaxPainService.findByFloor(14); LastMaxPain maxPain = lastMaxPainService.findByFloor(14);
int startEmployeeId = 0; int startEmployeeId = 0;
if (maxPain != null) { if (maxPain != null) {
startEmployeeId = maxPain.getId(); startEmployeeId = maxPain.getEmployeeId();
} }
List<Employee> employeeList = employeeService.findStartList(startEmployeeId, 14, 30); List<Employee> employeeList = employeeService.findStartList(startEmployeeId, 14, 30);
Integer maxEmploeeId = 0; Integer maxEmploeeId = 0;
...@@ -206,6 +217,17 @@ public class FeiShuEventController { ...@@ -206,6 +217,17 @@ public class FeiShuEventController {
maxEmploeeId = employees.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0); maxEmploeeId = employees.stream().map(Employee::getId).max(Comparator.comparing(x -> x)).orElse(0);
employeeList.addAll(employees); 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);
AtomicInteger i = new AtomicInteger(); AtomicInteger i = new AtomicInteger();
employeeList.forEach(it -> { employeeList.forEach(it -> {
Pain pain = new Pain(); Pain pain = new Pain();
...@@ -214,6 +236,7 @@ public class FeiShuEventController { ...@@ -214,6 +236,7 @@ public class FeiShuEventController {
pain.setFloor(it.getFloor()); pain.setFloor(it.getFloor());
pain.setIndex(i.getAndIncrement()); pain.setIndex(i.getAndIncrement());
pain.setName(it.getName()); pain.setName(it.getName());
pain.setDepartMentName(departmentMap.getOrDefault(it.getDepartmentId(), new FeiShuDepartmentDTO()).getName());
painService.create(pain); painService.create(pain);
}); });
/* massageService.sendMassageMsgCardToPiPiChat(userList);*/ /* massageService.sendMassageMsgCardToPiPiChat(userList);*/
...@@ -261,4 +284,23 @@ public class FeiShuEventController { ...@@ -261,4 +284,23 @@ public class FeiShuEventController {
feiShuChatDTO.setIdList(new String[]{openId}); feiShuChatDTO.setIdList(new String[]{openId});
return feiShuApiService.joinChatList(feiShuChatDTO); 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();
}
} }
...@@ -58,7 +58,7 @@ public class SendMsgUseFeiShu { ...@@ -58,7 +58,7 @@ public class SendMsgUseFeiShu {
userList.add(pushPainBO); userList.add(pushPainBO);
userList.add(pushPainBO1); userList.add(pushPainBO1);
userList.add(pushPainBO2); userList.add(pushPainBO2);
massageService.sendMassageMsgCardToPiPiChat(userList); massageService.sendMassageMsgCardToPiPiChat(userList,feiShuConfig.getChatId());
return ResultGenerator.genSuccessResult(); return ResultGenerator.genSuccessResult();
} }
} }
...@@ -26,4 +26,6 @@ public interface PainDao { ...@@ -26,4 +26,6 @@ public interface PainDao {
List<Pain> findListAsc(int limit); List<Pain> findListAsc(int limit);
List<Pain> findBackIndex(@Param(value = "index") Integer index, @Param(value = "limit") int limit); List<Pain> findBackIndex(@Param(value = "index") Integer index, @Param(value = "limit") int limit);
void deleteAllByFloor(int floor);
} }
...@@ -16,4 +16,5 @@ public class Pain { ...@@ -16,4 +16,5 @@ public class Pain {
private String timeRange; private String timeRange;
private Integer floor; private Integer floor;
private String messageId; private String messageId;
private String departMentName; //部门名
} }
package com.pipihelper.project.feishu.service;
import com.pipihelper.project.feishu.dao.ChatMessageDao;
import com.pipihelper.project.feishu.entity.ChatMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ChatMessageService {
@Autowired
private ChatMessageDao chatMessageDao;
public ChatMessage findById(Integer id) {
return chatMessageDao.findById(id);
}
public void deleteById(Integer id) {
chatMessageDao.deleteById(id);
}
public void create(ChatMessage chatMessage) {
chatMessageDao.create(chatMessage);
}
public void update(ChatMessage chatMessage) {
chatMessageDao.update(chatMessage);
}
public List<ChatMessage> findAll() {
return chatMessageDao.findAll();
}
public List<ChatMessage> findListChatAndType(String chatId, Integer type) {
return chatMessageDao.findListChatAndType(chatId, type);
}
}
...@@ -52,4 +52,8 @@ public class PainService { ...@@ -52,4 +52,8 @@ public class PainService {
public List<Pain> findBackIndex(Integer index,int limit) { public List<Pain> findBackIndex(Integer index,int limit) {
return painDao.findBackIndex(index,limit); return painDao.findBackIndex(index,limit);
} }
public void deleteAllByFloor(int floor) {
painDao.deleteAllByFloor(floor);
}
} }
...@@ -39,7 +39,7 @@ public class MassageMsgCardSerivce { ...@@ -39,7 +39,7 @@ public class MassageMsgCardSerivce {
public String genMassageMsgCardForSingleStart(){ public String genMassageMsgCardForSingleStart(){
String fileName = String.format("/templates/massage-single-msg-card-start.json"); String fileName = String.format("/templates/massage-single-msg-card-next.json");
String msgCardContent = String.format(getInteractiveCardStr(fileName)); String msgCardContent = String.format(getInteractiveCardStr(fileName));
return msgCardContent; return msgCardContent;
} }
......
...@@ -5,10 +5,12 @@ import com.pipihelper.project.feishu.bo.PushPainBO; ...@@ -5,10 +5,12 @@ import com.pipihelper.project.feishu.bo.PushPainBO;
import com.pipihelper.project.feishu.dto.FeiShuConfig; import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO; import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.entity.Pain; 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.FeiShuApiService;
import com.pipihelper.project.feishu.service.PainService; import com.pipihelper.project.feishu.service.PainService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -36,7 +38,11 @@ public class MassageService { ...@@ -36,7 +38,11 @@ public class MassageService {
@Autowired @Autowired
private PainService painService; 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<>(); List<List<String>> pushUser = new ArrayList<>();
for(PushPainBO pushPainBO:pushPainBOList){ for(PushPainBO pushPainBO:pushPainBOList){
List<String> user = new ArrayList<>(); List<String> user = new ArrayList<>();
...@@ -68,7 +74,7 @@ public class MassageService { ...@@ -68,7 +74,7 @@ public class MassageService {
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO(); FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive"); feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(content); feiShuMsgDTO.setContent(content);
feiShuMsgDTO.setReceiveId(feiShuConfig.getChatId()); feiShuMsgDTO.setReceiveId(chatId);
log.info(feiShuMsgDTO.toString()); log.info(feiShuMsgDTO.toString());
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id"); feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
} }
...@@ -80,44 +86,30 @@ public class MassageService { ...@@ -80,44 +86,30 @@ public class MassageService {
patchMsg.put("content", msgCardContent); patchMsg.put("content", msgCardContent);
feiShuApiService.patchMsg(messageId, patchMsg); feiShuApiService.patchMsg(messageId, patchMsg);
} }
//
// public void updateMassageMsgCardToPiPiChat(){ //更新群消息
// List<PushPainBO> pushPainBOList = @Async
// List<List<String>> pushUser = new ArrayList<>(); public void updateMassageMsgCardToPiPiChat(String chatId){
// for(PushPainBO pushPainBO:pushPainBOList){ List<Pain> pains = painService.findAll();
// List<String> user = new ArrayList<>(); String messageId = chatMessageService.findListChatAndType(chatId, 1).get(0).getMessageId();
// //给单个用户发送 List<List<String>> pushUser = new ArrayList<>();
// String singleContent = massageMsgCardSerivce.genMassageMsgCardForSingle(); for(Pain pain:pains){
// log.info("给单个用户发送按摩消息:{}",singleContent); List<String> user = new ArrayList<>();
// FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO(); //构建给大群发送的名单
// feiShuMsgDTO.setMsgType("interactive"); user.add(pain.getIndex().toString());
// feiShuMsgDTO.setContent(singleContent); user.add(pain.getName());
// feiShuMsgDTO.setReceiveId(pushPainBO.getOpenId()); user.add(pain.getDepartMentName());
// log.info(feiShuMsgDTO.toString()); user.add(pain.getTimeRange());
// JSONObject sendMsgResponse = feiShuApiService.sendMsg(feiShuMsgDTO, "open_id"); user.add("");
// String messageId = sendMsgResponse.getJSONObject("data").getString("message_id"); pushUser.add(user);
// //更新按摩记录表中的messageId }
// Pain pain = painService.findByOpenId(pushPainBO.getOpenId()); //给大群更新发送消息
// pain.setMessageId(messageId); String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
// painService.update(pain); log.info("给大群发送按摩消息:{}",content);
// //构建给大群发送的名单 JSONObject patchMsg = new JSONObject();
// user.add(pushPainBO.getIndex().toString()); patchMsg.put("content", content);
// user.add(pushPainBO.getName()); feiShuApiService.patchMsg(messageId, patchMsg);
// 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");
// }
......
...@@ -52,6 +52,9 @@ public class MassageNoticeScheduleService { ...@@ -52,6 +52,9 @@ public class MassageNoticeScheduleService {
for(Pain pain:pains){ for(Pain pain:pains){
String messageId = pain.getMessageId(); String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId); massageService.updateSingleMassageMsgCardWhenBegin(messageId);
//1代表正在按
pain.setStatus(1);
painService.update(pain);
JSONObject noticeMsg = new JSONObject(); JSONObject noticeMsg = new JSONObject();
noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId())); noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId()));
//发送应用内提醒 //发送应用内提醒
...@@ -60,4 +63,27 @@ public class MassageNoticeScheduleService { ...@@ -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);
// }
//
// }
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<result column="floor" property="floor"/> <result column="floor" property="floor"/>
<result column="message_id" property="messageId"/> <result column="message_id" property="messageId"/>
<result column="name" property="name"/> <result column="name" property="name"/>
<result column="depart_ment_name" property="departMentName"/>
<result column="index" property="index"/> <result column="index" property="index"/>
</resultMap> </resultMap>
...@@ -19,7 +20,7 @@ ...@@ -19,7 +20,7 @@
</resultMap>--> </resultMap>-->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id,open_id,start_time,end_time,status,floor,message_id,name id,open_id,start_time,end_time,status,floor,message_id,name,depart_ment_name
</sql> </sql>
<select id="findById" parameterType="java.lang.Integer" resultMap="PainResultMap"> <select id="findById" parameterType="java.lang.Integer" resultMap="PainResultMap">
...@@ -63,6 +64,10 @@ ...@@ -63,6 +64,10 @@
</where> </where>
</select> </select>
<delete id="deleteAllByFloor">
delete from t_pain where floor = #{floor}
</delete>
<select id="findByIndex" parameterType="java.lang.String" resultMap="PainResultMap"> <select id="findByIndex" parameterType="java.lang.String" resultMap="PainResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
...@@ -87,8 +92,8 @@ ...@@ -87,8 +92,8 @@
<insert id="create" useGeneratedKeys="true" keyProperty="id" <insert id="create" useGeneratedKeys="true" keyProperty="id"
parameterType="com.pipihelper.project.feishu.entity.Pain"> parameterType="com.pipihelper.project.feishu.entity.Pain">
insert into t_pain (open_id, start_time, end_time, status, floor,message_id,name) insert into t_pain (open_id, start_time, end_time, status, floor,message_id,name,depart_ment_name)
values (#{openId}, #{startTime}, #{endTime}, #{status},#{floor},#{messageId},#{name}) values (#{openId}, #{startTime}, #{endTime}, #{status},#{floor},#{messageId},#{name},#{departMentName})
</insert> </insert>
<update id="waitPain" parameterType="com.pipihelper.project.feishu.entity.Pain"> <update id="waitPain" parameterType="com.pipihelper.project.feishu.entity.Pain">
...@@ -125,6 +130,9 @@ ...@@ -125,6 +130,9 @@
<if test="name != null"> <if test="name != null">
name = #{name}, name = #{name},
</if> </if>
<if test="departMentName != null">
depart_ment_name = #{departMentName},
</if>
</set> </set>
<where> <where>
id = #{id} id = #{id}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!