use of com.bc.pmpheep.back.po.PmphUser 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.PmphUser in project pmph by BCSquad.
the class UserMessageServiceImpl method listMyMessageOfIcon.
@Override
public PageResult<MyMessageVO> listMyMessageOfIcon(PageParameter<MyMessageVO> pageParameter) throws CheckedServiceException {
if (ObjectUtil.isNull(pageParameter.getParameter().getUserId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户id为空!");
}
if (ObjectUtil.isNull(pageParameter.getParameter().getUserType())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户类型为空!");
}
PageResult<MyMessageVO> pageResult = new PageResult<MyMessageVO>();
Integer total = userMessageDao.listMyMessageTotal(pageParameter);
PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
if (total > 0) {
List<MyMessageVO> list = userMessageDao.listMyMessage(pageParameter);
for (MyMessageVO myMessageVO : list) {
switch(myMessageVO.getSenderType()) {
case 0:
myMessageVO.setSenderName("系统");
break;
case 1:
PmphUser pmphUser = pmphUserService.get(myMessageVO.getSenderId());
myMessageVO.setSenderAvatar(pmphUser.getAvatar());
myMessageVO.setSenderName(pmphUser.getRealname());
break;
case 2:
WriterUser writerUser = writerUserService.get(myMessageVO.getSenderId());
myMessageVO.setSenderAvatar(writerUser.getAvatar());
myMessageVO.setSenderName(writerUser.getRealname());
break;
case 3:
// 现在没有机构用户
break;
default:
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "发送者类型不正确!");
}
Message message = messageService.get(myMessageVO.getMsgId());
if (ObjectUtil.isNull(message)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "没有获取到内容!");
}
myMessageVO.setContent(message.getContent());
}
pageResult.setRows(list);
}
pageResult.setTotal(total);
return pageResult;
}
use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.
the class UserMessageServiceImpl method listMyMessage.
@Override
public PageResult<MyMessageVO> listMyMessage(PageParameter<MyMessageVO> pageParameter) throws CheckedServiceException {
if (ObjectUtil.isNull(pageParameter.getParameter().getUserId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户id为空!");
}
if (ObjectUtil.isNull(pageParameter.getParameter().getUserType())) {
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户类型为空!");
}
PageResult<MyMessageVO> pageResult = new PageResult<MyMessageVO>();
Integer total = userMessageDao.listMyMessageTotal(pageParameter);
PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
if (total > 0) {
List<MyMessageVO> list = userMessageDao.listMyMessage(pageParameter);
for (MyMessageVO myMessageVO : list) {
switch(myMessageVO.getSenderType()) {
case 0:
myMessageVO.setSenderName("系统");
break;
case 1:
PmphUser pmphUser = pmphUserService.get(myMessageVO.getSenderId());
myMessageVO.setSenderAvatar(pmphUser.getAvatar());
myMessageVO.setSenderName(pmphUser.getRealname());
break;
case 2:
WriterUser writerUser = writerUserService.get(myMessageVO.getSenderId());
myMessageVO.setSenderAvatar(writerUser.getAvatar());
myMessageVO.setSenderName(writerUser.getRealname());
break;
case 3:
// 现在没有机构用户
break;
default:
throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "发送者类型不正确!");
}
}
pageResult.setRows(list);
}
pageResult.setTotal(total);
return pageResult;
}
use of com.bc.pmpheep.back.po.PmphUser 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.back.po.PmphUser 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;
}
Aggregations