Explorar el Código

接口调试修改

gaoxing hace 8 años
padre
commit
bf2fb505c2

+ 50 - 28
cqb-base/src/main/java/com/qmth/cqb/base/web/CourseController.java

@@ -2,17 +2,26 @@ package com.qmth.cqb.base.web;
 
 import java.util.List;
 
-import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 import com.google.gson.Gson;
 import com.qmth.cqb.base.dao.CourseRepo;
 import com.qmth.cqb.base.model.Course;
 import com.qmth.cqb.base.service.CourseService;
 
+import io.swagger.annotations.ApiOperation;
+
 /**
  * Created by songyue on 16/12/26.
  */
@@ -23,83 +32,96 @@ public class CourseController {
 
     @Autowired
     Gson gson;
-    
+
     @Autowired
     CourseRepo courseRepo;
 
     @Autowired
     CourseService courseService;
 
-
     /**
      * 获取全部课程
+     * 
      * @return
      */
-    @ApiOperation(value="获取全部课程",notes="获取全部课程")
+    @ApiOperation(value = "获取全部课程", notes = "获取全部课程")
     @GetMapping(value = "/course/{curPage}/{pageSize}")
-    public ResponseEntity getAllCourse(@ModelAttribute Course searchCondition,
-                                       @PathVariable int curPage,
-                                       @PathVariable int pageSize){
-        return new ResponseEntity(courseService.findAll(searchCondition,curPage,pageSize),
-                HttpStatus.OK);
+    public ResponseEntity getAllCourse(@ModelAttribute Course searchCondition, @PathVariable int curPage,
+            @PathVariable int pageSize) {
+        return new ResponseEntity(courseService.findAll(searchCondition, curPage, pageSize), HttpStatus.OK);
     }
 
     /**
      * 更新课程
+     * 
      * @param course
      * @return
      */
-    @ApiOperation(value="更新课程",notes="更新课程")
+    @ApiOperation(value = "更新课程", notes = "更新课程")
     @PutMapping(value = "/course")
-    public ResponseEntity updateCourse(@ModelAttribute Course course){
-    	return new ResponseEntity(courseRepo.save(course),HttpStatus.OK);
+    public ResponseEntity updateCourse(@ModelAttribute Course course) {
+        return new ResponseEntity(courseRepo.save(course), HttpStatus.OK);
     }
 
     /**
      * 新增课程
+     * 
      * @param course
      * @return
      */
-    @ApiOperation(value="新增课程",notes="新增课程")
+    @ApiOperation(value = "新增课程", notes = "新增课程")
     @PostMapping(value = "/course")
-    public ResponseEntity addCourse(@ModelAttribute Course course){
-    	return new ResponseEntity(courseRepo.save(course),HttpStatus.OK);
+    public ResponseEntity addCourse(@ModelAttribute Course course) {
+        return new ResponseEntity(courseRepo.save(course), HttpStatus.OK);
     }
 
     /**
      * 删除课程
+     * 
      * @param coruse_id
      * @return
      */
-    @ApiOperation(value="删除课程",notes="删除课程")
+    @ApiOperation(value = "删除课程", notes = "删除课程")
     @DeleteMapping(value = "/course/{coruse_id}")
-    public ResponseEntity removeCourse(@PathVariable String coruse_id){
+    public ResponseEntity removeCourse(@PathVariable String coruse_id) {
         courseRepo.delete(coruse_id);
-    	return new ResponseEntity(HttpStatus.OK);
+        return new ResponseEntity(HttpStatus.OK);
     }
-    
+
     /**
      * 根据课程名称或者课程编号获取课程信息
+     * 
      * @param keyword
      * @return
      */
-    @ApiOperation(value="根据课程名称或者课程编号获取课程信息",notes="根据课程名称或者课程编号获取课程信息")
+    @ApiOperation(value = "根据课程名称或者课程编号获取课程信息", notes = "根据课程名称或者课程编号获取课程信息")
     @GetMapping(value = "/course")
-    public ResponseEntity getCourseByKeyword(@RequestParam String keyword){
-        return new ResponseEntity(courseService.findCoursesByKeyword(keyword),
-                HttpStatus.OK);
+    public ResponseEntity getCourseByKeyword(@RequestParam String keyword) {
+        return new ResponseEntity(courseService.findCoursesByKeyword(keyword), HttpStatus.OK);
     }
 
     /**
      * 根据课程编号获取课程信息
+     * 
      * @param courseNo
      * @return
      */
-    @ApiOperation(value="根据课程编号获取课程信息",notes="根据课程编号获取课程信息")
+    @ApiOperation(value = "根据课程编号获取课程信息", notes = "根据课程编号获取课程信息")
     @GetMapping(value = "/course/{courseNo}")
-    public ResponseEntity getCourseByNo(@PathVariable String courseNo){
-        return new ResponseEntity(courseRepo.findByCourseNo(courseNo),
-                HttpStatus.OK);
+    public ResponseEntity getCourseByNo(@PathVariable String courseNo) {
+        return new ResponseEntity(courseRepo.findByCourseNo(courseNo), HttpStatus.OK);
+    }
+
+    /**
+     * 查询所有课程
+     *
+     * @return
+     */
+    @ApiOperation(value = " 查询所有课程", notes = "查询所有课程")
+    @GetMapping(value = "/course/allCourses")
+    public ResponseEntity getAllCourses() {
+        List<Course> courses = courseRepo.findAll();
+        return new ResponseEntity(courses, HttpStatus.OK);
     }
 
 }

+ 6 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/dao/PaperRepo.java

@@ -3,21 +3,23 @@ package com.qmth.cqb.paper.dao;
 import java.util.List;
 import java.util.Map;
 
-import com.qmth.cqb.utils.enums.PaperStatus;
-import com.qmth.cqb.utils.enums.PaperType;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.mongodb.repository.MongoRepository;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import com.qmth.cqb.paper.model.Paper;
+import com.qmth.cqb.utils.enums.PaperStatus;
+import com.qmth.cqb.utils.enums.PaperType;
 
-public interface PaperRepo extends MongoRepository<Paper, String>,QueryByExampleExecutor<Paper> {
+public interface PaperRepo extends MongoRepository<Paper, String>, QueryByExampleExecutor<Paper> {
 
     List<Paper> findByParams(Map params);
 
     Page<Paper> findByPaperType(PaperType paperType, Pageable pageable);
 
-    Page<Paper> findByPaperStatus(PaperStatus paperStatus,Pageable pageable);
+    Page<Paper> findByPaperStatus(PaperStatus paperStatus, Pageable pageable);
+
+    Paper findByName(String name);
 
 }

+ 16 - 12
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -8,7 +8,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-import java.util.stream.Collectors;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
@@ -63,7 +62,6 @@ public class ImportPaperService {
 
     @Autowired
     PaperService paperService;
-    
 
     @Autowired
     CourseRepo courseRepo;
@@ -92,11 +90,12 @@ public class ImportPaperService {
     /**
      * 导入试卷
      * 
-     * @param file
+     * @param courseNo
      * @return
      */
-    public String ImportPaper(String paperName, File file) {
-        String errorInfo = processImportPaper(paperName, file);
+    public String ImportPaper(String paperName, String courseNo, File file) {
+        String errorInfo = paperService.checkPaperName(paperName);
+        // errorInfo += processImportPaper(paperName, courseNo, file);
         if (StringUtils.isEmpty(errorInfo)) {
             return "success";
         } else {
@@ -144,7 +143,7 @@ public class ImportPaperService {
      * 
      * @param file
      */
-    public String processImportPaper(String paperName, File file) {
+    public String processImportPaper(String paperName, String courseNo, File file) {
 
         WordprocessingMLPackage wordMLPackage;
         WordprocessingMLPackage tmpWordMlPackage;
@@ -165,6 +164,8 @@ public class ImportPaperService {
             // 创建试卷类
             Paper paper = new Paper();
 
+            paper.setCourseNo(courseNo);
+
             // 设置试卷
             initPaper(paper, paperName);
 
@@ -562,7 +563,7 @@ public class ImportPaperService {
         }
 
         // 设置预设分数
-        if(StringUtils.isNumeric(quesScore)){
+        if (StringUtils.isNumeric(quesScore)) {
             question.setScore(Double.parseDouble(quesScore));
         }
         // 一般大题明细需要设置分数
@@ -619,7 +620,7 @@ public class ImportPaperService {
 
                 Question subQues = new Question();
                 subQues.setQuestionType(getQuesStructType(nestedQuesType));
-                if(StringUtils.isNumeric(importPaperCheck.getQuesScore())){
+                if (StringUtils.isNumeric(importPaperCheck.getQuesScore())) {
                     subQues.setScore(Double.parseDouble(importPaperCheck.getQuesScore()));
                 }
 
@@ -754,8 +755,6 @@ public class ImportPaperService {
         question.setQuesPkg(DocxProcessUtil.getPkgByte(wordMLPackage));
     }
 
-    
-    
     /**
      * 构造一张空白的导入类型试卷
      * 
@@ -764,9 +763,13 @@ public class ImportPaperService {
      * @param paperName
      * @return
      */
-    public Paper saveBlankPaper(String courseNo, String paperName) {
+    public String saveBlankPaper(String courseNo, String paperName) {
         Paper paper = new Paper();
         String courseName = courseRepo.findByCourseNo(courseNo).getCourseName();
+        String msg = paperService.checkPaperName(paperName);
+        if (msg != null) {
+            return msg;
+        }
         initPaper(paper, paperName);
         paper.setCourseNo(courseNo);
         paper.setCourseName(courseName);
@@ -776,6 +779,7 @@ public class ImportPaperService {
         pd.setPaper(paper);
         paperRepo.save(paper);
         paperDetailRepo.save(pd);
-        return paper;
+        msg = "success";
+        return msg;
     }
 }

+ 16 - 3
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java

@@ -499,7 +499,7 @@ public class PaperService {
         Paper paper = paperRepo.findOne(paperId);
         PaperDetail pd = paperDetailRepo.findOne(paperDetailId);
         List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaperDetail(pd);
-        List<PaperDetailUnit> saveUnits = paperDetailUnitRepo.findByPaperDetail(pd);
+        List<PaperDetailUnit> saveUnits = new ArrayList<PaperDetailUnit>();
         for (Question ques : questions) {
             PaperDetailUnit pdu = new PaperDetailUnit();
             pdu.setPaper(paper);
@@ -508,8 +508,6 @@ public class PaperService {
             pdu.setCreateTime(CommonUtils.getCurDateTime());
             pdu.setPaperDetail(pd);
             pdus.add(pdu);
-            Collections.sort(pdus);
-            pdu.setNumber(pdus.indexOf(pdu) + 1);
             if (ques.getScore() == null || ques.getScore() == 0d) {
                 pdu.setScore(0d);
             } else {
@@ -517,9 +515,24 @@ public class PaperService {
             }
             saveUnits.add(pdu);
         }
+        Collections.sort(pdus);
+        for (int i = 0; i < saveUnits.size(); i++) {
+            saveUnits.get(i).setNumber(pdus.indexOf(saveUnits.get(i)) + 1);
+        }
+
         paperDetailUnitRepo.save(saveUnits);
         formatPaper(paper);
         return paper;
+    }
+
+    public String checkPaperName(String paperName) {
+        String msg = null;
+        Paper paper = paperRepo.findByName(paperName);
+        if (paper != null) {
+            msg = "试卷名称重复,请重新命名";
+        }
+        return msg;
 
     }
+
 }

+ 20 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java

@@ -1,6 +1,8 @@
 package com.qmth.cqb.paper.web;
 
 import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -43,10 +45,19 @@ public class ImportPaperController {
      */
     @ApiOperation(value = "导入试卷", notes = "导入试卷")
     @PostMapping(value = "/importPaper")
-    public String importPaper(@RequestParam String paperName, @RequestParam("file") CommonsMultipartFile file) {
+    public ResponseEntity importPaper(  @RequestParam String paperName, 
+                                @RequestParam String courseNo,
+                                @RequestParam("file") CommonsMultipartFile file) {
         File tempFile = importPaperService.getUploadFile(file);
-        String returnStr = importPaperService.ImportPaper(paperName, tempFile);
-        return returnStr;
+        String returnStr = importPaperService.ImportPaper(paperName, courseNo, tempFile);
+        Map map = new HashMap();      
+        if (returnStr.equals("success")) {
+            return new ResponseEntity(returnStr, HttpStatus.OK);
+        } else {
+            map.put("errorMsg", returnStr);
+            return new ResponseEntity(map, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+        //return returnStr;
     }
 
     /**
@@ -58,7 +69,12 @@ public class ImportPaperController {
     @ApiOperation(value = "保存导入类型空白试卷", notes = "保存导入类型空白试卷")
     @PostMapping(value = "/importPaper/saveBlankPaper/{courseNo}/{paperName}")
     public ResponseEntity saveBlankPaper(@PathVariable String courseNo, @PathVariable String paperName) {
-        return new ResponseEntity(importPaperService.saveBlankPaper(courseNo, paperName), HttpStatus.OK);
+        String msg = importPaperService.saveBlankPaper(courseNo, paperName);
+        if (msg.equals("success")) {
+            return new ResponseEntity(msg, HttpStatus.OK);
+        } else {
+            return new ResponseEntity(msg, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
     }
 
 }

+ 7 - 10
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperDetailController.java

@@ -7,10 +7,8 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -35,7 +33,7 @@ public class PaperDetailController {
 
     @Autowired
     PaperService paperService;
-    
+
     @Autowired
     PaperRepo paperRepo;
 
@@ -71,8 +69,7 @@ public class PaperDetailController {
      */
     @ApiOperation(value = "更新试卷中的大题", notes = "更新试卷中的大题")
     @PostMapping(value = "/updatePaperDetail/{paperId}")
-    public ResponseEntity updatePaperDetail(@PathVariable String paperId,
-                                            @RequestBody PaperDetail pd) {
+    public ResponseEntity updatePaperDetail(@PathVariable String paperId, @RequestBody PaperDetail pd) {
         pd.setPaper(paperRepo.findOne(paperId));
         PaperDetail paperDetail = paperDetailService.savePaperDetail(pd);
         return new ResponseEntity(paperDetail, HttpStatus.OK);
@@ -95,14 +92,14 @@ public class PaperDetailController {
     /**
      * 删除大题
      * 
-     * @param detail_id
+     * @param detailId
      * @return
      */
     @ApiOperation(value = "删除大题", notes = "删除大题")
-    @DeleteMapping(value = "/paperDetail/{detail_id}")
-    public ResponseEntity removePaperDetail(@PathVariable String detail_id) {
-        paperDetailService.deletePaperDetail(detail_id);
-        return new ResponseEntity(detail_id, HttpStatus.OK);
+    @DeleteMapping(value = "/paperDetail/{detailId}")
+    public ResponseEntity removePaperDetail(@PathVariable String detailId) {
+        paperDetailService.deletePaperDetail(detailId);
+        return new ResponseEntity(detailId, HttpStatus.OK);
     }
 
     /**