Search in sources :

Example 6 with Textbook

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

the class FileDownLoadController method exportTopic.

/**
 * Description:设置选题号页面导出选题号
 *
 * @author:lyc
 * @date:2018年1月23日下午6:18:41
 * @param
 * @return void
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "设置选题号页面导出选题号信息")
@RequestMapping(value = "/textbook/exportTopic", method = RequestMethod.GET)
public void exportTopic(Long materialId, HttpServletRequest request, HttpServletResponse response) {
    List<Textbook> list = textbookService.listTopicNumber(materialId);
    Workbook workbook = null;
    if (list.size() == 0) {
        list.add(new Textbook());
    }
    try {
        workbook = excelHelper.fromTextbookTopic(list, "选题号导出");
    } catch (CheckedServiceException | IllegalArgumentException | IllegalAccessException e) {
        logger.warn("数据表格化的时候失败");
    }
    Material material = materialService.getMaterialById(materialId);
    String fileName = returnFileName(request, material.getMaterialName() + ".xls");
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/force-download");
    response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
    try (OutputStream out = response.getOutputStream()) {
        workbook.write(out);
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.warn("文件下载时出现IO异常: {}", e.getMessage());
        throw new CheckedServiceException(CheckedExceptionBusiness.FILE, CheckedExceptionResult.FILE_DOWNLOAD_FAILED, "文件在传输时中断");
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) Textbook(com.bc.pmpheep.back.po.Textbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) Workbook(org.apache.poi.ss.usermodel.Workbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Textbook

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

the class DecPositionServiceImpl method updateDecPositionEditorSelection.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Integer updateDecPositionEditorSelection(String jsonDecPosition, Integer selectionType, Integer editorOrSubeditorType, Integer unselectedHold, Long textbookId, String sessionId) throws CheckedServiceException, IOException {
    if (StringUtil.isEmpty(jsonDecPosition)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "遴选职位不能为空");
    }
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    Integer count = 0;
    List<DecPosition> decPositions = // json字符串转List对象集合
    new JsonUtil().getArrayListObjectFromStr(DecPosition.class, jsonDecPosition);
    // 编委遴选界面 (0:未选中)
    Integer unselectedHold_0 = 0;
    if (CollectionUtil.isEmpty(decPositions) && unselectedHold_0 == unselectedHold && 2 == editorOrSubeditorType && 1 == selectionType) {
        // 编委遴选界面,没有人员被选中也可以进行暂存
        // 查询书籍下所有申报id
        List<Long> ids = decPositionService.getDecPositionIdByBookId(textbookId, editorOrSubeditorType);
        // 初始化作家职位申报表
        if (CollectionUtil.isNotEmpty(ids)) {
            decPositionService.updateDecPositionSetDefault(ids, editorOrSubeditorType);
        }
    } else {
        if (CollectionUtil.isEmpty(decPositions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "遴选职位为空");
        }
        // (1:确定,2:发布)
        Integer selectionType_1 = 1;
        Integer selectionType_2 = 2;
        // 获取书籍id
        textbookId = decPositions.get(0).getTextbookId();
        // 原来的历史遴选记录
        List<DecPosition> oldlist = decPositionService.listChosenDecPositionsByTextbookId(textbookId);
        // 1:确定
        if (selectionType_1.intValue() == selectionType.intValue()) {
            // 查询书籍下所有申报id
            List<Long> ids = decPositionService.getDecPositionIdByBookId(textbookId, editorOrSubeditorType);
            if (2 == editorOrSubeditorType) {
                // 遴选的编委ID
                List<Long> newEditorialMemberIds = new ArrayList<Long>();
                for (DecPosition decPosition : decPositions) {
                    if (1 == decPosition.getChosenPosition() || 8 == decPosition.getChosenPosition()) {
                        if (!ids.contains(decPosition.getId())) {
                            newEditorialMemberIds.add(decPosition.getId());
                        }
                    }
                }
                if (newEditorialMemberIds.isEmpty()) {
                    Textbook textbook = textbookService.getTextbookById(textbookId);
                    if (0 != textbook.getRevisionTimes()) {
                        textbookService.updatRevisionTimesByTextBookId(-1, textbookId);
                    }
                } else {
                    textbookService.updatRevisionTimesByTextBookId(1, textbookId);
                }
                // 清楚dec_position_temp表
                decPositionTempService.deleteDecPositionTempByTextbookId(textbookId);
            }
            // 初始化作家职位申报表
            if (CollectionUtil.isNotEmpty(ids)) {
                decPositionService.updateDecPositionSetDefault(ids, editorOrSubeditorType);
            }
            if (CollectionUtil.isNotEmpty(decPositions)) {
                count = decPositionDao.updateDecPositionEditorSelection(decPositions);
            }
            if (ObjectUtil.isNull(textbookId)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "书籍id为空");
            }
            // 用户类型
            Integer userType = 1;
            // 获取修改者id
            Long updaterId = pmphUser.getId();
            // 添加新的遴选记录
            textbookLogService.addTextbookLog(oldlist, textbookId, updaterId, userType);
        }
        // 2:发布
        if (selectionType_2.intValue() == selectionType.intValue()) {
            // 发布的时候 先确认
            this.updateDecPositionEditorSelection(jsonDecPosition, 1, editorOrSubeditorType, unselectedHold, textbookId, sessionId);
            if (ObjectUtil.isNull(textbookId)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "书籍id为空");
            }
            // 获取当前书籍书申报信息(包含没有被遴选上的)
            List<DecPosition> decPositionsList = decPositionService.listDecPositionsByTextBookIds(new ArrayList<Long>(Arrays.asList(textbookId)));
            if (CollectionUtil.isEmpty(decPositionsList)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "当前书籍还未遴选主编,副主编");
            }
            // DecPositionPublished对象集合
            List<DecPositionPublished> decPositionPublisheds = new ArrayList<DecPositionPublished>(decPositionsList.size());
            for (DecPosition decPosition : decPositionsList) {
                // 筛选出遴选上的主编副主编人员
                Integer chosenPosition = decPosition.getChosenPosition();
                if (null != chosenPosition && (chosenPosition == 4 || chosenPosition == 2 || chosenPosition == 12 || chosenPosition == 10)) {
                    chosenPosition = chosenPosition > 8 ? chosenPosition - 8 : chosenPosition;
                    decPositionPublisheds.add(new DecPositionPublished(pmphUser.getId(), decPosition.getDeclarationId(), textbookId, decPosition.getPresetPosition(), chosenPosition, decPosition.getRank(), decPosition.getSyllabusId(), decPosition.getSyllabusName()));
                }
            }
            // 已经公布的列表
            List<DecPositionPublished> lst = decPositionPublishedService.getDecPositionPublishedListByBookId(textbookId);
            List<DecPositionPublished> addNew = new ArrayList<DecPositionPublished>(16);
            for (DecPositionPublished item : lst) {
                // 编委 | 数字编委
                if (item.getChosenPosition() == 1 || item.getChosenPosition() >= 8) {
                    // item.setChosenPosition(item.getChosenPosition() > 8
                    // ?(item.getChosenPosition()-8):item.getChosenPosition() );
                    addNew.add(item);
                }
            }
            // 加入主编副主编
            for (DecPositionPublished item : decPositionPublisheds) {
                boolean no = true;
                for (DecPositionPublished itemadd : addNew) {
                    if (itemadd.getDeclarationId().intValue() == item.getDeclarationId().intValue()) {
                        no = false;
                        itemadd.setChosenPosition(item.getChosenPosition() + 8);
                        break;
                    }
                }
                if (no) {
                    addNew.add(item);
                }
            }
            // clear Id
            for (DecPositionPublished item : addNew) {
                item.setId(null);
            }
            // 对比重新发布之前于之后的不同
            List<DecPositionPublished> newMessage = new ArrayList<>();
            for (DecPositionPublished now : decPositionPublisheds) {
                DecPositionPublished published = decPositionPublishedService.getDecPositionByDeclarationId(now.getDeclarationId(), now.getTextbookId());
                if (ObjectUtil.isNull(published)) {
                    newMessage.add(now);
                }
                for (DecPositionPublished old : lst) {
                    if (now.getDeclarationId().equals(old.getDeclarationId())) {
                        if (!now.getChosenPosition().equals(old.getChosenPosition()) || !now.getRank().equals(old.getRank())) {
                            newMessage.add(now);
                        }
                    }
                }
            }
            // 先删除当前发布人已发布的
            decPositionPublishedService.deleteDecPositionPublishedByTextBookId(textbookId);
            // 再添加
            decPositionPublishedService.batchInsertDecPositionPublished(addNew);
            // 发布时更新textbook表中is_chief_published(是否已公布主编/副主编)字段
            count = textbookService.updateTextbook(new Textbook(textbookId, true));
            if (count > 0) {
                // 发送消息
                systemMessageService.sendWhenConfirmFirstEditor(textbookId, newMessage);
            }
        }
    }
    return count;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) JsonUtil(com.bc.pmpheep.back.util.JsonUtil) DecPosition(com.bc.pmpheep.back.po.DecPosition) NewDecPosition(com.bc.pmpheep.back.vo.NewDecPosition) Textbook(com.bc.pmpheep.back.po.Textbook)

Example 8 with Textbook

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

the class DecPositionServiceImpl method batchPublishEditor.

@Override
public Integer batchPublishEditor(List<Long> textbookIds, String sessionId) throws CheckedServiceException, IOException {
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(pmphUser.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    if (ObjectUtil.isNull(textbookIds)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "未选中书籍");
    }
    Integer count = 0;
    for (Long textbookId : textbookIds) {
        // 查询当前书籍已遴选的主编,副主编
        List<DecPosition> listDecPositions = this.getEditorByTextbookId(textbookId);
        if (CollectionUtil.isEmpty(listDecPositions)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "当前选中书籍还未遴选主编,副主编");
        }
        // DecPositionPublished对象集合
        List<DecPositionPublished> decPositionPublisheds = new ArrayList<DecPositionPublished>(listDecPositions.size());
        for (DecPosition decPosition : listDecPositions) {
            decPositionPublisheds.add(new DecPositionPublished(pmphUser.getId(), decPosition.getDeclarationId(), textbookId, decPosition.getPresetPosition(), decPosition.getChosenPosition(), decPosition.getRank(), decPosition.getSyllabusId(), decPosition.getSyllabusName()));
        }
        // 删除已发布的主编,副主编
        decPositionPublishedService.deletePublishedEditorByTextbookId(textbookId);
        // 重新发布
        // 再添加
        decPositionPublishedService.batchInsertDecPositionPublished(decPositionPublisheds);
        // 发布时更新textbook表中is_chief_published(是否已公布主编/副主编)字段
        count = textbookService.updateTextbook(new Textbook(textbookId, true));
        if (count > 0) {
            // 发送消息
            systemMessageService.sendWhenConfirmFirstEditor(textbookId, decPositionPublisheds);
        }
    }
    return count;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) DecPosition(com.bc.pmpheep.back.po.DecPosition) NewDecPosition(com.bc.pmpheep.back.vo.NewDecPosition) ArrayList(java.util.ArrayList) Textbook(com.bc.pmpheep.back.po.Textbook) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished)

Example 9 with Textbook

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

the class MaterialServiceImpl method updateMaterial.

@Override
public String updateMaterial(Long id, String sessionId) throws CheckedServiceException {
    Material material = materialDao.getMaterialById(id);
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (pmphUser.getIsAdmin() || pmphUser.getId().equals(material.getDirector()) || pmphUser.getId().equals(material.getFounderId())) {
        List<Textbook> list = textbookService.getTextbookByMaterialId(id);
        for (Textbook textbook : list) {
            PmphGroup group = pmphGroupService.getPmphGroupByTextbookId(textbook.getId());
            if (ObjectUtil.notNull(group)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "您在" + textbook.getTextbookName() + "书籍下还有未解散的小组,请先解散小组");
            }
        }
        material = new Material();
        material.setId(id);
        material.setIsDeleted(true);
        materialDao.updateMaterial(material);
        cmsContentService.updateCmsContentByMaterialId(id);
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.ILLEGAL_PARAM, "您没有删除教材" + material.getMaterialName() + "的权限");
    }
    return "SUCCESS";
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) Textbook(com.bc.pmpheep.back.po.Textbook) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) Material(com.bc.pmpheep.back.po.Material) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException)

Example 10 with Textbook

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

the class SystemMessageService method sendWhenPubfinalResult.

/**
 * 某一本书的最终结果公布 或者 整套教材全部公布时 向当选者和学校管理员发送消息
 *
 * @author Mryang
 * @createDate 2017年11月19日 上午11:24:31
 * @param textBookId
 * @throws CheckedServiceException
 * @throws IOException
 */
