|
@@ -32,10 +32,12 @@ public class ExcelInputService {
|
|
InputStream inputStream = null;
|
|
InputStream inputStream = null;
|
|
String fileName = fileSaveName;
|
|
String fileName = fileSaveName;
|
|
String fileFullPath = null;
|
|
String fileFullPath = null;
|
|
|
|
+ String fileType =null;
|
|
|
|
|
|
try {
|
|
try {
|
|
inputStream = file.getInputStream();
|
|
inputStream = file.getInputStream();
|
|
fileName = file.getOriginalFilename();
|
|
fileName = file.getOriginalFilename();
|
|
|
|
+
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
@@ -78,14 +80,16 @@ public class ExcelInputService {
|
|
|
|
|
|
|
|
|
|
// 解析File文件,并将为数据库表中各字段赋值,并将数据数据插入数据库中
|
|
// 解析File文件,并将为数据库表中各字段赋值,并将数据数据插入数据库中
|
|
- public void excelToMongo(String address, String fileSaveName) {
|
|
|
|
|
|
+ public Map<String, Boolean> excelToMongo(String address, String fileSaveName) {
|
|
Integer orderId=UUID.randomUUID().toString().hashCode();
|
|
Integer orderId=UUID.randomUUID().toString().hashCode();
|
|
orderId = orderId < 0 ? -orderId : orderId;
|
|
orderId = orderId < 0 ? -orderId : orderId;
|
|
Long task_id = Long.valueOf(orderId);
|
|
Long task_id = Long.valueOf(orderId);
|
|
Long case_id = task_id;
|
|
Long case_id = task_id;
|
|
String task_name = fileSaveName;
|
|
String task_name = fileSaveName;
|
|
|
|
+ List<String> fieldList = null;
|
|
Task task = new Task(task_id, case_id, task_name);
|
|
Task task = new Task(task_id, case_id, task_name);
|
|
taskDao.save(task);
|
|
taskDao.save(task);
|
|
|
|
+ Map<String, Boolean> insert_map = new HashMap<>();
|
|
|
|
|
|
try {
|
|
try {
|
|
// 输入文件
|
|
// 输入文件
|
|
@@ -98,12 +102,19 @@ public class ExcelInputService {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
- List<Document> documents = new ArrayList<Document>();
|
|
|
|
- List<String> fieldList = new ArrayList<String>();
|
|
|
|
|
|
+ fieldList = new ArrayList<String>();
|
|
// 获取Excel文档中第一个表单
|
|
// 获取Excel文档中第一个表单
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
// 获取表单第一行作为表头
|
|
// 获取表单第一行作为表头
|
|
Row topRow = sheet.getRow(0);
|
|
Row topRow = sheet.getRow(0);
|
|
|
|
+ if (topRow == null) {
|
|
|
|
+ insert_map.put("file_is_null", true);
|
|
|
|
+ insert_map.put("insert_success", false);
|
|
|
|
+ return insert_map;
|
|
|
|
+ } else {
|
|
|
|
+ insert_map.put("file_is_null", false);
|
|
|
|
+
|
|
|
|
+ }
|
|
for (Cell cell : topRow) {
|
|
for (Cell cell : topRow) {
|
|
fieldList.add(cell.toString());
|
|
fieldList.add(cell.toString());
|
|
}
|
|
}
|
|
@@ -111,6 +122,7 @@ public class ExcelInputService {
|
|
System.out.println("文件列表" + fieldList);
|
|
System.out.println("文件列表" + fieldList);
|
|
// 获得表单的行数
|
|
// 获得表单的行数
|
|
int rows = sheet.getLastRowNum() + 1;
|
|
int rows = sheet.getLastRowNum() + 1;
|
|
|
|
+
|
|
// 获得每行的列数
|
|
// 获得每行的列数
|
|
int colunms = fieldList.size();
|
|
int colunms = fieldList.size();
|
|
// 从第二行开始遍历表格
|
|
// 从第二行开始遍历表格
|
|
@@ -119,6 +131,11 @@ public class ExcelInputService {
|
|
Row row = sheet.getRow(i);
|
|
Row row = sheet.getRow(i);
|
|
String exam_case_id = task_id+"-"+ case_id;
|
|
String exam_case_id = task_id+"-"+ case_id;
|
|
long create_time_millis = System.currentTimeMillis();
|
|
long create_time_millis = System.currentTimeMillis();
|
|
|
|
+ extendBug.setBugCategory("空");
|
|
|
|
+ extendBug.setSeverity((short) 0);
|
|
|
|
+ extendBug.setRecurrent((short) 0);
|
|
|
|
+ extendBug.setTitle("空");
|
|
|
|
+ extendBug.setDescription("空");
|
|
extendBug.setExamId(task_id+"");
|
|
extendBug.setExamId(task_id+"");
|
|
extendBug.setCaseId(case_id+"");
|
|
extendBug.setCaseId(case_id+"");
|
|
extendBug.setExamCaseId(exam_case_id);
|
|
extendBug.setExamCaseId(exam_case_id);
|
|
@@ -129,22 +146,49 @@ public class ExcelInputService {
|
|
*/
|
|
*/
|
|
for (int j = 0; j < colunms; j++) {
|
|
for (int j = 0; j < colunms; j++) {
|
|
Cell cell = row.getCell(j);
|
|
Cell cell = row.getCell(j);
|
|
- if(j == 0){
|
|
|
|
- String title = cell.toString();
|
|
|
|
|
|
+ String topName = fieldList.get(j);
|
|
|
|
+ if(topName.equals("title") || topName.equals("题目")){
|
|
|
|
+ String title;
|
|
|
|
+ if(cell == null || cell.toString().equals("")){
|
|
|
|
+ title = "null";
|
|
|
|
+ }else{
|
|
|
|
+ title = cell.toString();
|
|
|
|
+ }
|
|
extendBug.setTitle(title);
|
|
extendBug.setTitle(title);
|
|
- }else if(j == 1){
|
|
|
|
- String bug_category = cell.toString();
|
|
|
|
|
|
+ }else if(topName.equals("bug_category") || topName.equals("分类")){
|
|
|
|
+ String bug_category;
|
|
|
|
+ if(cell == null || cell.toString().equals("")){
|
|
|
|
+ bug_category = "null";
|
|
|
|
+ }else{
|
|
|
|
+ bug_category = cell.toString();
|
|
|
|
+ }
|
|
extendBug.setBugCategory(bug_category);
|
|
extendBug.setBugCategory(bug_category);
|
|
- }else if(j == 2){
|
|
|
|
- int num = new Double(Double.parseDouble(cell.toString())).intValue();
|
|
|
|
|
|
+ }else if(topName.equals("severity") || topName.equals("严重等级")){
|
|
|
|
+ int num;
|
|
|
|
+ if(cell == null || cell.toString().equals("")){
|
|
|
|
+ num = 0;
|
|
|
|
+ }else{
|
|
|
|
+ num = new Double(Double.parseDouble(cell.toString())).intValue();
|
|
|
|
+ }
|
|
short severity = (short)num;
|
|
short severity = (short)num;
|
|
extendBug.setSeverity(severity);
|
|
extendBug.setSeverity(severity);
|
|
- }else if(j == 3){
|
|
|
|
- int num = new Double(Double.parseDouble(cell.toString())).intValue();
|
|
|
|
|
|
+ }else if(topName.equals("recurrent") || topName.equals("复现程度")){
|
|
|
|
+ int num;
|
|
|
|
+ if(cell == null || cell.toString().equals("")){
|
|
|
|
+ num = 0;
|
|
|
|
+ }else{
|
|
|
|
+ num = new Double(Double.parseDouble(cell.toString())).intValue();
|
|
|
|
+ }
|
|
short recurrent = (short)num;
|
|
short recurrent = (short)num;
|
|
extendBug.setRecurrent(recurrent);
|
|
extendBug.setRecurrent(recurrent);
|
|
}else{
|
|
}else{
|
|
- String description = cell.toString();
|
|
|
|
|
|
+ String description;
|
|
|
|
+ if(cell == null || cell.toString().equals("")){
|
|
|
|
+ description = "null";
|
|
|
|
+ }else{
|
|
|
|
+ description = cell.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
extendBug.setDescription(description);
|
|
extendBug.setDescription(description);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -156,8 +200,12 @@ public class ExcelInputService {
|
|
// 导入成功后将本地文件夹删除
|
|
// 导入成功后将本地文件夹删除
|
|
File file = new File(address);
|
|
File file = new File(address);
|
|
file.delete();
|
|
file.delete();
|
|
|
|
+ insert_map.put("insert_success", true);
|
|
|
|
+ return insert_map;
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
System.err.println(e.getClass().getName() + ": " + e.getMessage());
|
|
System.err.println(e.getClass().getName() + ": " + e.getMessage());
|
|
|
|
+ insert_map.put("insert_success", false);
|
|
|
|
+ return insert_map;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|