Commit b7d1d463 by zhangshaowu

Merge remote-tracking branch 'origin/master'

2 parents fbdfc69b c607f49c
Showing 26 changed files with 722 additions and 210 deletions
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));
}
}
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;
}
}
package com.pipihelper.project.feishu.controller;
import cn.hutool.core.collection.CollUtil;
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;
......@@ -18,12 +18,16 @@ 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.*;
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;
import com.pipihelper.project.feishu.service.LastMaxPainService;
import com.pipihelper.project.feishu.service.PainService;
import com.pipihelper.project.feishu.service.massage.MassageMsgCardSerivce;
import com.pipihelper.project.feishu.service.massage.MassageService;
import com.pipihelper.project.feishu.utils.FeiShuEventDataDecrypter;
import com.pipihelper.project.utils.CacheUtil;
import jdk.nashorn.internal.ir.CatchNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -35,7 +39,13 @@ import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
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;
import java.util.stream.Stream;
......@@ -63,6 +73,8 @@ public class FeiShuEventController {
@Autowired
private EmployeeService employeeService;
@Autowired
private ChatMessageService chatMessageService;
@Autowired
private LastMaxPainService lastMaxPainService;
@Autowired
private PainService painService;
......@@ -73,10 +85,10 @@ public class FeiShuEventController {
@PostMapping("/event")
public JSONObject event(@RequestBody String s) throws Exception {
JSONObject reqJsonObject = JSON.parseObject(s);
System.out.println(s);
log.info("接收到事件,密文:{}", s);
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getEncryptKey());
JSONObject encryptJsonObject = JSON.parseObject(d.decrypt(reqJsonObject.getString("encrypt")));
System.out.println(encryptJsonObject);
log.info("接收到事件,明文:{}", encryptJsonObject);
if (encryptJsonObject.containsKey("challenge")) {
return encryptJsonObject;
}
......@@ -85,9 +97,8 @@ public class FeiShuEventController {
return null;
}
if ("im.message.receive_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
} else if ("im.message.message_read_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageMessageReadV1(feiShuEventDTO);
log.info("处理单聊事件:{}",feiShuEventDTO);
feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
}
return null;
}
......@@ -108,35 +119,33 @@ public class FeiShuEventController {
// 都需要返回 不能点击的卡片json
if ("revice".equals(actionTypeSecond)) {
// 接受按摩
String fileName = String.format("/templates/massage-singel-msg-card-end.json.json");
String fileName = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName, "感谢支持");
return getInteractiveCardStr(fileName, "您已接受啦~");
} else if ("giveUp".equals(actionTypeSecond)) {
// 放弃 - 往大群中发送抢按摩机会卡片
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setReceiveId(feiShuConfig.getChatId());
String fileName = String.format("/templates/massage-msg-card-rob.json.json");
String fileName = String.format("/templates/massage-msg-card-rob.json");
String msgCardContent = String.format(massageMsgCardSerivce.getInteractiveCardStr(fileName), feiShuMsgCardEventDTO.getOpen_id());
feiShuMsgDTO.setContent(msgCardContent);
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json.json");
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "遗憾放弃");
return getInteractiveCardStr(fileName1, "怕疼的家伙~");
} else if ("wait".equals(actionTypeSecond)) {
// 推迟 将当前用户放到队列最后 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String waitUserId = feiShuMsgCardEventDTO.getOpen_id();
painService.waitPain(waitUserId);
//ToDo 没有按摩群的id
//更新大群
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
//没有按摩群的id
// massageService.updateMassageMsgCardToPiPiChat();
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json.json");
return getInteractiveCardStr(fileName1, "已为你推迟到最后");
//更新按摩群
massageService.updateMassageMsgCardToPiPiChat((String) CacheUtil.get("chatId"));
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "已为你推迟到队尾");
} else if ("rob".equals(actionTypeSecond)) {
// 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
massageService.updateMassageMsgCardToPiPiChat(feiShuConfig.getChatId());
return rob(feiShuMsgCardEventDTO);
} else if ("next".equals(actionTypeSecond)) {
// 当前按完,有请下一位
......@@ -144,15 +153,24 @@ public class FeiShuEventController {
Pain oldPain = painService.findByOpenId(endUserId);
oldPain.setStatus(2);
painService.update(oldPain);
List<Pain> painList = painService.findBackIndex(oldPain.getIndex(), 1);
List<Pain> painList = painService.findBackIndex(oldPain.getPindex(), 1);
if (CollectionUtil.isNotEmpty(painList)) {
Pain noticePain = CollectionUtil.getFirst(painList);
noticePain.setStatus(1);
painService.update(noticePain);
massageService.updateSingleMassageMsgCardWhenBegin(noticePain.getMessageId());
//按摩群中同步发送按摩进度信息
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
String msg = "当前按摩进度:" + String.format("<at user_id=\\\"%s\\\">%s</at>", noticePain.getOpenId(), noticePain.getName());
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setReceiveId((String) CacheUtil.get("chatId"));
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
}
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json.json");
return getInteractiveCardStr(fileName1, "欢迎下次光临~");
String fileName1 = String.format("/templates/massage-singel-msg-card-end.json");
return getInteractiveCardStr(fileName1, "您本次的massage之旅已结束~");
}
default:
}
......@@ -162,18 +180,14 @@ public class FeiShuEventController {
public synchronized JSONObject rob(FeiShuMsgCardEventDTO feiShuMsgCardEventDTO) {
String oldUserId = feiShuMsgCardEventDTO.getAction().getValue().getKey().split("\\.")[2];
String robUserId = feiShuMsgCardEventDTO.getOpen_id();
Pain oldPain = painService.findByOpenId(oldUserId);
oldPain.setOpenId(robUserId);
painService.update(oldPain);
FeiShuChatDTO feiShuChatDTO = new FeiShuChatDTO();
feiShuChatDTO.setChatId((String) CacheUtil.get("chatId"));
feiShuChatDTO.setIdList(new String[]{feiShuMsgCardEventDTO.getOpen_id()});
feiShuApiService.joinChatList(feiShuChatDTO);
//ToDo 更新大群和按摩群的大卡片,异步
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json.json.json");
return getInteractiveCardStr(fileName1, "已经被抢啦啦啦~");
Employee employee = employeeService.findByOpenId(robUserId);
massageService.robSingle(robUserId,oldUserId,employee.getName());
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json");
return getInteractiveCardStr(fileName1, "已经被" + employee.getName() + "抢啦,啦啦~");
}
/**
* 读取模板文件
*
......@@ -193,88 +207,102 @@ public class FeiShuEventController {
return null;
}
@PostMapping("/delete-chat-list")
public Object deleteChat() {
String chatId = (String) CacheUtil.get("chatId");
log.info("删除群组id:{}", chatId);
feiShuApiService.deleteChatList(chatId);
return null;
}
@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.setIndex(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);
chatMessageService.deleteAll();
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) {
......@@ -309,9 +337,13 @@ public class FeiShuEventController {
@PostMapping("/start")
public Result start() {
List<Pain> pains = painService.findListAsc(3);
StringBuilder userString = new StringBuilder();
for (Pain pain : pains) {
String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId);
userString.append(String.format("<at user_id=\"%s\">%s</at>", pain.getOpenId(), pain.getName()));
//1代表正在按
pain.setStatus(1);
painService.update(pain);
......@@ -321,6 +353,31 @@ public class FeiShuEventController {
log.info("发送应用内容消息提醒");
feiShuApiService.patchUrgentApp(messageId, noticeMsg);
}
//按摩群中同步发送按摩进度信息
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
String msg = "当前按摩进度:" + userString;
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setReceiveId((String) CacheUtil.get("chatId"));
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
return ResultGenerator.genSuccessResult();
}
@PostMapping("/send-msg")
public Result sendMsg(String receiveId, String msg, String receiveIdType) {
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
if (receiveId.equals("-1")) {
receiveId = (String) CacheUtil.get("chatId");
}
feiShuMsgDTO.setReceiveId(receiveId);
log.info("已机器人身份发送消息:{}", feiShuMsgDTO.toString());
feiShuApiService.sendMsg(feiShuMsgDTO, receiveIdType);
return ResultGenerator.genSuccessResult();
}
......
......@@ -19,4 +19,6 @@ public interface ChatMessageDao {
List<ChatMessage> findAll();
List<ChatMessage> findListChatAndType(@Param(value = "chatId") String chatId, @Param(value = "type") Integer type);
void deleteAll();
}
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);
}
......@@ -25,7 +25,9 @@ public interface PainDao {
List<Pain> findListAsc(int limit);
List<Pain> findBackIndex(@Param(value = "index") Integer index, @Param(value = "limit") int limit);
List<Pain> findBackIndex(@Param(value = "pindex") Integer pindex, @Param(value = "limit") int limit);
void deleteAllByFloor(int floor);
List<Pain> findAllByFloor(@Param(value = "floor") int floor);
}
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;
}
......@@ -8,7 +8,7 @@ import java.util.Date;
public class Pain {
private Integer id;
private String openId;
private Integer index;
private Integer pindex;
private String name;
private Integer status;
private Date startTime;
......
......@@ -36,4 +36,8 @@ public class ChatMessageService {
public List<ChatMessage> findListChatAndType(String chatId, Integer type) {
return chatMessageDao.findListChatAndType(chatId, type);
}
public void deleteAll() {
chatMessageDao.deleteAll();
}
}
......@@ -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);
});
}
......
......@@ -25,7 +25,6 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
......@@ -156,7 +155,7 @@ public class FeiShuApiService {
@Async
public JSONObject patchUrgentApp(String message_id, JSONObject content) {
String api = "/im/v1/messages/" + message_id + "/urgent_sms?user_id_type=user_id";
String api = "/im/v1/messages/" + message_id + "/urgent_app?user_id_type=open_id";
OkHttpClient client = new OkHttpClient();
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
RequestBody requestBody = RequestBody.create(content.toString(), MediaType.parse("application/json"));
......@@ -180,7 +179,7 @@ public class FeiShuApiService {
@Async
public JSONObject patchUrgentSms(String message_id, JSONObject content) {
String api = "/im/v1/messages/" + message_id + "/urgent_app?user_id_type=open_id";
String api = "/im/v1/messages/" + message_id + "/urgent_sms?user_id_type=user_id";
OkHttpClient client = new OkHttpClient();
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
RequestBody requestBody = RequestBody.create(content.toString(), MediaType.parse("application/json"));
......@@ -433,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();
......@@ -454,6 +453,26 @@ public class FeiShuApiService {
}
}
public String deleteChatList(String chatId) {
String api = "/im/v1/chats/:{chat_id}";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + getTenantToken());
headers.set("Content-Type", "application/json; charset=utf-8");
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
try {
HttpEntity<String> requestEntity = new HttpEntity<>(headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, String.class, chatId);
System.out.println(responseEntity.getBody());
Type type = new TypeReference<FeiShuResultDTO>() {
}.getType();
FeiShuResultDTO feiShuResultDTO = JSONObject.parseObject(responseEntity.getBody(), type);
return feiShuResultDTO.getData().getChatId();
} catch (Exception e) {
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
}
}
/**
* 群发消息
* https://open.feishu.cn/document/ukTMukTMukTM/ucDO1EjL3gTNx4yN4UTM
......
package com.pipihelper.project.feishu.service;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventHeaderDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventReceiveMessageDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.tx.dto.TxConfig;
import com.pipihelper.project.tx.service.TxApiService;
import com.tencentcloudapi.tbp.v20190627.models.Group;
import com.tencentcloudapi.tbp.v20190627.models.TextProcessResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.regex.Pattern;
/**
* @Description: TODO
......@@ -41,22 +48,37 @@ public class FeiShuEventService {
@Async
public void imMessageReceiveV1(FeiShuEventDTO feiShuEventDTO){
FeiShuEventHeaderDTO feiShuEventHeaderDTO = feiShuEventDTO.getHeader();
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
//单独处理群消息
if (message.getChat_id().equals(feiShuConfig.getChatId())
|| message.getChat_id().equals(feiShuConfig.getChatId())) { //判断是否为指定群消息
return;
if(message.getChat_type().equals("p2p")) {
robotTalk(feiShuEventDTO);
}
else {
//如果是单聊
if(message.getChat_type().equals("p2p")) {
// robotTalk(feiShuEventDTO);
}
public void robotTalk(FeiShuEventDTO feiShuEventDTO){
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setReceiveId(sender.getSender_id().getOpen_id());
if(message.getMessage_type().equals("text")){
JSONObject jsonObjectText = JSON.parseObject(message.getContent());
String inputText = jsonObjectText.getString("text");
String uuid = IdUtil.randomUUID();
TextProcessResponse textProcessResponse = txApiService.txTextProcessRequest(uuid, inputText);
for (Group group : textProcessResponse.getResponseMessage().getGroupList()) {
JSONObject content = new JSONObject();
content.put("text", group.getContent());
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setMsgType("text");
feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
}
}
}
}
}
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;
}
}
package com.pipihelper.project.feishu.service;
import cn.hutool.core.collection.CollectionUtil;
import com.pipihelper.project.feishu.dao.PainDao;
import com.pipihelper.project.feishu.entity.Pain;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
public class PainService {
......@@ -13,6 +20,14 @@ public class PainService {
@Autowired
private PainDao painDao;
private final static List<PindexFloor> pindexFloors = new ArrayList<>();
static {
pindexFloors.add(new PindexFloor().setStartIndex(1).setEndIndex(12).setTimeRange("15:00-16:00").setFloor(14));
pindexFloors.add(new PindexFloor().setStartIndex(13).setEndIndex(24).setTimeRange("16:00-17:00").setFloor(14));
pindexFloors.add(new PindexFloor().setStartIndex(25).setEndIndex(30).setTimeRange("17:00-17:30").setFloor(14));
}
public void create(Pain pain) {
painDao.create(pain);
}
......@@ -37,6 +52,29 @@ 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);
if (CollectionUtil.isEmpty(painList)) {
return new ArrayList<>();
}
painList = painList.stream().sorted(Comparator.comparing(Pain::getPindex)).collect(Collectors.toList());
AtomicInteger atomicInteger = new AtomicInteger(1);
painList.forEach(pain -> {
int increment = atomicInteger.getAndIncrement();
pain.setPindex(increment);
String timeRange = pindexFloors.stream().filter(it -> it.floor != null && it.floor == floor)
.filter(it -> increment <= it.getEndIndex() && increment >= it.getStartIndex()).findFirst().get().timeRange;
pain.setTimeRange(timeRange);
});
return painList;
}
public void waitPain(String openId) {
Pain pain = new Pain();
pain.setOpenId(openId);
......@@ -49,11 +87,20 @@ public class PainService {
return painDao.findListAsc(limit);
}
public List<Pain> findBackIndex(Integer index,int limit) {
return painDao.findBackIndex(index,limit);
public List<Pain> findBackIndex(Integer pindex, int limit) {
return painDao.findBackIndex(pindex, limit);
}
public void deleteAllByFloor(int floor) {
painDao.deleteAllByFloor(floor);
}
@Data
@Accessors(chain = true)
public static class PindexFloor {
private Integer startIndex;
private Integer endIndex;
private String timeRange;
private Integer floor;
}
}
......@@ -3,11 +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;
......@@ -42,24 +45,26 @@ public class MassageService {
private ChatMessageService chatMessageService;
//给群里发送消息
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList, String chatId){
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList, String chatId) {
List<List<String>> pushUser = new ArrayList<>();
for(PushPainBO pushPainBO:pushPainBOList){
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);
if (chatId.equals(feiShuConfig.getChatId())) {
//给单个用户发送
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());
......@@ -70,17 +75,24 @@ public class MassageService {
}
//给大群发送消息
String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
log.info("给大群发送按摩消息:{}",content);
log.info("给大群发送按摩消息:{}", content);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(content);
feiShuMsgDTO.setReceiveId(chatId);
log.info(feiShuMsgDTO.toString());
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
JSONObject rep = feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
String messageId = rep.getJSONObject("data").getString("message_id");
ChatMessage chatMessage = new ChatMessage();
chatMessage.setChatId(chatId);
chatMessage.setMessageId(messageId);
chatMessage.setType(1);
chatMessageService.create(chatMessage);
}
public void updateSingleMassageMsgCardWhenBegin(String messageId){
public void updateSingleMassageMsgCardWhenBegin(String messageId) {
JSONObject patchMsg = new JSONObject();
String msgCardContent = massageMsgCardSerivce.genMassageMsgCardForSingleStart();
patchMsg.put("content", msgCardContent);
......@@ -89,14 +101,15 @@ public class MassageService {
//更新群消息
@Async
public void updateMassageMsgCardToPiPiChat(String chatId){
List<Pain> pains = painService.findAll();
public void updateMassageMsgCardToPiPiChat(String chatId) {
List<Pain> pains = painService.findAllReorderByFloor(14);
System.out.println(pains);
String messageId = chatMessageService.findListChatAndType(chatId, 1).get(0).getMessageId();
List<List<String>> pushUser = new ArrayList<>();
for(Pain pain:pains){
for (Pain pain : pains) {
List<String> user = new ArrayList<>();
//构建给大群发送的名单
user.add(pain.getIndex().toString());
user.add(pain.getPindex().toString());
user.add(pain.getName());
user.add(pain.getDepartMentName());
user.add(pain.getTimeRange());
......@@ -105,13 +118,48 @@ public class MassageService {
}
//给大群更新发送消息
String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
log.info("给大群发送按摩消息:{}",content);
log.info("给大群发送按摩消息:{}", content);
JSONObject patchMsg = new JSONObject();
patchMsg.put("content", content);
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);
}
}
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.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.LastMaxPainService;
import com.pipihelper.project.feishu.service.PainService;
import com.pipihelper.project.feishu.service.massage.MassageService;
import com.pipihelper.project.utils.CacheUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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,58 +54,152 @@ public class MassageNoticeScheduleService {
@Autowired
private FeiShuApiService feiShuApiService;
@Autowired
private EmployeeService employeeService;
@Autowired
private LastMaxPainService lastMaxPainService;
@Autowired
private ChatMessageService chatMessageService;
@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() {
employeeService.uprsetAllEmployee();
chatMessageService.deleteAll();
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);
}
}
}
/**
* 每周四定时生成要按摩的人员名单,并发送大群和单人消息
* 每周四18:00删除当天的群聊
*/
@Async
@Scheduled(cron = "0 0 10 * * ?")
public void sendMsgCardToPipiChat(){
// @Async
// @Scheduled(cron = "0 0 18 * * ?")
public void deleteChatList() {
String chatId = (String) CacheUtil.get("chatId");
feiShuApiService.deleteChatList(chatId);
}
/**
* 当天时间2:55,给第一波三个人更新卡片,并发送应用内提醒
*/
// @Async
// @Scheduled(cron = "0 0 10 * * ?")
public void massageStart(){
public void massageStart() {
List<Pain> pains = painService.findListAsc(3);
for(Pain pain:pains){
// String msg = "{\"text\":\"当前按摩进度:<at user_id=\\\"%s\\\">%s</at> <at user_id=\\\"%s\\\">%s</at> <at user_id=\\\"%s\\\">%s</at>\"}";
StringBuilder userString = new StringBuilder();
for (Pain pain : pains) {
String messageId = pain.getMessageId();
massageService.updateSingleMassageMsgCardWhenBegin(messageId);
userString.append(String.format("<at user_id=\"%s\">%s</at>", pain.getOpenId(), pain.getName()));
//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);
}
//按摩群中同步发送按摩进度信息
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
String msg = "当前按摩进度:" + userString;
JSONObject content = new JSONObject();
content.put("text", msg);
feiShuMsgDTO.setMsgType("text");
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setReceiveId((String) CacheUtil.get("chatId"));
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
}
// /**
// * 当天时间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);
// }
//
// }
}
......@@ -7,10 +7,11 @@ import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Component
public class CacheUtil {
private static final long DEFAULT_TIMEOUT = 3600;
private static final long DEFAULT_TIMEOUT = 3600 * 1000 * 10;
private static final int DEFAULT_CAPACITY = 1024;
private static final Timer timer;
private static final int MAX_CAPACITY = 10000;
......@@ -25,7 +26,7 @@ public class CacheUtil {
}
/**
* 缓存任务清除类
* 缓存任务清除类
*/
static class ClearTask extends TimerTask {
private String key;
......@@ -40,6 +41,7 @@ public class CacheUtil {
}
}
//私有化构造方法
private CacheUtil() {
......@@ -47,7 +49,7 @@ public class CacheUtil {
//==================缓存的增删改查
/**
* 添加缓存
* 添加缓存
*/
public static boolean put(String key, Object object) {
if (checkCapacity()) {
......@@ -60,7 +62,7 @@ public class CacheUtil {
}
/**
* 添加缓存
* 添加缓存
*/
public static boolean put(String key, Object object, int time_out) {
if (checkCapacity()) {
......@@ -73,14 +75,14 @@ public class CacheUtil {
/**
* 判断容量大小
* 判断容量大小
*/
public static boolean checkCapacity() {
return map.size() < MAX_CAPACITY;
}
/**
* 批量增加缓存
* 批量增加缓存
*/
public static boolean put(Map<String, Object> m, int time_out) {
if (map.size() + m.size() <= MAX_CAPACITY) {
......@@ -94,14 +96,14 @@ public class CacheUtil {
}
/**
* 删除缓存
* 删除缓存
*/
public static void remove(String key) {
map.remove(key);
}
/**
* 清除所有缓存
* 清除所有缓存
*/
public void clearAll() {
if (map.size() > 0) {
......@@ -111,14 +113,14 @@ public class CacheUtil {
}
/**
* 获取缓存
* 获取缓存
*/
public static Object get(String key) {
return map.get(key);
}
/**
* 是否包含某个缓存
* 是否包含某个缓存
*/
public static boolean isContain(String key) {
return map.contains(key);
......
......@@ -28,7 +28,7 @@ public class GraphicsGenerationUtil {
totalcol = data.get(0).size();
}
// 图片宽度
int imageWidth = 1024;
int imageWidth = 750;
// 行高
int rowheight = 40;
// 图片高度
......
......@@ -27,6 +27,11 @@
</where>
</select>
<delete id="deleteAll">
delete from t_chat_message
</delete>
<select id="findListChatAndType" resultMap="ChatMessageResultMap">
select
<include refid="Base_Column_List"/>
......
<?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>
......@@ -12,7 +12,7 @@
<result column="message_id" property="messageId"/>
<result column="name" property="name"/>
<result column="depart_ment_name" property="departMentName"/>
<result column="index" property="index"/>
<result column="pindex" property="pindex"/>
</resultMap>
<!-- <resultMap id="BuffConfigResultBOMap" type="com.pipihelper.project.feishu.entity.Deployee"
......@@ -20,7 +20,8 @@
</resultMap>-->
<sql id="Base_Column_List">
id,open_id,start_time,end_time,status,floor,message_id,name,depart_ment_name
id
,open_id,start_time,end_time,status,floor,message_id,name,depart_ment_name,`pindex`
</sql>
<select id="findById" parameterType="java.lang.Integer" resultMap="PainResultMap">
......@@ -32,14 +33,23 @@
</where>
</select>
<select id="findAllByFloor" parameterType="java.lang.Integer" resultMap="PainResultMap">
select
<include refid="Base_Column_List"/>
from t_pain
<where>
floor = #{floor}
</where>
</select>
<select id="findBackIndex" resultMap="PainResultMap">
select
<include refid="Base_Column_List"/>
from t_pain
<where>
index >= #{index}
pindex >= #{pindex}
and status = 0
order by index asc
order by pindex asc
limit #{limit}
</where>
</select>
......@@ -50,7 +60,7 @@
from t_pain
<where>
status = 0
order by index asc
order by pindex asc
limit #{limit}
</where>
</select>
......@@ -65,7 +75,9 @@
</select>
<delete id="deleteAllByFloor">
delete from t_pain where floor = #{floor}
delete
from t_pain
where floor = #{floor}
</delete>
<select id="findByIndex" parameterType="java.lang.String" resultMap="PainResultMap">
......@@ -73,7 +85,7 @@
<include refid="Base_Column_List"/>
from t_pain
<where>
index = #{index}
pindex = #{pindex}
</where>
</select>
......@@ -92,12 +104,12 @@
<insert id="create" useGeneratedKeys="true" keyProperty="id"
parameterType="com.pipihelper.project.feishu.entity.Pain">
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},#{departMentName})
insert into t_pain (open_id, start_time, end_time, status, floor, message_id, name, depart_ment_name, pindex)
values (#{openId}, #{startTime}, #{endTime}, #{status}, #{floor}, #{messageId}, #{name}, #{departMentName},#{pindex})
</insert>
<update id="waitPain" 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
UPDATE t_pain set pindex = ((SELECT selected_value FROM (SELECT MAX(pindex) AS selected_value FROM t_pain) AS
sub_selected_value) + 1)
<where>
open_id = #{openId}
......@@ -133,6 +145,9 @@
<if test="departMentName != null">
depart_ment_name = #{departMentName},
</if>
<if test="pindex != null">
pindex = #{pindex},
</if>
</set>
<where>
id = #{id}
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "已经被抢啦啦啦~",
"content": "%s",
"tag": "lark_md"
}
}
......@@ -15,7 +15,7 @@
"header": {
"template": "turquoise",
"title": {
"content": "👻 按摩提醒请查收!",
"content": "👻 有按摩名额空余啦!",
"tag": "plain_text"
}
}
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "当前空余一个名额",
"content": "有人怕疼放弃了,快来抢吧!",
"tag": "lark_md"
}
},
......@@ -16,7 +16,7 @@
{
"tag": "button",
"text": {
"content": "😁 我",
"content": "😁 我不怕",
"tag": "plain_text"
},
"type": "default",
......@@ -31,7 +31,7 @@
"header": {
"template": "turquoise",
"title": {
"content": "👻 按摩提醒请查收!",
"content": "👻 有按摩名额空余啦!",
"tag": "plain_text"
}
}
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "1. 按摩时间15:00-17:30;\n2. 按摩时长每人15分钟,3人一组,按照图片顺序从上至下依次进行;\n3. 按完请在自己的卡片上点击完成,系统会自动@下一位成员;4. 放弃请直接点击放弃,名额将会发送到大群秒杀,先到先得;\n5. 有事暂时来不了,可以推迟到最后;\n6. 轮到你的时候超过1分钟未确认,将自动调换至末尾,@下一位成员;",
"content": "1. 按摩时间15:00-17:30;\n2. 按摩时长每人15分钟,3人一组,按照图片顺序从上至下依次进行;\n3. 按完记得在自己的卡片上点击完成哦,系统会自动通知下一位成员;4. 点击放弃,名额将会发送到大群秒杀,先到先得;\n5. 有事暂时来不了,可以推迟到队伍最后;\n",
"tag": "lark_md"
}
},
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "欢呼吧,你排到了按摩哦!",
"content": "欢呼吧,你本周有按摩名额哦!",
"tag": "lark_md"
}
},
......@@ -38,7 +38,7 @@
{
"tag": "button",
"text": {
"content": "😢 等一下",
"content": "😢 我最后来",
"tag": "plain_text"
},
"type": "default",
......
......@@ -7,7 +7,7 @@
{
"tag": "div",
"text": {
"content": "欢呼吧,你排到了按摩哦!",
"content": "按摩到你了哦!",
"tag": "lark_md"
}
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!