use of com.bc.pmpheep.back.po.UserMessage in project pmph by BCSquad.
the class MigrationStageSeven method userMessage_messageAttachment.
public void userMessage_messageAttachment() {
// case WHEN e.sysflag=0 then 1 when e.sysflag=1 and e.usertype=2 then 3 else 2 end
String sql = "select " + "DISTINCT " + "a.msgid , " + "a.msgcontent , " + "case WHEN a.msgtype =12 then 1 else 0 end msgtype , " + "a.msgtitle title, " + "case WHEN a.msgtype =12 then d.new_pk else 0 end senderid , " + "case WHEN a.msgtype =12 and d.sysflag=0 then 1 when a.msgtype=12 and d.sysflag=1 and d.usertype=2 then 3 when a.msgtype=12 then 2 else 0 end sendertype , " + "ifnull(e.new_pk,f.new_pk) receiverid, " + "case WHEN e.new_pk is null then case WHEN f.sysflag=0 then 1 when f.sysflag=1 and f.usertype=2 then 3 else 2 end " + " else case WHEN e.sysflag=0 then 1 when e.sysflag=1 and e.usertype=2 then 3 else 2 end " + "end receivertype, " + "case WHEN e.new_pk is null then a.recivetype " + " else b.recivetype " + "end isread , " + "0 iswithdraw, " + "b.isdelete isdeleted, " + "b.senddate gt, " + "ifnull(b.recivedate,b.senddate) ut " + "from sys_messages a " + "LEFT JOIN sys_msgrecive b on b.msgid=a.msgid " + "LEFT JOIN (select a.userid,a.new_pk,a.sysflag,b.usertype from sys_user a left join sys_userext b on b.userid=a.userid ) d on d.userid =a.formuser " + "LEFT JOIN (select a.userid,a.new_pk,a.sysflag,b.usertype from sys_user a left join sys_userext b on b.userid=a.userid ) e on e.userid =b.touser " + "LEFT JOIN (select a.userid,a.new_pk,a.sysflag,b.usertype from sys_user a left join sys_userext b on b.userid=a.userid ) f on f.userid =a.touser ";
// String tableName="";
// JdbcHelper.addColumn(tableName); //增加new_pk字段
List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
List<Map<String, Object>> excel = new LinkedList<>();
Map<String, String> msgidOldAndNew = new HashMap<String, String>(maps.size());
Map<String, Object> result = new LinkedHashMap<>();
// 模块名称
excptionList.add(new Object[] { "消息" });
// 模块标题
excptionList.add(new Object[] { "消息标题", "问题", "原因分析", "处理方式" });
int excptionListOldSize = excptionList.size();
int count = 0;
int correctCount = 0;
int[] state = { 0, 0, 0, 0, 0, 0 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
for (Map<String, Object> map : maps) {
StringBuilder exception = new StringBuilder("");
// 先保存这条记录
String title = (String) map.get("title");
if (StringUtil.isEmpty(title)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("消息标题查询到为空值。"));
excptionList.add(new Object[] { "", "消息标题为空", "", "不导入该条数据" });
excel.add(map);
if (state[0] == 0) {
reason.append("查询不到对应的消息。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
Long senderid = (Long) map.get("senderid");
if (ObjectUtil.isNull(senderid)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("发送者id查询到为空值。"));
excptionList.add(new Object[] { title, "找不到对应的发送者", "清理了测试用户引起", "不导入该条数据" });
excel.add(map);
if (state[1] == 0) {
reason.append("找不到消息的发送者。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
}
Long receiverid = (Long) map.get("receiverid");
if (ObjectUtil.isNull(receiverid)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("接收者id查询到为空值。"));
excptionList.add(new Object[] { title, "找不到对应的接收者", "清理了测试用户引起", "不导入该条数据" });
excel.add(map);
if (state[2] == 0) {
reason.append("找不到消息的接收者。");
dealWith.append("放弃迁移。");
state[2] = 1;
}
continue;
}
Short msgtype = new Short(String.valueOf(map.get("msgtype")));
if (ObjectUtil.isNull(msgtype)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("消息类型查询到为空值。"));
excptionList.add(new Object[] { title, "找不到对应的消息类型", "原平台最开始没有分类消息", "设置为'系统消息'类型导入新库表" });
excel.add(map);
msgtype = 0;
if (state[3] == 0) {
reason.append("找不到消息的类型。");
dealWith.append("设为默认值迁入数据库。");
state[3] = 1;
}
}
Short sendertype = new Short(String.valueOf(map.get("sendertype")));
if (ObjectUtil.isNull(sendertype)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("发送者类型查询到为空值。"));
excptionList.add(new Object[] { title, "找不到对应的发送者类型", "", "设置为'系统消息'类型导入新库表" });
excel.add(map);
sendertype = 0;
if (state[4] == 0) {
reason.append("找不到发送者人员类型。");
dealWith.append("设为默认值迁入数据库。");
state[4] = 1;
}
}
Short receivertype = new Short(String.valueOf((map.get("receivertype"))));
if (ObjectUtil.isNull(receivertype)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("接收者类型查询到为空值。"));
excptionList.add(new Object[] { title, "找不到对应的接收者类型", "", "设置为'系统消息'类型导入新库表" });
excel.add(map);
receivertype = 0;
if (state[5] == 0) {
reason.append("找不到消息接收者的人员类型。");
dealWith.append("设为默认值迁入数据库。");
state[5] = 1;
}
}
Boolean isread = "1".equals(map.get("isread"));
Boolean iswithdraw = "1".equals(map.get("iswithdraw"));
Boolean isdeleted = "1".equals(map.get("isdeleted"));
Timestamp gt = (Timestamp) map.get("gt");
Timestamp ut = (Timestamp) map.get("ut");
UserMessage userMessage = new UserMessage("---------", title, msgtype, senderid, sendertype, receiverid, receivertype, isread, iswithdraw, isdeleted, gt, ut);
userMessage = userMessageSevice.addUserMessage(userMessage);
count++;
long pk = userMessage.getId();
if (count % 1000 == 0) {
// 打印进度
logger.info("执行了:" + (count * 100.0) / maps.size() + "%");
}
// 对html里面内置的图片处理
String msgid = String.valueOf(map.get("msgid"));
// MongoDB对应主键
String msg_id = msgidOldAndNew.get(msgid);
if (StringUtil.isEmpty(msg_id)) {
// 消息主体没有存入
String msgcontent = (String) map.get("msgcontent");
if (msgcontent.contains("img src=")) {
List<String> srcs = JdbcHelper.getImgSrc(msgcontent);
for (String src : srcs) {
try {
String mongoId = fileService.migrateFile(src.replace("/pmph_imesp", ""), FileType.MSG_IMG, pk);
msgcontent = msgcontent.replace(src, "/pmpheep/image/" + mongoId);
} catch (IOException ex) {
logger.warn("无法根据文章内容中的图片路径找到指定文件{}", ex.getMessage());
}
}
}
Message message = new Message(msgcontent);
message = messageService.add(message);
msg_id = message.getId();
msgidOldAndNew.put(msgid, msg_id);
// 附件处理
sql = "select c.* from sys_messages a " + "LEFT JOIN ( " + "sELECT * FROM pub_addfileinfo WHERE tablename ='SYS_MESSAGES' AND childsystemname='sysNotice' " + ")C ON C.tablekeyid = A.msgid where c.fileid is not null and a.msgid =?";
List<Map<String, Object>> message_attachments = JdbcHelper.getJdbcTemplate().queryForList(sql, new Object[] { msgid });
for (Map<String, Object> message_attachment : message_attachments) {
MessageAttachment messageAttachment = new MessageAttachment();
messageAttachment.setMsgId(msg_id);
messageAttachment.setAttachment("-----------");
messageAttachment.setAttachmentName((String) message_attachment.get("filename"));
messageAttachment = messageAttachmentService.addMessageAttachment(messageAttachment);
String mongoId = null;
try {
mongoId = fileService.migrateFile((String) message_attachment.get("fildir"), FileType.MSG_FILE, messageAttachment.getId());
} catch (Exception e) {
}
if (null != mongoId) {
messageAttachment.setAttachment(mongoId);
messageAttachmentService.updateMessageAttachment(messageAttachment);
}
}
}
userMessage.setMsgId(msg_id);
userMessageSevice.updateUserMessage(userMessage);
if (null == map.get("exception")) {
correctCount++;
}
}
// 没有错误数据
if (excptionList.size() == excptionListOldSize) {
excptionList.remove(excptionList.size() - 1);
excptionList.remove(excptionList.size() - 1);
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "消息-用户映射表(多对多)", "user_message");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != maps.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "user_message");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "消息-用户映射表(多对多)");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.size());
result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, maps.size() - count);
result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
SQLParameters.STATISTICS_RESULT.add(result);
}
logger.info("'{}'表迁移完成,异常条目数量:{}", "sys_messages", excel.size());
logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
// 记录信息
Map<String, Object> msg = new HashMap<>();
msg.put("result", "sys_messages 表迁移完成" + count + "/" + maps.size());
SQLParameters.STATISTICS.add(msg);
}
use of com.bc.pmpheep.back.po.UserMessage in project pmph by BCSquad.
the class UserMessageServiceTest method testUpdateUserMessage.
/*@Test
@Rollback(Const.ISROLLBACK)
public void testListMessageState(){
MessageStateVO messageStateVO = new MessageStateVO();
PageParameter pageParameter = new PageParameter<>();
PageResult pageResult = new PageResult<>();
pageParameter.setParameter(messageStateVO);
pageResult = userMessageService.listMessageState(pageParameter, "");
Assert.assertNotNull("查询成功了", pageResult);
}*/
@Test
@Rollback(Const.ISROLLBACK)
public void testUpdateUserMessage() {
Random random = new Random();
UserMessage userMessage = userMessageService.addUserMessage(new UserMessage(String.valueOf(random.nextInt(200)), "asdhga", (short) 1, Long.parseLong(String.valueOf(random.nextInt(200))), (short) 1, Long.parseLong(String.valueOf(random.nextInt(200))), (short) 1, true, true, true, null, null));
int num = -1;
num = userMessageService.updateUserMessage(userMessage);
Assert.assertTrue("修改成功", num >= 0);
}
use of com.bc.pmpheep.back.po.UserMessage 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.back.po.UserMessage in project pmph by BCSquad.
the class UserMessageServiceImpl method getUserMessageById.
@Override
public Map<String, Object> getUserMessageById(Long userMsgId) {
Map<String, Object> resultMap = new HashMap<String, Object>();
if (ObjectUtil.isNull(userMsgId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息ID为空!");
}
UserMessage userMessage = userMessageDao.getUserMessageById(userMsgId);
if (ObjectUtil.isNull(userMessage)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户消息对象为空!");
}
String realName = null;
if (Const.SENDER_TYPE_0 == userMessage.getSenderType() || Const.SENDER_TYPE_1 == userMessage.getSenderType()) {
PmphUser pmphUser = pmphUserService.get(userMessage.getSenderId());
realName = pmphUser.getRealname();
}
if (Const.SENDER_TYPE_2 == userMessage.getSenderType()) {
WriterUser writerUser = writerUserService.get(userMessage.getSenderId());
realName = writerUser.getRealname();
}
if (Const.SENDER_TYPE_3 == userMessage.getSenderType()) {
OrgUser orgUser = orgUserService.getOrgUserById(userMessage.getSenderId());
realName = orgUser.getRealname();
}
// 主键ID
resultMap.put("msgId", userMessage.getId());
// 标题
resultMap.put("title", userMessage.getTitle());
// 发送者
resultMap.put("senderName", realName);
// 发送时间
resultMap.put("senderDate", userMessage.getGmtCreate());
// 获取消息内容
Message message = messageService.get(userMessage.getMsgId());
if (ObjectUtil.notNull(message)) {
// throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE,
// CheckedExceptionResult.NULL_PARAM, "消息对象为空!");
// 内容
resultMap.put("content", message.getContent());
List<MessageAttachment> messageAttachments = messageAttachmentService.getMessageAttachmentByMsgId(message.getId());
if (CollectionUtil.isNotEmpty(messageAttachments)) {
for (MessageAttachment mAttachment : messageAttachments) {
String attachmentId = mAttachment.getAttachment();
mAttachment.setAttachment(Const.FILE_DOWNLOAD + attachmentId);
}
}
// 内容附件
resultMap.put("MessageAttachment", messageAttachments);
}
return resultMap;
}
use of com.bc.pmpheep.back.po.UserMessage 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();
}
Aggregations