Search in sources :

Example 1 with WriterUserRole

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

the class MigrationStageTwo method writerUserRole.

protected void writerUserRole() {
    String tableName = "sys_userrole";
    // 增加new_pk字段
    JdbcHelper.addColumn(tableName);
    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 " + "LEFT JOIN sys_userext d ON a.userid = d.userid " + "WHERE b.sysflag = 1 AND d.usertype != 2 ;";
    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, 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(userId)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "此用户不存在。");
            excel.add(map);
            if (state[0] == 0) {
                reason.append("此用户不存在。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        // 按客户要求删除该数据
        if (ObjectUtil.isNull(roleId)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "已删除。");
            excel.add(map);
            if (state[1] == 0) {
                reason.append("没有此角色。");
                dealWith.append("根据客户反馈放弃迁移。");
                state[1] = 1;
            }
            continue;
        }
        WriterUserRole writerUserRole = new WriterUserRole();
        writerUserRole.setUserId(userId);
        writerUserRole.setRoleId(roleId);
        writerUserRole = writerUserRoleService.addWriterUserRole(writerUserRole);
        count++;
        Long pk = writerUserRole.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "userroleid", userroleId);
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "作家-角色关联表", "writer_user_role");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "writer_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("writer_user_role迁移完成");
    logger.info("原数据库表共{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "writer_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) WriterUserRole(com.bc.pmpheep.back.po.WriterUserRole) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with WriterUserRole

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

the class WriterRoleServiceTest method testGetUserRole.

@Test
@Rollback(Const.ISROLLBACK)
public void testGetUserRole() {
    int num = -1;
    num = writerRoleService.addUserRole(1L, 2L);
    WriterUserRole writerUserRole = writerRoleService.getUserRole(1L, 2L);
    Assert.assertNotNull("是否查询成功", writerUserRole);
    num = writerRoleService.deleteUserRole(1L, 2L);
    Assert.assertNotNull("是否删除成功", num >= 0);
    num = writerRoleService.deleteUserRoles(1L);
    Assert.assertNotNull("是否删除成功", num >= 0);
}
Also used : WriterUserRole(com.bc.pmpheep.back.po.WriterUserRole) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with WriterUserRole

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

the class WriterUserRoleServiceTest method testGetWriterUserRoleById.

@Test
@Rollback(Const.ISROLLBACK)
public void testGetWriterUserRoleById() {
    WriterUserRole writerUserRole = this.addWriterUserRole();
    WriterUserRole wur = testService.getWriterUserRoleById(writerUserRole.getId());
    Assert.assertNotNull("不为空", wur);
}
Also used : WriterUserRole(com.bc.pmpheep.back.po.WriterUserRole) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 4 with WriterUserRole

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

the class WriterUserRoleServiceTest method testDeleteWriterUserRoleById.

@Test
@Rollback(Const.ISROLLBACK)
public void testDeleteWriterUserRoleById() {
    WriterUserRole writerUserRole = this.addWriterUserRole();
    Integer bInteger = testService.deleteWriterUserRoleById(writerUserRole.getId());
    Assert.assertTrue("是否删除成功", bInteger > 0 ? true : false);
}
Also used : WriterUserRole(com.bc.pmpheep.back.po.WriterUserRole) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 5 with WriterUserRole

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

the class WriterUserRoleServiceTest method testAddWriterUserRole.

@Test
@Rollback(Const.ISROLLBACK)
public void testAddWriterUserRole() throws Exception {
    // 新增
    WriterUserRole writerUserRole = this.addWriterUserRole();
    Assert.assertNotNull("是否保存成功", writerUserRole.getId());
// logger.info(testPar.toString());
}
Also used : WriterUserRole(com.bc.pmpheep.back.po.WriterUserRole) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Aggregations

WriterUserRole (com.bc.pmpheep.back.po.WriterUserRole)7 BaseTest (com.bc.pmpheep.test.BaseTest)6 Test (org.junit.Test)6 Rollback (org.springframework.test.annotation.Rollback)6 WriterRole (com.bc.pmpheep.back.po.WriterRole)1 WriterUser (com.bc.pmpheep.back.po.WriterUser)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1