Search in sources :

Example 11 with PmphGroup

use of com.bc.pmpheep.back.po.PmphGroup in project pmph by BCSquad.

the class WriterUserServiceImpl method getListWriterUser.

/**
 * 功能描述:分页查询作家用户
 *
 * @param page
 *            传入的查询数据
 * @return 需要的Page对象
 */
@Override
public PageResult<WriterUserManagerVO> getListWriterUser(PageParameter<WriterUserManagerVO> pageParameter, Long groupId) throws CheckedServiceException {
    String name = pageParameter.getParameter().getName();
    if (StringUtil.notEmpty(name)) {
        pageParameter.getParameter().setName(name);
    }
    String orgName = pageParameter.getParameter().getOrgName();
    if (StringUtil.notEmpty(orgName)) {
        pageParameter.getParameter().setOrgName(orgName);
    }
    PageResult<WriterUserManagerVO> pageResult = new PageResult<>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    // 当rank为1的时候 查询教师用户
    int total = 0;
    if (pageParameter.getParameter().getRank() == null || pageParameter.getParameter().getRank() != 1) {
        // 当rank不为1的时候
        total = writerUserDao.getListWriterUserTotal(pageParameter);
        if (total > 0) {
            List<WriterUserManagerVO> list = writerUserDao.getListWriterUser(pageParameter);
            for (WriterUserManagerVO vo : list) {
                switch(vo.getRank()) {
                    case 0:
                        vo.setRankName("普通用户");
                        break;
                    case 1:
                        vo.setRankName("教师用户");
                        break;
                    case 2:
                        vo.setRankName("作家用户");
                        break;
                    case 3:
                        vo.setRankName("专家用户");
                        break;
                    default:
                        throw new CheckedServiceException(CheckedExceptionBusiness.WRITER_USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "该用户没有身份");
                }
            }
            pageResult.setRows(list);
        }
        pageResult.setTotal(total);
    } else {
        total = writerUserDao.getLsitisTeacherTotal(pageParameter);
        if (total > 0) {
            List<WriterUserManagerVO> list = writerUserDao.getLsitisTeacher(pageParameter);
            for (WriterUserManagerVO vo : list) {
                switch(vo.getRank()) {
                    case 0:
                        vo.setRankName("普通用户");
                        break;
                    case 1:
                        vo.setRankName("教师用户");
                        break;
                    case 2:
                        vo.setRankName("作家用户");
                        break;
                    case 3:
                        vo.setRankName("专家用户");
                        break;
                    default:
                        throw new CheckedServiceException(CheckedExceptionBusiness.WRITER_USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "该用户没有身份");
                }
            }
            pageResult.setRows(list);
        }
        pageResult.setTotal(total);
    }
    // 设置职位
    if (null != pageResult.getRows() && pageResult.getRows().size() > 0 && null != groupId) {
        // 清空职位
        for (WriterUserManagerVO writerUserManagerVO : pageResult.getRows()) {
            writerUserManagerVO.setPosition("无");
        }
        // 设置职位
        PmphGroup pmphGroup = pmphGroupService.getPmphGroupById(groupId);
        Long bookId = pmphGroup.getBookId();
        if (null != bookId && bookId.intValue() > 0) {
            // 查询这本书的发布职位
            List<DecPositionPublished> publisheds = decPositionPublishedService.getDecPositionPublishedListByBookId(bookId);
            if (null != publisheds && publisheds.size() > 0) {
                Map<Long, String> userIdsAndPostions = new HashMap<Long, String>();
                for (DecPositionPublished published : publisheds) {
                    Declaration declaration = declarationService.getDeclarationById(published.getDeclarationId());
                    String postiton = "无";
                    if (published.getChosenPosition().intValue() == 4 && null != published.getRank() && published.getRank() == 1) {
                        postiton = "主编(第一主编)";
                    } else if (published.getChosenPosition().intValue() == 4) {
                        postiton = "主编";
                    } else if (published.getChosenPosition().intValue() == 12 && null != published.getRank() && published.getRank() == 1) {
                        postiton = "主编(第一主编),数字编委";
                    } else if (published.getChosenPosition().intValue() == 12) {
                        postiton = "主编,数字编委";
                    } else if (published.getChosenPosition().intValue() == 2) {
                        postiton = "副主编";
                    } else if (published.getChosenPosition().intValue() == 10) {
                        postiton = "副主编,数字编委";
                    } else if (published.getChosenPosition().intValue() == 1) {
                        postiton = "编委";
                    } else if (published.getChosenPosition().intValue() == 9) {
                        postiton = "编委,数字编委";
                    }
                    userIdsAndPostions.put(declaration.getUserId(), postiton);
                }
                for (WriterUserManagerVO writerUserManagerVO : pageResult.getRows()) {
                    String postion = userIdsAndPostions.get(writerUserManagerVO.getId());
                    if (null != postion) {
                        writerUserManagerVO.setPosition(postion);
                    }
                }
            }
        }
    }
    // 设置职位 end
    return pageResult;
}
Also used : WriterUserManagerVO(com.bc.pmpheep.back.vo.WriterUserManagerVO) HashMap(java.util.HashMap) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) PageResult(com.bc.pmpheep.back.plugin.PageResult) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) Declaration(com.bc.pmpheep.back.po.Declaration)

