Search in sources :

Example 1 with PmphUserRole

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

the class PmphUserRoleServiceTest method test.

@Test
@Rollback(Const.ISROLLBACK)
public void test() {
    testService.addPmphUserRole(testPar);
    PmphUserRole pur = testService.getPmphUserRoleById(testPar.getId());
    Assert.assertNotNull("不为空", pur);
}
Also used : PmphUserRole(com.bc.pmpheep.back.po.PmphUserRole) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 2 with PmphUserRole

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

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

the class MigrationStageThree method pmphUserRole.

protected void pmphUserRole() {
    // 此表在图3中已经添加new_pk,运行顺序是先图3再图2
    String tableName = "sys_userrole";
    String sql = "SELECT a.userroleid,b.userid,b.new_pk user_new_pk,c.roleid,c.new_pk role_new_pk " + "FROM sys_userrole a " + "LEFT JOIN sys_user b ON a.userid = b.userid " + "LEFT JOIN sys_role c ON a.roleid = c.roleid " + "WHERE b.sysflag = 0 OR b.usercode = 'admin';";
    List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
    List<Map<String, Object>> excel = new LinkedList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int count = 0;
    // 统计正常数据的数量
    int correctCount = 0;
    // 识别当前数据异常是否存在的标识
    int[] state = { 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    for (Map<String, Object> map : maps) {
        Double userroleId = (Double) map.get("userroleid");
        Long userId = (Long) map.get("user_new_pk");
        Long roleId = (Long) map.get("role_new_pk");
        if (ObjectUtil.isNull(roleId)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "用户所属角色被删除。");
            excel.add(map);
            if (state[0] == 0) {
                reason.append("用户所属角色被删除。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        PmphUserRole pmphUserRole = new PmphUserRole();
        pmphUserRole.setUserId(userId);
        pmphUserRole.setRoleId(roleId);
        pmphUserRole = pmphUserRoleService.addPmphUserRole(pmphUserRole);
        count++;
        Long pk = pmphUserRole.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "userroleid", userroleId);
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "社内用户-角色关联表", "pmph_user_role");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "pmph_user_role");
        result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "社内用户-角色关联表");
        result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.size());
        result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
        result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
        result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
        result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, maps.size() - count);
        result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
        result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
        SQLParameters.STATISTICS_RESULT.add(result);
    }
    logger.info("pmph_user_role表迁移完成");
    logger.info("原数据库表共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "pmph_user_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) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PmphUserRole(com.bc.pmpheep.back.po.PmphUserRole)

Example 4 with PmphUserRole

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

the class PmphUserServiceImpl method updatePmphUserOfBack.

@Override
public String updatePmphUserOfBack(PmphUserManagerVO pmphUserManagerVO) throws CheckedServiceException {
    PmphUser username = pmphUserDao.get(pmphUserManagerVO.getId());
    if (!username.getUsername().equals(pmphUserManagerVO.getUsername())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户账号不相同");
    }
    if (ObjectUtil.isNull(pmphUserManagerVO.getId())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户ID为空时禁止更新用户");
    }
    if (StringUtil.strLength(pmphUserManagerVO.getUsername()) > 20) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户名需要小于20字符");
    }
    if (StringUtil.strLength(pmphUserManagerVO.getRealname()) > 20) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "姓名需要小于20字符");
    }
    if (!StringUtil.isEmpty(pmphUserManagerVO.getHandphone())) {
        if (!ValidatUtil.checkMobileNumber(pmphUserManagerVO.getHandphone())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "电话格式不正确");
        }
    }
    if (!StringUtil.isEmpty(pmphUserManagerVO.getEmail())) {
        if (!ValidatUtil.checkEmail(pmphUserManagerVO.getEmail())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱格式不正确");
        }
    }
    if (StringUtil.isEmpty(pmphUserManagerVO.getRealname())) {
        pmphUserManagerVO.setRealname(pmphUserManagerVO.getUsername());
    }
    int num = pmphUserDao.updatePmphUserOfBack(pmphUserManagerVO);
    String result = "FAIL";
    if (num > 0) {
        pmphUserRoleDao.deletePmphUserRoleByUserId(pmphUserManagerVO.getId());
        String pmphRoles = pmphUserManagerVO.getRoleIds();
        if (!StringUtil.isEmpty(pmphRoles)) {
            String[] roleIds = pmphRoles.split(",");
            for (String roleId : roleIds) {
                PmphUserRole pmphUserRole = new PmphUserRole(pmphUserManagerVO.getId(), Long.valueOf(roleId));
                pmphUserRoleDao.addPmphUserRole(pmphUserRole);
            }
        }
        result = "SUCCESS";
    }
    return result;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphUserRole(com.bc.pmpheep.back.po.PmphUserRole)

Aggregations

PmphUserRole (com.bc.pmpheep.back.po.PmphUserRole)4 PmphUser (com.bc.pmpheep.back.po.PmphUser)2 Org (com.bc.pmpheep.back.po.Org)1 OrgUser (com.bc.pmpheep.back.po.OrgUser)1 PmphDepartment (com.bc.pmpheep.back.po.PmphDepartment)1 PmphRole (com.bc.pmpheep.back.po.PmphRole)1 WriterUser (com.bc.pmpheep.back.po.WriterUser)1 DesRun (com.bc.pmpheep.back.util.DesRun)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 BaseTest (com.bc.pmpheep.test.BaseTest)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Test (org.junit.Test)1 Rollback (org.springframework.test.annotation.Rollback)1