Explorar el Código

添加提示 ,修改添加任务页面样式

insomniaLee hace 4 años
padre
commit
549031ab07

+ 9 - 8
src/main/java/com/mooctest/controller/TaskController.java

@@ -3,6 +3,7 @@ package com.mooctest.controller;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.mooctest.data.BugDTO;
+import com.mooctest.data.SimpleResponse;
 import com.mooctest.data.TaskDTO;
 import com.mooctest.model.BugData;
 import com.mooctest.model.MasterReport;
@@ -175,6 +176,7 @@ public class TaskController {
 
     @GetMapping("/addCrowdTask")
     public String addCrowdTask(Model model){
+        model.addAttribute("templateUrl",useOss?"http://mooctest-site.oss-cn-shanghai.aliyuncs.com/excel-template.xlsx":urlPrefix+"excel-template.xlsx");
         return "addCrowdTask";
     }
 
@@ -185,20 +187,19 @@ public class TaskController {
 
     @PostMapping("/addCrowdTask")
     @ResponseBody
-    public String addCrowdTask2(@RequestParam("name")String name,@RequestParam("description")String description,
-                                @RequestParam("time")String time,@RequestParam("type")String type,
-                                @RequestParam("webUrl")String webUrl,@RequestParam(value = "apk",required = false)MultipartFile apk,
-                                @RequestParam("requirement") MultipartFile requirement,@RequestParam("threePage") MultipartFile threePage,
-                                Model model){
-//        String templateUrl  = useOss?""
-        model.addAttribute("templateUrl",useOss?"http://mooctest-site.oss-cn-shanghai.aliyuncs.com/excel-template.xlsx":urlPrefix+"excel-template.xlsx");
-        return taskService.addCrowdTask(name, description, time, type, webUrl, apk, requirement, threePage);
+    public SimpleResponse addCrowdTask2(@RequestParam("name")String name, @RequestParam("description")String description,
+                                        @RequestParam("time")String time, @RequestParam("type")String type,
+                                        @RequestParam("os")String os, @RequestParam("threePage") MultipartFile threePage,
+                                        Model model){
+        if(true)return  new SimpleResponse(200,"success");
+        return taskService.addCrowdTask(name, description, time, type, os, threePage);
     }
 
     @PostMapping("/importTask")
     @ResponseBody
     public String importTask2(@RequestParam("number")String number,@RequestParam("number")String originId,
                               @RequestParam("zipFile") MultipartFile zipFile,@RequestParam("jsonFile") MultipartFile jsonFile){
+        if(true)return  "success";
 
         return taskService.importTask(number, originId, zipFile, jsonFile)?"success":"导出失败";
     }

+ 15 - 0
src/main/java/com/mooctest/data/SimpleResponse.java

@@ -0,0 +1,15 @@
+package com.mooctest.data;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@Builder
+@NoArgsConstructor
+public class SimpleResponse {
+    private int status;
+    private String message;
+}

+ 37 - 13
src/main/java/com/mooctest/service/TaskService.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.mooctest.dao.MasterReportDao;
 import com.mooctest.dao.TaskDao;
 import com.mooctest.dao2.CrowdTaskDao;
+import com.mooctest.data.SimpleResponse;
 import com.mooctest.data.TaskDTO;
 import com.mooctest.model.CrowdTask;
 import com.mooctest.model.Task;
@@ -264,30 +265,27 @@ public class TaskService {
         if(threePage ==null || threePage.isEmpty()) return "请提交三级页面";
         String threePageUrl = fileService.uploadFile(threePage);
         try {
-            boolean flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),"",getMaxCaseId()+1,type,description,name);
-            return flag ?"success":"创建失败";
+            long flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),"",getMaxCaseId()+1,type,description,name);
+            return flag!=-1 ?""+flag:"创建失败";
         } catch (Exception e) {
             e.printStackTrace();
             return "创建众测失败";
         }
     }
 
-    public String addCrowdTask(String name,String description,String time,String type,String webUrl,MultipartFile apk,MultipartFile requirement,MultipartFile threePage){
-        if (requirement==null||requirement.isEmpty()) return "请提交需求文档";
-        if(threePage ==null || threePage.isEmpty()) return "请提交三级页面";
-        if(type.equals(TaskUtil.TaskType.MOBILE.getTaskType())&&(apk==null ||apk.isEmpty()))return "请提交APK文件";
+    public SimpleResponse addCrowdTask(String name, String description, String time, String type, String os, MultipartFile threePage){
+        if(threePage ==null || threePage.isEmpty()) return new SimpleResponse(400,"请提交三级页面");
         String threePageUrl = fileService.uploadFile(threePage);
-        String requirementUrl = fileService.uploadFile(requirement);
         try {
-            boolean flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),"",getMaxCaseId()+1,type,description,name);
-            return flag ?"success":"创建失败";
+            long flag = createCrowdTest(threePageUrl,threePage.getOriginalFilename(),generatePaperType(type,os),getMaxCaseId()+1,type,description,name);
+            return flag!=-1 ?new SimpleResponse(200,"创建成功,id为"+flag):new SimpleResponse(400,"创建失败");
         } catch (Exception e) {
             e.printStackTrace();
-            return "创建众测失败";
+            return new SimpleResponse(400,"创建众测失败");
         }
     }
 
