Search in sources :

Example 11 with Material

use of com.bc.pmpheep.back.po.Material 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)

Example 12 with Material

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

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

the class PmphUserServiceImpl method getListPmphUser.

@Override
public PageResult<PmphUserManagerVO> getListPmphUser(PageParameter<PmphUserManagerVO> pageParameter, Long groupId) throws CheckedServiceException {
    String name = pageParameter.getParameter().getName();
    if (StringUtil.notEmpty(name)) {
        pageParameter.getParameter().setName(name);
    }
    String path = pageParameter.getParameter().getPath();
    Long departmentId = pageParameter.getParameter().getDepartmentId();
    if (StringUtil.notEmpty(path) && ObjectUtil.notNull(departmentId)) {
        pageParameter.getParameter().setPath(path + "-" + java.lang.String.valueOf(departmentId) + '-');
    }
    PageResult<PmphUserManagerVO> pageResult = new PageResult<>();
    PageParameterUitl.CopyPageParameter(pageParameter, pageResult);
    int total = pmphUserDao.getListPmphUserTotal(pageParameter);
    if (total > 0) {
        List<PmphUserManagerVO> list = pmphUserDao.getListPmphUser(pageParameter);
        for (PmphUserManagerVO pmphUserManagerVO : list) {
            List<PmphRoleVO> pmphRoles = pmphRoleDao.listPmphUserRoleByUserId(pmphUserManagerVO.getId());
            pmphUserManagerVO.setPmphRoles(pmphRoles);
        }
        pageResult.setRows(list);
    }
    pageResult.setTotal(total);
    // 设置职位
    if (null != pageResult.getRows() && pageResult.getRows().size() > 0 && null != groupId) {
        // 清空职位
        for (PmphUserManagerVO pmphUserManagerVO : pageResult.getRows()) {
            pmphUserManagerVO.setPosition("无");
        }
        PmphGroup pmphGroup = pmphGroupService.getPmphGroupById(groupId);
        Long bookId = pmphGroup.getBookId();
        if (null != bookId && bookId.intValue() > 0) {
            Textbook textbook = textbookService.getTextbookById(bookId);
            Material material = materialService.getMaterialById(textbook.getMaterialId());
            List<MaterialProjectEditorVO> projects = materialProjectEditorService.listMaterialProjectEditors(textbook.getMaterialId());
            for (PmphUserManagerVO pmphUserManagerVO : pageResult.getRows()) {
                Long pmphUserId = pmphUserManagerVO.getId();
                String posotion = null;
                if (material.getDirector().intValue() == pmphUserId.intValue()) {
                    posotion = "主任";
                }
                if (null != projects && projects.size() > 0) {
                    for (MaterialProjectEditorVO item : projects) {
                        if (item.getEditorId().intValue() == pmphUserId.intValue()) {
                            posotion += (posotion == null) ? "项目编辑" : ",项目编辑";
                            break;
                        }
                    }
                }
                if (textbook.getPlanningEditor().intValue() == pmphUserId.intValue()) {
                    posotion += (posotion == null) ? "策划编辑" : ",策划编辑";
                }
                pmphUserManagerVO.setPosition(posotion == null ? "无" : posotion);
            }
        }
    }
    // 设置职位 end
    return pageResult;
}
Also used : Material(com.bc.pmpheep.back.po.Material) PageResult(com.bc.pmpheep.back.plugin.PageResult) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) PmphGroup(com.bc.pmpheep.back.po.PmphGroup) Textbook(com.bc.pmpheep.back.po.Textbook) PmphUserManagerVO(com.bc.pmpheep.back.vo.PmphUserManagerVO) PmphRoleVO(com.bc.pmpheep.back.vo.PmphRoleVO)

Example 14 with Material

use of com.bc.pmpheep.back.po.Material 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)

Example 15 with Material

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

the class TextbookServiceImpl method updateTextbookAndMaterial.

