Search in sources :

Example 86 with CheckedServiceException

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

the class SurveyTargetServiceImpl method reissueSurveyMessage.

@Override
public Integer reissueSurveyMessage(Message message, String title, Long surveyId, String sessionId) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(surveyId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷表Id为空");
    }
    if (StringUtil.isEmpty(title)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "问卷名称为空");
    }
    // MongoDB 消息插入
    message = messageService.add(message);
    if (StringUtil.isEmpty(message.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.OBJECT_NOT_FOUND, "储存失败!");
    }
    List<Long> listUserId = surveyQuestionAnswerService.getUserIdBySurveyId(surveyId);
    Integer count = 0;
    List<Long> orgIds = this.listOrgIdBySurveyId(surveyId);
    if (CollectionUtil.isNotEmpty(orgIds)) {
        count = orgIds.size();
        Long userId = pmphUser.getId();
        String surveyTitle = title + "-(问卷催办)";
        // 发送消息
        // 作家用户
        List<WriterUser> writerUserList = writerUserService.getWriterUserListByOrgIds(orgIds);
        // 系统消息
        List<UserMessage> userMessageList = new ArrayList<UserMessage>(writerUserList.size());
        for (WriterUser writerUser : writerUserList) {
            if (!listUserId.contains(writerUser.getId())) {
                userMessageList.add(new UserMessage(message.getId(), surveyTitle, Const.MSG_TYPE_1, userId, Const.SENDER_TYPE_1, writerUser.getId(), Const.RECEIVER_TYPE_2, 0L));
            }
        }
        // 发送消息
        if (CollectionUtil.isNotEmpty(userMessageList)) {
            // 插入消息发送对象数据
            userMessageService.addUserMessageBatch(userMessageList);
            // websocket发送的id集合
            List<String> websocketUserIds = new ArrayList<String>();
            for (UserMessage userMessage : userMessageList) {
                websocketUserIds.add(userMessage.getReceiverType() + "_" + userMessage.getReceiverId());
            }
            // webscokt发送消息
            if (CollectionUtil.isNotEmpty(websocketUserIds)) {
                WebScocketMessage webScocketMessage = new WebScocketMessage(message.getId(), Const.MSG_TYPE_1, userId, pmphUser.getRealname(), Const.SENDER_TYPE_1, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, surveyTitle, message.getContent(), DateUtil.getCurrentTime());
                myWebSocketHandler.sendWebSocketMessageToUser(websocketUserIds, webScocketMessage);
            }
        }
    }
    return count;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 87 with CheckedServiceException

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

the class SurveyTemplateServiceImpl method addQuestionAndOption.

/**
 * <pre>
 * 功能描述:添加问题及问题选项
 * 使用示范:
 *
 * @param surveyQuestionListVO
 * @return
 * </pre>
 */
private List<Long> addQuestionAndOption(List<SurveyQuestionListVO> surveyQuestionListVO) {
    List<Long> questionIds = new ArrayList<Long>(surveyQuestionListVO.size());
    for (SurveyQuestionListVO surveyQuestionLists : surveyQuestionListVO) {
        // 遍历获取问题的集合
        SurveyQuestion surveyQuestion = new SurveyQuestion(surveyQuestionLists.getTitle(), surveyQuestionLists.getType(), surveyQuestionLists.getSort(), // 问题实体
        surveyQuestionLists.getDirection());
        SurveyQuestion surveyQuestions = // 先保存问题
        surveyQuestionService.addSurveyQuestion(surveyQuestion);
        if (ObjectUtil.isNull(surveyQuestions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.QUESTIONNAIRE_SURVEY, CheckedExceptionResult.NULL_PARAM, "新增数据为空");
        }
        // 获取数据库新生成的问题id
        Long newId = surveyQuestions.getId();
        questionIds.add(newId);
        if (Const.SURVEY_QUESTION_TYPE_1 == surveyQuestionLists.getType() || Const.SURVEY_QUESTION_TYPE_2 == surveyQuestionLists.getType()) {
            List<SurveyQuestionOption> surveyQuestionOptionList = // 获取问题选项list
            surveyQuestionLists.getSurveyQuestionOptionList();
            for (SurveyQuestionOption surveyQuestionOptions : surveyQuestionOptionList) {
                // 遍历问题选项
                SurveyQuestionOption surveyQuestionOption = new SurveyQuestionOption(newId, surveyQuestionOptions.getOptionContent(), surveyQuestionOptions.getIsOther(), // 问题选项实体
                surveyQuestionOptions.getRemark());
                // 再保存问题选项
                surveyQuestionOptionService.addSurveyQuestionOption(surveyQuestionOption);
            }
        }
    }
    return questionIds;
}
Also used : SurveyQuestionOption(com.bc.pmpheep.back.po.SurveyQuestionOption) SurveyQuestionListVO(com.bc.pmpheep.back.vo.SurveyQuestionListVO) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) SurveyQuestion(com.bc.pmpheep.back.po.SurveyQuestion)

