Search in sources :

Example 76 with CheckedServiceException

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

Example 77 with CheckedServiceException

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

the class PmphGroupServiceImpl method addEditorSelcetionGroup.

@Override
public PmphGroup addEditorSelcetionGroup(String sessionId, List<PmphGroupMember> list, Long textbookId) throws CheckedServiceException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (list.size() == 0) {
        throw new CheckedServiceException(CheckedExceptionBusiness.GROUP, CheckedExceptionResult.NULL_PARAM, "成员名单为空,更新失败");
    }
    Textbook textbook = textbookService.getTextbookById(textbookId);
    list.get(0).setTextbookId(textbookId);
    list.get(0).setMaterialId(textbook.getMaterialId());
    // 未上传小组头像时,获取默认小组头像路径
    String groupImage = RouteUtil.DEFAULT_GROUP_IMAGE;
    PmphGroup pmphGroup = new PmphGroup();
    // 查询小组名称是否已存在 不存在直接用书名
    if (ObjectUtil.isNull(pmphGroupDao.getPmphGroupByGroupName(textbook.getTextbookName()))) {
        pmphGroup.setGroupName(textbook.getTextbookName());
    } else {
        // 存在则用书名加当前小组总数进行区分
        Long count = pmphGroupDao.getPmphGroupCount();
        pmphGroup.setGroupName(textbook.getTextbookName() + count);
    }
    pmphGroup.setGroupImage(groupImage);
    pmphGroup.setBookId(textbookId);
    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);
        // 批量把前台传入的作家用户添加到该小组
        pmphGroupMemberService.addPmphGroupMemberOnGroup(pmphGroup.getId(), list, sessionId);
    } 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) Textbook(com.bc.pmpheep.back.po.Textbook) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 78 with CheckedServiceException

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

the class PmphGroupServiceImpl method listPmphGroupFile.

@Override
public List<PmphGroupListVO> listPmphGroupFile(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<>();
    list = pmphGroupDao.getList(pmphGroup, pmphUser.getId());
    for (PmphGroupListVO pmphGroupListVO : list) {
        pmphGroupListVO.setGroupImage(RouteUtil.groupImage(pmphGroupListVO.getGroupImage()));
    }
    return list;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphGroupListVO(com.bc.pmpheep.back.vo.PmphGroupListVO)

Example 79 with CheckedServiceException

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

the class PmphUserServiceImpl method getListByUsernameAndRealname.

@Override
public PageResult<PmphUserManagerVO> getListByUsernameAndRealname(String name, int number, int size) throws CheckedServiceException {
    if (null == name || "".equals(name)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "模糊查询条件为空");
    }
    List<PmphUser> pmphUsers = pmphUserDao.getListByUsernameAndRealname(name, (number - 1) * size, size);
    PageResult<PmphUserManagerVO> page = new PageResult<>();
    page.setFirst(true);
    page.setLast(true);
    page.setPageNumber(number);
    page.setPageSize(size);
    if (!pmphUsers.isEmpty()) {
        List<PmphUserManagerVO> list = new ArrayList<>();
        for (PmphUser user : pmphUsers) {
            PmphUserManagerVO userVO = new PmphUserManagerVO();
            PmphDepartment department = pmphDepartmentDao.getPmphDepartmentById(user.getDepartmentId());
            if (null != department) {
                userVO.setDepartmentName(department.getDpName());
            }
            try {
                BeanUtils.copyProperties(userVO, user);
            } catch (BeansException ex) {
                throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.VO_CONVERSION_FAILED, ex.getMessage());
            }
            list.add(userVO);
        }
        page.setRows(list);
    }
    return page;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphUserManagerVO(com.bc.pmpheep.back.vo.PmphUserManagerVO) PageResult(com.bc.pmpheep.back.plugin.PageResult) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment) BeansException(org.springframework.beans.BeansException)

Example 80 with CheckedServiceException

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

the class PmphUserServiceImpl method updatePersonalData.

@Override
public boolean updatePersonalData(HttpServletRequest request, PmphUser pmphUser, String newAvatar) throws IOException {
    Long id = pmphUser.getId();
    if (null == id) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户ID为空时禁止更新用户");
    }
    if (!StringUtil.isEmpty(pmphUser.getEmail())) {
        if (!ValidatUtil.checkEmail(pmphUser.getEmail())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱不符合规范");
        }
    }
    if (!StringUtil.isEmpty(pmphUser.getHandphone())) {
        if (!ValidatUtil.checkMobileNumber(pmphUser.getHandphone())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "手机号码不符合规范");
        }
    }
    // 头像文件不为空
    if (null != newAvatar) {
        if (StringUtil.notEmpty(pmphUser.getAvatar())) {
            if (pmphUser.getAvatar().contains("/")) {
                String avatar = pmphUser.getAvatar();
                avatar = avatar.substring(avatar.lastIndexOf("/") + 1, avatar.length());
                fileService.remove(avatar);
            }
            if (pmphUser.getAvatar().contains("\\")) {
                String avatar = pmphUser.getAvatar();
                avatar = avatar.substring(avatar.lastIndexOf("\\") + 1, avatar.length());
                fileService.remove(avatar);
            }
        }
        pmphUser.setAvatar(newAvatar);
    }
    String avatar = pmphUser.getAvatar();
    if (null != avatar && avatar.contains("/")) {
        avatar = avatar.substring(avatar.lastIndexOf("/") + 1, avatar.length());
    }
    if (null != avatar && avatar.contains("\\")) {
        avatar = avatar.substring(avatar.lastIndexOf("\\") + 1, avatar.length());
    }
    if (null != avatar) {
        byte[] fileByte = (byte[]) request.getSession(false).getAttribute(avatar);
        String fileName = (String) request.getSession(false).getAttribute("fileName_" + avatar);
        String noticeId;
        // 保存通知文件
        InputStream sbs = new ByteArrayInputStream(fileByte);
        noticeId = fileService.save(sbs, fileName, ImageType.PMPH_USER_AVATAR, id);
        pmphUser.setAvatar(noticeId);
    }
    pmphUserDao.update(pmphUser);
    return true;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

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