Commit c9bafd46 by liushuangwu

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/pipihelper/project/feishu/controller/FeiShuEventController.java
#	src/main/resources/mybatis/PainMapper.xml
2 parents 1e0c4a9d b239fabf
package com.pipihelper.project.feishu.controller; package com.pipihelper.project.feishu.controller;
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;
...@@ -122,20 +123,35 @@ public class FeiShuEventController { ...@@ -122,20 +123,35 @@ public class FeiShuEventController {
} else if ("wait".equals(actionTypeSecond)) { } else if ("wait".equals(actionTypeSecond)) {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片 // 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String waitUserId = feiShuMsgCardEventDTO.getOpen_id(); String waitUserId = feiShuMsgCardEventDTO.getOpen_id();
JSONObject waitObj = feiShuApiService.getUserInfo(waitUserId); painService.waitPain(waitUserId);
//ToDo 更新大群和按摩群的大卡片,异步
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)) {
// 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片 // 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String oldUserId = feiShuMsgCardEventDTO.getAction().getValue().getKey().split("\\.")[2]; String oldUserId = feiShuMsgCardEventDTO.getAction().getValue().getKey().split("\\.")[2];
String robUserId = feiShuMsgCardEventDTO.getOpen_id(); String robUserId = feiShuMsgCardEventDTO.getOpen_id();
JSONObject oldObj = feiShuApiService.getUserInfo(oldUserId); Pain oldPain = painService.findByOpenId(oldUserId);
JSONObject robObj = feiShuApiService.getUserInfo(robUserId); oldPain.setOpenId(robUserId);
painService.update(oldPain);
//ToDo 更新大群和按摩群的大卡片,异步
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json.json.json"); String fileName1 = String.format("/templates/massage-msg-card-rob-end.json.json.json");
return getInteractiveCardStr(fileName1, "已经被抢啦啦啦~"); return getInteractiveCardStr(fileName1, "已经被抢啦啦啦~");
} else if ("next".equals(actionTypeSecond)) {
// 当前按完,有请下一位
String endUserId = feiShuMsgCardEventDTO.getOpen_id();
Pain oldPain = painService.findByOpenId(endUserId);
oldPain.setStatus(2);
painService.update(oldPain);
List<Pain> painList = painService.findBackIndex(oldPain.getIndex(), 1);
if (CollectionUtil.isNotEmpty(painList)) {
Pain noticePain = CollectionUtil.getFirst(painList);
noticePain.setStatus(1);
painService.update(noticePain);
massageService.updateSingleMassageMsgCardWhenBegin(noticePain.getMessageId());
}
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json.json");
return getInteractiveCardStr(fileName1, "欢迎下次光临~");
} }
default: default:
} }
......
...@@ -21,7 +21,9 @@ public interface PainDao { ...@@ -21,7 +21,9 @@ public interface PainDao {
List<Pain> findAll(); List<Pain> findAll();
void waitPain(Pain pain);
List<Pain> findListAsc(int limit); List<Pain> findListAsc(int limit);
List<Pain> findBackIndex(@Param(value = "openId") String openId,@Param(value = "limit") int limit); List<Pain> findBackIndex(@Param(value = "index") Integer index, @Param(value = "limit") int limit);
} }
...@@ -134,7 +134,6 @@ public class FeiShuApiService { ...@@ -134,7 +134,6 @@ public class FeiShuApiService {
} }
} }
@Async
public JSONObject patchMsg(String message_id, JSONObject content) { public JSONObject patchMsg(String message_id, JSONObject content) {
String api = "/im/v1/messages/"; String api = "/im/v1/messages/";
OkHttpClient client = new OkHttpClient(); OkHttpClient client = new OkHttpClient();
......
...@@ -37,11 +37,19 @@ public class PainService { ...@@ -37,11 +37,19 @@ public class PainService {
return painDao.findAll(); return painDao.findAll();
} }
public void waitPain(String openId) {
Pain pain = new Pain();
pain.setOpenId(openId);
painDao.waitPain(pain);
}
public List<Pain> findListAsc(int limit) { public List<Pain> findListAsc(int limit) {
return painDao.findListAsc(limit); return painDao.findListAsc(limit);
} }
public List<Pain> findBackIndex(String openId,int limit) { public List<Pain> findBackIndex(Integer index,int limit) {
return painDao.findBackIndex(openId,limit); return painDao.findBackIndex(index,limit);
} }
} }
...@@ -38,6 +38,13 @@ public class MassageMsgCardSerivce { ...@@ -38,6 +38,13 @@ public class MassageMsgCardSerivce {
} }
public String genMassageMsgCardForSingleStart(){
String fileName = String.format("/templates/massage-single-msg-card-start.json");
String msgCardContent = String.format(getInteractiveCardStr(fileName));
return msgCardContent;
}
public String genMassageMsgCardForCompany(List<List<String>> pushUser){ public String genMassageMsgCardForCompany(List<List<String>> pushUser){
try { try {
List<String> title = Arrays.asList("序号","姓名","部门","时间段","签到"); List<String> title = Arrays.asList("序号","姓名","部门","时间段","签到");
......
...@@ -62,6 +62,7 @@ public class MassageService { ...@@ -62,6 +62,7 @@ public class MassageService {
user.add(""); user.add("");
pushUser.add(user); pushUser.add(user);
} }
//给大群发送消息
String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser); String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
log.info("给大群发送按摩消息:{}",content); log.info("给大群发送按摩消息:{}",content);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO(); FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
...@@ -73,5 +74,52 @@ public class MassageService { ...@@ -73,5 +74,52 @@ public class MassageService {
} }
public void updateSingleMassageMsgCardWhenBegin(String messageId){
JSONObject patchMsg = new JSONObject();
String msgCardContent = massageMsgCardSerivce.genMassageMsgCardForSingleStart();
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");
// }
} }
package com.pipihelper.project.scheduled; package com.pipihelper.project.scheduled;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.entity.Pain;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.PainService;
import com.pipihelper.project.feishu.service.massage.MassageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
/** /**
* @Description: TODO * @Description: TODO
* @author: charles * @author: charles
* @date: 2022年10月15日 17:26 * @date: 2022年10月15日 17:26
*/ */
@Slf4j
@Component
public class MassageNoticeScheduleService { public class MassageNoticeScheduleService {
@Autowired
private PainService painService;
@Autowired
private MassageService massageService;
@Autowired
private FeiShuApiService feiShuApiService;
/** /**
* 每周四定时生成要按摩的人员名单,并发送大群和单人消息 * 每周四定时生成要按摩的人员名单,并发送大群和单人消息
*/ */
...@@ -18,4 +40,24 @@ public class MassageNoticeScheduleService { ...@@ -18,4 +40,24 @@ public class MassageNoticeScheduleService {
public void sendMsgCardToPipiChat(){ public void sendMsgCardToPipiChat(){
} }
/**
* 当天时间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);
JSONObject noticeMsg = new JSONObject();
noticeMsg.put("user_id_list", Arrays.asList(pain.getOpenId()));
//发送应用内提醒
log.info("发送应用内容消息提醒");
feiShuApiService.patchUrgentApp(messageId, noticeMsg);
}
}
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +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="index" property="index"/>
</resultMap> </resultMap>
<!-- <resultMap id="BuffConfigResultBOMap" type="com.pipihelper.project.feishu.entity.Deployee" <!-- <resultMap id="BuffConfigResultBOMap" type="com.pipihelper.project.feishu.entity.Deployee"
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
from t_pain from t_pain
<where> <where>
index >= #{index} index >= #{index}
and status = 0
order by index asc order by index asc
limit #{limit} limit #{limit}
</where> </where>
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from t_pain from t_pain
<where> <where>
status = 0
order by index asc order by index asc
limit #{limit} limit #{limit}
</where> </where>
...@@ -61,6 +63,15 @@ ...@@ -61,6 +63,15 @@
</where> </where>
</select> </select>
<select id="findByIndex" parameterType="java.lang.String" resultMap="PainResultMap">
select
<include refid="Base_Column_List"/>
from t_pain
<where>
index = #{index}
</where>
</select>
<select id="findAll" resultMap="PainResultMap"> <select id="findAll" resultMap="PainResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
...@@ -81,6 +92,14 @@ ...@@ -81,6 +92,14 @@
</insert> </insert>
<update id="update" parameterType="com.pipihelper.project.feishu.entity.Pain"> <update id="update" parameterType="com.pipihelper.project.feishu.entity.Pain">
UPDATE t_pain set `index` = ((SELECT selected_value FROM (SELECT MAX(`index`) AS selected_value FROM t_pain) AS
sub_selected_value) + 1)
<where>
open_id = #{openId}
</where>
</update>
<update id="update" parameterType="com.pipihelper.project.feishu.entity.Pain">
update t_pain update t_pain
<set> <set>
<if test="openId != null"> <if test="openId != null">
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
{ {
"tag": "div", "tag": "div",
"text": { "text": {
"content": "%s", "content": "欢呼吧,你排到了按摩哦!",
"tag": "lark_md" "tag": "lark_md"
} }
}, },
......
{
"config": {
"wide_screen_mode": true,
"update_multi": true
},
"elements": [
{
"tag": "div",
"text": {
"content": "欢呼吧,你排到了按摩哦!",
"tag": "lark_md"
}
},
{
"actions": [
{
"tag": "button",
"text": {
"content": "按完了,有请下一位!",
"tag": "plain_text"
},
"type": "default",
"value": {
"key1": "massage-singel.next"
}
}
],
"tag": "action"
}
],
"header": {
"template": "turquoise",
"title": {
"content": "👻 按摩提醒请查收!",
"tag": "plain_text"
}
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!