Example 88 with CheckedServiceException

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

the class TextbookLogServiceImpl method addTextbookLog.

@Override
public void addTextbookLog(List<DecPosition> oldlist, Long textbookId, Long updaterId, int userType) throws CheckedServiceException {
    if (null == textbookId) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK_LOG, CheckedExceptionResult.NULL_PARAM, "书籍为空!");
    }
    if (null == updaterId) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK_LOG, CheckedExceptionResult.NULL_PARAM, "修改者为空!");
    }
    List<DecPosition> newlist = decPositionService.listChosenDecPositionsByTextbookId(textbookId);
    int addSumZhuBian = 0;
    StringBuilder addZhuBian = new StringBuilder("");
    int redSumZhuBian = 0;
    StringBuilder redZhuBian = new StringBuilder("");
    int addSumFuZhuBian = 0;
    StringBuilder addFuZhuBian = new StringBuilder("");
    int redSumFuZhuBian = 0;
    StringBuilder redFuZhuBian = new StringBuilder("");
    int addSumBianWei = 0;
    StringBuilder addBianWei = new StringBuilder("");
    int redSumBianWei = 0;
    StringBuilder redBianWei = new StringBuilder("");
    int addSumShuZiBianWei = 0;
    StringBuilder addShuZiBianWei = new StringBuilder("");
    int redSumShuZiBianWei = 0;
    StringBuilder redShuZiBianWei = new StringBuilder("");
    // 新旧申报的id
    List<Long> ids = new ArrayList<>(oldlist.size() + newlist.size());
    for (DecPosition oldDecPosition : oldlist) {
        ids.add(oldDecPosition.getDeclarationId());
    }
    for (DecPosition newDecPosition : newlist) {
        ids.add(newDecPosition.getDeclarationId());
    }
    List<Declaration> declarations = declarationService.getDeclarationByIds(ids);
    // 增加的
    for (DecPosition newDecPosition : newlist) {
        // 申报者
        Long declarationId = newDecPosition.getDeclarationId();
        // 新的申报表
        Declaration declaration = new Declaration();
        for (Declaration tempDeclaration : declarations) {
            if (tempDeclaration.getId().intValue() == declarationId.intValue()) {
                declaration = tempDeclaration;
                break;
            }
        }
        // 新选的职位
        Integer newChosenPosition = newDecPosition.getChosenPosition();
        // 是否是新增
        boolean isAdd = true;
        // 遍历出所有的旧的信息
        for (DecPosition oldDecPosition : oldlist) {
            if (oldDecPosition.getDeclarationId().intValue() == newDecPosition.getDeclarationId().intValue()) {
                isAdd = false;
                break;
            }
        }
        if (isAdd) {
            // 新增的主编
            if (null != newChosenPosition && (newChosenPosition == 4 || newChosenPosition == 12)) {
                addSumZhuBian++;
                addZhuBian.append("," + declaration.getRealname());
            }
            // 新增的副主编
            if (null != newChosenPosition && (newChosenPosition == 2 || newChosenPosition == 10)) {
                addSumFuZhuBian++;
                addFuZhuBian.append("," + declaration.getRealname());
            }
            // 新增的编委
            if (null != newChosenPosition && (newChosenPosition == 1 || newChosenPosition == 9)) {
                addSumBianWei++;
                addBianWei.append("," + declaration.getRealname());
            }
            // 新增的数字编委
            if (null != newChosenPosition && (newChosenPosition == 8 || newChosenPosition == 12 || newChosenPosition == 10 || newChosenPosition == 9)) {
                addSumShuZiBianWei++;
                addShuZiBianWei.append("," + declaration.getRealname());
            }
        }
    }
    // 减少的
    for (DecPosition oldDecPosition : oldlist) {
        // 申报者
        Long declarationId = oldDecPosition.getDeclarationId();
        // 老的申报表
        Declaration declaration = new Declaration();
        for (Declaration tempDeclaration : declarations) {
            if (tempDeclaration.getId().intValue() == declarationId.intValue()) {
                declaration = tempDeclaration;
                break;
            }
        }
        // 老的的职位
        Integer oldChosenPosition = oldDecPosition.getChosenPosition();
        // 是否删除
        boolean isDel = true;
        // 遍历出所有新的信息
        for (DecPosition newDecPosition : newlist) {
            if (oldDecPosition.getDeclarationId().intValue() == newDecPosition.getDeclarationId().intValue()) {
                isDel = false;
                break;
            }
        }
        if (isDel) {
            // 移除了主编
            if (null != oldChosenPosition && (oldChosenPosition == 4 || oldChosenPosition == 12)) {
                redSumZhuBian++;
                redZhuBian.append("," + declaration.getRealname());
            }
            // 移除了副主编
            if (null != oldChosenPosition && (oldChosenPosition == 2 || oldChosenPosition == 10)) {
                redSumFuZhuBian++;
                redFuZhuBian.append("," + declaration.getRealname());
            }
            // 移除了编委
            if (null != oldChosenPosition && (oldChosenPosition == 1 || oldChosenPosition == 9)) {
                redSumBianWei++;
                redBianWei.append("," + declaration.getRealname());
            }
            // 移除了编委
            if (null != oldChosenPosition && (oldChosenPosition == 8 || oldChosenPosition == 12 || oldChosenPosition == 10 || oldChosenPosition == 9)) {
                redSumShuZiBianWei++;
                redShuZiBianWei.append("," + declaration.getRealname());
            }
        }
    }
    // 职位被修改的
    StringBuilder updateString = new StringBuilder("");
    boolean allUpdate = false;
    for (DecPosition newDecPosition : newlist) {
        // 申报者
        Long declarationId = newDecPosition.getDeclarationId();
        // 新的申报表
        Declaration declaration = new Declaration();
        for (Declaration tempDeclaration : declarations) {
            if (tempDeclaration.getId().intValue() == declarationId.intValue()) {
                declaration = tempDeclaration;
                break;
            }
        }
        // 新选的职位
        Integer newChosenPosition = newDecPosition.getChosenPosition();
        Integer newRank = newDecPosition.getRank();
        newRank = newRank == null ? 0 : newRank;
        // 是否是新增
        boolean isUpdate = false;
        // 遍历出所有的旧的信息
        for (DecPosition oldDecPosition : oldlist) {
            Integer oldChosenPosition = oldDecPosition.getChosenPosition();
            Integer oldRank = oldDecPosition.getRank();
            oldRank = oldRank == null ? 0 : oldRank;
            // 修改的是职位或者排序 都算
            if (oldDecPosition.getDeclarationId().intValue() == newDecPosition.getDeclarationId().intValue() && !(newChosenPosition.intValue() == oldChosenPosition.intValue() && newRank.intValue() == oldRank.intValue())) {
                isUpdate = true;
                break;
            }
        }
        if (isUpdate) {
            allUpdate = true;
            updateString.append("," + declaration.getRealname());
        }
    }
    // 遍历错误信息
    if (addSumZhuBian > 0 || redSumZhuBian > 0 || addSumFuZhuBian > 0 || redSumFuZhuBian > 0 || addSumBianWei > 0 || redSumBianWei > 0 || addSumShuZiBianWei > 0 || redSumShuZiBianWei > 0 || allUpdate) {
        StringBuilder detail = new StringBuilder("");
        if (redSumZhuBian > 0) {
            detail.append("移除了" + redSumZhuBian + "位主编:[" + redZhuBian.toString().substring(1) + "];");
        }
        if (redSumFuZhuBian > 0) {
            detail.append("移除了" + redSumFuZhuBian + "位副主编:[" + redFuZhuBian.toString().substring(1) + "];");
        }
        if (redSumBianWei > 0) {
            detail.append("移除了" + redSumBianWei + "位编委:[" + redBianWei.toString().substring(1) + "];");
        }
        if (redSumShuZiBianWei > 0) {
            detail.append("移除了" + redSumShuZiBianWei + "位数字编辑:[" + redShuZiBianWei.toString().substring(1) + "];");
        }
        if (addSumZhuBian > 0) {
            detail.append("增加了" + addSumZhuBian + "位主编:[" + addZhuBian.toString().substring(1) + "];");
        }
        if (addSumFuZhuBian > 0) {
            detail.append("增加了" + addSumFuZhuBian + "位副主编:[" + addFuZhuBian.toString().substring(1) + "];");
        }
        if (addSumBianWei > 0) {
            detail.append("增加了" + addSumBianWei + "位编委:[" + addBianWei.toString().substring(1) + "];");
        }
        if (addSumShuZiBianWei > 0) {
            detail.append("增加了" + addSumShuZiBianWei + "位数字编辑:[" + addShuZiBianWei.toString().substring(1) + "];");
        }
        if (allUpdate) {
            detail.append("修改了:[" + updateString.toString().substring(1) + "]的职位信息;");
        }
        String detail2 = detail.toString();
        // 去掉最后一个;
        detail2 = detail2.substring(0, detail2.length() - 1);
        TextbookLog textbookLog = new TextbookLog();
        textbookLog.setDetail(detail2.length() >= 100 ? detail2.substring(0, 95) + "..." : detail2);
        textbookLog.setIsPmphUpdater(userType == 1);
        textbookLog.setTextbookId(textbookId);
        textbookLog.setUpdaterId(updaterId);
        textbookLogDao.addTextbookLog(textbookLog);
    }
}
Also used : ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) TextbookLog(com.bc.pmpheep.back.po.TextbookLog) DecPosition(com.bc.pmpheep.back.po.DecPosition) Declaration(com.bc.pmpheep.back.po.Declaration)

