Search in sources :

Example 1 with PmphRole

use of com.bc.pmpheep.back.po.PmphRole 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> decMainPosition = decPositionService.getMainDecPositionByTextbookId(textbook.getId());
            // 确认是否有主编副主编
            if (decMainPosition.size() == 0) {
                throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "还未遴选主编/副主编,不能进行公布");
            }
            // textbookDao.
            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);
    /*下面是向主任、项目编辑、策划编辑 发送企业微信推送*/
    // 向列表中书籍的主任、项目编辑、策划编辑,发送微信推送,内容拼接如下
    localMethodToLeaderWXMsg(pmphUser, textbooks, "结果公布");
    /**
     * 下面是发布更新最终结果表的数据
     */
    // 获取这些书的申报者
    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);
                        }
                    }
                }
            }
        }
    }
    // 被撤销的职位的人发动态
    for (DecPositionPublished old : olds) {
        // 初始化 是否被撤销
        boolean isDismissed = true;
        // 初始化 被撤销的职位
        int dismissPosition = old.getChosenPosition();
        for (DecPositionPublished now : decPositionPublishedLst) {
            if (old.getDeclarationId().equals(now.getDeclarationId()) && old.getTextbookId().equals(now.getTextbookId())) {
                isDismissed = false;
                // 被撤销的职务数字 = 原职务数字 按位与 (新职务数字 按位取反) [即原本有现在没有的]
                dismissPosition = old.getChosenPosition() & (~now.getChosenPosition());
            }
        }
        if (isDismissed) {
            // 撤销需要发动态的,从此处打开
            // 转换为文字
            String dismissPositionStr = "";
            if ((dismissPosition & 4) > 0) {
                dismissPositionStr += "主编";
            }
            if ((dismissPosition & 2) > 0) {
                dismissPositionStr += "副主编";
            }
            if ((dismissPosition & 1) > 0) {
                dismissPositionStr += "编委";
            }
            if ((dismissPosition & 8) > 0) {
                if (dismissPositionStr.length() > 0) {
                    dismissPositionStr += ",";
                }
                dismissPositionStr += "数字编委";
            }
            if (dismissPositionStr.length() > 0) {
                // 若存在被撤销的职务 发动态给相应作者
                // 添加动态信息
                WriterUserTrendst writerUserTrendst = new WriterUserTrendst();
                writerUserTrendst.setUserId(old.getWriterUserId());
                // 自己可见
                writerUserTrendst.setIsPublic(false);
                writerUserTrendst.setType(8);
                String detail = "";
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("title", CheckedExceptionBusiness.MATERIAL);
                // map.put("content", "抱歉,您《" + old.getTextbookName() + "》的"+dismissPositionStr+"职务已被取消。");
                map.put("content", "您参加的教材“" + material.getMaterialName() + "”的《" + old.getTextbookName() + "》遴选已结束。");
                map.put("img", 2);
                detail = new Gson().toJson(map);
                writerUserTrendst.setDetail(detail);
                writerUserTrendst.setCmsContentId(null);
                writerUserTrendst.setBookId(materialId);
                writerUserTrendst.setBookCommentId(null);
                writerUserTrendstService.addWriterUserTrendst(writerUserTrendst);
            }
        }
    }
    // 先删除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, pmphUser);
    }
    // 当教材遴选结束时给为遴选上的用户推送消息
    Material material2 = materialService.getMaterialById(materialId);
    if (ObjectUtil.notNull(material2)) {
        if (material2.getIsAllTextbookPublished()) {
            List<Declaration> declaration = declarationService.getPositionChooseLossByMaterialId(materialId);
            systemMessageService.sendWhenPositionChooserLoss(materialId, declaration, pmphUser);
            if (null != declaration && declaration.size() > 0) {
                for (Declaration d : declaration) {
                    // 添加动态信息
                    WriterUserTrendst writerUserTrendst = new WriterUserTrendst();
                    writerUserTrendst.setUserId(d.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", "教材已遴选结束,很遗憾,您未入选");
                    map.put("img", 2);
                    detail = new Gson().toJson(map);
                    writerUserTrendst.setDetail(detail);
                    writerUserTrendst.setCmsContentId(null);
                    writerUserTrendst.setBookId(materialId);
                    writerUserTrendst.setBookCommentId(null);
                    writerUserTrendstService.addWriterUserTrendst(writerUserTrendst);
                }
            }
        }
    }
    // 遍历被遴选人发送动态 和被修改成专家
    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)

