Search in sources :

Example 66 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.

the class SessionUtil method getWriterUserBySessionId.

/**
 * <pre>
 * 功能描述:根据SessionId获取用户对象(现阶段使用)
 * 使用示范:
 *
 * @return
 * </pre>
 */
public static WriterUser getWriterUserBySessionId(String sessionId) throws CheckedServiceException {
    HttpSession session = SessionContext.getSession(sessionId);
    if (ObjectUtil.isNull(session)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.SESSION, CheckedExceptionResult.USER_SESSION, "当前Session会话已过期,请重新登录!");
    }
    WriterUser writerUser = (WriterUser) session.getAttribute(Const.SESSION_WRITER_USER);
    return writerUser;
}
Also used : HttpSession(javax.servlet.http.HttpSession) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 67 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException in project pmph by BCSquad.

the class PmphDepartmentServiceImpl method deletePmphDepartmentBatch.

@Override
public Integer deletePmphDepartmentBatch(Long id) {
    if (null == id) {
        throw new CheckedServiceException(CheckedExceptionBusiness.PMPH_DEPARTMENT, CheckedExceptionResult.NULL_PARAM, "主键为空");
    }
    List<Long> ids = new ArrayList<Long>();
    ids.add(id);
    recursionPmphDepartment(new PmphUserDepartmentVO(id), ids);
    for (Long departmentId : ids) {
        if (pmphUserDao.getPmphUserByDepartmentId(departmentId).size() > 0) {
            throw new CheckedServiceException(CheckedExceptionBusiness.PMPH_DEPARTMENT, CheckedExceptionResult.ILLEGAL_PARAM, "部门中还有用户,不能删除部门");
        }
    }
    List<PmphUserDepartmentVO> idList = pmphDepartmentDao.getDepartmentId(id);
    for (PmphUserDepartmentVO idListVo : idList) {
        // 检查是否是子节点
        List<PmphUserDepartmentVO> idLists = pmphDepartmentDao.listPmphDepartment(idListVo.getId());
        if (idLists.size() > 0) {
            throw new CheckedServiceException(CheckedExceptionBusiness.PMPH_DEPARTMENT, CheckedExceptionResult.NULL_PARAM, "部门下还有子部门,不能删除部门");
        }
    }
    return pmphDepartmentDao.deletePmphDepartmentBatch(ids);
}
Also used : ArrayList(java.util.ArrayList) PmphUserDepartmentVO(com.bc.pmpheep.back.vo.PmphUserDepartmentVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 68 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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 69 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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 70 with CheckedServiceException

use of com.bc.pmpheep.service.exception.CheckedServiceException 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)

Aggregations

CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)208 PmphUser (com.bc.pmpheep.back.po.PmphUser)81 ArrayList (java.util.ArrayList)73 PageResult (com.bc.pmpheep.back.plugin.PageResult)33 Material (com.bc.pmpheep.back.po.Material)30 IOException (java.io.IOException)30 HashMap (java.util.HashMap)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)24 Workbook (org.apache.poi.ss.usermodel.Workbook)23 UserMessage (com.bc.pmpheep.back.po.UserMessage)22 LogDetail (com.bc.pmpheep.annotation.LogDetail)20 Message (com.bc.pmpheep.general.po.Message)20 Textbook (com.bc.pmpheep.back.po.Textbook)18 WriterUser (com.bc.pmpheep.back.po.WriterUser)17 OutputStream (java.io.OutputStream)17 CmsContent (com.bc.pmpheep.back.po.CmsContent)16 BufferedOutputStream (java.io.BufferedOutputStream)16 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14