ソースを参照

增加不同平台导入bug文件功能

bigwit11 4 年 前
コミット
93faa46732

+ 7 - 7
src/main/java/com/mooctest/controller/PaperController.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.mooctest.service.ExcelInputService;
 import com.mooctest.service.PaperService;
+import com.mooctest.util.ImportDataMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
@@ -28,6 +29,9 @@ public class PaperController {
     @Autowired
     ExcelInputService excelInputService;
 
+    @Autowired
+    ImportDataMap importDataMap;
+
     private String ITEM_GROUP_NAME = "item_group_list";
 
     @GetMapping("/addPaper")
@@ -36,25 +40,21 @@ public class PaperController {
         return "add_paper";
     }
 
-//    @GetMapping("/reloadTask")
-//    public String reloadTask ( Model model ){
-//        return "addTask";
-//    }
-
 
     @GetMapping("/addExcel")
     public String addExcel (Model model){
+        model.addAttribute("type_map", importDataMap.typeMap);
         return "add_excel_pro";
     }
 
 
     @PostMapping("/add_excel_pro")
     @ResponseBody
-    public  String excelToMongo (HttpServletResponse response, @RequestParam("name")String name, @RequestParam("excelFile") MultipartFile multipartFile) throws IOException {
+    public  String excelToMongo (@RequestParam("name")String name, @RequestParam("excelFile") MultipartFile multipartFile, @RequestParam("come") Integer comeFrom) throws IOException {
         // 从前端接收Excel文件,并返回文件保存的全路径
         String fileFullPath = excelInputService.saveMultipartFile(multipartFile, name);
         // 拿取文件,并将文件内容插入到Mongo数据库中
-        Map<String, Boolean> is_success = excelInputService.excelToMongo(fileFullPath, name);
+        Map<String, Boolean> is_success = excelInputService.excelToMongo(fileFullPath, name, comeFrom);
         String  insert_success_json= JSON.toJSONString(is_success);
         return insert_success_json;
     }

+ 0 - 1
src/main/java/com/mooctest/controller/TaskController.java

@@ -8,7 +8,6 @@ import com.mooctest.model.MasterReport;
 import com.mooctest.model.Task;
 import com.mooctest.service.*;
 import com.mooctest.util.ReportUtil;
-import org.apache.catalina.tribes.util.Arrays;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;

+ 53 - 6
src/main/java/com/mooctest/service/ExcelInputService.java

@@ -5,6 +5,7 @@ import com.mooctest.dao.TaskDao;
 import com.mooctest.event.EventUtil;
 import com.mooctest.model.ExtendBug;
 import com.mooctest.model.Task;
+import com.mooctest.util.ImportDataMap;
 import org.apache.commons.io.IOUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
@@ -33,6 +34,9 @@ public class ExcelInputService {
     @Autowired
     ExtendBugDao extendBugDao;
 
+    @Autowired
+    ImportDataMap importDataMap;
+
     // 接收前端文件,并将MultipartFile文件转换成File文件,并返回文件路径
     public String saveMultipartFile(MultipartFile file, String fileSaveName){
         OutputStream os = null;
@@ -70,7 +74,7 @@ public class ExcelInputService {
 
 
     // 解析File文件,并将为数据库表中各字段赋值,并将数据数据插入数据库中
-    public Map<String, Boolean> excelToMongo(String address, String fileSaveName) {
+    public Map<String, Boolean> excelToMongo(String address, String fileSaveName, Integer comeFrom) {
         Integer orderId=UUID.randomUUID().toString().hashCode();
         orderId = orderId < 0 ? -orderId : orderId;
         Long task_id = Long.valueOf(orderId);
@@ -80,6 +84,41 @@ public class ExcelInputService {
         Task task = new Task(task_id, case_id, task_name);
         taskDao.save(task);
         Map<String, Boolean> insert_map = new HashMap<>();
+        Map<String, String> typeMap = importDataMap.data.get(comeFrom);
+        String appTitle = typeMap.get("title");
+        String appBugCategor =  typeMap.get("bug_category");
+        String appSeverity =  typeMap.get("severity");
+        String appRecurrent=  typeMap.get("recurrent");
+        String appDescription=  typeMap.get("description");
+
+
+//        InputStream in = ExcelInputService.class.getClassLoader().getResourceAsStream(comeFrom+"-application.properties");
+//        //读取文件
+//        Properties properties=new Properties();
+//        try {
+//            properties.load(in);
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+
+//        String appTitle = null;
+//        String appBugCategor = null;
+//        String appSeverity = null;
+//        String appRecurrent= null;
+//        String appDescription= null;
+//        Map<String,String> dataMap = ImportDateMap.data.get("1");
+//        dataMap.get("tit")
+//        try {
+//            appTitle = new String(properties.getProperty("title").getBytes("ISO8859-1"), "GBK");
+//            appBugCategor =new String(properties.getProperty("bug_category").getBytes("ISO8859-1"), "GBK");
+//            appSeverity = new String(properties.getProperty("severity").getBytes("ISO8859-1"), "GBK");
+//            appRecurrent= new String(properties.getProperty("recurrent").getBytes("ISO8859-1"), "GBK");
+//            appDescription= new String(properties.getProperty("description").getBytes("ISO8859-1"), "GBK");
+//        } catch (UnsupportedEncodingException e) {
+//            e.printStackTrace();
+//        }
+//
+//        System.out.println(appTitle);
 
         try {
             // 输入文件
@@ -101,11 +140,14 @@ public class ExcelInputService {
                 insert_map.put("file_is_null", false);
 
             }
+
+            System.out.println("ok~~");
             for (Cell cell : topRow) {
                 fieldList.add(cell.toString());
             }
 
             logger.info("文件列表" + fieldList);
+            System.out.println("文件列表" + fieldList);
             // 获得表单的行数
             int rows = sheet.getLastRowNum() + 1;
 
@@ -133,7 +175,8 @@ public class ExcelInputService {
                 for (int j = 0; j < colunms; j++) {
                     Cell cell = row.getCell(j);
                     String topName = fieldList.get(j);
-                    if(topName.equals("title") || topName.equals("题目")){
+//                    if(topName.equals("title") || topName.equals("题目")){
+                    if(topName.equals(appTitle)){
                         String title;
                         if(cell == null || cell.toString().equals("")){
                             title = "空";
@@ -141,7 +184,8 @@ public class ExcelInputService {
                             title = cell.toString();
                         }
                         extendBug.setTitle(title);
-                    }else if(topName.equals("bug_category") || topName.equals("分类")){
+//                    }else if(topName.equals("bug_category") || topName.equals("分类")){
+                    }else if(topName.equals(appBugCategor)){
                         String bug_category;
                         if(cell == null || cell.toString().equals("")){
                             bug_category = "空";
@@ -149,7 +193,8 @@ public class ExcelInputService {
                             bug_category = cell.toString();
                         }
                         extendBug.setBugCategory(bug_category);
-                    }else if(topName.equals("severity") || topName.equals("严重等级")){
+//                    }else if(topName.equals("severity") || topName.equals("严重等级")){
+                    }else if(topName.equals(appSeverity)){
                         int num;
                         if(cell == null || cell.toString().equals("")){
                             num = 0;
@@ -158,7 +203,9 @@ public class ExcelInputService {
                         }
                         short severity = (short)num;
                         extendBug.setSeverity(severity);
-                    }else if(topName.equals("recurrent") || topName.equals("复现程度")){
+//                    }else if(topName.equals("recurrent") || topName.equals("复现程度")){
+                    }else if(topName.equals(appRecurrent)){
+
                         int num;
                         if(cell == null || cell.toString().equals("")){
                             num = 0;
@@ -167,7 +214,7 @@ public class ExcelInputService {
                         }
                         short recurrent = (short)num;
                         extendBug.setRecurrent(recurrent);
-                    }else{
+                    }else if(topName.equals(appDescription)){
                         String description;
                         if(cell == null || cell.toString().equals("")){
                             description = "空";

+ 39 - 0
src/main/java/com/mooctest/util/ImportDataMap.java

@@ -0,0 +1,39 @@
+package com.mooctest.util;
+
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+@Component
+public class ImportDataMap{
+
+    public static Map<String,String> typeMap = new HashMap<>();
+
+    static {
+        typeMap.put("1","JIRA格式");
+        typeMap.put("2","禅道格式");
+    }
+
+
+    public static Map<Integer,Map<String,String>> data = new HashMap<>();
+
+    static {
+        Map<String,String> jiraMap = new HashMap<>();
+        jiraMap.put("title","摘要");
+        jiraMap.put("bug_category","标签");
+        jiraMap.put("severity","安全级别");
+        jiraMap.put("recurrent","优先级");
+        jiraMap.put("description","描述");
+        data.put(1,jiraMap);
+
+        Map<String,String> chandaoMap = new HashMap<>();
+        chandaoMap.put("title","Bug标题");
+        chandaoMap.put("bug_category","Bug类型");
+        chandaoMap.put("severity","严重程度");
+        chandaoMap.put("recurrent","优先级");
+        chandaoMap.put("description","重现步骤");
+        data.put(2,chandaoMap);
+    }
+}

BIN
src/main/resources/static/images/icons/priorities/0.png


+ 21 - 6
src/main/resources/templates/add_excel_pro.html

@@ -129,8 +129,8 @@
         <!-- Content Header (Page header) -->
         <section class="content-header">
             <h1>
-                新建众审任务
-                <small>众包审核</small>
+                新建导入bug文件
+                <small>新建任务</small>
             </h1>
             <ol class="breadcrumb">
                 <li><a href="/home"><i class="fa fa-dashboard"></i> 主页</a></li>
@@ -146,16 +146,28 @@
                     <h3 class="box-title">基本信息</h3>
                </div>
 
-                <div class="box-body">
-                    <form id="form" action="/excelToMongo" class="form-horizontal"  method="post" enctype="multipart/form-data">
+                <div class="box-body" >
+                    <form id="form" action="/add_excel_pro" class="form-horizontal"  method="post" enctype="multipart/form-data">
                         <!-- text input -->
+
                         <div class="form-group">
                             <label class="col-sm-2 control-label">名称</label>
                             <div class="col-sm-10">
-                                <input type="text" class="form-control" id="name" name="name" onblur="checkName()" />
+                                <input type="text" class="form-control" id="name" name="name" style="width: 35%" onblur="checkName()" />
                                 <span name="name_span" style="color: #ff0000"></span>
                             </div>
                         </div>
+
+                        <div class="form-group">
+                            <label class="col-sm-2 control-label">文件来源</label>
+                            <div class="col-sm-10">
+                                <select id="come" class="form-control" style="width: 35%">
+                                    <option th:each="mapItem : ${type_map}"
+                                            th:value="${mapItem.key}" th:text="${mapItem.value}"></option>
+                                </select>
+                            </div>
+                        </div>
+
                         <div class="form-group">
                             <label   class="col-sm-2 control-label">导入Bug文件</label>
                             <div class="col-sm-10">
@@ -164,6 +176,8 @@
                                 <span name="file_span" style="color: #ff0000"></span>
                             </div>
                         </div>
+
+
                         <span id="submit_span"></span>
                         <input class="btn btn-success pull-right" type="button" value="提交" id="submit_file" onmousemove="checkSubmit()" onclick="check_success()">
                     </form>
@@ -324,7 +338,7 @@
         var file_size=file.size;//文件的字节数
 
 
-        if(file_type != "xls" && file_type != "xlsx"){
+        if(file_type != "xls" && file_type != "xlsx" && file_type != "csv"){
             file_span.innerText="文件类型错误,请导入excel文件";
             file_flag = false;
         }else {
@@ -368,6 +382,7 @@
         var params = new FormData();
         params.append("name",$("#name").val())
         params.append("excelFile",document.getElementById('excel_file').files[0])
+        params.append("come",$("#come").val());
         $.ajax({
             type:"post",
             url:"/add_excel_pro",