Example 2 with PmphRole

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

the class TextbookServiceImpl method getPower.

private Integer getPower(Long materialId, PmphUser pmphUser, Material material) {
    // 教材权限的检查
    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;
        }
    }
    // 教材主任检查
    if (null == power) {
        if (null != material && null != material.getDirector()) {
            // 2948 N198-组织机构核对完成后,在教材申报发通知的时候,选择的主任(可能是主任,某个部门的普通员工),要求选择的主任的所有归属单位的主任都有和选择主任的权限一样。
            List<PmphUser> parentDeptsDirectors = pmphUserService.getSomebodyParentDeptsPmphUserOfSomeRole(material.getDirector(), null, "主任");
            for (PmphUser PDDirector : parentDeptsDirectors) {
                if (pmphUser.getId().equals(PDDirector.getId())) {
                    // 我是教材的主任 的部门或上级部门的主任
                    power = 2;
                    break;
                }
            }
            if (pmphUser.getId().equals(material.getDirector())) {
                // 我是教材的主任 本人
                power = 2;
            }
        }
    }
    // 教材项目编辑检查
    if (null == power) {
        List<MaterialProjectEditorVO> materialProjectEditors = materialProjectEditorService.listMaterialProjectEditors(materialId);
        if (null != materialProjectEditors && materialProjectEditors.size() > 0) {
            for (MaterialProjectEditorVO materialProjectEditor : materialProjectEditors) {
                if (null != materialProjectEditor && null != materialProjectEditor.getEditorId() && materialProjectEditor.getEditorId().equals(pmphUser.getId())) {
                    // 我是教材的项目编辑
                    power = 3;
                }
            }
        }
    }
    // 教材策划编辑检查
    if (null == power) {
        Integer num = materialService.getPlanningEditorSum(materialId, pmphUser.getId());
        if (null != num && num > 0) {
            // 我是教材的策划编辑编辑
            power = 4;
        }
    }
    if (null == power) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "该教材您没操作权限");
    }
    return power;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) PmphRole(com.bc.pmpheep.back.po.PmphRole)

Example 3 with PmphRole

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

the class MigrationStageThree method pmphRole.

protected void pmphRole() {
    String tableName = "sys_role";
    List<Map<String, Object>> maps = JdbcHelper.queryForList(tableName);
    List<Map<String, Object>> excel = new LinkedList<>();
    int count = 0;
    for (Map<String, Object> map : maps) {
        Double roleId = (Double) map.get("roleid");
        String rolename = (String) map.get("rolename");
        Integer isDisabled = (Integer) map.get("isvalid");
        Integer sort = (Integer) map.get("sortno");
        if (ObjectUtil.notNull(sort) && sort < 0) {
            sort = 999;
        }
        String note = (String) map.get("memo");
        PmphRole pmphRole = new PmphRole();
        pmphRole.setRoleName(rolename);
        pmphRole.setIsDisabled(isDisabled != 1);
        pmphRole.setSort(sort);
        pmphRole.setNote(note);
        pmphRole = pmphRoleService.addPmphRole(pmphRole);
        count++;
        Long pk = pmphRole.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "roleid", roleId);
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "社内用户角色表", "pmph_role");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    logger.info("pmph_role表迁移完成");
    logger.info("原数据库表共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "pmph_role表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) PmphRole(com.bc.pmpheep.back.po.PmphRole) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with PmphRole

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

the class AddTestUser method addTestUser.

