Search in sources :

Example 1 with Area

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

the class AreaSeviceTest method testGetAreaChirldren.

@Test
public void testGetAreaChirldren() {
    Area area = addArea();
    List<AreaTreeVO> listAreaTreeVOs = areaService.getAreaChirldren(area.getId());
    Assert.assertNotNull("有子节点", listAreaTreeVOs);
}
Also used : Area(com.bc.pmpheep.back.po.Area) AreaTreeVO(com.bc.pmpheep.back.vo.AreaTreeVO) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 2 with Area

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

the class MigrationStageOne method area.

protected void area() {
    // 要迁移的旧库表名
    String tableName = "ba_areacode";
    // 增加new_pk字段
    JdbcHelper.addColumn(tableName);
    // 取得该表中所有数据
    List<Map<String, Object>> maps = JdbcHelper.queryForList(tableName);
    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) {
        /* 根据MySQL字段类型进行类型转换 */
        BigDecimal areaId = (BigDecimal) map.get("AreaID");
        BigDecimal parentCode = (BigDecimal) map.get("ParentCode");
        String areaName = map.get("AreaName").toString();
        if (StringUtil.isEmpty(areaName)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "找不到区域名称。");
            excel.add(map);
            logger.error("区域名称为空,此结果将被记录在Excel中");
            if (state[0] == 0) {
                reason.append("找不到区域名称。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        if (ObjectUtil.isNull(parentCode)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "找不到区域省-市-县路径。");
            excel.add(map);
            logger.error("父区域编码为空,此结果将被记录在Excel中");
            if (state[1] == 0) {
                reason.append("找不到区域省-市-县路径。");
                dealWith.append("设为默认值0迁入数据库。");
                state[1] = 1;
            }
        }
        /* 开始新增新表对象,并设置属性值 */
        Area area = new Area();
        area.setAreaName(areaName);
        long parentPk = 0L;
        /**
         * 该对象默认为根节点,如果不是根节点,则根据parentCode反查父节点的new_pk。 注意此处由于ba_areacode表爷爷-父亲-儿子是按正序排列的,父节点总是已经被插入到新表,所以不需要再次循环。
         */
        if (parentCode.intValue() != 0) {
            // 返回Long型新主键
            parentPk = JdbcHelper.getPrimaryKey(tableName, "AreaID", parentCode);
        }
        area.setParentId(parentPk);
        area = areaService.addAreaStage(area);
        long pk = area.getId();
        // 更新旧表中new_pk字段
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "AreaID", areaId);
        count++;
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "区域表", "area");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "area");
        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("area表迁移完成");
    logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "area表迁移完成" + 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) WriterPoint(com.bc.pmpheep.back.po.WriterPoint) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) Area(com.bc.pmpheep.back.po.Area) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with Area

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

the class AreaSeviceTest method testDeleteAreaById.

@Test
public void testDeleteAreaById() {
    Area area = addArea();
    Integer count = areaService.deleteAreaById(area.getId());
    Assert.assertTrue("如果删除成功更新数应该会大于或等于1", count >= 1);
}
Also used : Area(com.bc.pmpheep.back.po.Area) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 4 with Area

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

the class AreaSeviceTest method testUpdateArea.

@Test
public void testUpdateArea() {
    Area area = addArea();
    areaService.updateArea(new Area(area.getId(), "测试区域修改方法"));
    Area area1 = areaService.getAreaById(area.getId());
    Assert.assertEquals("是否更新成功", "测试区域修改方法", area1.getAreaName());
}
Also used : Area(com.bc.pmpheep.back.po.Area) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Example 5 with Area

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

the class AreaSeviceTest method testAddArea.

@Test
public void testAddArea() {
    Area area = addArea();
    logger.info("插入的Area对象=" + area.toString());
    Assert.assertNotNull("插入内容后返回的Area不应为空", area.getId());
}
Also used : Area(com.bc.pmpheep.back.po.Area) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest)

Aggregations

Area (com.bc.pmpheep.back.po.Area)7 BaseTest (com.bc.pmpheep.test.BaseTest)5 Test (org.junit.Test)5 WriterPoint (com.bc.pmpheep.back.po.WriterPoint)1 AreaTreeVO (com.bc.pmpheep.back.vo.AreaTreeVO)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1