public void sendWhenPubfinalResult(Long textBookId, List<DecPositionPublished> decPositionPublishedLst) throws CheckedServiceException, IOException {
    Textbook textbook = textbookService.getTextbookById(textBookId);
    Material material = materialService.getMaterialById(textbook.getMaterialId());
    // 给主编、副主编、编委、数字编委发送
    String msg = "";
    for (DecPositionPublished decPosition : decPositionPublishedLst) {
        if (null != decPosition.getChosenPosition()) {
            if (decPosition.getChosenPosition() == 8) {
                msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的数字编委";
            }
            if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
                if (null != decPosition.getRank() && decPosition.getRank() == 1) {
                    if (decPosition.getChosenPosition() == 4) {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的第一主编";
                    } else {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的第一主编、数字编委";
                    }
                } else {
                    if (decPosition.getChosenPosition() == 4) {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的主编";
                    } else {
                        msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的主编、数字编委";
                    }
                }
            }
            if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
                if (decPosition.getChosenPosition() == 2) {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的副主编";
                } else {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的副主编、数字编委";
                }
            }
            if (decPosition.getChosenPosition() == 1 || 9 == decPosition.getChosenPosition()) {
                if (decPosition.getChosenPosition() == 1) {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的编委";
                } else {
                    msg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,恭喜您当选[<font color='red'>" + textbook.getTextbookName() + "</font>]的编委、数字编委";
                }
            }
            // 获取申报表
            Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
            // 存入消息主体
            Message message = new Message(msg);
            message = messageService.add(message);
            String msg_id = message.getId();
            // 发送消息给申报者
            userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), declaration.getUserId(), new Short("2"), null));
            // websocket推送页面消息
            WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msg, DateUtil.getCurrentTime());
            List<String> userIds = new ArrayList<String>(1);
            userIds.add("2_" + declaration.getUserId());
            myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
        }
    }
    // 给学校管理员发送消息
    if (material.getIsAllTextbookPublished()) {
        // 所有都发布了
        String orgMsg = "《<font color='red'>" + material.getMaterialName() + "</font>》的编写团队遴选已结束,贵校共[{sum}]位老师当选,名单如下:";
        // 根据教材Id查询对应的书籍集合
        List<Textbook> textbooks = textbookService.getTextbookByMaterialId(material.getId());
        List<Long> bookIds = new ArrayList<Long>();
        for (Textbook book : textbooks) {
            bookIds.add(book.getId());
        }
        // 根据书籍获取当选了该书籍的人员所属机构
        List<Org> orgs = orgService.listBeElectedOrgByBookIds(bookIds);
        for (Org org : orgs) {
            // 根据orgid和bookid获取该机构某些已公布的书的申报职位
            List<DecPosition> decPositions = decPositionService.listDecPositionsByTextbookIdAndOrgid(bookIds, org.getId());
            if (null != decPositions && decPositions.size() > 0) {
                String msgContent = orgMsg;
                int sum = 0;
                for (int i = 0; i < decPositions.size(); i++) {
                    DecPosition decPosition = decPositions.get(i);
                    Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
                    msgContent += "</br>" + "[<font color='red'>" + declaration.getRealname() + "</font>]";
                    msgContent += " - " + textbookService.getTextbookById(decPosition.getTextbookId()).getTextbookName() + " - ";
                    if (null != decPosition.getChosenPosition()) {
                        if (decPosition.getChosenPosition() == 8) {
                            msgContent += "数字编委";
                        }
                        if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
                            if (decPosition.getRank() == 1) {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "第一主编";
                                } else {
                                    msgContent += "第一主编、数字编委";
                                }
                            } else {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "主编";
                                } else {
                                    msgContent += "主编、数字编委";
                                }
                            }
                        }
                        if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
                            if (decPosition.getChosenPosition() == 2) {
                                msgContent += "副主编";
                            } else {
                                msgContent += "副主编、数字编委";
                            }
                        }
                        if (decPosition.getChosenPosition() == 1 || decPosition.getChosenPosition() == 9) {
                            if (decPosition.getChosenPosition() == 1) {
                                msgContent += "编委";
                            } else {
                                msgContent += "编委、数字编委";
                            }
                        }
                    }
                    sum++;
                }
                msgContent.replace("{sum}", String.valueOf(sum));
                // 存入消息主体
                Message message = new Message(msgContent);
                message = messageService.add(message);
                String msg_id = message.getId();
                // 获取机构管理员
                OrgUser orgUser = orgUserService.getOrgUserByOrgId(org.getId());
                // 发送消息给申报者
                userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null));
                // websocket推送页面消息
                WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
                List<String> userIds = new ArrayList<String>(1);
                userIds.add("3_" + orgUser.getId());
                myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
            }
        }
    // 《全国高等学校五年制临床医学专业第九轮规划教材》的编写团队遴选已结束,贵校共[5]位老师当选,名单如下:
    // [丁志国] - 局部解剖学 - 第一主编
    // [王海滨] - 医学影像学 - 第二主编
    // [雷国华] - 医学计算机应用 - 副主编
    // [孙风梅] - 医学文献检索与论文写作 - 编委
    // [宋守君] - 医患沟通 - 编委
    } else {
        String orgMsg = "《<font color='red'>" + material.getMaterialName() + "</font>》[<font color='red'>" + textbook.getTextbookName() + "</font>]的最终结果已公布,贵校老师";
        // 《全国高等学校五年制临床医学专业第九轮规划教材》[传染病学]的最终结果已公布,贵校老师[丁志国]当选第一主编,[丁志国]当选第一主编,[丁志国]当选第一主编
        // 先要将学校分队
        List<Long> bookIds = new ArrayList<Long>();
        bookIds.add(textBookId);
        // 根据教材Id查询对应的书籍集合
        List<Org> orgs = orgService.listBeElectedOrgByBookIds(bookIds);
        for (Org org : orgs) {
            // 根据orgid和bookid获取该机构某些已公布的书的申报职位
            List<DecPosition> decPositions = decPositionService.listDecPositionsByTextbookIdAndOrgid(bookIds, org.getId());
            if (null != decPositions && decPositions.size() > 0) {
                // 拼装消息
                String msgContent = orgMsg;
                for (int i = 0; i < decPositions.size(); i++) {
                    DecPosition decPosition = decPositions.get(i);
                    Declaration declaration = declarationService.getDeclarationById(decPosition.getDeclarationId());
                    if (i > 0) {
                        msgContent += ",";
                    }
                    msgContent += "[<font color='red'>" + declaration.getRealname() + "</font>]当选";
                    if (null != decPosition.getChosenPosition()) {
                        if (decPosition.getChosenPosition() == 8) {
                            msgContent += "数字编委";
                        }
                        if (decPosition.getChosenPosition() == 4 || decPosition.getChosenPosition() == 12) {
                            if (decPosition.getRank() == 1) {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "第一主编";
                                } else {
                                    msgContent += "第一主编、数字编委";
                                }
                            } else {
                                if (decPosition.getChosenPosition() == 4) {
                                    msgContent += "主编";
                                } else {
                                    msgContent += "主编、数字编委";
                                }
                            }
                        }
                        if (decPosition.getChosenPosition() == 2 || decPosition.getChosenPosition() == 10) {
                            if (decPosition.getChosenPosition() == 2) {
                                msgContent += "副主编";
                            } else {
                                msgContent += "副主编、数字编委";
                            }
                        }
                        if (decPosition.getChosenPosition() == 1 || decPosition.getChosenPosition() == 9) {
                            if (decPosition.getChosenPosition() == 1) {
                                msgContent += "编委";
                            } else {
                                msgContent += "编委、数字编委";
                            }
                        }
                    }
                }
                // 存入消息主体
                Message message = new Message(msgContent);
                message = messageService.add(message);
                String msg_id = message.getId();
                // 获取机构管理员
                OrgUser orgUser = orgUserService.getOrgUserByOrgId(org.getId());
                // 发送消息给申报者
                userMessageService.addUserMessage(new UserMessage(msg_id, messageTitle, new Short("0"), 0L, new Short("0"), orgUser.getId(), new Short("3"), null));
                // websocket推送页面消息
                WebScocketMessage webScocketMessage = new WebScocketMessage(msg_id, Const.MSG_TYPE_0, 0L, "系统", Const.SENDER_TYPE_0, Const.SEND_MSG_TYPE_0, RouteUtil.DEFAULT_USER_AVATAR, messageTitle, msgContent, DateUtil.getCurrentTime());
                List<String> userIds = new ArrayList<String>(1);
                userIds.add("3_" + orgUser.getId());
                myWebSocketHandler.sendWebSocketMessageToUser(userIds, webScocketMessage);
            }
        }
    }
}
Also used : UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) Org(com.bc.pmpheep.back.po.Org) OrgUser(com.bc.pmpheep.back.po.OrgUser) ArrayList(java.util.ArrayList) Material(com.bc.pmpheep.back.po.Material) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) DecPosition(com.bc.pmpheep.back.po.DecPosition) Textbook(com.bc.pmpheep.back.po.Textbook) Declaration(com.bc.pmpheep.back.po.Declaration)

Aggregations

Textbook (com.bc.pmpheep.back.po.Textbook)25 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)18 ArrayList (java.util.ArrayList)14 Material (com.bc.pmpheep.back.po.Material)12 PmphUser (com.bc.pmpheep.back.po.PmphUser)7 DecPosition (com.bc.pmpheep.back.po.DecPosition)6 DecPositionPublished (com.bc.pmpheep.back.po.DecPositionPublished)5 Declaration (com.bc.pmpheep.back.po.Declaration)4 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)4 IOException (java.io.IOException)4 Workbook (org.apache.poi.ss.usermodel.Workbook)4 UserMessage (com.bc.pmpheep.back.po.UserMessage)3 Message (com.bc.pmpheep.general.po.Message)3 BaseTest (com.bc.pmpheep.test.BaseTest)3 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)3 Gson (com.google.gson.Gson)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Rollback (org.springframework.test.annotation.Rollback)3 DeclarationEtcBO (com.bc.pmpheep.back.bo.DeclarationEtcBO)2