public void addTestUser() {
    String pmphUserData = "[" + "{'username':'yewutest01','realname':'业务测试账号A','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest02','realname':'业务测试账号B','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'系统管理员'},{'roleName':'项目编辑'}]}," + "{'username':'yewutest03','realname':'业务测试账号C','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest04','realname':'业务测试账号D','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest05','realname':'业务测试账号E','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest06','realname':'业务测试账号F','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest07','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest08','realname':'业务测试账号H','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[]}," + "{'username':'yewutest09','realname':'业务测试账号I','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'}]}," + "{'username':'yewutest10','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'},{'roleName':'其他用户'}]}" + "]";
    Gson gson = new Gson();
    List<TestPmphUserBo> testPmphUsers = gson.fromJson(pmphUserData, new TypeToken<ArrayList<TestPmphUserBo>>() {
    }.getType());
    for (TestPmphUserBo user : testPmphUsers) {
        PmphDepartment pmphDepartment = pmphDepartmentService.getPmphDepartmentByName(user.getDepartment());
        PmphUser pmphUser = new PmphUser();
        pmphUser.setUsername(user.getUsername());
        pmphUser.setRealname(user.getRealname());
        pmphUser.setPassword(user.getPassword());
        pmphUser.setDepartmentId(pmphDepartment == null ? 0L : pmphDepartment.getId());
        pmphUser.setAvatar(user.getAvatar());
        pmphUser = pmphUserService.add(pmphUser);
        for (PmphRole pmphRole : user.getRoles()) {
            pmphRole = pmphRoleService.getByName(pmphRole.getRoleName());
            PmphUserRole pmphUserRole = new PmphUserRole();
            pmphUserRole.setUserId(pmphUser.getId());
            pmphUserRole.setRoleId(pmphRole == null ? 0L : pmphRole.getId());
            pmphUserRoleService.addPmphUserRole(pmphUserRole);
        }
    }
    String orgData = "[" + "{'orgName':'北京测试学校','orgType':'本科','areaName':'北京市','username':'bjcsxxtest','password':'123456','realname':'北京学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'bjzuojia01','password':'888888','nickname':'北京作家01','realname':'北京作家01'}," + "{'username':'bjzuojia02','password':'888888','nickname':'北京作家02','realname':'北京作家02'}," + "{'username':'bjzuojia03','password':'888888','nickname':'北京作家03','realname':'北京作家03'}," + "{'username':'bjzuojia04','password':'888888','nickname':'北京作家04','realname':'北京作家04'}," + "{'username':'bjzuojia05','password':'888888','nickname':'北京作家05','realname':'北京作家05'}," + "{'username':'bjzuojia06','password':'888888','nickname':'北京作家06','realname':'北京作家06'}," + "{'username':'bjzuojia07','password':'888888','nickname':'北京作家07','realname':'北京作家07'}," + "{'username':'bjzuojia08','password':'888888','nickname':'北京作家08','realname':'北京作家08'}," + "{'username':'bjzuojia09','password':'888888','nickname':'北京作家09','realname':'北京作家09'}," + "{'username':'bjzuojia10','password':'888888','nickname':'北京作家10','realname':'北京作家10'}," + "{'username':'bjzuojia11','password':'888888','nickname':'北京作家11','realname':'北京作家11'}" + "]" + "}," + "{'orgName':'天津测试学校','orgType':'本科','areaName':'天津市','username':'tjcsxxtest','password':'123456','realname':'天津学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'tjzuojia01','password':'888888','nickname':'天津作家01','realname':'天津作家01'}," + "{'username':'tjzuojia02','password':'888888','nickname':'天津作家02','realname':'天津作家02'}," + "{'username':'tjzuojia03','password':'888888','nickname':'天津作家03','realname':'天津作家03'}," + "{'username':'tjzuojia04','password':'888888','nickname':'天津作家04','realname':'天津作家04'}," + "{'username':'tjzuojia05','password':'888888','nickname':'天津作家05','realname':'天津作家05'}," + "{'username':'tjzuojia06','password':'888888','nickname':'天津作家06','realname':'天津作家06'}," + "{'username':'tjzuojia07','password':'888888','nickname':'天津作家07','realname':'天津作家07'}," + "{'username':'tjzuojia08','password':'888888','nickname':'天津作家08','realname':'天津作家08'}," + "{'username':'tjzuojia09','password':'888888','nickname':'天津作家09','realname':'天津作家09'}," + "{'username':'tjzuojia10','password':'888888','nickname':'天津作家10','realname':'天津作家10'}," + "{'username':'tjzuojia11','password':'888888','nickname':'天津作家11','realname':'天津作家11'}" + "]" + "}" + "]";
    List<TestOrgBo> orgBos = gson.fromJson(orgData, new TypeToken<ArrayList<TestOrgBo>>() {
    }.getType());
    for (TestOrgBo testOrgBo : orgBos) {
        Org org = new Org();
        org.setParentId(0L);
        org.setOrgName(testOrgBo.getOrgName());
        org.setOrgTypeId(orgTypeService.listOrgTypeByTypeName(testOrgBo.getOrgType()).get(0).getId());
        org.setAreaId(areaService.getAreaIdByName(testOrgBo.getAreaName()));
        org = orgService.addOrg(org);
        OrgUser orgUser = new OrgUser();
        orgUser.setUsername(testOrgBo.getUsername());
        orgUser.setPassword(new DesRun("", testOrgBo.getPassword()).enpsw);
        orgUser.setOrgId(org.getId());
        orgUser.setRealname(testOrgBo.getRealname());
        orgUser.setAvatar(testOrgBo.getAreaName());
        orgUser = orgUserService.addOrgUser(orgUser);
        for (WriterUser writerUser : testOrgBo.getWriterUsers()) {
            writerUser.setOrgId(org.getId());
            writerUserService.add(writerUser);
        }
    }
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) Org(com.bc.pmpheep.back.po.Org) OrgUser(com.bc.pmpheep.back.po.OrgUser) Gson(com.google.gson.Gson) PmphRole(com.bc.pmpheep.back.po.PmphRole) TypeToken(com.google.gson.reflect.TypeToken) DesRun(com.bc.pmpheep.back.util.DesRun) WriterUser(com.bc.pmpheep.back.po.WriterUser) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment) PmphUserRole(com.bc.pmpheep.back.po.PmphUserRole)