@Override
public Integer updateTextbookAndMaterial(Long[] ids, String sessionId, Long materialId) throws CheckedServiceException, Exception {
    // 获取当前用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    // if (!pmphUser.getIsAdmin()) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
    // CheckedExceptionResult.ILLEGAL_PARAM,
    // "该用户没有操作权限");
    // }
    // 教材权限的检查
    List<PmphRole> pmphRoles = pmphUserService.getListUserRole(pmphUser.getId());
    Integer power = null;
    // 系统管理员权限检查
    for (PmphRole pmphRole : pmphRoles) {
        if (null != pmphRole && null != pmphRole.getRoleName() && "系统管理员".equals(pmphRole.getRoleName())) {
            // 我是系统管理原
            power = 1;
        }
    }
    // 教材主任检查
    Material material = materialService.getMaterialById(materialId);
    if (null == power) {
        if (null != material && null != material.getDirector() && pmphUser.getId().equals(material.getDirector())) {
            // 我是教材的主任
            power = 2;
        }
    }
    List<Textbook> textbooks = textbookDao.getTextbooks(ids);
    if (textbooks.size() > 0) {
        for (Textbook textbook : textbooks) {
            // 是否存在策划编辑
            if (ObjectUtil.isNull(textbook.getPlanningEditor())) {
                throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "还未选择策划编辑,不能进行公布");
            }
            // 是否发布主编
            if (!textbook.getIsChiefPublished()) {
                throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "还未发布主编/副主编,不能进行公布");
            }
            List<DecPosition> decPosition = decPositionService.getDecPositionByTextbookId(textbook.getId());
            // 是否确认编委
            if (decPosition.size() == 0) {
                throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "还未确认编委,不能进行公布");
            }
        }
    }
    Material materials = new Material();
    List<Long> textBookIds = new ArrayList<>(textbooks.size());
    for (Textbook textbook : textbooks) {
        // if(Const.TRUE==textbook.getIsPublished()){
        // throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK,
        // CheckedExceptionResult.ILLEGAL_PARAM,"名单已确认");
        // }
        // if(textbook.getIsPublished()) {
        Textbook textbook2 = new Textbook(textbook.getId(), textbook.getRevisionTimes().intValue() + 1).setIsPublished(true);
        textbook2.setRevisionTimes(textbook.getRevisionTimes().intValue() + 1);
        textbookDao.updateTextbook(textbook2);
        // }else {
        // Textbook textbook2 = new Textbook(textbook.getId(), 0).setIsPublished(true);
        // textbook2.setRevisionTimes(0) ;
        // textbookDao.updateTextbook(textbook2);
        // }
        materials.setId(textbook.getMaterialId());
        textBookIds.add(textbook.getId());
    }
    // textbookDao.updateBookPublished(textBooks);
    // textbookDao.updateTextbook(textbook);
    /**
     * 下面是发布更新最终结果表的数据
     */
    // 获取这些书的申报者
    List<DecPosition> lst = decPositionService.listDecPositionsByTextBookIds(textBookIds);
    // 这些书的被遴选者
    List<DecPositionPublished> decPositionPublishedLst = new ArrayList<DecPositionPublished>(lst.size());
    for (DecPosition decPosition : lst) {
        if (null == decPosition || null == decPosition.getChosenPosition() || decPosition.getChosenPosition() <= 0) {
            continue;
        }
        DecPositionPublished decPositionPublished = new DecPositionPublished();
        decPositionPublished.setPublisherId(pmphUser.getId());
        decPositionPublished.setDeclarationId(decPosition.getDeclarationId());
        decPositionPublished.setTextbookId(decPosition.getTextbookId());
        decPositionPublished.setPresetPosition(decPosition.getPresetPosition());
        decPositionPublished.setIsOnList(true);
        decPositionPublished.setChosenPosition(decPosition.getChosenPosition());
        decPositionPublished.setRank(decPosition.getRank());
        decPositionPublished.setSyllabusId(decPosition.getSyllabusId());
        decPositionPublished.setSyllabusName(decPosition.getSyllabusName());
        decPositionPublishedLst.add(decPositionPublished);
    }
    List<DecPositionPublished> olds = decPositionPublishedService.getDecPositionPublishedListByBookIds(textBookIds);
    List<DecPositionPublished> sends = new ArrayList<>();
    for (DecPositionPublished now : decPositionPublishedLst) {
        if (ObjectUtil.notNull(now.getRank())) {
            sends.add(now);
        } else {
            DecPositionPublished published = decPositionPublishedService.getDecPositionByDeclarationId(now.getDeclarationId(), now.getTextbookId());
            if (ObjectUtil.isNull(published)) {
                sends.add(now);
            }
            for (DecPositionPublished old : olds) {
                if (old.getDeclarationId().equals(now.getDeclarationId()) && old.getTextbookId().equals(now.getTextbookId())) {
                    if (!old.getChosenPosition().equals(now.getChosenPosition())) {
                        sends.add(now);
                    } else {
                        if (null == now.getRank() && null == now.getRank()) {
                        } else if (null != now.getRank() && null != now.getRank()) {
                            if (!now.getRank().equals(now.getRank())) {
                                sends.add(now);
                            }
                        } else {
                            sends.add(now);
                        }
                    }
                }
            }
        }
    }
    // 先删除dec_position_published表中的所有数据
    decPositionPublishedService.deleteDecPositionPublishedByBookIds(textBookIds);
    // 向dec_position_published插入新数据
    decPositionPublishedService.batchInsertDecPositionPublished(decPositionPublishedLst);
    /**
     * 发布更新最终结果表的数据 ---end ---
     */
    // List<Textbook> books = materialDao.getMaterialAndTextbook(materials);
    List<Textbook> books = textbookService.getTextbookByMaterialId(materials.getId());
    Integer count = 0;
    /* 通过遍历查看教材下面所有书籍是否公布,当数据全部公布则该教材改为最终公布 */
    for (Textbook book : books) {
        if (book.getIsPublished()) {
            count++;
        }
    }
    if (count == books.size()) {
        // 检查有没有再次公布
        PageResult<BookPositionVO> listBookPosition = this.listBookPosition(1, 9999999, null, null, null, materials.getId(), sessionId);
        boolean haveNo = true;
        for (BookPositionVO bookPositionVO : listBookPosition.getRows()) {
            if (bookPositionVO.getIsPublished() && bookPositionVO.getRepub()) {
                haveNo = false;
                break;
            }
        }
        if (haveNo) {
            count = materialDao.updateMaterialPublished(materials);
        }
    }
    // 发送消息
    for (Textbook textbook : textbooks) {
        systemMessageService.sendWhenPubfinalResult(textbook.getId(), sends);
    }
    // 当教材遴选结束时给为遴选上的用户推送消息
    Material material2 = materialService.getMaterialById(materialId);
    if (ObjectUtil.notNull(material2)) {
        if (material2.getIsAllTextbookPublished()) {
            List<Declaration> declaration = declarationService.getPositionChooseLossByMaterialId(materialId);
            systemMessageService.sendWhenPositionChooserLoss(materialId, declaration);
        }
    }
    // 遍历被遴选人发送动态 和被修改成专家
    for (DecPositionPublished decPositionPublished : decPositionPublishedLst) {
        if (null == decPositionPublished || null == decPositionPublished.getChosenPosition() || decPositionPublished.getChosenPosition() <= 0) {
            continue;
        }
        // 获取申报表
        Declaration declarationById = declarationService.getDeclarationById(decPositionPublished.getDeclarationId());
        // 修改成专家
        WriterUser writerUser = new WriterUser();
        writerUser.setId(declarationById.getUserId());
        writerUser.setIsExpert(true);
        writerUser.setRank(3);
        writerUserService.update(writerUser);
        // 获取书籍
        Textbook textbook = textbookService.getTextbookById(decPositionPublished.getTextbookId());
        // 作家遴选
        String showChosenPosition = "";
        if (decPositionPublished.getChosenPosition() != 0) {
            switch(decPositionPublished.getChosenPosition()) {
                case 1:
                    showChosenPosition = "编委";
                    break;
                case 2:
                    showChosenPosition = "副主编";
                    break;
                case 3:
                    showChosenPosition = "副主编,编委";
                    break;
                case 4:
                    showChosenPosition = "主编";
                    break;
                case 5:
                    showChosenPosition = "主编,编委";
                    break;
                case 6:
                    showChosenPosition = "主编,副主编";
                    break;
                case 7:
                    showChosenPosition = "主编,副主编,编委";
                    break;
                case 8:
                    showChosenPosition = "数字编委";
                    break;
                case 9:
                    showChosenPosition = "编委,数字编委";
                    break;
                case 10:
                    showChosenPosition = "副主编,数字编委";
                    break;
                case 11:
                    showChosenPosition = "副主编,编委,数字编委";
                    break;
                case 12:
                    showChosenPosition = "主编,数字编委";
                    break;
                case 13:
                    showChosenPosition = "主编,编委,数字编委";
                    break;
                case 14:
                    showChosenPosition = "主编,副主编,数字编委";
                    break;
                case 15:
                    showChosenPosition = "主编,副主编,编委,数字编委";
                    break;
                default:
                    break;
            }
        }
        // 添加动态信息
        WriterUserTrendst writerUserTrendst = new WriterUserTrendst();
        writerUserTrendst.setUserId(declarationById.getUserId());
        // 自己可见
        writerUserTrendst.setIsPublic(false);
        writerUserTrendst.setType(8);
        String detail = "";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", CheckedExceptionBusiness.MATERIAL);
        map.put("content", "您已被遴选为《" + textbook.getTextbookName() + "》的" + showChosenPosition + "。");
        map.put("img", 1);
        detail = new Gson().toJson(map);
        writerUserTrendst.setDetail(detail);
        writerUserTrendst.setCmsContentId(null);
        writerUserTrendst.setBookId(declarationById.getMaterialId());
        writerUserTrendst.setBookCommentId(null);
        writerUserTrendstService.addWriterUserTrendst(writerUserTrendst);
    }
    return count;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) PmphRole(com.bc.pmpheep.back.po.PmphRole) Declaration(com.bc.pmpheep.back.po.Declaration) WriterUser(com.bc.pmpheep.back.po.WriterUser) WriterUserTrendst(com.bc.pmpheep.back.po.WriterUserTrendst) PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) BookPositionVO(com.bc.pmpheep.back.vo.BookPositionVO) DecPosition(com.bc.pmpheep.back.po.DecPosition) Textbook(com.bc.pmpheep.back.po.Textbook)

Aggregations

Material (com.bc.pmpheep.back.po.Material)37 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)30 ArrayList (java.util.ArrayList)18 Textbook (com.bc.pmpheep.back.po.Textbook)12 PmphUser (com.bc.pmpheep.back.po.PmphUser)11 Declaration (com.bc.pmpheep.back.po.Declaration)10 HashMap (java.util.HashMap)8 UserMessage (com.bc.pmpheep.back.po.UserMessage)7 Gson (com.google.gson.Gson)7 IOException (java.io.IOException)7 LogDetail (com.bc.pmpheep.annotation.LogDetail)6 CmsContent (com.bc.pmpheep.back.po.CmsContent)6 MaterialExtra (com.bc.pmpheep.back.po.MaterialExtra)6 MaterialProjectEditorVO (com.bc.pmpheep.back.vo.MaterialProjectEditorVO)6 Message (com.bc.pmpheep.general.po.Message)6 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)6 BufferedOutputStream (java.io.BufferedOutputStream)6 OutputStream (java.io.OutputStream)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 Workbook (org.apache.poi.ss.usermodel.Workbook)6