Search in sources :

Example 1 with PmphGroupMemberVO

use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.

the class PmphGroupFileServiceImpl method addPmphGroupFile.

/**
 * @param pmphGroupFile
 *            实体对象
 * @return 带主键的 PmphGroupFile
 * @throws CheckedServiceException
 * @update Mryang 2017.10.13 15:30
 */
@Override
public String addPmphGroupFile(Long[] ids, MultipartFile file, String sessionId) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser) || ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(ids) || ids.length == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "参数不能为空");
    }
    if (ObjectUtil.isNull(file)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "文件不能为空");
    }
    Long userId = pmphUser.getId();
    List<PmphGroupFile> list = new ArrayList<>();
    for (Long id : ids) {
        if (ObjectUtil.isNull(id)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "小组id不能为空");
        }
        PmphGroupMemberVO pmphGroupMemberVO = pmphGroupMemberService.getPmphGroupMemberByMemberId(id, userId, false);
        PmphGroupFile pmphGroupFile = new PmphGroupFile(id, pmphGroupMemberVO.getId(), "0" + pmphGroupMemberVO.getId(), file.getOriginalFilename(), 0, null);
        Long fileLenth = file.getSize();
        pmphGroupFile.setFileSize(Double.valueOf(fileLenth / 1024));
        pmphGroupFileDao.addPmphGroupFile(pmphGroupFile);
        list.add(pmphGroupFile);
    }
    // list.get(0).getId()获取上传的第一条数据的id
    String fileId = fileService.save(file, FileType.GROUP_FILE, list.get(0).getId());
    for (PmphGroupFile pmphGroupFile : list) {
        pmphGroupFile.setFileId(fileId);
        pmphGroupFileDao.updatePmphGroupFile(pmphGroupFile);
        PmphGroupMemberVO pmphGroupMemberVO = pmphGroupMemberService.getPmphGroupMemberByMemberId(pmphGroupFile.getGroupId(), userId, false);
        pmphGroupMessageService.addGroupMessage(pmphGroupMemberVO.getDisplayName() + "上传了文件" + file.getOriginalFilename(), pmphGroupFile.getGroupId(), sessionId, Const.SENDER_TYPE_0);
    }
    return "success";
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupFile(com.bc.pmpheep.back.po.PmphGroupFile) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 2 with PmphGroupMemberVO

use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.

the class PmphGroupMemberServiceImpl method deletePmphGroupMemberByIds.

@Override
public String deletePmphGroupMemberByIds(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 (userid == pmphGroupMember.getUserId() && !pmphGroupMember.getIsWriter()) {
                throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "您无权限删除管理员,请重新选择");
            }
            if (pmphUser.getIsAdmin() || currentUser.getIsFounder()) {
                // 只有小组创建者和超级管理员可以删除小组成员
                if (pmphGroupMemberDao.getPmphGroupMemberById(id).getIsFounder()) {
                    throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "小组创建者不能删除,请重新选择");
                }
                pmphGroupMemberDao.deletePmphGroupMemberById(id);
            } else {
                // 管理员进入的方法
                if (currentUser.getIsAdmin() && (pmphGroupMember.getIsFounder() || pmphGroupMember.getIsAdmin())) {
                    throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "您无权限删除管理员,请重新选择");
                } else {
                    pmphGroupMemberDao.deletePmphGroupMemberById(id);
                }
            }
        }
        result = "SUCCESS";
    }
    return result;
}
Also used : PmphGroupMember(com.bc.pmpheep.back.po.PmphGroupMember) PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 3 with PmphGroupMemberVO

use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.

the class PmphGroupMemberServiceImpl method isFounder.

