Search in sources :

Example 36 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser 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 37 with PmphUser

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

the class PmphGroupMemberServiceImpl method addEditorBookGroup.

@Override
public String addEditorBookGroup(Long textbookId, 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 = textbookService.getTextbookById(textbookId);
    // 查询教材信息
    Material material = materialService.getMaterialById(textbook.getMaterialId());
    // 查询该教材是否存在项目编辑
    MaterialProjectEditor materialProjectEditor = materialProjectEditorService.getMaterialProjectEditorByMaterialIdAndUserId(material.getId(), pmphUser.getId());
    // 通过书籍id查询所有主编、副主编、编委
    List<TextbookDecVO> textbookDecVOs = decPositionService.getTextbookEditorList(textbookId);
    List<PmphGroupMember> list = new ArrayList<PmphGroupMember>(textbookDecVOs.size());
    // 通过书籍id查询小组
    PmphGroup pmphGroup = pmphGroupService.getPmphGroupByTextbookId(textbookId);
    // 判断当前教材是否有更新小组的权限
    // 小组权限的判断
    Long materialId = textbook.getMaterialId();
    String myPower = textbookService.listBookPosition(1, 9999, null, "[" + textbookId + "]", null, materialId, sessionId).getRows().get(0).getMyPower();
    String groupPower = myPower.substring(6, 7);
    if ("1".equals(groupPower)) {
        // if(null!=material.getPlanPermission()||null!=material.getProjectPermission()){
        // if(!BinaryUtil.getBit(material.getPlanPermission(), 7)||!BinaryUtil.getBit(material.getProjectPermission(), 7)){
        // throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
        // CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有更新成员权限 ");
        // }
        // }
        // 通过小组id查询小组现有成员
        List<PmphGroupMember> pmphGroupMembers = pmphGroupMemberDao.listPmphGroupMembers(pmphGroup.getId());
        List<Long> groupUserIdList = new ArrayList<Long>(pmphGroupMembers.size());
        for (PmphGroupMember pmphGroupMember : pmphGroupMembers) {
            groupUserIdList.add(pmphGroupMember.getUserId());
        }
        // 通过遍历把不存在的成员添加到list中
        for (TextbookDecVO textbookDecVO : textbookDecVOs) {
            Long userId = textbookDecVO.getUserId();
            if (!groupUserIdList.contains(userId)) {
                list.add(new PmphGroupMember(userId, Const.TRUE, textbook.getMaterialId(), textbookId));
            }
        }
        if (CollectionUtil.isEmpty(list)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.SUCCESS, "小组成员已是最新");
        }
        pmphGroupMemberService.addPmphGroupMemberOnGroup(pmphGroup.getId(), list, sessionId);
        result = "SUCCESS";
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.ILLEGAL_PARAM, "该用户没有更新成员权限 ");
    }
    return result;
}
Also used : MaterialProjectEditor(com.bc.pmpheep.back.po.MaterialProjectEditor) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) PmphGroupMember(com.bc.pmpheep.back.po.PmphGroupMember) Textbook(com.bc.pmpheep.back.po.Textbook) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) TextbookDecVO(com.bc.pmpheep.back.vo.TextbookDecVO)

Example 38 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser 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 39 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser 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 40 with PmphUser

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

the class PmphGroupServiceImpl method addPmphGroupOnGroup.

@Override
public PmphGroup addPmphGroupOnGroup(String file, PmphGroup pmphGroup, HttpServletRequest request) throws CheckedServiceException, IOException {
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.notNull(pmphGroupDao.getPmphGroupByGroupName(pmphGroup.getGroupName()))) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "该小组名称已被使用,请重新输入");
    }
    // 未上传小组头像时,获取默认小组头像路径
    String groupImage = RouteUtil.DEFAULT_GROUP_IMAGE;
    if (!StringUtil.isEmpty(file)) {
        groupImage = saveFileToMongoDB(file, request);
    }
    pmphGroup.setGroupImage(groupImage);
    pmphGroup.setFounderId(pmphUser.getId());
    pmphGroupDao.addPmphGroup(pmphGroup);
    if (null != pmphGroup.getId()) {
        // 判断是否新增小组成功,如果成功则调用PmphGroupMemberService添加小组成员的方法将创建者添加到小组中
        PmphGroupMember pmphGroupMember = new PmphGroupMember();
        pmphGroupMember.setGroupId(pmphGroup.getId());
        pmphGroupMember.setIsFounder(true);
        pmphGroupMember.setUserId(pmphUser.getId());
        pmphGroupMember.setDisplayName(pmphUser.getRealname());
        pmphGroupMemberService.addPmphGroupMember(pmphGroupMember);
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.OBJECT_NOT_FOUND, "添加小组失败");
    }
    return pmphGroup;
}
Also used : PmphGroupMember(com.bc.pmpheep.back.po.PmphGroupMember) PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Aggregations

PmphUser (com.bc.pmpheep.back.po.PmphUser)102 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)81 ArrayList (java.util.ArrayList)33 PageResult (com.bc.pmpheep.back.plugin.PageResult)17 HashMap (java.util.HashMap)13 Material (com.bc.pmpheep.back.po.Material)11 WriterUser (com.bc.pmpheep.back.po.WriterUser)11 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)10 PmphRole (com.bc.pmpheep.back.po.PmphRole)9 UserMessage (com.bc.pmpheep.back.po.UserMessage)9 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)9 BaseTest (com.bc.pmpheep.test.BaseTest)9 Test (org.junit.Test)9 CmsContent (com.bc.pmpheep.back.po.CmsContent)8 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)8 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)7 Textbook (com.bc.pmpheep.back.po.Textbook)7 WriterUserTrendst (com.bc.pmpheep.back.po.WriterUserTrendst)6 Gson (com.google.gson.Gson)6 OrgUser (com.bc.pmpheep.back.po.OrgUser)5