use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.
the class CmsContentServiceImpl method updateCmsContent.
@Override
public Integer updateCmsContent(CmsContent cmsContent, String[] files, String[] imgFile, String content, String[] attachment, String[] imgAttachment, String scheduledTime, String sessionId, HttpServletRequest request) throws CheckedServiceException, IOException {
Integer count = 0;
// 获取当前登陆用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (StringUtil.notEmpty(content)) {
// 更新MongoDB 内容
contentService.update(new Content(cmsContent.getMid(), content));
}
if (ObjectUtil.isNull(cmsContent)) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
if (ObjectUtil.isNull(cmsContent.getMaterialId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.CMS, CheckedExceptionResult.NULL_PARAM, "教材ID为空");
}
// 信息快报/公告管理(发布),审核时间就为当前时间
if (Const.CMS_AUTHOR_STATUS_2 == cmsContent.getAuthStatus().shortValue()) {
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_2);
cmsContent.setIsStaging(Const.FALSE);
cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
cmsContent.setIsPublished(true);
} else if (Const.CMS_AUTHOR_STATUS_0 == cmsContent.getAuthStatus().shortValue()) {
if (cmsContent.getIsStaging()) {
// 信息快报/公告管理(暂存)
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_0);
cmsContent.setAuthDate(null);
cmsContent.setIsPublished(false);
}
} else if (Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
// 文章管理,退回
cmsContent.setAuthUserId(pmphUser.getId());
cmsContent.setAuthStatus(Const.CMS_AUTHOR_STATUS_1);
cmsContent.setAuthDate(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
cmsContent.setIsDeleted(false);
cmsContent.setIsPublished(false);
}
if (cmsContent.getCategoryId() == Const.CMS_CATEGORY_ID_1 && cmsContent.getAuthorType() == Const.CMS_AUTHOR_TYPE_2 && cmsContent.getAuthStatus() == Const.CMS_AUTHOR_STATUS_0 && Const.TRUE == cmsContent.getIsStaging()) {
cmsContent.setIsStaging(false);
}
// 再次编辑时间
cmsContent.setGmtReedit(DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime()));
// 撤销
if (null != cmsContent.getIsPublished()) {
cmsContent.setIsStaging(cmsContent.getIsPublished());
} else {
cmsContent.setIsStaging(false);
}
count = cmsContentDao.updateCmsContent(cmsContent);
if (// 内容管理,退回发送消息
count > 0 && Const.CMS_AUTHOR_STATUS_1.shortValue() == cmsContent.getAuthStatus().shortValue()) {
// MongoDB 消息插入
String categoryName = "文章管理";
if (Const.CMS_CATEGORY_ID_2.longValue() == cmsContent.getCategoryId().longValue()) {
categoryName = "信息快报管理";
} else if (Const.CMS_CATEGORY_ID_3.longValue() == cmsContent.getCategoryId().longValue()) {
categoryName = "公告管理";
}
// 退回时发送消息内容
StringBuilder sb = new StringBuilder();
sb.append(categoryName);
sb.append("中您添加的《 ");
sb.append(cmsContent.getTitle());
sb.append(" 》已被退回 !");
if (StringUtil.notEmpty(cmsContent.getReturnReason())) {
sb.append("<br/><br/>退回理由为:");
sb.append(cmsContent.getReturnReason());
}
Message message = messageService.add(new Message(sb.toString()));
if (StringUtil.isEmpty(message.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
}
String returnContentTitle = "内容管理审核退回";
// 系统消息
List<UserMessage> userMessageList = new ArrayList<UserMessage>(4);
userMessageList.add(new UserMessage(message.getId(), returnContentTitle, Const.MSG_TYPE_1, pmphUser.getId(), Const.SENDER_TYPE_1, cmsContent.getAuthorId(), cmsContent.getAuthorType(), 0L));
// 发送消息
if (CollectionUtil.isNotEmpty(userMessageList)) {
// 插入消息发送对象数据
userMessageService.addUserMessageBatch(userMessageList);
// websocket发送的id集合
List<String> websocketUserIds = new ArrayList<String>();
for (UserMessage userMessage : userMessageList) {
websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
}
// webscokt发送消息
if (CollectionUtil.isNotEmpty(websocketUserIds)) {
WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, pmphUser.getId(), pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, returnContentTitle, message.getContent(), DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
}
}
}
// 当文章通过的时候给用户增加积分
if (Const.CMS_CATEGORY_ID_1.longValue() == cmsContent.getCategoryId().longValue() && Const.CMS_AUTHOR_STATUS_2.shortValue() == cmsContent.getAuthStatus().shortValue() && Const.CMS_AUTHOR_TYPE_2 == cmsContent.getAuthorType()) {
String ruleName = "发表文章";
writerPointLogService.addWriterPointLogByRuleName(ruleName, cmsContent.getAuthorId());
}
// 删除附件
if (ArrayUtil.isNotEmpty(attachment)) {
// 删除CmsExtra 表
cmsExtraService.deleteCmsExtraByAttachment(attachment);
// 删除MongoDB对应的文件
for (int i = 0; i < attachment.length; i++) {
fileService.remove(attachment[i]);
}
}
// 文章封面
if (ArrayUtil.isNotEmpty(imgAttachment)) {
// 删除CmsExtra 表
cmsExtraService.deleteCmsExtraByAttachment(imgAttachment);
// 删除MongoDB对应的文件
for (int i = 0; i < imgAttachment.length; i++) {
fileService.remove(imgAttachment[i]);
}
if (ArrayUtil.isEmpty(imgFile)) {
// 如果删除了封面没上传,就使用默认封面
this.updateCmsContent(new CmsContent(cmsContent.getId(), "DEFAULT"));
}
}
// 保存附件到MongoDB
this.saveFileToMongoDB(request, files, imgFile, cmsContent.getId());
return count;
}
use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.
the class UserMessageServiceImpl method addOrUpdateUserMessage.
@Override
public Integer addOrUpdateUserMessage(HttpServletRequest request, Message message, String title, Integer sendType, String orgIds, Long senderId, String userIds, String bookIds, boolean isSave, String[] files, String sessionId) throws CheckedServiceException, IOException {
if (ObjectUtil.isNull(sendType)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "发送对象未选择,请选择!");
}
if (title.length() > 50) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息标题不能超过50个字");
}
// 如果 补发不进行消息插入
if (isSave) {
// MongoDB 消息插入
message = messageService.add(message);
}
if (StringUtil.isEmpty(message.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
}
// 发送者id
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "操作人为空!");
}
// 是否为补发消息设置(发送者ID)
Long senderUserId;
if (ObjectUtil.isNull(senderId)) {
// 新发消息,发送者Id为登陆用户ID
senderUserId = pmphUser.getId();
} else {
// 补发消息,发送者Id为当前补发消息的发送者ID
senderUserId = senderId;
}
// 装储存数据
List<UserMessage> userMessageList = new ArrayList<UserMessage>();
// 1 发送给学校管理员 //2 所有人
if (Const.SEND_OBJECT_1.intValue() == sendType.intValue() || Const.SEND_OBJECT_2.intValue() == sendType.intValue()) {
if (StringUtil.isEmpty(orgIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "参数错误!");
}
String[] orgIds1 = StringUtil.str2StrArray(orgIds);
List<Long> orgIds2 = new ArrayList<Long>(orgIds1.length);
for (String id : orgIds1) {
if (StringUtil.notEmpty(id)) {
orgIds2.add(Long.parseLong(id));
}
}
List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(orgIds2);
// 机构用户
for (OrgUser orgUser : orgUserList) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, orgUser.getId(), Const.RECEIVER_TYPE_3, 0L));
}
// 作家用户
if (Const.SEND_OBJECT_2.intValue() == sendType.intValue()) {
List<WriterUser> writerUserList = writerUserService.getWriterUserListByOrgIds(orgIds2);
for (WriterUser writerUser : writerUserList) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 0L));
}
}
}
// 3 指定用户
if (Const.SEND_OBJECT_3.intValue() == sendType.intValue()) {
if (StringUtil.isEmpty(userIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "没有选中发送人!");
}
String[] ids = StringUtil.str2StrArray(userIds);
for (String id : ids) {
if (StringUtil.notEmpty(id)) {
String userType = id.split("_")[0];
String userId = id.split("_")[1];
if (StringUtil.notEmpty(userId) && StringUtil.isNumeric(userId)) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, Long.parseLong(userId), new Short(userType), 0L));
}
}
}
}
// 4 发送给教材所有报名者
if (Const.SEND_OBJECT_4.intValue() == sendType.intValue()) {
if (StringUtil.isEmpty(bookIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "书籍为空!");
}
String[] ids = StringUtil.str2StrArray(bookIds);
List<Long> userIdList = decPositionService.listDecPositionsByTextbookIds(ids);
for (Long userId : userIdList) {
userMessageList.add(new UserMessage(message.getId(), title, Const.MSG_TYPE_1, senderUserId, Const.SENDER_TYPE_1, userId, Const.RECEIVER_TYPE_2, 0L));
}
// 获取到书籍id然后根据书籍id在dec_position表中获取到申报表id根据申报表id在declaration表中获取作家id放入userMessage的接收人中
}
// 如果是补发,进入下面操作 进行已发人员筛出
if (!isSave) {
// 查询当前消息内容
Message msg = messageService.get(message.getId());
if (ObjectUtil.notNull(msg)) {
message.setContent(msg.getContent());
}
List<UserMessage> temp = new ArrayList<UserMessage>();
// 已经发送的人员列表
List<UserMessage> sendedList = userMessageDao.getMessageByMsgId(message.getId());
// 已发送消息是否撤回
Boolean isWithdraw = false;
for (UserMessage userMessage : userMessageList) {
// 没有发送
boolean flag = false;
for (UserMessage uMessage : sendedList) {
if (!isWithdraw) {
if (uMessage.getIsWithdraw()) {
// 判断消息是否撤回
isWithdraw = true;
}
}
if (userMessage.getReceiverId().longValue() == uMessage.getReceiverId().longValue() && userMessage.getReceiverType().shortValue() == uMessage.getReceiverType().shortValue()) {
flag = true;
break;
}
}
if (!flag) {
temp.add(userMessage);
}
}
userMessageList = temp;
// 补发,取消撤回当前已发送的消息
if (isWithdraw) {
this.updateCancelToWithdraw(message.getId());
}
}
// 插入消息发送对象数据
if (CollectionUtil.isNotEmpty(userMessageList)) {
userMessageDao.addUserMessageBatch(userMessageList);
}
// websocket发送的id集合
List<String> websocketUserIds = new ArrayList<String>();
for (UserMessage userMessage : userMessageList) {
websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
}
// webscokt发送消息
if (CollectionUtil.isNotEmpty(websocketUserIds)) {
WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, senderUserId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, title, message.getContent(), DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
// 添加附件到MongoDB表中
saveFileToMongoDB(request, files, message.getId());
}
return userMessageList.size();
}
use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.
the class UserMessageServiceImpl method addOneUserMessage.
@Override
public Integer addOneUserMessage(Message message, Long receiverId, String sessionId) throws CheckedServiceException, IOException {
// 发送者id
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "发送人为空!");
}
// MongoDB 消息插入
message = messageService.add(message);
if (StringUtil.isEmpty(message.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
}
// 新发消息,发送者Id为登陆用户ID
Long senderUserId = pmphUser.getId();
// 装储存数据
UserMessage userMessage = new UserMessage();
// 私信发送
if (null == receiverId) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "接收人为空!");
} else {
userMessage = new UserMessage(message.getId(), "系统消息", Const.MSG_TYPE_0, senderUserId, Const.SENDER_TYPE_1, receiverId, Const.RECEIVER_TYPE_2);
}
// 插入消息发送对象数据
Integer res = userMessageDao.addUserMessage(userMessage);
// websocket发送的id
List<String> websocketUserId = new ArrayList<String>();
websocketUserId.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
// webscokt发送消息
if (CollectionUtil.isNotEmpty(websocketUserId)) {
WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_0, senderUserId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, message.getContent(), DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(websocketUserId, webScocketMessage);
}
return res;
}
use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.
the class SystemMessageService method sendWhenInviteJoinGroup.
/**
* 任意用户被邀请进入小组 向被邀请人发出
*
* @author Mryang
* @createDate 2017年11月17日 下午2:16:36
* @param inviterName
* 邀请人名字
* @param groupId
* 小组id
* @param invitedPersonIds
* 被邀请人ids
* @param invitedPersonType
* 被邀请人类型: 1=社内用户/2=作家/3=机构用户
* @throws CheckedServiceException
* @throws IOException
*/
public void sendWhenInviteJoinGroup(String inviterName, Long groupId, List<Long> invitedPersonIds, short invitedPersonType) throws CheckedServiceException, IOException {
if (StringUtils.isEmpty(inviterName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "邀请人为空");
}
if (null == invitedPersonIds || invitedPersonIds.size() == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "被邀请人为空");
}
// 获取小组
PmphGroup pmphGroup = pmphGroupService.getPmphGroupById(groupId);
if (null == pmphGroup) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "小组不存在");
}
String msgContent = "您被[<font color='red'>" + inviterName + "</font>]邀请加入[<font color='red'>" + pmphGroup.getGroupName() + "]</font>小组";
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 组装消息和消息对象
List<UserMessage> userMessageList = new ArrayList<UserMessage>(invitedPersonIds.size());
List<String> userIds = new ArrayList<String>(invitedPersonIds.size());
for (Long id : invitedPersonIds) {
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), id, invitedPersonType, null);
userMessageList.add(userMessage);
userIds.add(invitedPersonType + "_" + id);
}
// 发送消息
userMessageService.addUserMessageBatch(userMessageList);
// websocket推送页面消息
WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
use of com.bc.pmpheep.websocket.WebScocketMessage in project pmph by BCSquad.
the class SystemMessageService method sendWhenTeacherCertificationAudit.
/**
* 教师认证审 向教师用户发送消息
*
* @author Mryang
* @createDate 2017年11月17日 下午2:52:53
* @param auditorOrgName
* 认证机构名称,如:首都医科大学,如是人卫社认证的审核,则为:人民卫生出版社
* @param teacherIds
* 教师ids
* @param isPass
* true 通过/false 退回
* @throws CheckedServiceException
* @throws IOException
*/
public void sendWhenTeacherCertificationAudit(String auditorOrgName, List<Long> teacherIds, boolean isPass) throws CheckedServiceException, IOException {
if (StringUtils.isEmpty(auditorOrgName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "审核机构为空");
}
if (null == teacherIds || teacherIds.size() == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "认证的教师为空");
}
// 存入消息主体
// 退回
String msgContent = "抱歉,您提交的教师认证资料已被[<font color='red'>" + auditorOrgName + "</font>]管理员退回,请您核对后重试";
if (isPass) {
// 通过
msgContent = "恭喜!您提交的教师认证资料已通过[<font color='red'>" + auditorOrgName + "</font>]管理员审核";
}
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 组装消息和消息对象
List<UserMessage> userMessageList = new ArrayList<UserMessage>(teacherIds.size());
List<String> userIds = new ArrayList<String>(teacherIds.size());
// 发送消息
for (Long id : teacherIds) {
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), id, new Short("2"), null);
userMessageList.add(userMessage);
userIds.add("2_" + id);
}
userMessageService.addUserMessageBatch(userMessageList);
// websocket推送页面消息
WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
Aggregations