use of com.bc.pmpheep.back.po.OrgUser 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.back.po.OrgUser in project pmph by BCSquad.
the class WriterUserCertificationServiceImpl method updateWriterUserCertificationProgressByUserId.
@Override
public Integer updateWriterUserCertificationProgressByUserId(Short progress, Long[] userIds, HttpServletRequest request) throws CheckedServiceException, Exception {
String sessionId = CookiesUtil.getSessionId(request);
PmphUser pmphuser = SessionUtil.getPmphUserBySessionId(sessionId);
List<WriterUserCertification> writerUserCertifications = this.getWriterUserCertificationByUserIds(userIds);
if (ObjectUtil.isNull(progress)) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEACHER_CHECK, CheckedExceptionResult.NULL_PARAM, "参数为空");
}
Integer count = 0;
List<WriterUserCertification> wUserCertifications = new ArrayList<WriterUserCertification>(writerUserCertifications.size());
List<WriterUser> writerUsers = new ArrayList<>();
for (WriterUserCertification writerUserCertification : writerUserCertifications) {
if (Const.WRITER_PROGRESS_0 == writerUserCertification.getProgress()) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户信息未提交,不能审核");
}
if (Const.WRITER_PROGRESS_2 == writerUserCertification.getProgress() || Const.WRITER_PROGRESS_3 == writerUserCertification.getProgress()) {
throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "已审核的用户不能再次审核");
}
wUserCertifications.add(new WriterUserCertification(writerUserCertification.getUserId(), progress));
writerUsers.add(new WriterUser(writerUserCertification.getUserId()));
}
if (CollectionUtil.isNotEmpty(wUserCertifications)) {
// 教师审核通过的同时修改普通用户级别为教师
count = writerUserCertificationDao.updateWriterUserCertificationProgressByUserId(wUserCertifications);
List<WriterUser> list = writerUserService.getWriterUserRankList(writerUsers);
for (WriterUser writerUser : list) {
// 当级别为0并且是通过的时候修改
if (0 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setRank(1);
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为0并且是退回的时候修改
} else if (0 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
// 当级别为1并且是通过的时候修改
} else if (1 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为1并且是退回的时候修改
} else if (1 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
// 当级别为2并且是通过的时候修改
} else if (2 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为2并且是退回的时候修改
} else if (2 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
// 当级别为3并且是通过的时候修改
} else if (3 == writerUser.getRank() && 3 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(true);
writerUserService.updateWriterUserRank(wrs);
}
// 当级别为2并且是退回的时候修改
} else if (3 == writerUser.getRank() && 2 == progress.intValue()) {
for (WriterUser wrs : writerUsers) {
wrs.setAuthUserType(1);
wrs.setAuthUserId(pmphuser.getId());
wrs.setIsTeacher(false);
writerUserService.updateWriterUser(wrs);
}
}
}
}
// 认证通过或退回的推送消息
Boolean isPass = null;
if (2 == progress) {
isPass = false;
}
if (3 == progress) {
isPass = true;
}
if (null != isPass) {
List<Long> teacherIds = new ArrayList<>();
for (int i = 0; i < userIds.length; i++) {
teacherIds.add(userIds[0]);
}
// 获取用户认证类型和认证人
List<WriterUser> users = writerUserService.getWriterUserList(userIds);
for (WriterUser writerUser : users) {
if (1 == writerUser.getAuthUserType()) {
// 社内用户
PmphUser pmphUser = pmphUserService.get(writerUser.getAuthUserId());
systemMessageService.sendWhenTeacherCertificationAudit(pmphUser.getRealname(), teacherIds, isPass);
}
if (2 == writerUser.getAuthUserType()) {
// 学校机构用户
OrgUser orgUsers = orgUserService.getOrgUserById(writerUser.getAuthUserId());
Org org = orgService.getOrgById(orgUsers.getOrgId());
systemMessageService.sendWhenTeacherCertificationAudit(org.getOrgName(), teacherIds, isPass);
}
}
}
return count;
}
use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class SystemMessageService method sendWhenPubfinalResult.
/**
* 某一本书的最终结果公布 或者 整套教材全部公布时 向当选者和学校管理员发送消息
*
* @author Mryang
* @createDate 2017年11月19日 上午11:24:31
* @param textBookId
* @throws CheckedServiceException
* @throws IOException
*/
public void sendWhenPubfinalResult(Long textBookId, List<DecPositionPublished> decPositionPublishedLst) throws CheckedServiceException, IOException {
Textbook textbook = textbookService.getTextbookById(textBookId);
Material material = materialService.getMaterialById(textbook.getMaterialId());
// 给主编、副主编、编委、数字编委发送
String msg = "";
for (DecPositionPublished decPosition : decPositionPublishedLst) {
if (null != decPosition.getChosenPosition()) {
if (decPosition.getChosenPosition() == 8) {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的数字编委";
}
if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
if (null != decPosition.getRank() && decPosition.getRank() == 1) {
if (decPosition.getChosenPosition() == 4) {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的第一主编";
} else {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的第一主编、数字编委";
}
} else {
if (decPosition.getChosenPosition() == 4) {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的主编";
} else {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的主编、数字编委";
}
}
}
if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
if (decPosition.getChosenPosition() == 2) {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的副主编";
} else {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的副主编、数字编委";
}
}
if (decPosition.getChosenPosition() == 1 || 9 == decPosition.getChosenPosition()) {
if (decPosition.getChosenPosition() == 1) {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的编委";
} else {
msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的编委、数字编委";
}
}
// 获取申报表
Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
// 存入消息主体
Message message = new Message(msg);
message = messageService.add(message);
String msg_id = message.getId();
// 发送消息给申报者
userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), declaration.getUserId(), new Short("2"), null));
// 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, msg, DateUtil.getCurrentTime());
List<String> userIds = new ArrayList<String>(1);
userIds.add("2_" + declaration.getUserId());
myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
}
// 给学校管理员发送消息
if (material.getIsAllTextbookPublished()) {
// 所有都发布了
String orgMsg = "《<font color='red'>" + material.getMaterialName() + "</font>》的编写团队遴选已结束,贵校共[{sum}]位老师当选,名单如下:";
// 根据教材Id查询对应的书籍集合
List<Textbook> textbooks = textbookService.getTextbookByMaterialId(material.getId());
List<Long> bookIds = new ArrayList<Long>();
for (Textbook book : textbooks) {
bookIds.add(book.getId());
}
// 根据书籍获取当选了该书籍的人员所属机构
List<Org> orgs = orgService.listBeElectedOrgByBookIds(bookIds);
for (Org org : orgs) {
// 根据orgid和bookid获取该机构某些已公布的书的申报职位
List<DecPosition> decPositions = decPositionService.listDecPositionsByTextbookIdAndOrgid(bookIds, org.getId());
if (null != decPositions && decPositions.size() > 0) {
String msgContent = orgMsg;
int sum = 0;
for (int i = 0; i < decPositions.size(); i++) {
DecPosition decPosition = decPositions.get(i);
Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
msgContent += "</br>" + "[<font color='red'>" + declaration.getRealname() + "</font>]";
msgContent += " - " + textbookService.getTextbookById(decPosition.getTextbookId()).getTextbookName() + " - ";
if (null != decPosition.getChosenPosition()) {
if (decPosition.getChosenPosition() == 8) {
msgContent += "数字编委";
}
if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
if (decPosition.getRank() == 1) {
if (decPosition.getChosenPosition() == 4) {
msgContent += "第一主编";
} else {
msgContent += "第一主编、数字编委";
}
} else {
if (decPosition.getChosenPosition() == 4) {
msgContent += "主编";
} else {
msgContent += "主编、数字编委";
}
}
}
if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
if (decPosition.getChosenPosition() == 2) {
msgContent += "副主编";
} else {
msgContent += "副主编、数字编委";
}
}
if (decPosition.getChosenPosition() == 1 || decPosition.getChosenPosition() == 9) {
if (decPosition.getChosenPosition() == 1) {
msgContent += "编委";
} else {
msgContent += "编委、数字编委";
}
}
}
sum++;
}
msgContent.replace("{sum}", String.valueOf(sum));
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 获取机构管理员
OrgUser orgUser = orgUserService.getOrgUserByOrgId(org.getId());
// 发送消息给申报者
userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null));
// 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());
List<String> userIds = new ArrayList<String>(1);
userIds.add("3_" + orgUser.getId());
myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
}
// 《全国高等学校五年制临床医学专业第九轮规划教材》的编写团队遴选已结束,贵校共[5]位老师当选,名单如下:
// [丁志国] - 局部解剖学 - 第一主编
// [王海滨] - 医学影像学 - 第二主编
// [雷国华] - 医学计算机应用 - 副主编
// [孙风梅] - 医学文献检索与论文写作 - 编委
// [宋守君] - 医患沟通 - 编委
} else {
String orgMsg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,贵校老师";
// 《全国高等学校五年制临床医学专业第九轮规划教材》[传染病学]的最终结果已公布,贵校老师[丁志国]当选第一主编,[丁志国]当选第一主编,[丁志国]当选第一主编
// 先要将学校分队
List<Long> bookIds = new ArrayList<Long>();
bookIds.add(textBookId);
// 根据教材Id查询对应的书籍集合
List<Org> orgs = orgService.listBeElectedOrgByBookIds(bookIds);
for (Org org : orgs) {
// 根据orgid和bookid获取该机构某些已公布的书的申报职位
List<DecPosition> decPositions = decPositionService.listDecPositionsByTextbookIdAndOrgid(bookIds, org.getId());
if (null != decPositions && decPositions.size() > 0) {
// 拼装消息
String msgContent = orgMsg;
for (int i = 0; i < decPositions.size(); i++) {
DecPosition decPosition = decPositions.get(i);
Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
if (i > 0) {
msgContent += ",";
}
msgContent += "[<font color='red'>" + declaration.getRealname() + "</font>]当选";
if (null != decPosition.getChosenPosition()) {
if (decPosition.getChosenPosition() == 8) {
msgContent += "数字编委";
}
if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
if (decPosition.getRank() == 1) {
if (decPosition.getChosenPosition() == 4) {
msgContent += "第一主编";
} else {
msgContent += "第一主编、数字编委";
}
} else {
if (decPosition.getChosenPosition() == 4) {
msgContent += "主编";
} else {
msgContent += "主编、数字编委";
}
}
}
if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
if (decPosition.getChosenPosition() == 2) {
msgContent += "副主编";
} else {
msgContent += "副主编、数字编委";
}
}
if (decPosition.getChosenPosition() == 1 || decPosition.getChosenPosition() == 9) {
if (decPosition.getChosenPosition() == 1) {
msgContent += "编委";
} else {
msgContent += "编委、数字编委";
}
}
}
}
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 获取机构管理员
OrgUser orgUser = orgUserService.getOrgUserByOrgId(org.getId());
// 发送消息给申报者
userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null));
// 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());
List<String> userIds = new ArrayList<String>(1);
userIds.add("3_" + orgUser.getId());
myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
}
}
}
}
use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class SurveyTargetServiceImpl method batchSaveSurveyTargetByList.
@Override
public Integer batchSaveSurveyTargetByList(Message message, SurveyTargetVO surveyTargetVO, String sessionId) throws Exception {
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
if (ObjectUtil.isNull(surveyTargetVO.getSurveyId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷表Id为空");
}
if (CollectionUtil.isEmpty(surveyTargetVO.getOrgIds())) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "学校Id为空");
}
if (StringUtil.isEmpty(surveyTargetVO.getStartTime())) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷开始时间为空");
}
if (StringUtil.isEmpty(surveyTargetVO.getEndTime())) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷结束时间为空");
}
Timestamp statTime = DateUtil.str2Timestam(surveyTargetVO.getStartTime());
Timestamp endTime = DateUtil.str2Timestam(surveyTargetVO.getEndTime());
if (statTime.getTime() > DateUtil.getCurrentTimeByYMD().getTime()) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷开始时间不能大于今天");
}
if (endTime.getTime() < DateUtil.getCurrentTimeByYMD().getTime()) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷结束时间不能小于今天");
}
if (statTime.getTime() > endTime.getTime()) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.ILLEGAL_PARAM, "开始日期不能大于结束日期");
}
List<Long> orgIds = this.listOrgIdBySurveyId(surveyTargetVO.getSurveyId());
Integer count = 0;
// 当前用户
Long userId = pmphUser.getId();
List<Long> listOrgId = new ArrayList<Long>();
if (CollectionUtil.isEmpty(orgIds)) {
// 第一次发布
listOrgId.addAll(surveyTargetVO.getOrgIds());
surveyService.updateSurvey(new Survey(surveyTargetVO.getSurveyId(), Const.SURVEY_STATUS_1, DateUtil.str2Timestam(surveyTargetVO.getStartTime()), DateUtil.str2Timestam(surveyTargetVO.getEndTime())));
} else {
// 第二次发布
for (Long id : surveyTargetVO.getOrgIds()) {
if (!orgIds.contains(id)) {
listOrgId.add(id);
}
}
}
List<SurveyTarget> list = new ArrayList<SurveyTarget>(listOrgId.size());
for (Long orgId : listOrgId) {
list.add(new SurveyTarget(userId, surveyTargetVO.getSurveyId(), orgId));
}
if (CollectionUtil.isNotEmpty(list)) {
// 保存发起问卷中间表
count = surveyTargetDao.batchSaveSurveyTargetByList(list);
}
if (count > 0) {
// MongoDB 消息插入
message = messageService.add(message);
if (StringUtil.isEmpty(message.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
}
// 发送消息
List<WriterUser> writerUserList = // 作家用户
writerUserService.getWriterUserListByOrgIds(listOrgId);
// 系统消息
List<UserMessage> userMessageList = new ArrayList<UserMessage>(writerUserList.size());
for (WriterUser writerUser : writerUserList) {
userMessageList.add(new UserMessage(message.getId(), surveyTargetVO.getTitle(), Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 0L));
}
// 获取学校管理员集合
List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(listOrgId);
// 收件人邮箱
List<String> orgUserEmail = new ArrayList<String>(orgUserList.size());
for (OrgUser orgUser : orgUserList) {
userMessageList.add(new UserMessage(message.getId(), surveyTargetVO.getTitle(), Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, orgUser.getId(), Const.RECEIVER_TYPE_3, 0L));
if (!"-".equals(orgUser.getEmail()) && !"null".equals(orgUser.getEmail())) {
// orgUserEmail.add(orgUser.getEmail());// 获取学校管理员邮箱地址
}
}
// Integer size = orgUserEmail.size();
String[] emails = new String[] { "515944204@qq.com", "2310870657@qq.com", "501331000@qq.com" };
// String[] toEmail = (String[]) orgUserEmail.toArray(new String[size]);
if (ArrayUtil.isEmpty(emails)) {
throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "收件人邮箱为空");
}
// 发送邮件
JavaMailSenderUtil javaMailSenderUtil = new JavaMailSenderUtil();
String serverUrl = getLogin2frontUrl().substring(0, getLogin2frontUrl().lastIndexOf("/"));
// 给学校管理员发送邮件
javaMailSenderUtil.sendMail(surveyTargetVO.getTitle(), // message.getContent(),
"<p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'>您好:</span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'> 现有一份《" + surveyTargetVO.getTitle() + "》需要您登陆下面地址,填写您宝贵意见。</span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-align: left;'><span style='font-family: 黑体, SimHei;'> 登陆地址:<a href='" + serverUrl + "/survey/writeSurvey.action?surveyId=" + surveyTargetVO.getSurveyId() + "'>人卫E教平台</a><br/></span></p><p style='margin: 5px 0px; color: rgb(0, 0, 0); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;'><br/></p>", emails);
// 发送消息
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, userId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, surveyTargetVO.getTitle(), message.getContent(), DateUtil.getCurrentTime());
myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
}
}
}
return count;
}
use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class SystemMessageService method sendWhenSubmitDeclarationForm.
/**
* 作家教材申报表 给学校管理员发送或者人卫教材相关人员发送消息
*
* @author Mryang
* @createDate 2017年11月17日 下午4:31:19
* @param declarationId
* 申报id
* @throws CheckedServiceException
* @throws IOException
*/
public void sendWhenSubmitDeclarationForm(Long declarationId) throws CheckedServiceException, IOException {
// 获取申报表
Declaration declaration = declarationService.getDeclarationById(declarationId);
if (null == declaration) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "申报表不存在");
}
if (null == declaration.getOrgId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "认证的管理员为空");
}
Material material = materialService.getMaterialById(declaration.getMaterialId());
if (declaration.getOrgId() == 0) {
// 提交的人卫社
// 项目编辑 策划编辑 主任 id
String msgContent = "[<font color='red'>" + declaration.getRealname() + "</font>]提交了《<font color='red'>" + material.getMaterialName() + "</font>》申报表,请及时进行资料审核";
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 主任id
Long directorId = material.getDirector();
// 项目编辑列表
List<MaterialProjectEditorVO> materialProjectEditorList = materialProjectEditorService.listMaterialProjectEditors(material.getId());
// 批量保存的消息集合
List<UserMessage> userMessageList = new ArrayList<UserMessage>(materialProjectEditorList.size() + 1);
List<String> userIds = new ArrayList<String>(materialProjectEditorList.size() + 1);
userMessageList.add(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), directorId, new Short("1"), null));
userIds.add("1_" + directorId);
for (MaterialProjectEditorVO materialProjectEditor : materialProjectEditorList) {
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), materialProjectEditor.getEditorId(), new Short("1"), null);
userMessageList.add(userMessage);
userIds.add("1_" + materialProjectEditor.getEditorId());
}
// 策划编辑
// 我申报的书籍
List<DecPosition> decPositionList = decPositionService.listDecPositions(declarationId);
for (DecPosition decPosition : decPositionList) {
Textbook textbook = textbookService.getTextbookById(decPosition.getTextbookId());
if (null != textbook && null != textbook.getPlanningEditor()) {
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), textbook.getPlanningEditor(), new Short("1"), null);
userMessageList.add(userMessage);
userIds.add("1_" + textbook.getPlanningEditor());
}
}
// 发送消息
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);
} else {
// 提交的机构
String msgContent = "贵校老师[<font color='red'>" + declaration.getRealname() + "</font>]提交了《<font color='red'>" + material.getMaterialName() + "</font>》申报表,请及时进行资料审核、打印并快递申报纸质表";
// 存入消息主体
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 获取机构用户
List<Long> orgIds = new ArrayList<Long>(1);
orgIds.add(declaration.getOrgId());
List<OrgUser> orgUserList = orgUserService.getOrgUserListByOrgIds(orgIds);
List<UserMessage> userMessageList = new ArrayList<UserMessage>(orgUserList.size());
List<String> userIds = new ArrayList<String>(orgUserList.size());
for (OrgUser orgUser : orgUserList) {
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null);
userMessageList.add(userMessage);
userIds.add("3_" + orgUser.getId());
}
// 发送消息
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