添加待办功能
This commit is contained in:
parent
a9f1a8fb14
commit
5bb0b3c789
@ -10,9 +10,11 @@ import com.cm.websocket.handler.TextSendHandler;
|
||||
import com.cm.websocket.manager.AppSocketSessionManager;
|
||||
import com.cm.websocket.pojo.AppSocketMessage;
|
||||
import com.cm.websocket.pojo.AppSocketSession;
|
||||
import com.cm.websocket.service.INoticeService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.OnClose;
|
||||
@ -38,6 +40,8 @@ import java.util.List;
|
||||
public class WebSocket {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WebSocket.class);
|
||||
private static ApplicationContext applicationContext;
|
||||
private ApplicationContext serviceContext = applicationContext;
|
||||
|
||||
/**
|
||||
* 连接成功
|
||||
@ -97,6 +101,8 @@ public class WebSocket {
|
||||
listOnlineUser(session, appSocketMessage);
|
||||
} else if (AppSocketTypeEnum.SEARCH_ONLINE_USER_FRIEND.getValue() == appSocketMessage.getType()) {
|
||||
listOnlineUserFriend(session, appSocketMessage);
|
||||
} else if (AppSocketTypeEnum.SEARCH_COUNT_NEED_TO_DEALT_WITH.getValue() == appSocketMessage.getType()) {
|
||||
countNeedToDealWith(session, appSocketMessage);
|
||||
}
|
||||
} catch (SessionException e) {
|
||||
sendStatusBody = new AppSocketMessage.SendStatusBody(SendStatusEnum.SESSION_ERROR.getValue(), SendStatusEnum.SESSION_ERROR, e.getMessage());
|
||||
@ -119,6 +125,22 @@ public class WebSocket {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 待办总数
|
||||
*
|
||||
* @param session
|
||||
* @param appSocketMessage
|
||||
*/
|
||||
private void countNeedToDealWith(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);
|
||||
List<AppSocketMessage.CountNeedToDealWithBody> counts = noticeService.listNoticeCount(userId, countNeedToDealWithBody);
|
||||
|
||||
send(session, appSocketMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* APP注册会话
|
||||
*
|
||||
@ -277,4 +299,7 @@ public class WebSocket {
|
||||
send(fromSession, appSocketMessage);
|
||||
}
|
||||
|
||||
public static void setApplicationContext(ApplicationContext applicationContext) {
|
||||
WebSocket.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package com.cm.websocket.controller.apis.message;
|
||||
|
||||
import com.cm.common.annotation.CheckRequestBodyAnnotation;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import com.cm.common.result.ErrorResult;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import com.cm.websocket.pojo.vos.message.NoticeVO;
|
||||
import com.cm.websocket.service.IMessageService;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
@ -50,4 +49,12 @@ public class MessageController {
|
||||
return messageService.sendByAppIdTarget(appId, target);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "通知消息", notes = "通知消息接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("noticewithtarget")
|
||||
@CheckRequestBodyAnnotation
|
||||
public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception {
|
||||
return messageService.saveNoticeWithTarget(noticeVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.cm.websocket.controller.message;
|
||||
package com.cm.websocket.controller.resource.message;
|
||||
|
||||
import com.cm.common.annotation.CheckRequestBodyAnnotation;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
@ -38,7 +38,7 @@ public class MessageResourceController {
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("noticewithtarget")
|
||||
@CheckRequestBodyAnnotation
|
||||
public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) {
|
||||
public SuccessResult saveNoticeWithTarget(@RequestBody NoticeVO noticeVO) throws Exception {
|
||||
return messageService.saveNoticeWithTarget(noticeVO);
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
package com.cm.websocket.dao;
|
||||
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.exception.UpdateException;
|
||||
import com.cm.websocket.pojo.pos.NoticePO;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: INoticeDao
|
||||
* @Description: 消息通知
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/3/29 4:37 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Repository
|
||||
public interface INoticeDao {
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param params
|
||||
* @throws SaveException
|
||||
*/
|
||||
void save(Map<String, Object> params) throws SaveException;
|
||||
|
||||
/**
|
||||
* 修改已办
|
||||
*
|
||||
* @param params
|
||||
* @throws UpdateException
|
||||
*/
|
||||
void updateHandle(Map<String, Object> params) throws UpdateException;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<NoticePO> listPO(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 系统列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<String> listSystems(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 模块列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<String> listModules(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<String> listMenus(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 统计
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
Integer count(Map<String, Object> params) throws SearchException;
|
||||
}
|
@ -65,7 +65,7 @@ public enum AppSocketTypeEnum {
|
||||
*/
|
||||
NOTICE_GROUP_MESSAGE(107),
|
||||
/**
|
||||
* 群目标通知
|
||||
* 目标通知,用于APP打开特定页面
|
||||
*/
|
||||
NOTICE_TARGET_MESSAGE(108),
|
||||
/**
|
||||
@ -76,6 +76,10 @@ public enum AppSocketTypeEnum {
|
||||
* 查询朋友在线用户,body 为查询用户的 userId
|
||||
*/
|
||||
SEARCH_ONLINE_USER_FRIEND(601),
|
||||
/**
|
||||
* 查询全部待办总数
|
||||
*/
|
||||
SEARCH_COUNT_NEED_TO_DEALT_WITH(602),
|
||||
/**
|
||||
* 发送状态,body 为 BaseResult 的 JSON 字符串
|
||||
*/
|
||||
|
@ -259,4 +259,43 @@ public class AppSocketMessage {
|
||||
}
|
||||
}
|
||||
|
||||
public static class CountNeedToDealWithBody {
|
||||
private String system;
|
||||
private String module;
|
||||
private String menu;
|
||||
private Integer count;
|
||||
|
||||
public String getSystem() {
|
||||
return system == null ? "" : system;
|
||||
}
|
||||
|
||||
public void setSystem(String system) {
|
||||
this.system = system;
|
||||
}
|
||||
|
||||
public String getModule() {
|
||||
return module == null ? "" : module;
|
||||
}
|
||||
|
||||
public void setModule(String module) {
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
public String getMenu() {
|
||||
return menu == null ? "" : menu;
|
||||
}
|
||||
|
||||
public void setMenu(String menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count == null ? 0 : count;
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,198 @@
|
||||
package com.cm.websocket.pojo.pos;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: NoticePO
|
||||
* @Description: 消息通知
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/3/29 4:39 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class NoticePO {
|
||||
|
||||
private Long id;
|
||||
private String noticeId;
|
||||
private String noticeTitle;
|
||||
private String noticeMsg;
|
||||
private String noticeTarget;
|
||||
private String noticeSystem;
|
||||
private String noticeModule;
|
||||
private String noticeMenu;
|
||||
private String noticeServiceId;
|
||||
private String userId;
|
||||
private Integer isHandle;
|
||||
private String gmtCreate;
|
||||
private String creator;
|
||||
private String gmtModified;
|
||||
private String modifier;
|
||||
private Integer isDelete;
|
||||
|
||||
public Long getId() {
|
||||
return id == null ? 0 : id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNoticeId() {
|
||||
return noticeId == null ? "" : noticeId;
|
||||
}
|
||||
|
||||
public void setNoticeId(String noticeId) {
|
||||
this.noticeId = noticeId;
|
||||
}
|
||||
|
||||
public String getNoticeTitle() {
|
||||
return noticeTitle == null ? "" : noticeTitle;
|
||||
}
|
||||
|
||||
public void setNoticeTitle(String noticeTitle) {
|
||||
this.noticeTitle = noticeTitle;
|
||||
}
|
||||
|
||||
public String getNoticeMsg() {
|
||||
return noticeMsg == null ? "" : noticeMsg;
|
||||
}
|
||||
|
||||
public void setNoticeMsg(String noticeMsg) {
|
||||
this.noticeMsg = noticeMsg;
|
||||
}
|
||||
|
||||
public String getNoticeTarget() {
|
||||
return noticeTarget == null ? "" : noticeTarget;
|
||||
}
|
||||
|
||||
public void setNoticeTarget(String noticeTarget) {
|
||||
this.noticeTarget = noticeTarget;
|
||||
}
|
||||
|
||||
public String getNoticeSystem() {
|
||||
return noticeSystem == null ? "" : noticeSystem;
|
||||
}
|
||||
|
||||
public void setNoticeSystem(String noticeSystem) {
|
||||
this.noticeSystem = noticeSystem;
|
||||
}
|
||||
|
||||
public String getNoticeModule() {
|
||||
return noticeModule == null ? "" : noticeModule;
|
||||
}
|
||||
|
||||
public void setNoticeModule(String noticeModule) {
|
||||
this.noticeModule = noticeModule;
|
||||
}
|
||||
|
||||
public String getNoticeMenu() {
|
||||
return noticeMenu == null ? "" : noticeMenu;
|
||||
}
|
||||
|
||||
public void setNoticeMenu(String noticeMenu) {
|
||||
this.noticeMenu = noticeMenu;
|
||||
}
|
||||
|
||||
public String getNoticeServiceId() {
|
||||
return noticeServiceId == null ? "" : noticeServiceId;
|
||||
}
|
||||
|
||||
public void setNoticeServiceId(String noticeServiceId) {
|
||||
this.noticeServiceId = noticeServiceId;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId == null ? "" : userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Integer getIsHandle() {
|
||||
return isHandle == null ? 0 : isHandle;
|
||||
}
|
||||
|
||||
public void setIsHandle(Integer isHandle) {
|
||||
this.isHandle = isHandle;
|
||||
}
|
||||
|
||||
public String getGmtCreate() {
|
||||
return gmtCreate == null ? "" : gmtCreate;
|
||||
}
|
||||
|
||||
public void setGmtCreate(String gmtCreate) {
|
||||
this.gmtCreate = gmtCreate;
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return creator == null ? "" : creator;
|
||||
}
|
||||
|
||||
public void setCreator(String creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public String getGmtModified() {
|
||||
return gmtModified == null ? "" : gmtModified;
|
||||
}
|
||||
|
||||
public void setGmtModified(String gmtModified) {
|
||||
this.gmtModified = gmtModified;
|
||||
}
|
||||
|
||||
public String getModifier() {
|
||||
return modifier == null ? "" : modifier;
|
||||
}
|
||||
|
||||
public void setModifier(String modifier) {
|
||||
this.modifier = modifier;
|
||||
}
|
||||
|
||||
public Integer getIsDelete() {
|
||||
return isDelete == null ? 0 : isDelete;
|
||||
}
|
||||
|
||||
public void setIsDelete(Integer isDelete) {
|
||||
this.isDelete = isDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"id\":")
|
||||
.append(id);
|
||||
sb.append(",\"noticeId\":\"")
|
||||
.append(noticeId).append('\"');
|
||||
sb.append(",\"noticeTitle\":\"")
|
||||
.append(noticeTitle).append('\"');
|
||||
sb.append(",\"noticeMsg\":\"")
|
||||
.append(noticeMsg).append('\"');
|
||||
sb.append(",\"noticeTarget\":\"")
|
||||
.append(noticeTarget).append('\"');
|
||||
sb.append(",\"noticeSystem\":\"")
|
||||
.append(noticeSystem).append('\"');
|
||||
sb.append(",\"noticeModule\":\"")
|
||||
.append(noticeModule).append('\"');
|
||||
sb.append(",\"noticeMenu\":\"")
|
||||
.append(noticeMenu).append('\"');
|
||||
sb.append(",\"noticeServiceId\":\"")
|
||||
.append(noticeServiceId).append('\"');
|
||||
sb.append(",\"userId\":\"")
|
||||
.append(userId).append('\"');
|
||||
sb.append(",\"isHandle\":")
|
||||
.append(isHandle);
|
||||
sb.append(",\"gmtCreate\":\"")
|
||||
.append(gmtCreate).append('\"');
|
||||
sb.append(",\"creator\":\"")
|
||||
.append(creator).append('\"');
|
||||
sb.append(",\"gmtModified\":\"")
|
||||
.append(gmtModified).append('\"');
|
||||
sb.append(",\"modifier\":\"")
|
||||
.append(modifier).append('\"');
|
||||
sb.append(",\"isDelete\":")
|
||||
.append(isDelete);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -42,6 +42,14 @@ public class NoticeVO {
|
||||
private String msg;
|
||||
@ApiModelProperty(name = "target", value = "目标字符串")
|
||||
private String target;
|
||||
@ApiModelProperty(name = "system", value = "系统")
|
||||
private String system;
|
||||
@ApiModelProperty(name = "module", value = "模块")
|
||||
private String module;
|
||||
@ApiModelProperty(name = "menu", value = "菜单")
|
||||
private String menu;
|
||||
@ApiModelProperty(name = "serviceId", value = "业务ID")
|
||||
private String serviceId;
|
||||
|
||||
public List<String> getUserIds() {
|
||||
return userIds == null ? new ArrayList<>() : userIds;
|
||||
@ -74,6 +82,38 @@ public class NoticeVO {
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getSystem() {
|
||||
return system == null ? "" : system;
|
||||
}
|
||||
|
||||
public void setSystem(String system) {
|
||||
this.system = system;
|
||||
}
|
||||
|
||||
public String getModule() {
|
||||
return module == null ? "" : module;
|
||||
}
|
||||
|
||||
public void setModule(String module) {
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
public String getMenu() {
|
||||
return menu == null ? "" : menu;
|
||||
}
|
||||
|
||||
public void setMenu(String menu) {
|
||||
this.menu = menu;
|
||||
}
|
||||
|
||||
public String getServiceId() {
|
||||
return serviceId == null ? "" : serviceId;
|
||||
}
|
||||
|
||||
public void setServiceId(String serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public interface IMessageService {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws SearchException;
|
||||
SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws Exception;
|
||||
|
||||
/**
|
||||
* 群发文本消息
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.cm.websocket.service;
|
||||
|
||||
import com.cm.websocket.pojo.AppSocketMessage;
|
||||
import com.cm.websocket.pojo.vos.message.NoticeVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: INoticeService
|
||||
* @Description: 消息通知
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/3/29 4:36 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface INoticeService {
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param userId
|
||||
* @param notice
|
||||
*/
|
||||
void save(String userId, NoticeVO.Notice notice) throws Exception;
|
||||
|
||||
/**
|
||||
* 通知数量
|
||||
*
|
||||
* @param userId
|
||||
* @param countNeedToDealWithBody
|
||||
* @return
|
||||
*/
|
||||
List<AppSocketMessage.CountNeedToDealWithBody> listNoticeCount(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody);
|
||||
|
||||
/**
|
||||
* 统计
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
Integer count(Map<String, Object> params);
|
||||
}
|
@ -3,7 +3,6 @@ package com.cm.websocket.service.impl;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.exception.SaveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.plugin.interfaces.IUserImBaseService;
|
||||
import com.cm.common.plugin.pojo.bos.user.UserDepartmentResourceBO;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
@ -16,6 +15,7 @@ import com.cm.websocket.pojo.AppSocketMessage;
|
||||
import com.cm.websocket.pojo.AppSocketSession;
|
||||
import com.cm.websocket.pojo.vos.message.NoticeVO;
|
||||
import com.cm.websocket.service.IMessageService;
|
||||
import com.cm.websocket.service.INoticeService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -39,6 +39,8 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi
|
||||
|
||||
@Autowired
|
||||
private IUserImBaseService userImBaseService;
|
||||
@Autowired
|
||||
private INoticeService noticeService;
|
||||
|
||||
@Override
|
||||
public SuccessResult sendByAppId(String appId) {
|
||||
@ -79,7 +81,7 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws SearchException {
|
||||
public SuccessResult saveNoticeWithTarget(NoticeVO noticeVO) throws Exception {
|
||||
for (NoticeVO.Notice notice : noticeVO.getNoticies()) {
|
||||
if (notice.getUserIds() == null || notice.getUserIds().isEmpty()) {
|
||||
continue;
|
||||
@ -101,6 +103,11 @@ public class MessageServiceImpl extends AbstractService implements IMessageServi
|
||||
JSONObject.toJSONString(noticeBody));
|
||||
WebSocket.send(session, appSocketMessage);
|
||||
}
|
||||
// 保存通知记录
|
||||
List<String> userIds = notice.getUserIds();
|
||||
for (String userId : userIds) {
|
||||
noticeService.save(userId, notice);
|
||||
}
|
||||
}
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
@ -0,0 +1,152 @@
|
||||
package com.cm.websocket.service.impl;
|
||||
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.utils.UUIDUtil;
|
||||
import com.cm.websocket.dao.INoticeDao;
|
||||
import com.cm.websocket.pojo.AppSocketMessage;
|
||||
import com.cm.websocket.pojo.vos.message.NoticeVO;
|
||||
import com.cm.websocket.service.INoticeService;
|
||||
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.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: NoticeServiceImpl
|
||||
* @Description: 消息通知
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/3/29 4:36 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class NoticeServiceImpl extends AbstractService implements INoticeService {
|
||||
|
||||
@Autowired
|
||||
private INoticeDao noticeDao;
|
||||
|
||||
@Override
|
||||
public void save(String userId, NoticeVO.Notice notice) throws Exception {
|
||||
Map<String, Object> params = getHashMap(16);
|
||||
params.put("noticeId", UUIDUtil.getUUID());
|
||||
params.put("userId", userId);
|
||||
params.put("noticeTitle", notice.getTitle());
|
||||
params.put("noticeMsg", notice.getMsg());
|
||||
params.put("noticeTarget", notice.getTarget());
|
||||
params.put("noticeSystem", notice.getSystem());
|
||||
params.put("noticeModule", notice.getModule());
|
||||
params.put("noticeMenu", notice.getMenu());
|
||||
params.put("noticeServiceId", notice.getServiceId());
|
||||
params.put("isHandle", 0);
|
||||
setSaveInfoByUserId(params, "1");
|
||||
noticeDao.save(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppSocketMessage.CountNeedToDealWithBody> listNoticeCount(String userId, AppSocketMessage.CountNeedToDealWithBody countNeedToDealWithBody) {
|
||||
List<AppSocketMessage.CountNeedToDealWithBody> noticeCounts = new ArrayList<>();
|
||||
Map<String, Object> params = getHashMap(10);
|
||||
params.put("userId", userId);
|
||||
params.put("isHandle", 0);
|
||||
if (StringUtils.isBlank(countNeedToDealWithBody.getSystem())) {
|
||||
// 系统为空,按系统统计
|
||||
List<String> systems = listSystems(userId);
|
||||
for (String system : systems) {
|
||||
params.put("noticeSystem", system);
|
||||
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
||||
systemCount.setSystem(system);
|
||||
systemCount.setCount(count(params));
|
||||
noticeCounts.add(systemCount);
|
||||
}
|
||||
} else if (StringUtils.isBlank(countNeedToDealWithBody.getModule())) {
|
||||
// 模块为空,按模块统计
|
||||
List<String> modules = listModules(userId, countNeedToDealWithBody.getSystem());
|
||||
params.put("noticeSystem", countNeedToDealWithBody.getSystem());
|
||||
for (String module : modules) {
|
||||
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
||||
systemCount.setSystem(countNeedToDealWithBody.getSystem());
|
||||
systemCount.setModule(countNeedToDealWithBody.getModule());
|
||||
params.put("noticeModule", module);
|
||||
systemCount.setCount(count(params));
|
||||
noticeCounts.add(systemCount);
|
||||
}
|
||||
} else if (StringUtils.isBlank(countNeedToDealWithBody.getMenu())) {
|
||||
// 菜单为空,按菜单统计
|
||||
List<String> menus = listMenus(userId, countNeedToDealWithBody.getSystem(), countNeedToDealWithBody.getModule());
|
||||
params.put("noticeSystem", countNeedToDealWithBody.getSystem());
|
||||
params.put("noticeModule", countNeedToDealWithBody.getModule());
|
||||
for (String menu : menus) {
|
||||
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
||||
systemCount.setSystem(countNeedToDealWithBody.getSystem());
|
||||
systemCount.setModule(countNeedToDealWithBody.getModule());
|
||||
params.put("noticeMenu", menu);
|
||||
systemCount.setCount(count(params));
|
||||
noticeCounts.add(systemCount);
|
||||
}
|
||||
} else {
|
||||
// 都不为空,具体菜单数量
|
||||
AppSocketMessage.CountNeedToDealWithBody systemCount = new AppSocketMessage.CountNeedToDealWithBody();
|
||||
systemCount.setSystem(countNeedToDealWithBody.getSystem());
|
||||
systemCount.setModule(countNeedToDealWithBody.getModule());
|
||||
systemCount.setMenu(countNeedToDealWithBody.getMenu());
|
||||
params.put("noticeSystem", countNeedToDealWithBody.getSystem());
|
||||
params.put("noticeModule", countNeedToDealWithBody.getModule());
|
||||
params.put("noticeModule", countNeedToDealWithBody.getModule());
|
||||
params.put("noticeMenu", countNeedToDealWithBody.getMenu());
|
||||
systemCount.setCount(count(params));
|
||||
noticeCounts.add(systemCount);
|
||||
}
|
||||
return noticeCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer count(Map<String, Object> params) {
|
||||
Integer count = noticeDao.count(params);
|
||||
return count == null ? 0 : count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统列表
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
private List<String> listSystems(String userId) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
params.put("userId", userId);
|
||||
return noticeDao.listSystems(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模块列表
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
private List<String> listModules(String userId, String noticeSystem) {
|
||||
Map<String, Object> params = getHashMap(4);
|
||||
params.put("userId", userId);
|
||||
params.put("noticeSystem", noticeSystem);
|
||||
return noticeDao.listModules(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
private List<String> listMenus(String userId, String noticeSystem, String noticeModule) {
|
||||
Map<String, Object> params = getHashMap(6);
|
||||
params.put("userId", userId);
|
||||
params.put("noticeSystem", noticeSystem);
|
||||
params.put("noticeModule", noticeModule);
|
||||
return noticeDao.listMenus(params);
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package com.cm.websocket.startup;
|
||||
|
||||
import com.cm.websocket.WebSocket;
|
||||
import com.cm.websocket.manager.AppSocketSessionManager;
|
||||
import com.cm.websocket.service.IMessageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@ -22,10 +24,13 @@ public class WebSocketStartUp implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private IMessageService messageService;
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
AppSocketSessionManager.getInstance().setMessageService(messageService);
|
||||
WebSocket.setApplicationContext(applicationContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,207 @@
|
||||
<?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.cm.websocket.dao.INoticeDao">
|
||||
|
||||
<resultMap id="noticePO" type="com.cm.websocket.pojo.pos.NoticePO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="notice_id" property="noticeId"/>
|
||||
<result column="notice_title" property="noticeTitle"/>
|
||||
<result column="notice_msg" property="noticeMsg"/>
|
||||
<result column="notice_target" property="noticeTarget"/>
|
||||
<result column="notice_system" property="noticeSystem"/>
|
||||
<result column="notice_module" property="noticeModule"/>
|
||||
<result column="notice_menu" property="noticeMenu"/>
|
||||
<result column="notice_service_id" property="noticeServiceId"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="is_handle" property="isHandle"/>
|
||||
<result column="gmt_create" property="gmtCreate"/>
|
||||
<result column="creator" property="creator"/>
|
||||
<result column="gmt_modified" property="gmtModified"/>
|
||||
<result column="modifier" property="modifier"/>
|
||||
<result column="is_delete" property="isDelete"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 保存 -->
|
||||
<insert id="save" parameterType="map">
|
||||
INSERT INTO socket_notice(
|
||||
notice_id,
|
||||
notice_title,
|
||||
notice_msg,
|
||||
notice_target,
|
||||
notice_system,
|
||||
notice_module,
|
||||
notice_menu,
|
||||
notice_service_id,
|
||||
user_id,
|
||||
is_handle,
|
||||
gmt_create,
|
||||
creator,
|
||||
gmt_modified,
|
||||
modifier,
|
||||
is_delete
|
||||
) VALUES(
|
||||
#{noticeId},
|
||||
#{noticeTitle},
|
||||
#{noticeMsg},
|
||||
#{noticeTarget},
|
||||
#{noticeSystem},
|
||||
#{noticeModule},
|
||||
#{noticeMenu},
|
||||
#{noticeServiceId},
|
||||
#{userId},
|
||||
#{isHandle},
|
||||
#{gmtCreate},
|
||||
#{creator},
|
||||
#{gmtModified},
|
||||
#{modifier},
|
||||
#{isDelete}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新已办状态 -->
|
||||
<update id="updateHandle" parameterType="map">
|
||||
UPDATE
|
||||
socket_notice
|
||||
SET
|
||||
is_handle = #{isHandle},
|
||||
gmt_modified = #{gmtModified},
|
||||
modifier = #{modifier}
|
||||
WHERE
|
||||
notice_service_id = #{noticeServiceId}
|
||||
</update>
|
||||
|
||||
<!-- 列表 -->
|
||||
<select id="listPO" parameterType="map" resultMap="noticePO">
|
||||
SELECT
|
||||
notice_id,
|
||||
notice_title,
|
||||
notice_msg,
|
||||
notice_target,
|
||||
notice_system,
|
||||
notice_module,
|
||||
notice_menu,
|
||||
notice_service_id,
|
||||
user_id,
|
||||
is_handle,
|
||||
gmt_create,
|
||||
creator,
|
||||
gmt_modified,
|
||||
modifier,
|
||||
is_delete
|
||||
FROM
|
||||
socket_notice
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="noticeSystem != null and noticeSystem != ''">
|
||||
AND
|
||||
notice_system = #{noticeSystem}
|
||||
</if>
|
||||
<if test="noticeModule != null and noticeModule != ''">
|
||||
AND
|
||||
notice_module = #{noticeModule}
|
||||
</if>
|
||||
<if test="noticeMenu != null and noticeMenu">
|
||||
AND
|
||||
notice_menu = #{noticeMenu}
|
||||
</if>
|
||||
<if test="userId != null and userId != ''">
|
||||
AND
|
||||
user_id = #{userId}
|
||||
</if>
|
||||
<if test="isHandle != null">
|
||||
AND
|
||||
is_handle = #{isHandle}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 系统列表 -->
|
||||
<select id="listSystems" parameterType="map" resultType="java.lang.String">
|
||||
SELECT
|
||||
notice_system
|
||||
FROM
|
||||
socket_notice
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="userId != null and userId != ''">
|
||||
AND
|
||||
user_id = #{userId}
|
||||
</if>
|
||||
GROUP BY
|
||||
notice_system
|
||||
</select>
|
||||
|
||||
<!-- 模块列表 -->
|
||||
<select id="listModules" parameterType="map" resultType="java.lang.String">
|
||||
SELECT
|
||||
notice_module
|
||||
FROM
|
||||
socket_notice
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="userId != null and userId != ''">
|
||||
AND
|
||||
user_id = #{userId}
|
||||
</if>
|
||||
<if test="noticeSystem != null and noticeSystem != ''">
|
||||
AND
|
||||
notice_system = #{noticeSystem}
|
||||
</if>
|
||||
GROUP BY
|
||||
notice_module
|
||||
</select>
|
||||
|
||||
<!-- 菜单列表 -->
|
||||
<select id="listMenus" parameterType="map" resultType="java.lang.String">
|
||||
SELECT
|
||||
notice_menu
|
||||
FROM
|
||||
socket_notice
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="userId != null and userId != ''">
|
||||
AND
|
||||
user_id = #{userId}
|
||||
</if>
|
||||
<if test="noticeSystem != null and noticeSystem != ''">
|
||||
AND
|
||||
notice_system = #{noticeSystem}
|
||||
</if>
|
||||
<if test="noticeModule != null and noticeModule != ''">
|
||||
AND
|
||||
notice_module = #{noticeModule}
|
||||
</if>
|
||||
GROUP BY
|
||||
notice_menu
|
||||
</select>
|
||||
|
||||
<!-- 统计 -->
|
||||
<select id="count" parameterType="map" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
socket_notice
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="userId != null and userId != ''">
|
||||
AND
|
||||
user_id = #{userId}
|
||||
</if>
|
||||
<if test="noticeSystem != null and noticeSystem != ''">
|
||||
AND
|
||||
notice_system = #{noticeSystem}
|
||||
</if>
|
||||
<if test="noticeModule != null and noticeModule != ''">
|
||||
AND
|
||||
notice_module = #{noticeModule}
|
||||
</if>
|
||||
<if test="noticeMenu != null and noticeMenu != ''">
|
||||
AND
|
||||
notice_menu = #{noticeMenu}
|
||||
</if>
|
||||
<if test="isHandle != null">
|
||||
AND
|
||||
is_handle = #{isHandle}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user