提交 a4dde7fd 编写于 作者: tangyaolong's avatar tangyaolong

催办消息全量、分页接口开发

上级 f681bdd4
...@@ -6,6 +6,7 @@ import cn.ibizlab.core.notify.domain.MsgBody; ...@@ -6,6 +6,7 @@ import cn.ibizlab.core.notify.domain.MsgBody;
import cn.ibizlab.core.notify.domain.MsgOpenAccess; import cn.ibizlab.core.notify.domain.MsgOpenAccess;
import cn.ibizlab.core.notify.domain.MsgTemplate; import cn.ibizlab.core.notify.domain.MsgTemplate;
import cn.ibizlab.core.notify.domain.MsgUserAccount; import cn.ibizlab.core.notify.domain.MsgUserAccount;
import cn.ibizlab.core.notify.filter.MsgBodySearchContext;
import cn.ibizlab.core.notify.service.IMsgBodyService; import cn.ibizlab.core.notify.service.IMsgBodyService;
import cn.ibizlab.core.notify.service.IMsgOpenAccessService; import cn.ibizlab.core.notify.service.IMsgOpenAccessService;
import cn.ibizlab.core.notify.service.IMsgTemplateService; import cn.ibizlab.core.notify.service.IMsgTemplateService;
...@@ -33,15 +34,20 @@ import com.google.gson.Gson; ...@@ -33,15 +34,20 @@ import com.google.gson.Gson;
import lombok.SneakyThrows; import lombok.SneakyThrows;
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.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@Service @Service
@Slf4j @Slf4j
...@@ -97,13 +103,19 @@ public class NotifyCoreService { ...@@ -97,13 +103,19 @@ public class NotifyCoreService {
private static DingTalkClient createWorkRecordClient; private static DingTalkClient createWorkRecordClient;
private static DingTalkClient finishWorkRecordClient; private static DingTalkClient finishWorkRecordClient;
private static DingTalkClient getTokenClient; private static DingTalkClient getTokenClient;
private ConcurrentMap<String, Page<MsgBody>> msgMap = new ConcurrentHashMap<>();
private ConcurrentMap<String, Long> expireMap = new ConcurrentHashMap<>();
static { static {
getTokenClient = new DefaultDingTalkClient(dingTalkTokenApi); getTokenClient = new DefaultDingTalkClient(dingTalkTokenApi);
sendMsgClient = new DefaultDingTalkClient(dingTalkSendMsgApi); sendMsgClient = new DefaultDingTalkClient(dingTalkSendMsgApi);
createWorkRecordClient=new DefaultDingTalkClient(dingTalkCreateWorkRecordApi); createWorkRecordClient=new DefaultDingTalkClient(dingTalkCreateWorkRecordApi);
finishWorkRecordClient = new DefaultDingTalkClient(dingTalkFinishWorkRecordApi); finishWorkRecordClient = new DefaultDingTalkClient(dingTalkFinishWorkRecordApi);
} }
@Value("${ibiz.notify.pagesize:10}")
private int pageSize;
@Value("${ibiz.notify.expiretime:300000}")
private Long expireTime;
@Autowired @Autowired
@Lazy @Lazy
RestTemplate restTemplate; RestTemplate restTemplate;
...@@ -642,4 +654,46 @@ public class NotifyCoreService { ...@@ -642,4 +654,46 @@ public class NotifyCoreService {
return openAccess; return openAccess;
} }
/**
* 获取某个用户全量存储催办消息
* @return
*/
public Page<MsgBody> getBacklogAllContent(String toUserId) {
MsgBodySearchContext context = new MsgBodySearchContext();
context.setN_tousers_in(toUserId);
context.setSize(Integer.MAX_VALUE);
context.setN_tousers_eq(toUserId);
Page<MsgBody> result = msgBodyService.searchDefault(context);
return result;
}
/**
* 获取某个用户分页存储催办消息
* @return
*/
public Page<MsgBody> getBacklogPageContent(String toUserId) {
MsgBodySearchContext context = new MsgBodySearchContext();
context.setSize(pageSize);
context.setN_tousers_eq(toUserId);
Page<MsgBody> result = msgBodyService.searchDefault(context);
msgMap.put(toUserId,result);
expireMap.put(toUserId,System.currentTimeMillis()) ;
return result;
}
/**
* 缓存某个用户分页催办消息
* @return
*/
public Page<MsgBody> getBacklogByPage(String toUserId) {
if(!msgMap.containsKey(toUserId) && !expireMap.containsKey(toUserId)){
return getBacklogPageContent(toUserId);
}else {
if(System.currentTimeMillis() - expireMap.get(toUserId) <= expireTime){
return msgMap.get(toUserId);
}else {
return getBacklogPageContent(toUserId);
}
}
}
} }
...@@ -4,12 +4,19 @@ import cn.ibizlab.api.dto.MsgBodyDTO; ...@@ -4,12 +4,19 @@ import cn.ibizlab.api.dto.MsgBodyDTO;
import cn.ibizlab.api.mapping.MsgBodyMapping; import cn.ibizlab.api.mapping.MsgBodyMapping;
import cn.ibizlab.core.extensions.domain.Template; import cn.ibizlab.core.extensions.domain.Template;
import cn.ibizlab.core.extensions.service.NotifyCoreService; import cn.ibizlab.core.extensions.service.NotifyCoreService;
import cn.ibizlab.core.notify.domain.MsgBody;
import cn.ibizlab.core.notify.filter.MsgBodySearchContext;
import cn.ibizlab.core.notify.filter.MsgUserAccountSearchContext;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List;
@RestController @RestController
public class NotifyCoreResource { public class NotifyCoreResource {
...@@ -66,4 +73,24 @@ public class NotifyCoreResource { ...@@ -66,4 +73,24 @@ public class NotifyCoreResource {
return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.finishDingTalkWorkRecord(msgId)); return ResponseEntity.status(HttpStatus.OK).body(notifyCoreService.finishDingTalkWorkRecord(msgId));
} }
/**
* 全量获取催办消息
* @param
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/notify/msgbody/getbacklogbypage/{tousers}")
public ResponseEntity<Page> getAllBacklogAll(@Validated @NotNull @PathVariable("tousers") String toUsers){
Page page = notifyCoreService.getBacklogAllContent(toUsers);
return ResponseEntity.status(HttpStatus.OK).body(new PageImpl(mapping.toDto(page.getContent()), page.getPageable(), page.getTotalElements()));
}
/**
* 分页获取催办消息
* @param
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/notify/msgbody/getbacklogbypage/{tousers}")
public ResponseEntity<Page> getBacklogByPage(@Validated @NotNull @PathVariable("tousers") String toUsers) {
Page page = notifyCoreService.getBacklogByPage(toUsers);
return ResponseEntity.status(HttpStatus.OK).body(new PageImpl(mapping.toDto(page.getContent()), page.getPageable(), page.getTotalElements()));
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册