Example 12 with PmphGroup

use of com.bc.pmpheep.back.po.PmphGroup 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);
}
Also used : UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage)

Example 13 with PmphGroup

use of com.bc.pmpheep.back.po.PmphGroup 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";
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) PmphGroupMessage(com.bc.pmpheep.back.po.PmphGroupMessage)

Example 14 with PmphGroup

use of com.bc.pmpheep.back.po.PmphGroup in project pmph by BCSquad.

the class PmphGroupServiceImpl method getlistPmphGroup.

@Override
public PageResult<PmphGroupListVO> getlistPmphGroup(PageParameter<PmphGroupListVO> pageParameter, String sessionId) throws CheckedServiceException {
    if (null == pageParameter) {
        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<>();
    PageResult<PmphGroupListVO> pageResult = new PageResult<>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    Integer total = 0;
    if (pmphUser.getIsAdmin()) {
        total = pmphGroupDao.getAdminCount();
        list = pmphGroupDao.getPmphGroupList(pageParameter);
        for (PmphGroupListVO pmphGroupListVO : list) {
            pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
        }
        pageResult.setRows(list);
        pageResult.setTotal(total);
    } else {
        PmphGroup pmphGroup = new PmphGroup();
        List<PmphGroupListVO> groupListVOs = pmphGroupDao.getList(pmphGroup, pmphUser.getId());
        for (PmphGroupListVO pmphGroupListVO : groupListVOs) {
            pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
        }
        if (groupListVOs.size() > 0) {
            pageResult.setRows(groupListVOs);
            pageResult.setTotal(groupListVOs.size());
        }
    }
    return pageResult;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphGroupListVO(com.bc.pmpheep.back.vo.PmphGroupListVO) PageResult(com.bc.pmpheep.back.plugin.PageResult)

Example 15 with PmphGroup

use of com.bc.pmpheep.back.po.PmphGroup in project pmph by BCSquad.

the class PmphGroupServiceImpl method updatePmphGroupOnGroup.

@Override
public PmphGroup updatePmphGroupOnGroup(String file, PmphGroup pmphGroup, HttpServletRequest request) throws CheckedServiceException, IOException {
    String sessionId = CookiesUtil.getSessionId(request);
    if (null == pmphGroup) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "参数对象不能为空");
    }
    if (null == pmphGroup.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "小组id不能为空");
    }
    PmphGroup group = pmphGroupDao.getPmphGroupByGroupName(pmphGroup.getGroupName());
    if (ObjectUtil.notNull(group)) {
        if (!pmphGroup.getId().equals(group.getId())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "小组名称重复");
        }
    }
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (pmphUser.getIsAdmin() || pmphGroupMemberService.isFounderOrisAdmin(pmphGroup.getId(), sessionId)) {
        // 超级管理员与小组创建者、管理者才能修改小组信息
        if (!StringUtil.isEmpty(file)) {
            Long id = pmphGroup.getId();
            PmphGroup pmphGroupOld = getPmphGroupById(id);
            if (null != pmphGroupOld && null != pmphGroupOld.getGroupImage() && !"".equals(pmphGroupOld.getGroupImage()) && !RouteUtil.DEFAULT_USER_AVATAR.equals(pmphGroupOld.getGroupImage())) {
                fileService.remove(pmphGroupOld.getGroupImage());
            }
            String newGroupImage = saveFileToMongoDB(file, request);
            pmphGroup.setGroupImage(newGroupImage);
        }
        pmphGroupDao.updatePmphGroup(pmphGroup);
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
    }
    return pmphGroup;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Aggregations

PmphGroup (com.bc.pmpheep.back.po.PmphGroup)18 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)13 PmphUser (com.bc.pmpheep.back.po.PmphUser)7 ArrayList (java.util.ArrayList)7 Textbook (com.bc.pmpheep.back.po.Textbook)4 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)4 PageResult (com.bc.pmpheep.back.plugin.PageResult)3 Material (com.bc.pmpheep.back.po.Material)3 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)3 UserMessage (com.bc.pmpheep.back.po.UserMessage)3 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)3 Message (com.bc.pmpheep.general.po.Message)3 HashMap (java.util.HashMap)3 LogDetail (com.bc.pmpheep.annotation.LogDetail)2 PmphGroupListVO (com.bc.pmpheep.back.vo.PmphGroupListVO)2 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2