Example 5 with PmphRole

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

the class PmphLoginController method login.

/**
 * <pre>
 * 功能描述:登陆
 * 使用示范:
 *
 * @param user
 * @param model
 * @return
 * </pre>
 * <p>
 * //* @throws SingleSignOnException
 */
@ResponseBody
// @OAuthRequired
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ResponseBean login(@RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "wechatUserId", required = false) String wechatUserId, @RequestParam(value = "token", required = false) String token, HttpServletRequest request) throws CheckedServiceException {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    logger.info("username => " + username);
    logger.info("password => " + password);
    // HttpSingleSignOnService service = new HttpSingleSignOnService();
    // String url = service.getSingleSignOnURL();
    // try {
    // 判断是否从企业微信App登陆
    String userAgent = request.getHeader("user-agent").toLowerCase();
    Boolean isTrue = userAgent == null || userAgent.indexOf("micromessenger") == -1 ? false : true;
    logger.info("user-agent  " + userAgent);
    if (isTrue) {
        if (StringUtil.notEmpty(token)) {
            String newToken = username + password + wechatUserId + "<pmpheep>";
            if (!newToken.equals(new DesRun(token).depsw)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户名密码错误!");
            }
            if ("sso".equals(wechatUserId)) {
                username = new DesRun(username).depsw;
                password = new DesRun(password).depsw;
            }
        }
    }
    PmphUser pmphUser = null;
    if (isTrue && StringUtil.notEmpty(wechatUserId) && !"sso".equals(wechatUserId) && !"pmphuserlogin".equals(wechatUserId)) {
        // 由微信--我的企业号 登录过来
        // if (isTrue) {//用户名 如果不为空,手动输入
        // 如果是微信登录过来 且wechatUserId 与 username 同时不为空,此时 维护 pmph_user_wechat 表
        PmphUserWechat pmphUserWechat = new PmphUserWechat();
        pmphUserWechat.setUsername(username);
        pmphUserWechat.setWechatId(wechatUserId);
        if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "请输入用户名和密码!");
        }
        pmphUser = pmphUserService.login(username, new DesRun("", password).enpsw);
        pmphUserWechat.setUserid(pmphUser.getId());
        // 微信 我的企业号 绑定userid
        pmphUserWechatService.add(pmphUserWechat);
        pmphUserService.updateUserOpenid(wechatUserId, username, pmphUser.getId());
    // pmphUser = pmphUserService.login(username, null);
    /* } else {//已经绑定
                pmphUser = pmphUserService.login(wechatUserId);
                username = "";
                password = "";
            }
*/
    } else if (StringUtil.notEmpty(wechatUserId) && "pmphuserlogin".equals(wechatUserId)) {
        // 社内用户单点登录
        if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "请输入用户名和密码!");
        }
        pmphUser = pmphUserService.login(username, password);
    } else if (StringUtil.notEmpty(wechatUserId) && "sso".equals(wechatUserId)) {
        // sso 登录
        if (StringUtil.isEmpty(username)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "单点登录失败");
        }
        pmphUser = pmphUserService.login(username, null);
    } else {
        // 正常输入用户名和密码登陆
        if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "请输入用户名和密码!");
        }
        pmphUser = pmphUserService.login(username, new DesRun("", password).enpsw);
    }
    // PmphUser pmphUser = pmphUserService.login(userName, null);
    pmphUser.setLoginType(Const.LOGIN_TYPE_PMPH);
    if (!RouteUtil.DEFAULT_USER_AVATAR.equals(pmphUser.getAvatar())) {
        pmphUser.setAvatar(RouteUtil.userAvatar(pmphUser.getAvatar()));
    }
    // 根据用户Id查询对应角色(是否为管理员)
    List<PmphRole> pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
    if (pmphRoles.isEmpty()) {
        // 添加默认权限
        pmphRoleService.addUserRole(pmphUser.getId(), 2L);
        pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
    }
    List<Long> roleIds = new ArrayList<Long>();
    for (PmphRole pmphRole : pmphRoles) {
        roleIds.add(pmphRole.getId());
        if (ObjectUtil.notNull(pmphRole)) {
            if (Const.LOGIN_USER_IS_ADMIN.equals(pmphRole.getRoleName()) || Const.LOGIN_USER_IS_ADMINS.equals(pmphRole.getRoleName()) || Const.LOGIN_SYS_USER_IS_ADMIN.equals(pmphRole.getRoleName())) {
                pmphUser.setIsAdmin(true);
            } else {
                pmphUser.setIsAdmin(false);
            }
        }
        if (Const.TRUE == pmphUser.getIsAdmin()) {
            break;
        }
    }
    // 根据用户Id查询对应权限Id
    List<Long> pmphUserPermissionIds = pmphUserService.getPmphUserPermissionByUserId(pmphUser.getId());
    // 判断是否从企业微信App登陆
    /* if (isTrue && StringUtil.notEmpty(username) && StringUtil.notEmpty(wechatUserId)) {
            pmphUserService.updateUserOpenid(wechatUserId, username);
        }*/
    // String materialPermission =
    // pmphUserService.getMaterialPermissionByUserId(pmphUser.getId()); 根据用户返回书籍
    // 验证成功在Session中保存用户信息
    request.getSession().setAttribute(Const.SESSION_PMPH_USER, pmphUser);
    // 验证成功在Session中保存用户Token信息
    request.getSession().setAttribute(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
    // pmphUserSessionId
    resultMap.put(Const.USER_SEESION_ID, request.getSession().getId());
    resultMap.put(Const.SESSION_PMPH_USER, pmphUser);
    resultMap.put(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
    resultMap.put("pmphUserPermissionIds", pmphUserPermissionIds);
    // resultMap.put("materialPermission", materialPermission);
    return new ResponseBean(resultMap);
// } catch (CheckedServiceException cException) {
// return new ResponseBean(cException);
// }
}
Also used : HashMap(java.util.HashMap) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphUserWechat(com.bc.pmpheep.back.po.PmphUserWechat) PmphRole(com.bc.pmpheep.back.po.PmphRole) DesRun(com.bc.pmpheep.back.util.DesRun) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PmphRole (com.bc.pmpheep.back.po.PmphRole)11 PmphUser (com.bc.pmpheep.back.po.PmphUser)9 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)8 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)5 DesRun (com.bc.pmpheep.back.util.DesRun)3 Map (java.util.Map)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 PageResult (com.bc.pmpheep.back.plugin.PageResult)2 Material (com.bc.pmpheep.back.po.Material)2 PmphUserWechat (com.bc.pmpheep.back.po.PmphUserWechat)2 WriterUser (com.bc.pmpheep.back.po.WriterUser)2 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 HttpSingleSignOnService (small.danfer.sso.http.HttpSingleSignOnService)2 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)1 DecPosition (com.bc.pmpheep.back.po.DecPosition)1 DecPositionPublished (com.bc.pmpheep.back.po.DecPositionPublished)1