use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.
the class SystemMessageService method sendWhenQuitGroup.
/**
* 任意用户退出小组 给小组创建者和管理员发送消息
*
* @author Mryang
* @createDate 2017年11月17日 下午2:41:26
* @param exitPersonName
* 退出人姓名
* @param groupId
* 退出的小组id
* @throws CheckedServiceException
* @throws IOException
*/
public void sendWhenQuitGroup(String exitPersonName, Long groupId) throws CheckedServiceException, IOException {
if (StringUtils.isEmpty(exitPersonName)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "退出人为空");
}
// 获取小组
PmphGroup pmphGroup = pmphGroupService.getPmphGroupById(groupId);
if (null == pmphGroup) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "小组不存在");
}
List<PmphGroupMemberVO> PmphGroupMemberVOList = pmphGroupMemberService.listPmphGroupMember(groupId, null);
if (null == PmphGroupMemberVOList || PmphGroupMemberVOList.size() == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "小组没有成员");
}
// 存入消息主体
String msgContent = "[<font color='red'>" + exitPersonName + "</font>]退出了[" + pmphGroup.getGroupName() + "]小组";
Message message = new Message(msgContent);
message = messageService.add(message);
String msg_id = message.getId();
// 组装消息和消息对象
List<UserMessage> userMessageList = new ArrayList<UserMessage>(PmphGroupMemberVOList.size());
List<String> userIds = new ArrayList<String>(PmphGroupMemberVOList.size());
for (PmphGroupMemberVO pmphGroupMemberVO : PmphGroupMemberVOList) {
if (pmphGroupMemberVO.getIsFounder() || pmphGroupMemberVO.getIsAdmin()) {
// 给创建者和管理员发送
UserMessage userMessage = new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), pmphGroupMemberVO.getUserId(), pmphGroupMemberVO.getUserType(), null);
userMessageList.add(userMessage);
userIds.add(pmphGroupMemberVO.getUserType() + "_" + pmphGroupMemberVO.getUserId());
}
}
// 发送消息
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.back.vo.PmphGroupMemberVO in project pmph by BCSquad.
the class PmphGroupMessageServiceImpl method addGroupMessage.
@Override
public String addGroupMessage(String msgConrent, Long groupId, String sessionId, Short senderType) throws CheckedServiceException, IOException {
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
Long userId = pmphUser.getId();
PmphGroupMemberVO pmphGroupMemberVO = pmphGroupMemberService.getPmphGroupMemberByMemberId(groupId, userId, // 获取后台用户
false);
if (ObjectUtil.isNull(pmphGroupMemberVO)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "您不是该小组成员,无法与其他成员对话或上传小组文件。");
}
PmphGroupMessage pmphGroupMessage;
if (senderType == 0) {
pmphGroupMessage = new PmphGroupMessage(groupId, 0L, msgConrent);
} else {
pmphGroupMessage = new PmphGroupMessage(groupId, pmphGroupMemberVO.getId(), msgConrent);
}
pmphGroupMessageDao.addPmphGroupMessage(pmphGroupMessage);
pmphGroupMessage = pmphGroupMessageDao.getPmphGroupMessageById(pmphGroupMessage.getId());
// 将该条消息创建时间作为最后一条消息时间放入该小组中
PmphGroup pmphGroup = new PmphGroup();
pmphGroup.setId(groupId);
pmphGroup.setGmtLastMessage(pmphGroupMessage.getGmtCreate());
pmphGroupDao.updatePmphGroup(pmphGroup);
// 进行推送消息步骤1.查询接收人的id 2.进行推送
List<PmphGroupMemberVO> list = pmphGroupMemberService.listPmphGroupMember(groupId, sessionId);
List<String> ids = new ArrayList<String>();
for (PmphGroupMemberVO groupMemberVO : list) {
String tempId = (groupMemberVO.getIsWriter() ? "2" : "1") + "_" + groupMemberVO.getUserId();
ids.add(tempId);
}
WebScocketMessage webScocketMessage = new WebScocketMessage(String.valueOf(pmphGroupMessage.getId()), Const.MSG_TYPE_3, userId, pmphGroupMemberVO.getDisplayName(), senderType, Const.SEND_MSG_TYPE_0, null, null, msgConrent, pmphGroupMessage.getGmtCreate());
webScocketMessage.setGroupId(groupId);
webScocketMessage.setSenderIcon(pmphGroupMemberVO.getAvatar());
handler.sendWebSocketMessageToUser(ids, webScocketMessage);
return "SUCCESS";
}
use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.
the class PmphGroupServiceImpl method listPmphGroup.
/**
* @introduction 根据小组名称模糊查询获取当前用户的小组
* @author Mryang
* @createDate 2017年9月20日 下午4:45:48
* @param pmphGroup
* @return List<PmphGroupListVO>
* @throws CheckedServiceException
*/
@Override
public List<PmphGroupListVO> listPmphGroup(PmphGroup pmphGroup, String sessionId) throws CheckedServiceException {
if (null == pmphGroup) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "参数对象为空");
}
// session PmphUser用户验证
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
List<PmphGroupListVO> list = new ArrayList<>();
if (pmphUser.getIsAdmin()) {
list = pmphGroupDao.listPmphGroup(pmphGroup.getGroupName());
for (PmphGroupListVO pmphGroupListVO : list) {
pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
}
} else {
list = pmphGroupDao.getList(pmphGroup, pmphUser.getId());
for (PmphGroupListVO pmphGroupListVO : list) {
pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
}
}
for (PmphGroupListVO pmphGroupListVO : list) {
PmphGroupMemberVO user = pmphGroupMemberService.getPmphGroupMemberByMemberId(pmphGroupListVO.getId(), pmphUser.getId(), false);
if (ObjectUtil.isNull(user)) {
pmphGroupListVO.setIsMember(false);
} else {
pmphGroupListVO.setIsMember(true);
}
}
return list;
}
use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.
the class PmphGroupFileServiceImpl method deletePmphGroupFileById.
/**
* @param id
* 主键id
* @return 影响行数
* @throws CheckedServiceException
*/
@Override
public String deletePmphGroupFileById(Long groupId, Long[] ids, String sessionId) throws CheckedServiceException {
String result = "FAIL";
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
}
Long userId = pmphUser.getId();
PmphGroupMemberVO currentUser = new PmphGroupMemberVO();
if (ObjectUtil.isNull(ids) || ids.length == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "主键为空");
} else {
if (!pmphUser.getIsAdmin()) {
currentUser = pmphGroupMemberService.getPmphGroupMemberByMemberId(groupId, userId, false);
}
for (Long id : ids) {
Long uploaderId = pmphGroupFileDao.getPmphGroupFileById(id).getMemberId();
if (pmphUser.getIsAdmin() || uploaderId.equals(currentUser.getId()) || currentUser.getIsFounder() || currentUser.getIsAdmin()) {
// 超级管理员、小组创建者、小组管理者、文件上传人才可以删除文件
PmphGroupFile pmphGroupFile = pmphGroupFileDao.getPmphGroupFileById(id);
Integer num = pmphGroupFileDao.getPmphGroupFileTotalByFileId(pmphGroupFile.getFileId());
if (1 == num) {
fileService.remove(pmphGroupFile.getFileId());
}
pmphGroupFileDao.deletePmphGroupFileById(id);
} else {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
}
}
result = "SUCCESS";
}
return result;
}
use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.
the class PmphGroupMemberServiceImpl method updateGroupMemberByIds.
@Override
public String updateGroupMemberByIds(Long groupId, Long[] ids, String sessionId) throws CheckedServiceException {
String result = "FAIL";
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (null == pmphUser || null == pmphUser.getId()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "该用户为空");
}
if (!pmphUser.getIsAdmin()) {
if (!isFounderOrisAdmin(groupId, sessionId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有操作权限");
}
}
Long userid = pmphUser.getId();
PmphGroupMemberVO currentUser = pmphGroupMemberDao.getPmphGroupMemberByMemberId(groupId, userid, false);
if (null == ids || ids.length == 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "主键不能为空");
} else {
for (Long id : ids) {
PmphGroupMember pmphGroupMember = pmphGroupMemberDao.getPmphGroupMemberById(id);
// }
if (pmphUser.getIsAdmin() || currentUser.getIsFounder()) {
// 只有小组创建者和超级管理员可以删除小组成员
if (pmphGroupMemberDao.getPmphGroupMemberById(id).getIsFounder()) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "小组创建者不能删除,请重新选择");
}
pmphGroupMemberDao.updateGroupMemberById(id);
} else {
// 管理员进入的方法
if (currentUser.getIsAdmin() && (pmphGroupMember.getIsFounder() || pmphGroupMember.getIsAdmin())) {
throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "您无权限删除管理员,请重新选择");
} else {
pmphGroupMemberDao.updateGroupMemberById(id);
}
}
}
result = "SUCCESS";
}
return result;
}
Aggregations