Example 89 with CheckedServiceException

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

the class TextbookLogServiceImpl method listTextbookLogByTextBookId.

@Override
public PageResult<TextbookLogVO> listTextbookLogByTextBookId(Long textbookId, Integer pageSize, Integer pageNumber, String updaterName) throws CheckedServiceException {
    if (null == textbookId) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK_LOG, CheckedExceptionResult.NULL_PARAM, "书籍为空!");
    }
    Map<String, Object> map = new HashMap<String, Object>(2);
    map.put("textbookId", textbookId);
    updaterName = StringUtil.toAllCheck(updaterName);
    if (null != updaterName) {
        map.put("updaterName", updaterName);
    }
    // 包装参数实体
    PageParameter<Map<String, Object>> pageParameter = new PageParameter<Map<String, Object>>(pageNumber, pageSize, map);
    // 返回实体
    PageResult<TextbookLogVO> pageResult = new PageResult<TextbookLogVO>();
    // 参数拷贝
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    // 获取总数
    Integer total = textbookLogDao.listTotalTextbookLogByTextBookId(pageParameter);
    if (null != total && total > 0) {
        List<TextbookLog> rows = textbookLogDao.listTextbookLogByTextBookId(pageParameter);
        List<TextbookLogVO> newRows = new ArrayList<TextbookLogVO>(rows.size());
        for (TextbookLog textbookLog : rows) {
            Long id = textbookLog.getId();
            String detail = textbookLog.getDetail();
            Timestamp gmtCreate = textbookLog.getGmtCreate();
            detail = detail.replace("{gmt_create}", DateUtil.format(gmtCreate));
            newRows.add(new TextbookLogVO(id, detail));
        }
        pageResult.setRows(newRows);
    }
    pageResult.setTotal(total);
    return pageResult;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) Timestamp(java.sql.Timestamp) PageResult(com.bc.pmpheep.back.plugin.PageResult) TextbookLog(com.bc.pmpheep.back.po.TextbookLog) TextbookLogVO(com.bc.pmpheep.back.vo.TextbookLogVO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 90 with CheckedServiceException

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

the class TextbookServiceImpl method getBookListVOs.

public List<BookListVO> getBookListVOs(Long materialId) throws CheckedServiceException {
    if (ObjectUtil.isNull(materialId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "教材id不能为空");
    }
    Material material = materialService.getMaterialById(materialId);
    Long materialType = material.getMaterialType();
    String path;
    try {
        path = materialTypeService.getMaterialTypeById(materialType).getPath();
    } catch (NullPointerException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "找不到此教材的分类");
    }
    if (StringUtil.isEmpty(path)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_TYPE, CheckedExceptionResult.NULL_PARAM, "分类路径为空");
    }
    if (path.indexOf("0-") != -1) {
        path = path.replaceFirst("0-", "");
    }
    String[] pathType = path.split("-");
    for (int i = 0; i < pathType.length; i++) {
        String type = materialTypeService.getMaterialTypeById(Long.valueOf(pathType[i])).getTypeName();
        pathType[i] = pathType[i].replace(pathType[i], type);
    }
    List<Textbook> bookList = textbookDao.getTextbookByMaterialId(materialId);
    List<BookListVO> books = new ArrayList<>();
    if (null == bookList || bookList.isEmpty()) {
        BookListVO bookListVO = new BookListVO();
        bookListVO.setMaterialId(material.getId());
        bookListVO.setMaterialName(material.getMaterialName());
        bookListVO.setMaterialRound(material.getMaterialRound());
        bookListVO.setMaterialType(pathType);
        bookListVO.setIsPublic(material.getIsPublic());
        books.add(bookListVO);
        return books;
    }
    for (Textbook textbook : bookList) {
        BookListVO bookListVO = new BookListVO();
        bookListVO.setMaterialId(material.getId());
        bookListVO.setMaterialName(material.getMaterialName());
        bookListVO.setMaterialRound(material.getMaterialRound());
        bookListVO.setMaterialType(pathType);
        bookListVO.setIsPublic(material.getIsPublic());
        bookListVO.setTextbook(textbook);
        if (CollectionUtil.isNotEmpty(decPositionService.listDecPositionsByTextbookId(textbook.getId())) && decPositionService.listDecPositionsByTextbookId(textbook.getId()).size() > 0) {
            bookListVO.setAllowedDelete(false);
        } else {
            bookListVO.setAllowedDelete(true);
        }
        books.add(bookListVO);
    }
    return books;
}
Also used : BookListVO(com.bc.pmpheep.back.vo.BookListVO) Textbook(com.bc.pmpheep.back.po.Textbook) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material)

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