添加待办通知
This commit is contained in:
parent
5bb0b3c789
commit
b12c286c08
@ -97,6 +97,8 @@ public class WebSocket {
|
|||||||
sendTextMessage(session, appSocketMessage);
|
sendTextMessage(session, appSocketMessage);
|
||||||
} else if (AppSocketTypeEnum.GROUP_MESSAGE.getValue() == appSocketMessage.getType()) {
|
} else if (AppSocketTypeEnum.GROUP_MESSAGE.getValue() == appSocketMessage.getType()) {
|
||||||
AppSocketSessionManager.getInstance().getMessageService().sendGroupTextMessage(session, appSocketMessage);
|
AppSocketSessionManager.getInstance().getMessageService().sendGroupTextMessage(session, appSocketMessage);
|
||||||
|
} else if (AppSocketTypeEnum.UPDATE_SERVICE_HANDLE_STATUS.getValue() == appSocketMessage.getType()) {
|
||||||
|
updateServiceHandleStatus(session, appSocketMessage);
|
||||||
} else if (AppSocketTypeEnum.SEARCH_ONLINE_USER.getValue() == appSocketMessage.getType()) {
|
} else if (AppSocketTypeEnum.SEARCH_ONLINE_USER.getValue() == appSocketMessage.getType()) {
|
||||||
listOnlineUser(session, appSocketMessage);
|
listOnlineUser(session, appSocketMessage);
|
||||||
} else if (AppSocketTypeEnum.SEARCH_ONLINE_USER_FRIEND.getValue() == appSocketMessage.getType()) {
|
} else if (AppSocketTypeEnum.SEARCH_ONLINE_USER_FRIEND.getValue() == appSocketMessage.getType()) {
|
||||||
@ -125,6 +127,19 @@ public class WebSocket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新业务处理状态并返回总数
|
||||||
|
*/
|
||||||
|
private void updateServiceHandleStatus(Session session, AppSocketMessage appSocketMessage) {
|
||||||
|
String userId = appSocketMessage.getFrom();
|
||||||
|
appSocketMessage.setTo(userId);
|
||||||
|
AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody = JSONObject.parseObject(appSocketMessage.getBody(), AppSocketMessage.CountNeedToDealWithBody.class);
|
||||||
|
INoticeService noticeService = serviceContext.getBean(INoticeService.class);
|
||||||
|
noticeService.updateHandleStatus(userId, countNeedToDealWithBody);
|
||||||
|
countNeedToDealWithBody.setServiceId(null);
|
||||||
|
countNeedToDealWith(session, appSocketMessage, noticeService, countNeedToDealWithBody);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 待办总数
|
* 待办总数
|
||||||
*
|
*
|
||||||
@ -136,8 +151,21 @@ public class WebSocket {
|
|||||||
appSocketMessage.setTo(userId);
|
appSocketMessage.setTo(userId);
|
||||||
AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody = JSONObject.parseObject(appSocketMessage.getBody(), AppSocketMessage.CountNeedToDealWithBody.class);
|
AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody = JSONObject.parseObject(appSocketMessage.getBody(), AppSocketMessage.CountNeedToDealWithBody.class);
|
||||||
INoticeService noticeService = serviceContext.getBean(INoticeService.class);
|
INoticeService noticeService = serviceContext.getBean(INoticeService.class);
|
||||||
List<AppSocketMessage.CountNeedToDealWithBody> counts = noticeService.listNoticeCount(userId, countNeedToDealWithBody);
|
countNeedToDealWith(session, appSocketMessage, noticeService, countNeedToDealWithBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待办总数
|
||||||
|
*
|
||||||
|
* @param session
|
||||||
|
* @param appSocketMessage
|
||||||
|
* @param noticeService
|
||||||
|
* @param countNeedToDealWithBody
|
||||||
|
*/
|
||||||
|
private void countNeedToDealWith(Session session, AppSocketMessage appSocketMessage, INoticeService noticeService, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody) {
|
||||||
|
appSocketMessage.setType(AppSocketTypeEnum.SEARCH_COUNT_NEED_TO_DEALT_WITH.getValue());
|
||||||
|
List<AppSocketMessage.CountNeedToDealWithBody> counts = noticeService.listNoticeCount(appSocketMessage.getFrom(), countNeedToDealWithBody);
|
||||||
|
appSocketMessage.setBody(JSONArray.toJSONString(counts));
|
||||||
send(session, appSocketMessage);
|
send(session, appSocketMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,15 @@ public class MessageController {
|
|||||||
@PostMapping("noticewithtarget")
|
@PostMapping("noticewithtarget")
|
||||||
@CheckRequestBodyAnnotation
|
@CheckRequestBodyAnnotation
|
||||||
public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception {
|
public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception {
|
||||||
return messageService.saveNoticeWithTarget(noticeVO);
|
return messageService.saveNoticeWithTarget(noticeVO, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "通知消息", notes = "通知消息接口")
|
||||||
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@PostMapping("noticewithtarget/save")
|
||||||
|
@CheckRequestBodyAnnotation
|
||||||
|
public SuccessResult saveNoticeWithTargetAndSave(@RequestBody NoticeVO noticeVO) throws Exception {
|
||||||
|
return messageService.saveNoticeWithTarget(noticeVO, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class MessageResourceController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IMessageService messageService;
|
private IMessageService messageService;
|
||||||
|
|
||||||
@ApiOperation(value = "通知消息", notes = "通知消息接口")
|
@ApiOperation(value = "通知消息(不保存记录)", notes = "通知消息(不保存记录)接口")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query")
|
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query")
|
||||||
})
|
})
|
||||||
@ -39,7 +39,18 @@ public class MessageResourceController {
|
|||||||
@PostMapping("noticewithtarget")
|
@PostMapping("noticewithtarget")
|
||||||
@CheckRequestBodyAnnotation
|
@CheckRequestBodyAnnotation
|
||||||
public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception {
|
public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception {
|
||||||
return messageService.saveNoticeWithTarget(noticeVO);
|
return messageService.saveNoticeWithTarget(noticeVO, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "通知消息(保存记录)", notes = "通知消息(保存记录)接口")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query")
|
||||||
|
})
|
||||||
|
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||||
|
@PostMapping("noticewithtarget/save")
|
||||||
|
@CheckRequestBodyAnnotation
|
||||||
|
public SuccessResult saveNoticeWithTargetAndSave(@RequestBody NoticeVO noticeVO) throws Exception {
|
||||||
|
return messageService.saveNoticeWithTarget(noticeVO, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,10 @@ public enum AppSocketTypeEnum {
|
|||||||
* 目标通知,用于APP打开特定页面
|
* 目标通知,用于APP打开特定页面
|
||||||
*/
|
*/
|
||||||
NOTICE_TARGET_MESSAGE(108),
|
NOTICE_TARGET_MESSAGE(108),
|
||||||
|
/**
|
||||||
|
* 更新业务的处理状态
|
||||||
|
*/
|
||||||
|
UPDATE_SERVICE_HANDLE_STATUS(501),
|
||||||
/**
|
/**
|
||||||
* 查询全部在线用户,body 为查询用户的 userId
|
* 查询全部在线用户,body 为查询用户的 userId
|
||||||
*/
|
*/
|
||||||
|
@ -263,6 +263,7 @@ public class AppSocketMessage {
|
|||||||
private String system;
|
private String system;
|
||||||
private String module;
|
private String module;
|
||||||
private String menu;
|
private String menu;
|
||||||
|
private String serviceId;
|
||||||
private Integer count;
|
private Integer count;
|
||||||
|
|
||||||
public String getSystem() {
|
public String getSystem() {
|
||||||
@ -289,6 +290,14 @@ public class AppSocketMessage {
|
|||||||
this.menu = menu;
|
this.menu = menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServiceId() {
|
||||||
|
return serviceId == null ? "" : serviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceId(String serviceId) {
|
||||||
|
this.serviceId = serviceId;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getCount() {
|
public Integer getCount() {
|
||||||
return count == null ? 0 : count;
|
return count == null ? 0 : count;
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,11 @@ public interface IMessageService {
|
|||||||
* 通知消息
|
* 通知消息
|
||||||
*
|
*
|
||||||
* @param noticeVO
|
* @param noticeVO
|
||||||
|
* @param save
|
||||||
* @return
|
* @return
|
||||||
* @throws SearchException
|
* @throws SearchException
|
||||||
*/
|
*/
|
||||||
SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws Exception;
|
SuccessResult saveNoticeWithTarget(NoticeVO noticeVO, boolean save) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群发文本消息
|
* 群发文本消息
|
||||||
|
@ -26,6 +26,15 @@ public interface INoticeService {
|
|||||||
*/
|
*/
|
||||||
void save(String userId, NoticeVO.Notice notice) throws Exception;
|
void save(String userId, NoticeVO.Notice notice) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新已办状态
|
||||||
|
*
|
||||||
|
* @param userId
|
||||||
|
* @param countNeedToDealWithBody
|
||||||
|
*/
|
||||||
|
void updateHandleStatus(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知数量
|
* 通知数量
|
||||||
*
|
*
|
||||||
@ -42,4 +51,5 @@ public interface INoticeService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Integer count(Map<String, Object> params);
|
Integer count(Map<String, Object> params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.cm.websocket.service.impl;
|
package com.cm.websocket.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.cm.common.base.AbstractService;
|
import com.cm.common.base.AbstractService;
|
||||||
import com.cm.common.exception.SaveException;
|
import com.cm.common.exception.SaveException;
|
||||||
@ -23,6 +24,9 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.websocket.Session;
|
import javax.websocket.Session;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
@ -41,6 +45,7 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi
|
|||||||
private IUserImBaseService userImBaseService;
|
private IUserImBaseService userImBaseService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private INoticeService noticeService;
|
private INoticeService noticeService;
|
||||||
|
private ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(1);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuccessResult sendByAppId(String appId) {
|
public SuccessResult sendByAppId(String appId) {
|
||||||
@ -81,7 +86,7 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws Exception {
|
public SuccessResult saveNoticeWithTarget(NoticeVO noticeVO, boolean save) throws Exception {
|
||||||
for (NoticeVO.Notice notice : noticeVO.getNoticies()) {
|
for (NoticeVO.Notice notice : noticeVO.getNoticies()) {
|
||||||
if (notice.getUserIds() == null || notice.getUserIds().isEmpty()) {
|
if (notice.getUserIds() == null || notice.getUserIds().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
@ -93,20 +98,42 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi
|
|||||||
notice.setMsg("您有一条系统消息");
|
notice.setMsg("您有一条系统消息");
|
||||||
}
|
}
|
||||||
List<AppSocketSession> appSocketSessions = AppSocketSessionManager.getInstance().listSessionByUserIds(notice.getUserIds());
|
List<AppSocketSession> appSocketSessions = AppSocketSessionManager.getInstance().listSessionByUserIds(notice.getUserIds());
|
||||||
for (AppSocketSession appSocketSession : appSocketSessions) {
|
// 推送3s后通知
|
||||||
Session session = appSocketSession.getSession();
|
scheduledExecutorService.schedule(() -> {
|
||||||
AppSocketMessage.NoticeBody noticeBody = new AppSocketMessage.NoticeBody(notice.getTitle(), notice.getMsg(), notice.getTarget());
|
for (AppSocketSession appSocketSession : appSocketSessions) {
|
||||||
AppSocketMessage appSocketMessage = new AppSocketMessage(AppSocketTypeEnum.NOTICE_TARGET_MESSAGE.getValue(),
|
Session session = appSocketSession.getSession();
|
||||||
true,
|
AppSocketMessage.NoticeBody noticeBody = new AppSocketMessage.NoticeBody(notice.getTitle(), notice.getMsg(), notice.getTarget());
|
||||||
AppSocketSessionManager.FORM_SYSTEM,
|
AppSocketMessage appSocketMessage = new AppSocketMessage(AppSocketTypeEnum.NOTICE_TARGET_MESSAGE.getValue(),
|
||||||
appSocketSession.getUserId(),
|
true,
|
||||||
JSONObject.toJSONString(noticeBody));
|
AppSocketSessionManager.FORM_SYSTEM,
|
||||||
WebSocket.send(session, appSocketMessage);
|
appSocketSession.getUserId(),
|
||||||
}
|
JSONObject.toJSONString(noticeBody));
|
||||||
// 保存通知记录
|
WebSocket.send(session, appSocketMessage);
|
||||||
List<String> userIds = notice.getUserIds();
|
}
|
||||||
for (String userId : userIds) {
|
}, 3, TimeUnit.SECONDS);
|
||||||
noticeService.save(userId, notice);
|
if (save) {
|
||||||
|
// 保存通知记录
|
||||||
|
List<String> userIds = notice.getUserIds();
|
||||||
|
for (String userId : userIds) {
|
||||||
|
noticeService.save(userId, notice);
|
||||||
|
}
|
||||||
|
// 3s后通知,保证事务提交
|
||||||
|
scheduledExecutorService.schedule(() -> {
|
||||||
|
// 更新状态待办
|
||||||
|
for (AppSocketSession appSocketSession : appSocketSessions) {
|
||||||
|
Session session = appSocketSession.getSession();
|
||||||
|
AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody = new AppSocketMessage.CountNeedToDealWithBody();
|
||||||
|
countNeedToDealWithBody.setSystem(notice.getSystem());
|
||||||
|
// 查询待办状态
|
||||||
|
List<AppSocketMessage.CountNeedToDealWithBody> counts = noticeService.listNoticeCount(appSocketSession.getUserId(), countNeedToDealWithBody);
|
||||||
|
AppSocketMessage appSocketMessage = new AppSocketMessage(AppSocketTypeEnum.SEARCH_COUNT_NEED_TO_DEALT_WITH.getValue(),
|
||||||
|
true,
|
||||||
|
AppSocketSessionManager.FORM_SYSTEM,
|
||||||
|
appSocketSession.getUserId(),
|
||||||
|
JSONArray.toJSONString(counts));
|
||||||
|
WebSocket.send(session, appSocketMessage);
|
||||||
|
}
|
||||||
|
}, 3, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new SuccessResult();
|
return new SuccessResult();
|
||||||
|
@ -47,6 +47,22 @@ public class NoticeServiceImpl extends AbstractService implements INoticeService
|
|||||||
noticeDao.save(params);
|
noticeDao.save(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateHandleStatus(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody) {
|
||||||
|
if (StringUtils.isBlank(countNeedToDealWithBody.getSystem())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(countNeedToDealWithBody.getServiceId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, Object> params = getHashMap(6);
|
||||||
|
params.put("isHandle", 1);
|
||||||
|
params.put("noticeSystem", countNeedToDealWithBody.getSystem());
|
||||||
|
params.put("noticeServiceId", countNeedToDealWithBody.getServiceId());
|
||||||
|
setUpdateInfoByUserId(params, userId);
|
||||||
|
noticeDao.updateHandle(params);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AppSocketMessage.CountNeedToDealWithBody> listNoticeCount(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody) {
|
public List<AppSocketMessage.CountNeedToDealWithBody> listNoticeCount(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody) {
|
||||||
List<AppSocketMessage.CountNeedToDealWithBody> noticeCounts = new ArrayList<>();
|
List<AppSocketMessage.CountNeedToDealWithBody> noticeCounts = new ArrayList<>();
|
||||||
@ -70,7 +86,7 @@ public class NoticeServiceImpl extends AbstractService implements INoticeService
|
|||||||
for (String module : modules) {
|
for (String module : modules) {
|
||||||
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
||||||
systemCount.setSystem(countNeedToDealWithBody.getSystem());
|
systemCount.setSystem(countNeedToDealWithBody.getSystem());
|
||||||
systemCount.setModule(countNeedToDealWithBody.getModule());
|
systemCount.setModule(module);
|
||||||
params.put("noticeModule", module);
|
params.put("noticeModule", module);
|
||||||
systemCount.setCount(count(params));
|
systemCount.setCount(count(params));
|
||||||
noticeCounts.add(systemCount);
|
noticeCounts.add(systemCount);
|
||||||
@ -84,6 +100,7 @@ public class NoticeServiceImpl extends AbstractService implements INoticeService
|
|||||||
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
||||||
systemCount.setSystem(countNeedToDealWithBody.getSystem());
|
systemCount.setSystem(countNeedToDealWithBody.getSystem());
|
||||||
systemCount.setModule(countNeedToDealWithBody.getModule());
|
systemCount.setModule(countNeedToDealWithBody.getModule());
|
||||||
|
systemCount.setMenu(menu);
|
||||||
params.put("noticeMenu", menu);
|
params.put("noticeMenu", menu);
|
||||||
systemCount.setCount(count(params));
|
systemCount.setCount(count(params));
|
||||||
noticeCounts.add(systemCount);
|
noticeCounts.add(systemCount);
|
||||||
|
@ -67,6 +67,8 @@
|
|||||||
gmt_modified = #{gmtModified},
|
gmt_modified = #{gmtModified},
|
||||||
modifier = #{modifier}
|
modifier = #{modifier}
|
||||||
WHERE
|
WHERE
|
||||||
|
notice_system = #{noticeSystem}
|
||||||
|
AND
|
||||||
notice_service_id = #{noticeServiceId}
|
notice_service_id = #{noticeServiceId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user