/** 重设所有部门编号。 */
 @Transactional
 public void updateAllSerialNo() {
   List<Dept> tops = getDao().query("from Dept d where d.parentDept is null");
   Map serialMap = new HashMap(100); // 用于存放部门ID-SerialNo
   // 计算所有部门编号,并将部门ID-部门编号的对应关系存入serialMap
   Integer serial = null;
   for (Dept top : tops) {
     serial = this.getSerial(top, serial);
     // String serialNo = getSerialNo(top);
     top.setSerialNo(buildSerialNo(null, serial));
     serialMap.put(top.getId(), buildSerialNo(null, serial));
     // getDao().saveObject(top);
     if (top.getChildDepts().size() > 0) {
       this.updateChildrenSerialNo(top, serialMap);
     }
   }
   // 批量更新部门编号
   Set<Integer> ids = serialMap.keySet();
   for (Integer id : ids) {
     Dept dept = get(id);
     getDao().evict(dept);
     dept.setSerialNo((String) serialMap.get(id));
     getDao().getHibernateTemplate().update(dept);
   }
 }
  /** 测试根据企业名称和区县ID取得企业信息 */
  @SuppressWarnings("unchecked")
  public void testGetCorpByName() {
    Corp corp = generateCorp("新龙公司", "时代方舟", county);
    corpManager.save(corp);
    Map corpRst = reportManager.getCorpMapByName("新龙公司", county.getId());

    assertNotNull(corpRst);
    assertEquals("新龙公司", corpRst.get("name"));
  }
  /** 测试根据区县ID取得该区县下所有的企业 */
  public void testGetCorpOfCounty() {
    Corp corp1 = generateCorp("新龙公司", "时代方舟A座", county);
    corp1.setBusinessLicense("2010011089");
    Corp corp2 = generateCorp("WIFI", "时代方舟B座", county);
    corpManager.save(corp1);
    corpManager.save(corp2);
    String[] corpRst = reportManager.getCorpOfCounty(county.getId());

    assertNotNull(corpRst);
    assertTrue(corpRst.length >= 2);
  }
  /** 测试根据任务ID取得该任务的详细信息 */
  public void testGetTaskDetailOfTask() {
    Task task = generateTask("测试任务及详细");
    TaskDetail taskDetail = generateTaskDetail("测试任务明细");
    taskDetail.setTask(task);
    taskDetail.setDept(county);
    taskManager.save(task);
    taskManager.getDao().save(taskDetail);
    TaskDetail taskDetailRst = reportManager.getTaskDetailOfTask(task.getId(), county.getId());

    assertNotNull(taskDetailRst);
  }
 /** 更新所有子部门的SerialNo */
 @Transactional
 public void updateChildrenSerialNo(Dept parent, Map serialMap) {
   logger.debug("Update " + parent.getName() + "'s children serial No.");
   Set<Dept> children = parent.getChildDepts();
   Integer serial = null;
   for (Dept child : children) {
     serial = this.getSerial(child, serial);
     child.setSerialNo(buildSerialNo(parent, serial));
     serialMap.put(child.getId(), buildSerialNo(parent, serial));
     // getDao().saveObject(child);
     if (child.getChildDepts().size() > 0) {
       updateChildrenSerialNo(child, serialMap);
     }
   }
 }