@Override
public Boolean isFounder(Long groupId, String sessionId) throws CheckedServiceException {
    boolean flag = false;
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    Long memberId = pmphUser.getId();
    PmphGroupMemberVO currentUser = pmphGroupMemberDao.getPmphGroupMemberByMemberId(groupId, memberId, false);
    if (currentUser.getIsFounder()) {
        flag = true;
    }
    return flag;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 4 with PmphGroupMemberVO

use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.

the class PmphGroupMemberServiceImpl method addPmphGroupMemberOnGroup.

@Override
public String addPmphGroupMemberOnGroup(Long groupId, List<PmphGroupMember> pmphGroupMembers, 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, "用户为空");
    }
    /**
     *        Textbook textbook=new Textbook();
     *        if(null!=pmphGroupMembers.get(0).getTextbookId()){
     *        	//查询书籍信息
     *        	textbook=textbookService.getTextbookById(pmphGroupMembers.get(0).getTextbookId());
     *        }
     *        Material material=new Material();
     *        if(null!=pmphGroupMembers.get(0).getMaterialId()){
     *        	 //查询教材信息
     *            material=materialService.getMaterialById(pmphGroupMembers.get(0).getMaterialId());
     *        }
     *        //查询该教材是否存在项目编辑
     *        MaterialProjectEditor materialProjectEditor=materialProjectEditorService.getMaterialProjectEditorByMaterialIdAndUserId(material.getId(), pmphUser.getId());
     *        ////判断当前教材是否有创建小组的权限
     *        if (!material.getDirector().equals(pmphUser.getId()) && !textbook.getPlanningEditor().equals(pmphUser.getId())
     *                && null == materialProjectEditor && !pmphUser.getIsAdmin()) {
     *            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
     *                    CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
     *
     *        }
     *        if (null != material.getPlanPermission()) {
     *            if (!BinaryUtil.getBit(material.getPlanPermission(), 7)) {
     *                throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
     *                        CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
     *            }
     *        }
     *        if (null != material.getProjectPermission()) {
     *            if (!BinaryUtil.getBit(material.getProjectPermission(), 7)) {
     *                throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
     *                        CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
     *            }
     *        }
     */
    // 小组权限的判断
    Long materialId = pmphGroupMembers.get(0).getMaterialId();
    Long textBookId = pmphGroupMembers.get(0).getTextbookId();
    String myPower = textbookService.listBookPosition(1, 9999, null, "[" + textBookId + "]", null, materialId, sessionId).getRows().get(0).getMyPower();
    String groupPower = myPower.substring(6, 7);
    /**
     *        if (pmphUser.getIsAdmin() || isFounderOrisAdmin(groupId, sessionId)
     *        		||material.getDirector()==pmphUser.getId()||textbook.getPlanningEditor()==pmphUser.getId()
     *        		||pmphUser.getId()==materialProjectEditor.getEditorId()) {// 是超级管理员或者该小组的创建人和管理员才可以添加成员
     */
    if ("1".equals(groupPower)) {
        // 小组权限的判断  end
        if (pmphGroupMembers.size() > 0) {
            List<Long> writers = new ArrayList<>();
            List<Long> pmphs = new ArrayList<>();
            for (PmphGroupMember pmphGroupMember : pmphGroupMembers) {
                PmphGroupMemberVO groupMember = pmphGroupMemberDao.getPmphGroupMemberByMemberId(groupId, pmphGroupMember.getUserId(), // 查看当前添加人员是否以前在小组中
                pmphGroupMember.getIsWriter());
                if (ObjectUtil.isNull(groupMember)) {
                    // 当前人员以前不在小组中
                    if (null == pmphGroupMember.getUserId()) {
                        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "成员id为空");
                    }
                    if (pmphGroupMember.getIsWriter()) {
                        WriterUser writerUser = writerUserService.get(pmphGroupMember.getUserId());
                        pmphGroupMember.setDisplayName(writerUser.getRealname());
                        writers.add(pmphGroupMember.getUserId());
                    } else {
                        PmphUser user = pmphUserService.get(pmphGroupMember.getUserId());
                        pmphGroupMember.setDisplayName(user.getRealname());
                        pmphs.add(pmphGroupMember.getUserId());
                    }
                    pmphGroupMember.setGroupId(groupId);
                    pmphGroupMemberDao.addPmphGroupMember(pmphGroupMember);
                } else {
                    if (groupMember.getIsDeleted()) {
                        pmphGroupMember.setGroupId(groupId);
                        pmphGroupMember.setIsDeleted(false);
                        pmphGroupMemberDao.update(pmphGroupMember);
                        if (groupMember.getIsWriter()) {
                            writers.add(pmphGroupMember.getUserId());
                        } else {
                            pmphs.add(pmphGroupMember.getUserId());
                        }
                    } else {
                        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户已在小组中,请勿重复添加");
                    }
                }
            }
            // 向添加的小组成员发送消息
            try {
                if (!writers.isEmpty()) {
                    // 向作家用户发送消息
                    systemMessageService.sendWhenInviteJoinGroup(pmphUser.getRealname(), groupId, writers, (short) 2);
                }
                if (!pmphs.isEmpty()) {
                    // 向社内用户发送消息
                    systemMessageService.sendWhenInviteJoinGroup(pmphUser.getRealname(), groupId, pmphs, (short) 1);
                }
            } catch (IOException e) {
                throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "发送消息失败" + e.getMessage());
            }
            result = "SUCCESS";
        } else {
            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "参数为空");
        }
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有此操作权限");
    }
    return result;
}
Also used : PmphGroupMember(com.bc.pmpheep.back.po.PmphGroupMember) PmphUser(com.bc.pmpheep.back.po.PmphUser) PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser) IOException(java.io.IOException)

Example 5 with PmphGroupMemberVO

use of com.bc.pmpheep.back.vo.PmphGroupMemberVO in project pmph by BCSquad.

the class PmphGroupMessageServiceImpl method deletePmphGroupMessageById.

/**
 * @param id
 * @return 影响行数
 * @throws CheckedServiceException
 * @throws IOException
 */
@Override
public String deletePmphGroupMessageById(Long id, String sessionId) throws CheckedServiceException, IOException {
    if (null == id) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "主键为空");
    }
    PmphGroupMessage pmphGroupMessage = pmphGroupMessageDao.getPmphGroupMessageById(id);
    Long groupId = pmphGroupMessage.getGroupId();
    int num = pmphGroupMessageDao.deletePmphGroupMessageById(id);
    if (num > 0) {
        // 删除成功 撤销消息
        WebScocketMessage webScocketMessage = new WebScocketMessage();
        webScocketMessage.setId(String.valueOf(id));
        webScocketMessage.setGroupId(groupId);
        webScocketMessage.setSendType(Const.SEND_MSG_TYPE_1);
        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);
        }
        handler.sendWebSocketMessageToUser(ids, webScocketMessage);
    }
    return "SUCCESS";
}
Also used : PmphGroupMemberVO(com.bc.pmpheep.back.vo.PmphGroupMemberVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) PmphGroupMessage(com.bc.pmpheep.back.po.PmphGroupMessage)

Aggregations

PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)14 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)14 PmphUser (com.bc.pmpheep.back.po.PmphUser)9 ArrayList (java.util.ArrayList)6 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)4 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)3 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)3 PmphGroupFile (com.bc.pmpheep.back.po.PmphGroupFile)2 PmphGroupMessage (com.bc.pmpheep.back.po.PmphGroupMessage)2 PmphGroupListVO (com.bc.pmpheep.back.vo.PmphGroupListVO)2 UserMessage (com.bc.pmpheep.back.po.UserMessage)1 WriterUser (com.bc.pmpheep.back.po.WriterUser)1 Message (com.bc.pmpheep.general.po.Message)1 IOException (java.io.IOException)1