Esempio n. 1
0
 /**
  * 批量保存字段
  *
  * @param dataTable
  */
 @Transactional(readOnly = false)
 public void saveTableColumns(DataTable dataTable) {
   List<Object> list = JsonParser.getFormTableDatas(TableColumn.class);
   for (Object obj : list) {
     TableColumn column = (TableColumn) obj;
     column.setCompanyId(ContextUtils.getCompanyId());
     column.setDataTableId(dataTable.getId());
     tableColumnDao.save(column);
   }
 }
Esempio n. 2
0
  @Transactional(readOnly = false)
  public List<TableColumn> importIntoData(File file, DataTable dataTable) throws IOException {
    List<TableColumn> columns = new ArrayList<TableColumn>();
    FileInputStream fileIn = null;

    try {
      List<TableColumn> exsitColumns =
          tableColumnManager.getTableColumnByDataTableId(dataTable.getId());
      for (TableColumn col : exsitColumns) {
        col.setDeleted(true);
        tableColumnManager.saveColumn(col, false);
      }
      fileIn = new FileInputStream(file);
      POIFSFileSystem fs = new POIFSFileSystem(fileIn);
      HSSFWorkbook wb = new HSSFWorkbook(fs);
      HSSFSheet sheet = wb.getSheetAt(0);
      HSSFRow row = null;
      TableColumn tableColumn = null;
      String val = null;
      for (int i = 1; i < sheet.getLastRowNum() + 1; i++) {
        row = sheet.getRow(i);
        tableColumn = new TableColumn();
        tableColumn.setName(row.getCell(0).getStringCellValue());
        tableColumn.setDbColumnName(row.getCell(1).getStringCellValue());
        tableColumn.setAlias(row.getCell(2).getStringCellValue());
        tableColumn.setDataType(DataType.valueOf(row.getCell(3).getStringCellValue()));
        tableColumn.setDefaultValue(row.getCell(4).getStringCellValue());
        val = row.getCell(5).getStringCellValue();
        tableColumn.setMaxLength(StringUtils.isEmpty(val) ? null : Integer.parseInt(val));
        tableColumn.setDisplayOrder(Integer.parseInt(getCellValue(row.getCell(6))));
        tableColumn.setDataTableId(dataTable.getId());
        tableColumnManager.saveColumn(tableColumn, false);
        columns.add(tableColumn);
      }
    } finally {
      if (fileIn != null) fileIn.close();
    }
    return columns;
  }