MassageService.java
5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.entity.Pain;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.PainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
* @Description: TODO
* @author: charles
* @date: 2022年10月15日 17:21
*/
@Service
@Transactional
@Slf4j
public class MassageService {
@Autowired
private MassageMsgCardSerivce massageMsgCardSerivce;
@Autowired
private FeiShuApiService feiShuApiService;
@Autowired
private FeiShuConfig feiShuConfig;
@Autowired
private PainService painService;
public void sendMassageMsgCardToPiPiChat(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");
}
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");
// }
}