Commit 4c9208d0 by zhaolianjie

卡片流程 - 下一位

1 parent c2422c65
......@@ -21,6 +21,8 @@ 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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -129,14 +131,7 @@ public class FeiShuEventController {
return getInteractiveCardStr(fileName1, "已为你推迟到最后");
} else if ("rob".equals(actionTypeSecond)) {
// 抢名额 - 掉延迟更新卡片接口 更新大群、按摩群的按摩时间安排卡片
String oldUserId = feiShuMsgCardEventDTO.getAction().getValue().getKey().split("\\.")[2];
String robUserId = feiShuMsgCardEventDTO.getOpen_id();
Pain oldPain = painService.findByOpenId(oldUserId);
oldPain.setOpenId(robUserId);
painService.update(oldPain);
//ToDo 更新大群和按摩群的大卡片,异步
String fileName1 = String.format("/templates/massage-msg-card-rob-end.json.json.json");
return getInteractiveCardStr(fileName1, "已经被抢啦啦啦~");
rob(feiShuMsgCardEventDTO);
} else if ("next".equals(actionTypeSecond)) {
// 当前按完,有请下一位
String endUserId = feiShuMsgCardEventDTO.getOpen_id();
......@@ -158,6 +153,21 @@ public class FeiShuEventController {
return null;
}
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, "已经被抢啦啦啦~");
}
/**
* 读取模板文件
*
......
......@@ -17,7 +17,7 @@ import com.pipihelper.project.feishu.dto.doc.FieldsDTO;
import com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuBatchMsgDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.utils.RedisUtil;
import com.pipihelper.project.utils.CacheUtil;
import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
......@@ -54,8 +54,7 @@ import java.util.List;
public class FeiShuApiService {
@Resource
private FeiShuConfig feiShuConfig;
@Autowired
private RedisUtil redisUtil;
private static ObjectMapper objectMapper = new ObjectMapper();
......@@ -428,6 +427,7 @@ public class FeiShuApiService {
Type type = new TypeReference<FeiShuResultDTO>() {
}.getType();
FeiShuResultDTO feiShuResultDTO = JSONObject.parseObject(responseEntity.getBody(), type);
CacheUtil.put("chatId", feiShuResultDTO.getData().getChatId());
return feiShuResultDTO.getData().getChatId();
} catch (Exception e) {
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
......
package com.pipihelper.project.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
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 int DEFAULT_CAPACITY = 1024;
private static final Timer timer;
private static final int MAX_CAPACITY = 10000;
private static final ConcurrentHashMap<String, Object> map;
private static final long SECOND_TIME = 1000;
static {
map = new ConcurrentHashMap<>(DEFAULT_CAPACITY);
timer = new Timer();
}
/**
* 缓存任务清除类
*/
static class ClearTask extends TimerTask {
private String key;
public ClearTask(String key) {
this.key = key;
}
@Override
public void run() {
CacheUtil.remove(key);
}
}
//私有化构造方法
private CacheUtil() {
}
//==================缓存的增删改查
/**
* 添加缓存
*/
public static boolean put(String key, Object object) {
if (checkCapacity()) {
map.put(key, object);
//默认缓存时间
timer.schedule(new ClearTask(key), DEFAULT_TIMEOUT);
return true;
}
return false;
}
/**
* 添加缓存
*/
public static boolean put(String key, Object object, int time_out) {
if (checkCapacity()) {
map.put(key, object);
//默认缓存时间
timer.schedule(new ClearTask(key), time_out * SECOND_TIME);
}
return false;
}
/**
* 判断容量大小
*/
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) {
map.putAll(map);
for (String key : m.keySet()) {
timer.schedule(new ClearTask(key), time_out * SECOND_TIME);
}
return true;
}
return false;
}
/**
* 删除缓存
*/
public static void remove(String key) {
map.remove(key);
}
/**
* 清除所有缓存
*/
public void clearAll() {
if (map.size() > 0) {
map.clear();
}
timer.cancel();
}
/**
* 获取缓存
*/
public static Object get(String key) {
return map.get(key);
}
/**
* 是否包含某个缓存
*/
public static boolean isContain(String key) {
return map.contains(key);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!