private XSSFSheet createTypeSheet(XSSFWorkbook workBook) { XSSFSheet typeSheet = workBook.createSheet(PRODUCTTYPE_SHEETNAME); List<ProductType> allTypes = productTypeDao.getAll(); Collections.sort(allTypes, new LftRgtTreeNodeComparator()); // 按左值排序。 List<AdjacencyNode<ProductType>> adjacencyNodes = new LftRgtTreeMenuTool<ProductType>().toAdjacencyNode(allTypes); int rownum = 0; XSSFRow typeTitleRow = typeSheet.createRow(rownum++); typeTitleRow.createCell(0, Cell.CELL_TYPE_STRING).setCellValue("类别名称"); typeTitleRow.createCell(1, Cell.CELL_TYPE_STRING).setCellValue("类别编号"); typeTitleRow.createCell(2, Cell.CELL_TYPE_STRING).setCellValue("父类编号"); for (AdjacencyNode<ProductType> productType : adjacencyNodes) { XSSFRow row = typeSheet.createRow(rownum); XSSFCell typeCell = row.createCell(0, Cell.CELL_TYPE_STRING); typeCell.setCellValue(productType.getNode().getName()); XSSFCell itemCell = row.createCell(1, Cell.CELL_TYPE_STRING); itemCell.setCellValue(productType.getNode().getItem()); if (productType.getParent() != null) { XSSFCell parentItemCell = row.createCell(2, Cell.CELL_TYPE_STRING); parentItemCell.setCellValue(productType.getParent().getItem()); } rownum++; } return typeSheet; }
@Override protected Boolean beforeSaveCheck(Product t) { if (t != null && t.getProductType() != null && t.getProductType().getId() != null) { ProductType type = productTypeDao.getById(t.getProductType().getId()); t.setItem(generateItem(type)); if (!checkExist(t)) { return super.beforeSaveCheck(t); } } return false; }