-    public boolean createCrowdTest(String file, String fileName, String paperType, Long caseId, String testType, String description, String appName) throws Exception {
+    public long createCrowdTest(String file, String fileName, String paperType, Long caseId, String testType, String description, String appName) throws Exception {
         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
         params.add("file", file);
         params.add("file_name", fileName);
@@ -302,8 +300,8 @@ public class TaskService {
                 ("http://" + reportHost  + "/Bug/api/extra/uploadExamUrl", params, String.class);
         if (responseEntity.getStatusCode().equals(HttpStatus.OK)){
             fileService.uploadJson(responseEntity.getBody(),caseId);
-            return true;
-        }else return false;
+            return caseId;
+        }else return -1;
     }
 
     public String getEncodeTaskReportUrl(long examId,long caseId){
@@ -391,4 +389,30 @@ public class TaskService {
         ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://" + reportHost  + "/Bug/api/data/inputFromFile", files, String.class);
         return responseEntity.getStatusCode().equals(HttpStatus.OK);
     }
+
+
+    private static String generatePaperType(String testType ,  String os){
+        String defaultValue = "\"windows\",\"linux\",\"macos\"";
+        StringBuffer value  = new StringBuffer();
+        if(os==null||os.length()==0){
+            if(testType.equals(TaskUtil.TaskType.MOBILE.getTaskType())){
+                value.append("\"Android\",\"ios\"");
+            }else{
+                value.append("\"windows\",\"linux\",\"macos\"");
+            }
+
+        }else{
+            String [] data =  os.split(";");
+            for(int i  =0;i<data.length;i++){
+                if(i!=data.length-1){
+                    value.append("\""+data[i]+"\",");
+                }else{
+                    value.append("\""+data[i]+"\"");
+                }
+            }
+        }
+        return  "{\"title\":\"测试报告名称\",\"subTitles\":[{\"name\":\"设备名称\", \"type\":\"text\"},{\"name\":\"设备品牌\",\"type\":\"text\"},{\"name\":\"操作系统\",\"type\":\"enum\",\"value\":["
+                +value.toString()
+                + "]}],\"caseList\":true,\"bugList\": true,\"testScript\":false,\"suppleReport\":false,\"testLog\":false}";
+    }
 }

+ 62 - 37
src/main/resources/templates/addCrowdTask.html

@@ -97,7 +97,7 @@
                     <div class="form-group">
                         <label class="col-sm-2 control-label" >任务类型</label>
                         <div class=" col-sm-4">
-                            <select class="form-control" id="testType" onchange="changeType()">
+                            <select class="form-control" id="testType" >
                                 <option >移动应用</option>
                                 <option >Web应用</option>
                             </select>
@@ -105,27 +105,27 @@
                     </div>
 
                     <!-- text input -->
-                    <div class="form-group" id="webUrl" style="display: none">
-                        <label class="col-sm-2 control-label">待测网站链接</label>
-                        <div class="col-sm-6">
-                            <input  onchange="checkNull(event)" class="form-control" id="websiteUrl" placeholder="请输入网站链接"/>
-                        </div>
-                    </div>
+<!--                    <div class="form-group" id="webUrl" style="display: none">-->
+<!--                        <label class="col-sm-2 control-label">待测网站链接</label>-->
+<!--                        <div class="col-sm-6">-->
+<!--                            <input  onchange="checkNull(event)" class="form-control" id="websiteUrl" placeholder="请输入网站链接"/>-->
+<!--                        </div>-->
+<!--                    </div>-->
 
-                    <div class="form-group" id="apkFile">
-                        <label for="testApplication"  class="col-sm-2 control-label">待测应用</label>
-                        <div class="col-sm-10">
-                            <input  type="file" id="testApplication"/>
-                            <!--                               <p class="help-block">Example block-level help text here.</p>-->
-                        </div>
-                    </div>
+<!--                    <div class="form-group" id="apkFile">-->
+<!--                        <label for="testApplication"  class="col-sm-2 control-label">待测应用</label>-->
+<!--                        <div class="col-sm-10">-->
+<!--                            <input  type="file" id="testApplication"/>-->
+<!--                            &lt;!&ndash;                               <p class="help-block">Example block-level help text here.</p>&ndash;&gt;-->
+<!--                        </div>-->
+<!--                    </div>-->
 
-                    <div class="form-group">
-                        <label for="testRequirement" class="col-sm-2 control-label">测试需求</label>
-                        <div class="col-sm-10">
-                            <input  type="file" id="testRequirement"/>
-                            <!--                               <p class="help-block">Example block-level help text here.</p>-->
-                        </div>
+<!--                    <div class="form-group">-->
+<!--                        <label for="testRequirement" class="col-sm-2 control-label">测试需求</label>-->
+<!--                        <div class="col-sm-10">-->
+<!--                            <input  type="file" id="testRequirement"/>-->
+<!--                            &lt;!&ndash;                               <p class="help-block">Example block-level help text here.</p>&ndash;&gt;-->
+<!--                        </div>-->
 <!--                    </div>-->
 
                     <div class="form-group">
@@ -171,6 +171,7 @@
 <script src="/static/AdminLTE/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
 <script src="/static/AdminLTE/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
 <script src="/static/AdminLTE/bower_components/select2/dist/js/select2.min.js"></script>
+<script src="/static/AdminLTE/bower_components/bootstrap-notify/dist/bootstrap-notify.min.js"></script>
 <!--<script src="/static/js/app_info.js"></script>-->
 <script type="text/javascript">
     $(document).ready(function(){
@@ -179,17 +180,17 @@
         $('#reservationtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, locale: { format: 'MM/DD/YYYY hh:mm A' }})
     });
 
-    changeType = function () {
-        var type = $('#testType').val();
-        if(type == 'Web应用'){
-            $('#apkFile').css('display','none');
-            $('#webUrl').css('display','block');
-        }else{
-            //移动应用
-            $('#apkFile').css('display','block');
-            $('#webUrl').css('display','none');
-        }
-    }
+    // changeType = function () {
+    //     var type = $('#testType').val();
+    //     if(type == 'Web应用'){
+    //         $('#apkFile').css('display','none');
+    //         $('#webUrl').css('display','block');
+    //     }else{
+    //         //移动应用
+    //         $('#apkFile').css('display','block');
+    //         $('#webUrl').css('display','none');
+    //     }
+    // }
     
     addTask = function(){
         //type  = 0  表示添加
@@ -200,9 +201,10 @@
         data.append('description',$('#description').val());
         data.append('time',$('#reservationtime').val());
         data.append('type',$('#testType').val());
-        data.append('webUrl',$('#webUrl').val());
-        if($('#testType').val() == '移动应用') data.append("apk",document.getElementById('testApplication').files[0])
-        data.append("requirement",document.getElementById('testRequirement').files[0])
+        data.append('os',$('#os').val());
+        // data.append('webUrl',$('#webUrl').val());
+        // if($('#testType').val() == '移动应用') data.append("apk",document.getElementById('testApplication').files[0])
+        // data.append("requirement",document.getElementById('testRequirement').files[0])
         data.append("threePage",document.getElementById('threePage').files[0])
         $.ajax({
             url: '/addCrowdTask',
@@ -211,9 +213,11 @@
             processData: false,
             contentType: false,
             success: function (result) {
-                if(result != 'success'){
+                console.log(result);
+                console.log(result.status != '200')
+                if(result.status != '200'){
                     $.notify({
-                        message: result
+                        message: result.message
                     },{
                         // settings
                         delay: 100,
@@ -222,7 +226,7 @@
                     });
                 }else {
                     $.notify({
-                        message: '添加成功'
+                        message: result.message
                     },{
                         delay: 100,
                         timer: 3000,
@@ -233,4 +237,25 @@
         });
     }
 
+
+    checkNull = function (event) {
+        var num = event.target.value;
+        console.log(num)
+        if(num!=null&&num.length!=0){
+            console.log(event.target.parentElement.parentElement)
+            event.target.parentElement.parentElement.setAttribute("class","form-group has-success")
+            if(event.target.nextSibling!=null){
+                event.target.nextSibling.remove();
+            }
+        }else{
+            var newNode = document.createElement("span");
+            newNode.setAttribute("class","help-block")
+            newNode.innerHTML =" 请填写 ";
+            if(event.target.nextSibling==null){
+                event.target.parentNode.insertBefore(newNode,event.target.nextSibling)
+            }
+            event.target.parentElement.parentElement.setAttribute("class","form-group has-error")
+        }
+    }
+
 </script>

+ 23 - 0
src/main/resources/templates/importTask.html

@@ -128,6 +128,7 @@
 <script src="/static/AdminLTE/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
 <script src="/static/AdminLTE/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
 <script src="/static/AdminLTE/bower_components/select2/dist/js/select2.min.js"></script>
+<script src="/static/AdminLTE/bower_components/bootstrap-notify/dist/bootstrap-notify.min.js"></script>
 <!--<script src="/static/js/app_info.js"></script>-->
 <script type="text/javascript">
     $(document).ready(function(){
@@ -153,6 +154,7 @@
             processData: false,
             contentType: false,
             success: function (result) {
+
                 if(result != 'success'){
                     $.notify({
                         message: result
@@ -176,4 +178,25 @@
         });
     }
 
+
+    checkNull = function (event) {
+        var num = event.target.value;
+        console.log(num)
+        if(num!=null&&num.length!=0){
+            console.log(event.target.parentElement.parentElement)
+            event.target.parentElement.parentElement.setAttribute("class","form-group has-success")
+            if(event.target.nextSibling!=null){
+                event.target.nextSibling.remove();
+            }
+        }else{
+            var newNode = document.createElement("span");
+            newNode.setAttribute("class","help-block")
+            newNode.innerHTML =" 请填写 ";
+            if(event.target.nextSibling==null){
+                event.target.parentNode.insertBefore(newNode,event.target.nextSibling)
+            }
+            event.target.parentElement.parentElement.setAttribute("class","form-group has-error")
+        }
+    }
+
 </script>