Browse Source

重构部分代码

宋悦 8 năm trước cách đây
mục cha
commit
92975b5603
33 tập tin đã thay đổi với 741 bổ sung1186 xóa
  1. 0 12
      cqb-base/src/main/java/com/qmth/cqb/base/dao/QuesTypeRepo.java
  2. 0 14
      cqb-base/src/main/java/com/qmth/cqb/base/dao/RoleRepo.java
  3. 0 13
      cqb-base/src/main/java/com/qmth/cqb/base/dao/UserRepo.java
  4. 0 81
      cqb-base/src/main/java/com/qmth/cqb/base/model/QuesType.java
  5. 0 72
      cqb-base/src/main/java/com/qmth/cqb/base/model/Role.java
  6. 0 104
      cqb-base/src/main/java/com/qmth/cqb/base/model/User.java
  7. 16 43
      cqb-base/src/main/java/com/qmth/cqb/base/service/CourseService.java
  8. 0 76
      cqb-base/src/main/java/com/qmth/cqb/base/service/QuesTypeService.java
  9. 0 34
      cqb-base/src/main/java/com/qmth/cqb/base/service/RoleService.java
  10. 0 35
      cqb-base/src/main/java/com/qmth/cqb/base/service/UserService.java
  11. 22 33
      cqb-base/src/main/java/com/qmth/cqb/base/web/CourseController.java
  12. 0 94
      cqb-base/src/main/java/com/qmth/cqb/base/web/QuesTypeController.java
  13. 0 79
      cqb-base/src/main/java/com/qmth/cqb/base/web/RoleController.java
  14. 0 80
      cqb-base/src/main/java/com/qmth/cqb/base/web/UserController.java
  15. 8 2
      cqb-comm-utils/pom.xml
  16. 44 0
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/PaperStatus.java
  17. 43 0
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/PaperType.java
  18. 1 1
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java
  19. 98 0
      cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/model/GenPaperDto.java
  20. 2 2
      cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java
  21. 20 1
      cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/web/GenPaperController.java
  22. 14 1
      cqb-paper/src/main/java/com/qmth/cqb/paper/dao/PaperRepo.java
  23. 0 86
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/ImportPaperSearchCondition.java
  24. 46 4
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/Paper.java
  25. 0 2
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailStruct.java
  26. 63 0
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperSearchInfo.java
  27. 63 73
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java
  28. 86 31
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java
  29. 23 71
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java
  30. 141 62
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperController.java
  31. 0 10
      cqb-starter/pom.xml
  32. 17 0
      cqb-starter/src/main/java/com/qmth/cqb/App.java
  33. 34 70
      cqb-starter/src/test/java/com/qmth/cqb/AppTest.java

+ 0 - 12
cqb-base/src/main/java/com/qmth/cqb/base/dao/QuesTypeRepo.java

@@ -1,12 +0,0 @@
-package com.qmth.cqb.base.dao;
-
-import com.qmth.cqb.base.model.QuesType;
-import org.springframework.data.mongodb.repository.MongoRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-/**
- * Created by songyue on 16/12/26.
- */
-public interface QuesTypeRepo extends MongoRepository<QuesType,String>,QueryByExampleExecutor<QuesType> {
-	QuesType findByTypeName(String typeName);
-}

+ 0 - 14
cqb-base/src/main/java/com/qmth/cqb/base/dao/RoleRepo.java

@@ -1,14 +0,0 @@
-package com.qmth.cqb.base.dao;
-
-import com.qmth.cqb.base.model.Role;
-import org.springframework.data.mongodb.repository.MongoRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-/**
- * Created by songyue on 16/12/26.
- */
-public interface RoleRepo extends MongoRepository<Role,String>,QueryByExampleExecutor<Role> {
-    Role findById(String id);
-}
- 
-

+ 0 - 13
cqb-base/src/main/java/com/qmth/cqb/base/dao/UserRepo.java

@@ -1,13 +0,0 @@
-package com.qmth.cqb.base.dao;
-
-import com.qmth.cqb.base.model.User;
-import org.springframework.data.mongodb.repository.MongoRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-/**
- * Created by songyue on 16/12/26.
- */
-public interface UserRepo extends MongoRepository<User, String>,QueryByExampleExecutor<User> {
-    User findByLoginName(String loginName);
-    User findById(String id);
-}

+ 0 - 81
cqb-base/src/main/java/com/qmth/cqb/base/model/QuesType.java

@@ -1,81 +0,0 @@
-package com.qmth.cqb.base.model;
-
-import org.springframework.data.annotation.Id;
-
-import java.io.Serializable;
-import java.util.Map;
-
-/**
- * Created by songyue on 16/12/26.
- */
-public class QuesType implements Serializable {
-    private static final long serialVersionUID = 1270577782388822573L;
-
-    @Id
-    private String id;
-
-    private String typeName;//类型名称
-
-    private String typeTitle;//类型标题
-
-    private String createTime;//创建时间
-
-    private String updateTime;//更新时间
-
-    private Map params;//类型参数
-
-    public static long getSerialVersionUID() {
-        return serialVersionUID;
-    }
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getTypeName() {
-        return typeName;
-    }
-
-    public void setTypeName(String typeName) {
-        this.typeName = typeName;
-    }
-
-    public Map getParams() {
-        return params;
-    }
-
-    public void setParams(Map params) {
-        this.params = params;
-    }
-
-    public String getTypeTitle() {
-        return typeTitle;
-    }
-
-    public void setTypeTitle(String typeTitle) {
-        this.typeTitle = typeTitle;
-    }
-
-    public String getCreateTime() {
-        return createTime;
-    }
-
-    public void setCreateTime(String createTime) {
-        this.createTime = createTime;
-    }
-
-    public String getUpdateTime() {
-        return updateTime;
-    }
-
-    public void setUpdateTime(String updateTime) {
-        this.updateTime = updateTime;
-    }
-
-    public QuesType() {
-    }
-}

+ 0 - 72
cqb-base/src/main/java/com/qmth/cqb/base/model/Role.java

@@ -1,72 +0,0 @@
-package com.qmth.cqb.base.model;
-
-import org.springframework.data.annotation.Id;
-import org.springframework.data.mongodb.core.mapping.Document;
-
-import java.io.Serializable;
-import java.util.Map;
-
-/**
- * Created by songyue on 16/12/26.
- */
-public class Role implements Serializable{
-    private static final long serialVersionUID = -312105867212825491L;
-
-    @Id
-    private String id;
-
-    private String roleName;
-
-    private String createTime;//创建时间
-
-    private String updateTime;//更新时间
-
-    private Map params;//额外参数,可动态添加
-
-    public static long getSerialVersionUID() {
-        return serialVersionUID;
-    }
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getRoleName() {
-        return roleName;
-    }
-
-    public void setRoleName(String roleName) {
-        this.roleName = roleName;
-    }
-
-    public Map getParams() {
-        return params;
-    }
-
-    public void setParams(Map params) {
-        this.params = params;
-    }
-
-    public String getCreateTime() {
-        return createTime;
-    }
-
-    public void setCreateTime(String createTime) {
-        this.createTime = createTime;
-    }
-
-    public String getUpdateTime() {
-        return updateTime;
-    }
-
-    public void setUpdateTime(String updateTime) {
-        this.updateTime = updateTime;
-    }
-
-    public Role() {
-    }
-}

+ 0 - 104
cqb-base/src/main/java/com/qmth/cqb/base/model/User.java

@@ -1,104 +0,0 @@
-package com.qmth.cqb.base.model;
-
-import org.springframework.data.annotation.Id;
-import org.springframework.data.mongodb.core.mapping.DBRef;
-
-import java.io.Serializable;
-import java.util.Map;
-
-/**
- * Created by songyue on 16/12/26.
- */
-public class User implements Serializable {
-
-    private static final long serialVersionUID = -2813076450724009433L;
-
-    @Id
-    private String id;//user id
-
-    private String loginName;//登录名
-
-    private String userName;//用户名
-
-    private String passWord;//密码
-
-    @DBRef
-    private Role role;//角色
-
-    private String createTime;//创建时间
-
-    private String updateTime;//更新时间
-
-    private Map params;//额外参数,可动态添加
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getLoginName() {
-        return loginName;
-    }
-
-    public void setLoginName(String loginName) {
-        this.loginName = loginName;
-    }
-
-    public String getUserName() {
-        return userName;
-    }
-
-    public void setUserName(String userName) {
-        this.userName = userName;
-    }
-
-    public String getPassWord() {
-        return passWord;
-    }
-
-    public void setPassWord(String passWord) {
-        this.passWord = passWord;
-    }
-
-    public Role getRole() {
-        return role;
-    }
-
-    public void setRole(Role role) {
-        this.role = role;
-    }
-
-    public Map getParams() {
-        return params;
-    }
-
-    public void setParams(Map params) {
-        this.params = params;
-    }
-
-    public static long getSerialVersionUID() {
-        return serialVersionUID;
-    }
-
-    public String getCreateTime() {
-        return createTime;
-    }
-
-    public void setCreateTime(String createTime) {
-        this.createTime = createTime;
-    }
-
-    public String getUpdateTime() {
-        return updateTime;
-    }
-
-    public void setUpdateTime(String updateTime) {
-        this.updateTime = updateTime;
-    }
-
-    public User() {
-    }
-}

+ 16 - 43
cqb-base/src/main/java/com/qmth/cqb/base/service/CourseService.java

@@ -1,25 +1,21 @@
 package com.qmth.cqb.base.service;
 
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
 
+import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
 
 import com.qmth.cqb.base.dao.CourseRepo;
 import com.qmth.cqb.base.model.Course;
-import com.qmth.cqb.utils.modal.NormalResponse;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
-
 /**
  * Created by songyue on 16/12/28.
  */
@@ -39,50 +35,27 @@ public class CourseService {
      * @param pageSize
      * @return
      */
-    public PagingAndSortingResponse<Course> findAll(Course searchCondition, int curPage, int pageSize){
-        Page<Course> courseList = courseRepo.findAll(Example.of(searchCondition),new PageRequest(curPage-1,pageSize));
-        return new PagingAndSortingResponse<Course>(courseList.getNumber(),courseList.getSize(),
-        		courseList.getTotalPages(),courseList.getTotalElements(),courseList.getContent());
+    public Page<Course> findAll(Course searchCondition, int curPage, int pageSize){
+        return courseRepo.findAll(Example.of(searchCondition),
+                new PageRequest(curPage - 1,pageSize));
     }
 
-    
-    /**
-     * 保存课程
-     * @param course
-     * @return
-     */
-    public NormalResponse saveCourse(Course course){
-    	Course tempCourse = courseRepo.save(course);
-        if(tempCourse != null){
-            return new NormalResponse(HttpStatus.OK.toString(),"success");
-        }else{
-            return new NormalResponse(HttpStatus.INTERNAL_SERVER_ERROR.toString(),"保存失败");
-        }
-    }
-    
-    /**
-     * 删除课程
-     * @param courseId
-     * @return
-     */
-    public NormalResponse deleteCourse(String courseId){
-    	courseRepo.delete(courseId);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
 
-    
     /**
-     * 根据课程名称或者课程No.查找课程
+     * 根据课程名称或者课程No查找课程
      * @param 
      * @return
      */
     public List<Course> findCoursesByKeyword(String keyword){
-    	keyword = keyword.replace("(","").replace(")", "");		
-    	Criteria likeNo = Criteria.where("courseNo").regex(keyword);//模糊匹配相当于SQL中“%Keyword%”
-	    Criteria likeName = Criteria.where("courseName").regex(keyword);
-	    Query query = new Query(new Criteria().orOperator(likeName,likeNo));
-	    List<Course> courselist = mongoTemplate.find(query, Course.class);
-	    return courselist;
-       
+        List<Course> courselist = new ArrayList<Course>();
+        if(StringUtils.isEmpty(keyword)){
+            return courselist;
+        }else{
+            Criteria likeNo = Criteria.where("courseNo").regex(keyword);//模糊匹配相当于SQL中“%Keyword%”
+            Criteria likeName = Criteria.where("courseName").regex(keyword);
+            Query query = new Query(new Criteria().orOperator(likeName,likeNo));
+            courselist = mongoTemplate.find(query, Course.class);
+            return courselist;
+        }
     }
 }

+ 0 - 76
cqb-base/src/main/java/com/qmth/cqb/base/service/QuesTypeService.java

@@ -1,76 +0,0 @@
-package com.qmth.cqb.base.service;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Service;
-
-import com.qmth.cqb.base.dao.QuesTypeRepo;
-import com.qmth.cqb.base.model.QuesType;
-import com.qmth.cqb.utils.modal.NormalResponse;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
-
-/**
- * Created by songyue on 16/12/28.
- */
-@Service
-public class QuesTypeService {
-	
-	@Autowired
-	QuesTypeRepo quesTypeRepo;
-	
-    @Autowired
-    MongoTemplate mongoTemplate;
-    
-    /**
-     * 查询所题型
-     * @param searchCondition
-     * @param curPage
-     * @param pageSize
-     * @return
-     */
-    public PagingAndSortingResponse<QuesType> findAll(QuesType searchCondition, int curPage, int pageSize){
-        Page<QuesType> quesTypeList = quesTypeRepo.findAll(Example.of(searchCondition),new PageRequest(curPage-1,pageSize));
-        return new PagingAndSortingResponse<QuesType>(quesTypeList.getNumber(),quesTypeList.getSize(),
-        		quesTypeList.getTotalPages(),quesTypeList.getTotalElements(),quesTypeList.getContent());
-    }
-
-    
-    /**
-     * 保存题型
-     * @param quesType
-     * @return
-     */
-    public QuesType saveQuesType(QuesType quesType){
-    	QuesType tempPaper = quesTypeRepo.save(quesType);
-    	return tempPaper;
-//        if(tempPaper != null){
-//            return new NormalResponse(HttpStatus.OK.toString(),"success");
-//        }else{
-//            return new NormalResponse(HttpStatus.INTERNAL_SERVER_ERROR.toString(),"保存失败");
-//        }
-    }
-    
-    /**
-     * 删除题型
-     * @param quesTypeId
-     * @return
-     */
-    public NormalResponse deleteQuesType(String quesTypeId){
-    	quesTypeRepo.delete(quesTypeId);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-    
-    /**
-     * 根据课程名称查找题型
-     * @param typeId
-     * @return
-     */
-    public QuesType findByName(String typeName){
-        return quesTypeRepo.findByTypeName(typeName);
-    }
-
-}

+ 0 - 34
cqb-base/src/main/java/com/qmth/cqb/base/service/RoleService.java

@@ -1,34 +0,0 @@
-package com.qmth.cqb.base.service;
-
-import com.qmth.cqb.base.dao.RoleRepo;
-import com.qmth.cqb.base.model.Role;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.stereotype.Service;
-
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
-
-/**
- * Created by songyue on 16/12/28.
- */
-@Service
-public class RoleService {
-    @Autowired
-    RoleRepo roleRepo;
-
-    @Autowired
-    MongoTemplate mongoTemplate;
-
-    public PagingAndSortingResponse<Role> findAll(Role searchCondition, PageRequest pageRequest){
-        ExampleMatcher matcher = ExampleMatcher.matching()
-                .withMatcher("roleName", startsWith());
-        Page<Role> roleList = roleRepo.findAll(Example.of(searchCondition,matcher),pageRequest);
-        return new PagingAndSortingResponse<Role>(roleList.getNumber(),roleList.getSize(),
-                roleList.getTotalPages(),roleList.getTotalElements(),roleList.getContent());
-    }
-}

+ 0 - 35
cqb-base/src/main/java/com/qmth/cqb/base/service/UserService.java

@@ -1,35 +0,0 @@
-package com.qmth.cqb.base.service;
-
-import com.qmth.cqb.base.dao.UserRepo;
-import com.qmth.cqb.base.model.User;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.stereotype.Service;
-
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
-
-/**
- * Created by songyue on 16/12/26.
- */
-@Service
-public class UserService {
-    @Autowired
-    UserRepo userRepo;
-
-    @Autowired
-    MongoTemplate mongoTemplate;
-
-    public PagingAndSortingResponse<User> findAll(User searchCondition, PageRequest pageRequest){
-        ExampleMatcher matcher = ExampleMatcher.matching()
-                .withMatcher("loginName", startsWith())
-                .withMatcher("userName", startsWith());
-        Page<User> userList = userRepo.findAll(Example.of(searchCondition,matcher),pageRequest);
-        return new PagingAndSortingResponse<User>(userList.getNumber(),userList.getSize(),
-                userList.getTotalPages(),userList.getTotalElements(),userList.getContent());
-    }
-}

+ 22 - 33
cqb-base/src/main/java/com/qmth/cqb/base/web/CourseController.java

@@ -3,28 +3,14 @@ package com.qmth.cqb.base.web;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Controller;
-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.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import com.google.gson.Gson;
 import com.qmth.cqb.base.dao.CourseRepo;
 import com.qmth.cqb.base.model.Course;
-import com.qmth.cqb.base.model.Role;
 import com.qmth.cqb.base.service.CourseService;
-import com.qmth.cqb.utils.modal.NormalResponse;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
 
 /**
  * Created by songyue on 16/12/26.
@@ -33,6 +19,7 @@ import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
 @RestController
 @RequestMapping("${api_cqb}/")
 public class CourseController {
+
     @Autowired
     Gson gson;
     
@@ -47,22 +34,22 @@ public class CourseController {
      * 获取全部课程
      * @return
      */
-    @GetMapping(value = "/course/all/{curPage}/{paseSize}")
-    public PagingAndSortingResponse<Course> getAllCourse(@ModelAttribute Course searchCondition, @PathVariable int curPage, @PathVariable int pageSize){
-        //return courseService.findAll(searchCondition,new PageRequest(curPage - 1,pageSize));
-        Page<Course> courseList = courseRepo.findAll(Example.of(searchCondition),new PageRequest(curPage-1,pageSize));
-        return new PagingAndSortingResponse<Course>(courseList.getNumber(),courseList.getSize(),
-        		courseList.getTotalPages(),courseList.getTotalElements(),courseList.getContent());
+    @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);
     }
 
     /**
      * 更新课程
-     * @param user
+     * @param course
      * @return
      */
     @PutMapping(value = "/course")
-    public NormalResponse updateCourse(@ModelAttribute Course course){
-    	return courseService.saveCourse(course);
+    public ResponseEntity updateCourse(@ModelAttribute Course course){
+    	return new ResponseEntity(courseRepo.save(course),HttpStatus.OK);
     }
 
     /**
@@ -71,28 +58,30 @@ public class CourseController {
      * @return
      */
     @PostMapping(value = "/course")
-    public NormalResponse addCourse(@ModelAttribute Course course){
-    	return courseService.saveCourse(course);
+    public ResponseEntity addCourse(@ModelAttribute Course course){
+    	return new ResponseEntity(courseRepo.save(course),HttpStatus.OK);
     }
 
     /**
      * 删除课程
-     * @param 课程ID coruse_id
+     * @param coruse_id
      * @return
      */
     @DeleteMapping(value = "/course/{coruse_id}")
-    public NormalResponse removeCourse(@PathVariable String coruse_id){
-    	return courseService.deleteCourse(coruse_id);
+    public ResponseEntity removeCourse(@PathVariable String coruse_id){
+        courseRepo.delete(coruse_id);
+    	return new ResponseEntity(HttpStatus.OK);
     }
     
     /**
      * 根据课程名称或者课程编号获取课程信息
-     * @param courseName
+     * @param keyword
      * @return
      */
-    @GetMapping(value = "/course/{keyword}")
-    public List<Course> getCourseByKeyword(@PathVariable String keyword){
-        return courseService.findCoursesByKeyword(keyword);
+    @GetMapping(value = "/course")
+    public ResponseEntity getCourseByKeyword(@RequestParam String keyword){
+        return new ResponseEntity(courseService.findCoursesByKeyword(keyword),
+                HttpStatus.OK);
     }
 
 }

+ 0 - 94
cqb-base/src/main/java/com/qmth/cqb/base/web/QuesTypeController.java

@@ -1,94 +0,0 @@
-package com.qmth.cqb.base.web;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Controller;
-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.RestController;
-
-import com.google.gson.Gson;
-import com.qmth.cqb.base.dao.QuesTypeRepo;
-import com.qmth.cqb.base.model.QuesType;
-import com.qmth.cqb.base.service.QuesTypeService;
-import com.qmth.cqb.utils.modal.NormalResponse;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
-
-/**
- * Created by songyue on 16/12/26.
- */
-@RestController
-@RequestMapping("${api_cqb}/")
-public class QuesTypeController {
-	
-    @Autowired
-    QuesTypeRepo quesTypeRepo;
-
-    @Autowired
-    Gson gson;
-    
-
-    @Autowired
-    QuesTypeService quesTypeService;
-
-
-    /**
-     * 获取全部题型
-     * @return
-     */
-    @GetMapping(value = "/quesType/all/{curPage}/{paseSize}")
-    public PagingAndSortingResponse<QuesType> getAllQuesType(@ModelAttribute QuesType searchCondition, @PathVariable int curPage, @PathVariable int pageSize){
-    	 return quesTypeService.findAll(searchCondition,curPage, pageSize);
-    }
-
-    /**
-     * 更新题型
-     * @param user
-     * @return
-     */
-    @PutMapping(value = "/quesType")
-    public NormalResponse updateQuesType(@ModelAttribute QuesType quesType){
-    	quesTypeService.saveQuesType(quesType);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-
-    /**
-     * 新增题型
-     * @param quesType
-     * @return
-     */
-    @PostMapping(value = "/quesType")
-    public NormalResponse addQuesType(@ModelAttribute QuesType quesType){
-	    quesTypeService.saveQuesType(quesType);
-	    return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-
-    /**
-     * 删除题型
-     * @param 题型ID quesType_id
-     * @return
-     */
-    @DeleteMapping(value = "/quesType/{quesType_id}")
-    //ResponseEntity
-    public NormalResponse removeQuesType(@PathVariable String quesType_id){
-    	return quesTypeService.deleteQuesType(quesType_id);
-    }
-    
-    /**
-     * 根据题型名称获取题型信息
-     * @param quesTypeName
-     * @return
-     */
-    @GetMapping(value = "/quesType/{quesType_name}")
-    public QuesType getQuesTypeByName(@PathVariable String quesType_name){
-        return quesTypeService.findByName(quesType_name);
-    }
-}

+ 0 - 79
cqb-base/src/main/java/com/qmth/cqb/base/web/RoleController.java

@@ -1,79 +0,0 @@
-package com.qmth.cqb.base.web;
-
-import com.google.gson.Gson;
-import com.qmth.cqb.base.dao.RoleRepo;
-import com.qmth.cqb.base.model.Role;
-import com.qmth.cqb.base.service.RoleService;
-import com.qmth.cqb.utils.modal.NormalResponse;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.*;
-
-/**
- * Created by songyue on 16/12/26.
- */
-@RestController
-@RequestMapping("${api_cqb}/")
-public class RoleController {
-    @Autowired
-    Gson gson;
-
-    @Autowired
-    RoleRepo roleRepo;
-
-    @Autowired
-    RoleService roleService;
-
-    /**
-     * 获取角色
-     * @param role_id
-     * @return
-     */
-    @GetMapping(value = "/role/{role_id}")
-    public Role getRoleById(@PathVariable String role_id){
-        return roleRepo.findById(role_id);
-    }
-
-    /**
-     * 获取全部角色
-     * @return
-     */
-    @GetMapping(value = "/role/all/{curPage}/{pageSize}")
-    public PagingAndSortingResponse<Role> getAllRole(@ModelAttribute Role searchCondition,@PathVariable int curPage,@PathVariable int pageSize){
-        return roleService.findAll(searchCondition,new PageRequest(curPage - 1,pageSize));
-    }
-
-    /**
-     * 更新角色
-     * @param role
-     * @return
-     */
-    @PutMapping(value = "/role")
-    public NormalResponse updateRole(@ModelAttribute Role role){
-        roleRepo.save(role);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-
-    /**
-     * 新增角色
-     * @param role
-     * @return
-     */
-    @PostMapping(value = "/role")
-    public NormalResponse addRole(@ModelAttribute Role role){
-        roleRepo.save(role);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-
-    /**
-     * 删除角色
-     * @param role_id
-     * @return
-     */
-    @DeleteMapping(value = "/role/{role_id}")
-    public NormalResponse removeRole(@PathVariable String role_id){
-        roleRepo.delete(role_id);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }}

+ 0 - 80
cqb-base/src/main/java/com/qmth/cqb/base/web/UserController.java

@@ -1,80 +0,0 @@
-package com.qmth.cqb.base.web;
-
-import com.google.gson.Gson;
-import com.qmth.cqb.base.dao.UserRepo;
-import com.qmth.cqb.base.model.User;
-import com.qmth.cqb.base.service.UserService;
-import com.qmth.cqb.utils.modal.NormalResponse;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.*;
-
-/**
- * Created by songyue on 16/12/26.
- */
-@RestController
-@RequestMapping("${api_cqb}/")
-public class UserController {
-    @Autowired
-    Gson gson;
-
-    @Autowired
-    UserRepo userRepo;
-
-    @Autowired
-    UserService userService;
-
-    /**
-     * 获取用户
-     * @param user_id
-     * @return
-     */
-    @GetMapping(value = "/user/{user_id}")
-    public User getUserById(@PathVariable String user_id){
-        return userRepo.findById(user_id);
-    }
-
-    /**
-     * 获取全部用户
-     * @return
-     */
-    @GetMapping(value = "/user/all/{curPage}/{paseSize}")
-    public PagingAndSortingResponse<User> getAllUser(@ModelAttribute User searchCondition, @PathVariable int curPage, @PathVariable int pageSize){
-        return userService.findAll(searchCondition,new PageRequest(curPage - 1,pageSize));
-    }
-
-    /**
-     * 更新用户
-     * @param user
-     * @return
-     */
-    @PutMapping(value = "/user")
-    public NormalResponse updateUser(@ModelAttribute User user){
-        userRepo.save(user);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-
-    /**
-     * 新增用户
-     * @param user
-     * @return
-     */
-    @PostMapping(value = "/user")
-    public NormalResponse addUser(@ModelAttribute User user){
-        userRepo.save(user);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-
-    /**
-     * 删除用户
-     * @param user_id
-     * @return
-     */
-    @DeleteMapping(value = "/user/{user_id}")
-    public NormalResponse removeUser(@PathVariable String user_id){
-        userRepo.delete(user_id);
-        return new NormalResponse(HttpStatus.OK.toString(),"success");
-    }
-}

+ 8 - 2
cqb-comm-utils/pom.xml

@@ -37,13 +37,13 @@
         <dependency>
             <groupId>io.springfox</groupId>
             <artifactId>springfox-swagger2</artifactId>
-            <version>${swagger-version}</version>
+            <version>2.6.1</version>
         </dependency>
 
         <dependency>
             <groupId>io.springfox</groupId>
             <artifactId>springfox-swagger-ui</artifactId>
-            <version>${swagger-version}</version>
+            <version>2.6.1</version>
         </dependency>
 
         <dependency>
@@ -165,5 +165,11 @@
             <version>1.11.3</version>
         </dependency>
 
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+            <version>1.3.2</version>
+        </dependency>
+
     </dependencies>
 </project>

+ 44 - 0
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/PaperStatus.java

@@ -0,0 +1,44 @@
+package com.qmth.cqb.utils.enums;
+
+/**
+ * Created by songyue on 17/3/15.
+ */
+public enum PaperStatus {
+
+    DRAFT(1L,"待审核"),
+    PASS(2L,"通过"),
+    NOPASS(3L,"不通过");
+
+
+    private Long id;
+    private String name;
+
+    private PaperStatus(Long id, String name) {
+        this.id = id;
+        this.name = name;;
+    }
+
+    private PaperStatus(){
+
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String toString(){
+        return getName();
+    }
+}

+ 43 - 0
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/PaperType.java

@@ -0,0 +1,43 @@
+package com.qmth.cqb.utils.enums;
+
+/**
+ * Created by songyue on 17/3/15.
+ */
+public enum PaperType {
+
+    IMPORT(1L,"导入"),
+    GENERATE(2L,"组卷");
+
+
+    private Long id;
+    private String name;
+
+    private PaperType(Long id, String name) {
+        this.id = id;
+        this.name = name;;
+    }
+
+    private PaperType(){
+
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String toString(){
+        return getName();
+    }
+}

+ 1 - 1
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java

@@ -653,7 +653,7 @@ public final class DocxProcessUtil {
             //添加资源文件定义
             for(Part p:parts){
                 wordMLPackage.getMainDocumentPart().addTargetPart(p,
-                                      RelationshipsPart.AddPartBehaviour.OVERWRITE_IF_NAME_EXISTS,
+                                      RelationshipsPart.AddPartBehaviour.REUSE_EXISTING,
                                       p.getSourceRelationship().getId());
             }
         }

+ 98 - 0
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/model/GenPaperDto.java

@@ -0,0 +1,98 @@
+package com.qmth.cqb.genpaper.model;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Condition;
+
+/**
+ * Created by songyue on 17/3/24.
+ */
+public class GenPaperDto implements Serializable{
+
+    private static final long serialVersionUID = -7738591929656796661L;
+
+    private String courseNo;//课程代码
+
+    private String courseName;//课程名称
+
+    private String paperName;//试卷名称
+
+    private List<String> paperIds;//试卷ID集合
+
+    private Map<String,Double> simpleParams;//简单组卷规则
+
+    private List<Condition> conditions;//精细组卷规则
+
+    private String creator;//创建人
+
+    private String paperStructId;//试卷模板Id
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getCourseNo() {
+        return courseNo;
+    }
+
+    public void setCourseNo(String courseNo) {
+        this.courseNo = courseNo;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getPaperName() {
+        return paperName;
+    }
+
+    public void setPaperName(String paperName) {
+        this.paperName = paperName;
+    }
+
+    public List<String> getPaperIds() {
+        return paperIds;
+    }
+
+    public void setPaperIds(List<String> paperIds) {
+        this.paperIds = paperIds;
+    }
+
+    public Map<String, Double> getSimpleParams() {
+        return simpleParams;
+    }
+
+    public void setSimpleParams(Map<String, Double> simpleParams) {
+        this.simpleParams = simpleParams;
+    }
+
+    public List<Condition> getConditions() {
+        return conditions;
+    }
+
+    public void setConditions(List<Condition> conditions) {
+        this.conditions = conditions;
+    }
+
+    public String getCreator() {
+        return creator;
+    }
+
+    public void setCreator(String creator) {
+        this.creator = creator;
+    }
+
+    public String getPaperStructId() {
+        return paperStructId;
+    }
+
+    public void setPaperStructId(String paperStructId) {
+        this.paperStructId = paperStructId;
+    }
+}

+ 2 - 2
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java

@@ -59,8 +59,8 @@ public class GenPaperService {
                 double sum = 0;
                 for (PaperDetailUnit pdu : unitList) {
                     sum += pdu.getScore();
-                    if (sum <= totalScore) {// 5 10 15 20 25 30
-                        selectedUnits.add(pdu);// 1 2 3 4 5 6
+                    if (sum <= totalScore) {
+                        selectedUnits.add(pdu);
                     } else {
                         break;
                     }

+ 20 - 1
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/web/GenPaperController.java

@@ -1,17 +1,36 @@
 package com.qmth.cqb.genpaper.web;
 
+import com.qmth.cqb.genpaper.model.GenPaperDto;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 
 import com.qmth.cqb.genpaper.service.GenPaperService;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * Created by songyue on 16/12/28.
  */
-@Controller
+@RestController
+@RequestMapping("${api_cqb}/")
 public class GenPaperController {
 
     @Autowired
     GenPaperService genPaperService;
 
+    @PostMapping("/genPaper/simple")
+    public ResponseEntity genPaperSimple(@RequestBody GenPaperDto genPaperDto){
+        return new ResponseEntity("", HttpStatus.OK);
+    }
+
+    @PostMapping("/genPaper/normal")
+    public ResponseEntity genPaperNormal(@RequestBody GenPaperDto genPaperDto){
+        return new ResponseEntity("", HttpStatus.OK);
+    }
+
+
 }

+ 14 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/dao/PaperRepo.java

@@ -1,10 +1,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;
 
 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);
+
 }

+ 0 - 86
cqb-paper/src/main/java/com/qmth/cqb/paper/model/ImportPaperSearchCondition.java

@@ -1,86 +0,0 @@
-package com.qmth.cqb.paper.model;
-
-import java.io.Serializable;
-import java.util.Map;
-
-public class ImportPaperSearchCondition implements Serializable{
-
-	private static final long serialVersionUID = 8273918442524569201L;
-
-	private String id;
-
-    private String paperName;//试卷名称
-
-    private String createTime;//创建时间
-
-    private String updateTime;//更新时间
-
-    private String creatorName;//录入员
-    
-    private String lastModifyName;//最后修改人名称
-
-    private String courseId;//课程ID
-        
-    
-	public String getId() {
-		return id;
-	}
-
-	public void setId(String id) {
-		this.id = id;
-	}
-
-	public String getPaperName() {
-		return paperName;
-	}
-
-	public void setPaperName(String paperName) {
-		this.paperName = paperName;
-	}
-
-	public String getCreateTime() {
-		return createTime;
-	}
-
-	public void setCreateTime(String createTime) {
-		this.createTime = createTime;
-	}
-
-	public String getUpdateTime() {
-		return updateTime;
-	}
-
-	public void setUpdateTime(String updateTime) {
-		this.updateTime = updateTime;
-	}
-
-	public String getCreatorName() {
-		return creatorName;
-	}
-
-	public void setCreatorName(String creatorName) {
-		this.creatorName = creatorName;
-	}
-
-	public String getLastModifyName() {
-		return lastModifyName;
-	}
-
-	public void setLastModifyName(String lastModifyName) {
-		this.lastModifyName = lastModifyName;
-	}
-
-	public String getCourseId() {
-		return courseId;
-	}
-
-	public void setCourseId(String courseId) {
-		this.courseId = courseId;
-	}
-
-	public static long getSerialversionuid() {
-		return serialVersionUID;
-	}
-
-	
-}

+ 46 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/model/Paper.java

@@ -4,6 +4,8 @@ import java.io.Serializable;
 import java.util.Map;
 
 import com.qmth.cqb.utils.CommonUtils;
+import com.qmth.cqb.utils.enums.PaperStatus;
+import com.qmth.cqb.utils.enums.PaperType;
 import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.index.Indexed;
 
@@ -37,6 +39,14 @@ public class Paper implements Serializable {
 
     private String html;//原始试卷html
 
+    private PaperStatus paperStatus;//试卷状态(待审核、通过、不通过)
+
+    private PaperType paperType;//试卷类型(导入、组卷)
+
+    private String courseNo;
+
+    private String courseName;
+
     private Map<String,String> params;//导入试卷属性
 
     public static long getSerialVersionUID() {
@@ -75,6 +85,14 @@ public class Paper implements Serializable {
         this.totalScore = totalScore;
     }
 
+    public String getCreator() {
+        return creator;
+    }
+
+    public void setCreator(String creator) {
+        this.creator = creator;
+    }
+
     public Integer getPaperDetailCount() {
         return paperDetailCount;
     }
@@ -115,6 +133,22 @@ public class Paper implements Serializable {
         this.html = html;
     }
 
+    public PaperStatus getPaperStatus() {
+        return paperStatus;
+    }
+
+    public void setPaperStatus(PaperStatus paperStatus) {
+        this.paperStatus = paperStatus;
+    }
+
+    public PaperType getPaperType() {
+        return paperType;
+    }
+
+    public void setPaperType(PaperType paperType) {
+        this.paperType = paperType;
+    }
+
     public Map<String, String> getParams() {
         return params;
     }
@@ -123,12 +157,20 @@ public class Paper implements Serializable {
         this.params = params;
     }
 
-    public String getCreator() {
-        return creator;
+    public String getCourseNo() {
+        return courseNo;
     }
 
-    public void setCreator(String creator) {
-        this.creator = creator;
+    public void setCourseNo(String courseNo) {
+        this.courseNo = courseNo;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
     }
 
     public Paper() {

+ 0 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailStruct.java

@@ -4,8 +4,6 @@ import java.io.Serializable;
 import java.util.Map;
 import java.util.List;
 
-import com.qmth.cqb.base.model.QuesType;
-
 /**
  * 试卷结构明细
  * Created by songyue on 16/12/28.

+ 63 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperSearchInfo.java

@@ -0,0 +1,63 @@
+package com.qmth.cqb.paper.model;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public class PaperSearchInfo implements Serializable{
+
+	private static final long serialVersionUID = 8273918442524569201L;
+
+    private String name;//试卷名称
+
+    private String createTime;//创建时间
+
+    private String creator;//录入员
+    
+    private String courseNo;//课程代码
+
+	private String [] paperIds;
+
+	public static long getSerialVersionUID() {
+		return serialVersionUID;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getCreateTime() {
+		return createTime;
+	}
+
+	public void setCreateTime(String createTime) {
+		this.createTime = createTime;
+	}
+
+	public String getCreator() {
+		return creator;
+	}
+
+	public void setCreator(String creator) {
+		this.creator = creator;
+	}
+
+	public String getCourseNo() {
+		return courseNo;
+	}
+
+	public void setCourseNo(String courseNo) {
+		this.courseNo = courseNo;
+	}
+
+	public String[] getPaperIds() {
+		return paperIds;
+	}
+
+	public void setPaperIds(String[] paperIds) {
+		this.paperIds = paperIds;
+	}
+}

+ 63 - 73
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -1,7 +1,5 @@
 package com.qmth.cqb.paper.service;
 
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
-
 import com.google.gson.Gson;
 import com.qmth.cqb.paper.dao.PaperDetailRepo;
 import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
@@ -15,19 +13,19 @@ import com.qmth.cqb.question.model.QuesOption;
 import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.question.model.QuestionType;
 import com.qmth.cqb.utils.CommonUtils;
+import com.qmth.cqb.utils.enums.PaperStatus;
+import com.qmth.cqb.utils.enums.PaperType;
 import com.qmth.cqb.utils.enums.QuesStructType;
 import com.qmth.cqb.utils.enums.QuesUnit;
 import com.qmth.cqb.utils.word.DocxProcessUtil;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
 import org.docx4j.wml.P;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 import java.io.*;
 
@@ -55,57 +53,33 @@ public class ImportPaperService {
     @Autowired
     PaperService paperService;
 
-
-    /**
-     * 查询所有已导入试卷
-     * @param searchCondition
-     * @param curPage
-     * @param pageSize
-     * @return
-     */
-    public Page<Paper> findAll(ImportPaperSearchCondition searchCondition,
-                               int curPage,
-                               int pageSize){
-    	Paper importPaper = new Paper();
-    	BeanUtils.copyProperties(searchCondition,importPaper);
-    	ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("paperName", startsWith());
-        return paperRepo.findAll(Example.of(importPaper,matcher),
-                new PageRequest(curPage - 1,pageSize));
-    }
-
-    /**
-     * 批量删除导入试卷
-     * @param paperIds
-     */
-    public void deleteImportPaper(String[] paperIds) {
-        paperService.deletePapers(paperIds);
-    }
-
     /**
-     * 查询所有已导入试卷
-     * @param courseId
-     * @param curPage
-     * @param pageSize
+     * 获取上传文件
+     * @param file
      * @return
      */
-    public Page<Paper> getImportPapersByCourseId(String courseId,int curPage,int pageSize){
-    	Paper importPaper = new Paper();
-    	if(!StringUtils.isEmpty(courseId)){
-        	Map<String,String> param = new HashMap<String,String>();
-        	param.put("courseId", courseId);
-        	importPaper.setParams(param);
-    	}
-        return paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage - 1,pageSize));
+    public File getUploadFile(CommonsMultipartFile file){
+        String fileName = file.getOriginalFilename();
+        File tempFile = new File(DocxProcessUtil.TEMP_FILE_IMP+fileName);
+        OutputStream os = null;
+        try {
+            os = new FileOutputStream(tempFile);
+            IOUtils.copyLarge(file.getInputStream(),os);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }finally {
+            IOUtils.closeQuietly(os);
+        }
+        return tempFile;
     }
 
-
     /**
      * 导入试卷
-     * @param inputStream
+     * @param file
      * @return
      */
-    public String ImportPaper(InputStream inputStream){
-        String errorInfo = processImportPaper(inputStream);
+    public String ImportPaper(String paperName,File file){
+        String errorInfo = processImportPaper(paperName,file);
         if(StringUtils.isEmpty(errorInfo)){
             return "success";
         }else{
@@ -148,9 +122,9 @@ public class ImportPaperService {
 
     /**
      * 处理导入试卷
-     * @param inputStream
+     * @param file
      */
-    public String processImportPaper(InputStream inputStream){
+    public String processImportPaper(String paperName,File file){
 
         WordprocessingMLPackage wordMLPackage;
         WordprocessingMLPackage tmpWordMlPackage;
@@ -158,7 +132,7 @@ public class ImportPaperService {
         ImportPaperCheck importPaperCheck = new ImportPaperCheck();
 
         try{
-            wordMLPackage = WordprocessingMLPackage.load(inputStream);
+            wordMLPackage = WordprocessingMLPackage.load(file);
             //初始化图片路径
             DocxProcessUtil.initPkgImage(wordMLPackage);
             //深拷贝临时pkg与最终写入数据库pkg
@@ -172,6 +146,9 @@ public class ImportPaperService {
             //创建试卷类
             Paper paper = new Paper();
 
+            //设置试卷
+            initPaper(paper,paperName);
+
             //创建空大题类
             PaperDetail paperDetail = null;
 
@@ -298,7 +275,8 @@ public class ImportPaperService {
                     return importPaperCheck.errorInfo;
                 }
             }
-
+            paper.setPaperDetailCount(mainQuesNum);
+            paper.setTotalScore((double)100);
             //保存导入试卷信息
             savePaper(paper,
                       paperDetails,
@@ -309,13 +287,27 @@ public class ImportPaperService {
         }catch (Exception e){
             e.printStackTrace();
             importPaperCheck.setErrorInfo(e.getMessage());
+        }finally {
+            wordMLPackage = null;
+            tmpWordMlPackage = null;
+            writePkg = null;
+            FileUtils.deleteQuietly(file);
         }
-        wordMLPackage = null;
-        tmpWordMlPackage = null;
-        writePkg = null;
         return importPaperCheck.errorInfo;
     }
 
+    /**
+     * 初始化试卷信息
+     * @param paper
+     * @param paperName
+     */
+    public void initPaper(Paper paper,String paperName){
+        paper.setName(paperName);
+        paper.setTitle(paperName);
+        paper.setPaperType(PaperType.IMPORT);
+        paper.setPaperStatus(PaperStatus.DRAFT);
+    }
+
     /**
      * 初始化大题头信息
      * @param paper
@@ -332,14 +324,12 @@ public class ImportPaperService {
 
         paperDetail.setPaper(paper);
 
-        //设置试卷
-        paper.setTitle(importPaperCheck.quesGroup);
-        paper.setName(importPaperCheck.quesGroup);
-        Map paramMap = new HashMap();
-        paramMap.put("courseNo",getCourseNo(importPaperCheck));
-        paramMap.put("courseName",getCourseName(importPaperCheck));
-        paper.setParams(paramMap);
-
+        //设置课程
+        if(StringUtils.isEmpty(paper.getCourseNo())
+                || StringUtils.isEmpty(paper.getCourseName())){
+            paper.setCourseNo(getCourseNo(importPaperCheck));
+            paper.setCourseName(getCourseName(importPaperCheck));
+        }
         //设置大题信息
         paperDetail.setName(importPaperCheck.quesName);
         paperDetail.setUnitCount(Integer.parseInt(importPaperCheck.quesCount));
@@ -382,24 +372,24 @@ public class ImportPaperService {
 
         String tmpErrorInfo = "";
         if(StringUtils.isEmpty(importPaperCheck.quesGroup)){
-            tmpErrorInfo += "试题分类为空或格式不正确";
+            tmpErrorInfo += "试题分类为空或格式不正确\n";
 
         }else if(StringUtils.isEmpty(importPaperCheck.quesType)){
-            tmpErrorInfo += "题型为空或格式不正确";
+            tmpErrorInfo += "题型为空或格式不正确\n";
 
         }else if(StringUtils.isEmpty(importPaperCheck.quesName)){
-            tmpErrorInfo += "大题名称为空或格式不正确";
+            tmpErrorInfo += "大题名称为空或格式不正确\n";
 
         }else if(StringUtils.isEmpty(importPaperCheck.quesCount)){
-            tmpErrorInfo += "题目数量为空或格式不正确";
+            tmpErrorInfo += "题目数量为空或格式不正确\n";
 
         }else if(StringUtils.isEmpty(importPaperCheck.quesScore)){
-            tmpErrorInfo += "分数为空或格式不正确";
+            tmpErrorInfo += "分数为空或格式不正确\n";
 
         }
         if(!StringUtils.isEmpty(importPaperCheck.quesType)
                 && !CommonUtils.checkQuesType(importPaperCheck.quesType)){
-            tmpErrorInfo += "题型必须是单选、多选、判断、填空、问答、套题中的一种";
+            tmpErrorInfo += "题型必须是单选、多选、判断、填空、问答、套题中的一种\n";
         }
         if(StringUtils.isEmpty(tmpErrorInfo)){
             return true;
@@ -557,7 +547,7 @@ public class ImportPaperService {
         importPaperCheck.setIndex(i);
         if(optionCount < 2){
             importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,
-                    subQuesNum) +"中选项格式不正确或有缺失,如没有缺失可尝试换行处理");
+                    subQuesNum) +"中选项格式不正确或有缺失,如没有缺失可尝试换行处理\n");
         }else{
             question.setQuesOptions(quesOptions);
         }
@@ -612,7 +602,7 @@ public class ImportPaperService {
                     DocxProcessUtil.formatPWordMl(quesAnwserWordMl));
         }else{
             importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,
-                    subQuesNum) +"答案为空或格式不正确");
+                    subQuesNum) +"答案为空或格式不正确\n");
         }
 
         //设置小题分数
@@ -669,7 +659,7 @@ public class ImportPaperService {
 
                 if(StringUtils.isEmpty(nestedQuesType)){
                     importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName
-                            ,subQuesNum)+ "小题型为空或格式不正确");
+                            ,subQuesNum)+ "小题型为空或格式不正确\n");
                     return;
                 }
 

+ 86 - 31
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java

@@ -4,10 +4,17 @@ import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import com.qmth.cqb.paper.model.PaperSearchInfo;
+import com.qmth.cqb.utils.BeanCopierUtil;
 import com.qmth.cqb.utils.CommonUtils;
+import com.qmth.cqb.utils.enums.PaperStatus;
+import com.qmth.cqb.utils.enums.PaperType;
 import org.apache.commons.collections4.IteratorUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
 import com.qmth.cqb.paper.dao.ExamPaperRepo;
@@ -29,9 +36,39 @@ public class PaperService {
 	PaperDetailService paperDetailService;
 	
 	@Autowired
-	ExamPaperRepo examPaperRepo; 
-	
-	
+	ExamPaperRepo examPaperRepo;
+
+	/**
+	 * 查询所有已导入试卷
+	 * @param paperSearchInfo
+	 * @param curPage
+	 * @param pageSize
+	 * @return
+	 */
+	public Page<Paper> getImportPapers(PaperSearchInfo paperSearchInfo,
+									   int curPage,
+									   int pageSize){
+		formatPaperSearchInfo(paperSearchInfo);
+		Paper importPaper = BeanCopierUtil.copyProperties(paperSearchInfo,Paper.class);
+		importPaper.setPaperType(PaperType.IMPORT);
+		return paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage - 1,pageSize));
+	}
+
+	/**
+	 * 查询所有已组试卷
+	 * @param paperSearchInfo
+	 * @param curPage
+	 * @param pageSize
+	 * @return
+	 */
+	public Page<Paper> getGenPapers(PaperSearchInfo paperSearchInfo,
+									int curPage,
+									int pageSize){
+		formatPaperSearchInfo(paperSearchInfo);
+		Paper importPaper = BeanCopierUtil.copyProperties(paperSearchInfo,Paper.class);
+		importPaper.setPaperType(PaperType.GENERATE);
+		return paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage - 1,pageSize));
+	}
 	
 	/**
 	 * 查询考试试卷
@@ -120,41 +157,59 @@ public class PaperService {
         return paperDetailService.getPaperDetailsByPaper(paperRepo.findOne(id));
     }
 
-    /**
-     * 按ID查询试卷
-     * @param id
-     * @return
+	/**
+	 * 批量删除试卷
+	 * @param paperIds
      */
-    public Paper findById(String id){
-        return paperRepo.findOne(id);
-    }
+	public void deletePapers(List<String> paperIds){
+		List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
+		paperDetailService.deletePaperDetailsByPapers(papers);
+		paperRepo.delete(papers);
+	}
 
-    /**
-     * 保存试卷
-     * @param pd
-     * @return
-     */
-    public Paper savePaper(Paper pd){
-        return paperRepo.save(pd);
-    }
+	/**
+	 * 批量通过试卷
+	 * @param paperIds
+	 */
+	public void passPapers(List<String> paperIds){
+		List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
+		papers.stream().forEach(paper -> {paper.setPaperStatus(PaperStatus.PASS);});
+		paperRepo.save(papers);
+	}
 
 	/**
-	 * 删除试卷
-	 * @param paper
-     */
-    public void deletePaper(Paper paper){
-    	paperDetailService.deletePaperDetailsByPaper(paper);
-		paperRepo.delete(paper);
+	 * 批量不通过试卷
+	 * @param paperIds
+	 */
+	public void noPassPapers(List<String> paperIds){
+		List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
+		papers.stream().forEach(paper -> {paper.setPaperStatus(PaperStatus.NOPASS);});
+		paperRepo.save(papers);
 	}
 
 	/**
-	 * 批量删除试卷
-	 * @param paperId
-     */
-	public void deletePapers(String [] paperId){
-		List<Paper> papers = CommonUtils.toList(paperRepo.findAll(Arrays.asList(paperId)));
-		paperDetailService.deletePaperDetailsByPapers(papers);
-		paperRepo.delete(papers);
+	 * 批量待审核试卷
+	 * @param paperIds
+	 */
+	public void initPapers(List<String> paperIds){
+		List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
+		papers.stream().forEach(paper -> {paper.setPaperStatus(PaperStatus.DRAFT);});
+		paperRepo.save(papers);
+	}
+
+	public void formatPaperSearchInfo(PaperSearchInfo paperSearchInfo){
+		if(StringUtils.isEmpty(paperSearchInfo.getCourseNo())){
+			paperSearchInfo.setCourseNo(null);
+		}
+		if(StringUtils.isEmpty(paperSearchInfo.getCreateTime())){
+			paperSearchInfo.setCreateTime(null);
+		}
+		if(StringUtils.isEmpty(paperSearchInfo.getCreator())){
+			paperSearchInfo.setCreator(null);
+		}
+		if(StringUtils.isEmpty(paperSearchInfo.getName())){
+			paperSearchInfo.setName(null);
+		}
 	}
 
 }

+ 23 - 71
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ImportPaperController.java

@@ -1,22 +1,20 @@
 package com.qmth.cqb.paper.web;
 
 import com.qmth.cqb.paper.dao.PaperRepo;
-import com.qmth.cqb.paper.model.ImportPaperSearchCondition;
+import com.qmth.cqb.paper.service.PaperService;
+import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 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.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
-import com.qmth.cqb.paper.model.Paper;
 import com.qmth.cqb.paper.service.ImportPaperService;
-import com.qmth.cqb.utils.modal.PagingAndSortingResponse;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.*;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Created by songyue on 16/12/28.
@@ -31,71 +29,25 @@ public class ImportPaperController {
     @Autowired
     PaperRepo paperRepo;
 
-    /**
-     * 获取导入试卷
-     * @param id
-     * @return
-     */
-    @GetMapping(value = "/importPaper/{id}")
-    public ResponseEntity getPaperById(@PathVariable String id){
-        return new ResponseEntity(paperRepo.findOne(id),HttpStatus.OK);
-    }
-
-    /**
-     * 获取全部导入试卷
-     * @return
-     */
-    @GetMapping(value = "/importPaper/{curPage}/{paseSize}")
-    public ResponseEntity getAllPaper(@ModelAttribute ImportPaperSearchCondition searchCondition,                                            @PathVariable int curPage,
-                                      @PathVariable int pageSize){
-
-      return new ResponseEntity(importPaperService.findAll(searchCondition,
-              curPage,pageSize), HttpStatus.OK);
-    }
-
-    /**
-     * 获取全部导入试卷
-     * @return
-     */
-    @GetMapping(value = "/importPaper/{courseId}/{curPage}/{pageSize}")
-    public ResponseEntity getImportPapersByCourseId(
-    		                              @PathVariable String courseId,
-    		                              @PathVariable int curPage,
-    		                              @PathVariable int pageSize
-    		                              ){
-      return new ResponseEntity(importPaperService.getImportPapersByCourseId(courseId,
-              curPage, pageSize),HttpStatus.OK);
-    }
-
-
-    /**
-     * 更新导入试卷信息
-     * @param 
-     * @return
-     */
-    @PutMapping(value = "/importPaper")
-    public ResponseEntity updatePaper(@ModelAttribute Paper paper){
-    	return new ResponseEntity(paperRepo.save(paper),HttpStatus.OK);
-    }
+    @Autowired
+    PaperService paperService;
 
     /**
-     * 新增导入试卷
-     * @param paper
+     * 导入试卷
+     * @param paperName
+     * @param file
      * @return
      */
     @PostMapping(value = "/importPaper")
-    public ResponseEntity addPaper(@ModelAttribute Paper paper){
-    	return new ResponseEntity(paperRepo.save(paper),HttpStatus.OK);
+    public ResponseEntity importPaper(@RequestParam String paperName,
+                                      @RequestParam("file") CommonsMultipartFile file){
+        File tempFile = importPaperService.getUploadFile(file);
+        String returnStr = importPaperService.ImportPaper(paperName,tempFile);
+        if(returnStr.equals("success")){
+            return new ResponseEntity(HttpStatus.OK);
+        }else{
+            return new ResponseEntity(returnStr,HttpStatus.INTERNAL_SERVER_ERROR);
+        }
     }
 
-    /**
-     * 删除导入试卷
-     * @param id
-     * @return
-     */
-    @DeleteMapping(value = "/importPaper/{id}")
-    public ResponseEntity removePaper(@PathVariable String id){
-    	paperRepo.delete(id);
-		return new ResponseEntity(HttpStatus.OK);
-    }
 }

+ 141 - 62
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperController.java

@@ -1,22 +1,21 @@
 package com.qmth.cqb.paper.web;
 
+import com.qmth.cqb.paper.dao.PaperRepo;
 import com.qmth.cqb.paper.model.Paper;
+import com.qmth.cqb.paper.model.PaperSearchInfo;
 import com.qmth.cqb.paper.service.PaperService;
 import io.swagger.annotations.ApiOperation;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.springframework.beans.factory.annotation.Autowired;
 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.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * Created by songyue on 16/12/28.
@@ -26,104 +25,184 @@ import org.springframework.web.bind.annotation.RestController;
 public class PaperController {
     @Autowired
     PaperService paperService;
+
+    @Autowired
+    PaperRepo paperRepo;
     
     /**
-     * 新增试卷
-     * @param paper
+     * 根据Id获取试卷
+     * @param paperId
      * @return
      */
-    @PostMapping(value = "/paper")
-    public ResponseEntity CreatePaper(@ModelAttribute Paper paper){
-      return new ResponseEntity(paperService.savePaper(paper),HttpStatus.OK);
+    @ApiOperation(value="根据Id获取试卷",notes="根据Id获取试卷")
+    @GetMapping(value = "/paper/{paperId}")
+    public ResponseEntity getPaperById(@PathVariable String paperId){
+        return new ResponseEntity(paperRepo.findOne(paperId),HttpStatus.OK);
     }
 
     /**
-     * 根据Id获取试卷
-     * @param paper_id
+     * 查询所有导入试卷
+     * @param paperSearchInfo
+     * @param curPage
+     * @param pageSize
+     * @return
+     */
+    @ApiOperation(value="查询所有导入试卷",notes="查询所有导入试卷")
+    @GetMapping(value = "/importPaper/{curPage}/{pageSize}")
+    public ResponseEntity getImportPapers(@ModelAttribute PaperSearchInfo paperSearchInfo,
+                                          @PathVariable int curPage,
+                                          @PathVariable int pageSize){
+        return new ResponseEntity(paperService.getImportPapers(paperSearchInfo,
+                curPage, pageSize),HttpStatus.OK);
+    }
+
+    /**
+     * 查询所有已组试卷
+     * @param paperSearchInfo
+     * @param curPage
+     * @param pageSize
      * @return
      */
-    @ApiOperation(value="获取单张试卷",notes="获取单张试卷")
-    @GetMapping(value = "/paper/{paper_id}")
-    public Paper getPaperById(@PathVariable String paper_id){
-        return paperService.findById(paper_id);
+    @ApiOperation(value="查询所有已组试卷",notes="查询所有已组试卷")
+    @GetMapping(value = "/genPaper/{curPage}/{pageSize}")
+    public ResponseEntity getGenPapers(@ModelAttribute PaperSearchInfo paperSearchInfo,
+                                       @PathVariable int curPage,
+                                       @PathVariable int pageSize){
+        return new ResponseEntity(paperService.getGenPapers(paperSearchInfo,
+                curPage, pageSize),HttpStatus.OK);
+    }
+
+    /**
+     * 删除试卷
+     * @param paperIds
+     * @return
+     */
+    @ApiOperation(value="删除试卷",notes="删除试卷")
+    @DeleteMapping(value = "/paper/{paperIds}")
+    public ResponseEntity delPaper(@PathVariable String paperIds){
+        List<String> paperList = Stream.of(paperIds.split(",")).collect(Collectors.toList());
+        paperService.deletePapers(paperList);
+        return new ResponseEntity(HttpStatus.OK);
+    }
+
+    /**
+     * 批量通过试卷
+     * @param paperSearchInfo
+     * @return
+     */
+    @ApiOperation(value="批量通过试卷",notes="批量通过试卷")
+    @PutMapping(value = "/paper/pass")
+    public ResponseEntity passPapers(@RequestBody PaperSearchInfo paperSearchInfo){
+        paperService.passPapers(Arrays.asList(paperSearchInfo.getPaperIds()));
+        return new ResponseEntity(HttpStatus.OK);
+    }
+
+    /**
+     * 批量不通过试卷
+     * @param paperSearchInfo
+     * @return
+     */
+    @ApiOperation(value="批量不通过试卷",notes="批量不通过试卷")
+    @PutMapping(value = "/paper/noPass")
+    public ResponseEntity noPassPapers(@RequestBody PaperSearchInfo paperSearchInfo){
+        paperService.noPassPapers(Arrays.asList(paperSearchInfo.getPaperIds()));
+        return new ResponseEntity(HttpStatus.OK);
+    }
+
+    /**
+     * 批量待审核试卷
+     * @param paperSearchInfo
+     * @return
+     */
+    @ApiOperation(value="批量待审核试卷",notes="批量待审核试卷")
+    @PutMapping(value = "/paper/draft")
+    public ResponseEntity initPapers(@RequestBody PaperSearchInfo paperSearchInfo){
+        paperService.initPapers(Arrays.asList(paperSearchInfo.getPaperIds()));
+        return new ResponseEntity(HttpStatus.OK);
     }
 
 
     /**
      * 获取卷库考试试卷
-     * @param exam_id
-     * @param course_code
-     * @param group_code
+     * @param examId
+     * @param courseCode
+     * @param groupCode
      * @return
      */
-    @GetMapping(value = "/paper/list/{exam_id}/{course_code}/{group_code}")
-    public List<Paper> listPaperById(@PathVariable String exam_id,
-                                     @PathVariable String course_code,
-                                     @PathVariable String group_code){
-        return paperService.listExamPapers(Long.parseLong(exam_id), course_code, group_code);
+    @ApiOperation(value="获取卷库考试试卷",notes="获取卷库考试试卷")
+    @GetMapping(value = "/paper/list/{examId}/{courseCode}/{groupCode}")
+    public List<Paper> listPaperById(@PathVariable String examId,
+                                     @PathVariable String courseCode,
+                                     @PathVariable String groupCode){
+        return paperService.listExamPapers(Long.parseLong(examId), courseCode, groupCode);
     }
     
     /**
      * 新增考试试卷
-     * @param exam_id
-     * @param course_code
-     * @param group_code
-     * @param paper_id
+     * @param examId
+     * @param courseCode
+     * @param groupCode
+     * @param paperId
      * @return
      */
-    @PostMapping(value = "/paper/join/{exam_id}/{course_code}/{group_code}/{paper_id}")
-    public ResponseEntity joinExamPaper(@PathVariable String exam_id,
-    		                            @PathVariable String course_code,
-    		                            @PathVariable String group_code,
-    		                            @PathVariable String paper_id){
-      paperService.joinToExamPaper(Long.parseLong(exam_id),
-              course_code, group_code, paper_id);
+    @ApiOperation(value="新增考试试卷",notes="新增考试试卷")
+    @PostMapping(value = "/paper/join/{examId}/{courseCode}/{groupCode}/{paperId}")
+    public ResponseEntity joinExamPaper(@PathVariable String examId,
+    		                            @PathVariable String courseCode,
+    		                            @PathVariable String groupCode,
+    		                            @PathVariable String paperId){
+      paperService.joinToExamPaper(Long.parseLong(examId),
+              courseCode, groupCode, paperId);
           return new ResponseEntity(HttpStatus.OK);
     }
     
     /**
      * 删除考试试卷
-     * @param exam_id
-     * @param course_code
-     * @param group_code
-     * @param paper_id
+     * @param examId
+     * @param courseCode
+     * @param groupCode
+     * @param paperId
      * @return
      */
-    @DeleteMapping(value = "/paper/release/{exam_id}/{course_code}/{group_code}/{paper_id}")
-    public ResponseEntity releaseExamPaper(@PathVariable String exam_id,
-                                           @PathVariable String course_code,
-                                           @PathVariable String group_code,
-                                           @PathVariable String paper_id){
+    @ApiOperation(value="删除考试试卷",notes="删除考试试卷")
+    @DeleteMapping(value = "/paper/release/{examId}/{courseCode}/{groupCode}/{paperId}")
+    public ResponseEntity releaseExamPaper(@PathVariable String examId,
+                                           @PathVariable String courseCode,
+                                           @PathVariable String groupCode,
+                                           @PathVariable String paperId){
 
-      paperService.releaseExamPaper(Long.parseLong(exam_id),
-              course_code, group_code, paper_id);
+      paperService.releaseExamPaper(Long.parseLong(examId),
+              courseCode, groupCode, paperId);
         return new ResponseEntity(HttpStatus.OK);
     }
     
     /**
      * 获取卷库考试试卷类型集合
-     * @param exam_id
-     * @param group_code
+     * @param examId
+     * @param courseCode
      * @return
      */
-    @GetMapping(value = "/paper/listCode/{exam_id}/{group_code}")
-    public Set<String> listGroup(@PathVariable String exam_id,@PathVariable String group_code){
-        return paperService.listGroupCodes(Long.parseLong(exam_id), group_code);
+    @ApiOperation(value="获取考试试卷类型集合",notes="获取考试试卷类型集合")
+    @GetMapping(value = "/paper/groupCode/{examId}/{courseCode}")
+    public Set<String> listGroup(@PathVariable String examId,
+                                 @PathVariable String courseCode){
+        return paperService.listGroupCodes(Long.parseLong(examId), courseCode);
     }
     
     
     /**
-     * 删除试卷类型
-     * @param exam_id
-     * @param course_code
-     * @param group_code
+     * 删除考试试卷类型
+     * @param examId
+     * @param courseCode
+     * @param groupCode
      * @return
      */
-    @DeleteMapping(value = "/paper/deleteCode/{exam_id}/{course_code}/{group_code}")
-    public ResponseEntity deleteGroup(@PathVariable String exam_id,
-                                      @PathVariable String course_code,
-                                      @PathVariable String group_code){
-      paperService.deletGroupCode(Long.parseLong(exam_id), course_code, group_code);
+    @ApiOperation(value="删除考试试卷类型",notes="删除考试试卷类型")
+    @DeleteMapping(value = "/paper/groupCode/{examId}/{courseCode}/{groupCode}")
+    public ResponseEntity deleteGroup(@PathVariable String examId,
+                                      @PathVariable String courseCode,
+                                      @PathVariable String groupCode){
+      paperService.deletGroupCode(Long.parseLong(examId), courseCode, groupCode);
         return new ResponseEntity(HttpStatus.OK);
     }
 }

+ 0 - 10
cqb-starter/pom.xml

@@ -85,16 +85,6 @@
             <optional>true</optional>
         </dependency>
         
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger2</artifactId>
-            <version>${swagger-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger-ui</artifactId>
-            <version>${swagger-version}</version>
-        </dependency>
 
     </dependencies>
 

+ 17 - 0
cqb-starter/src/main/java/com/qmth/cqb/App.java

@@ -3,13 +3,19 @@ package com.qmth.cqb;
 import com.qmth.cqb.utils.GridFSUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.multipart.MultipartResolver;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 
 /**
  * 项目入口主程序
  *
  */
 @SpringBootApplication
+@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
 public class App {
 
     @Autowired
@@ -18,4 +24,15 @@ public class App {
     public static void main(String[] args){
         SpringApplication.run(App.class, args);
     }
+
+    //显示声明CommonsMultipartResolver为mutipartResolver
+    @Bean(name = "multipartResolver")
+    public MultipartResolver multipartResolver(){
+        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
+        resolver.setDefaultEncoding("UTF-8");
+        resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
+        resolver.setMaxInMemorySize(40960);
+        resolver.setMaxUploadSize(200*1024*1024);//上传文件大小 50M 50*1024*1024
+        return resolver;
+    }
 }

+ 34 - 70
cqb-starter/src/test/java/com/qmth/cqb/AppTest.java

@@ -1,9 +1,6 @@
 package com.qmth.cqb;
 
 import com.google.gson.Gson;
-import com.qmth.cqb.base.dao.UserRepo;
-import com.qmth.cqb.base.model.User;
-import com.qmth.cqb.base.service.UserService;
 import com.qmth.cqb.paper.dao.*;
 import com.qmth.cqb.paper.model.*;
 import com.qmth.cqb.paper.service.ExportPaperService;
@@ -15,28 +12,31 @@ import com.qmth.cqb.question.model.Question;
 import com.qmth.cqb.question.model.QuestionType;
 import com.qmth.cqb.utils.GridFSUtil;
 import com.qmth.cqb.utils.enums.ExtractPolicy;
+import com.qmth.cqb.utils.enums.PaperType;
 import com.qmth.cqb.utils.enums.QuesStructType;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.util.HashMap;
 import java.util.List;
 
 import com.qmth.cqb.utils.word.DocxProcessUtil;
 import org.apache.log4j.Logger;
 import org.docx4j.Docx4J;
 import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
-import org.docx4j.openpackaging.parts.relationships.Namespaces;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.util.ArrayList;
+import java.util.Map;
 
 /**
  * Unit test for simple App.
@@ -45,11 +45,6 @@ import java.util.ArrayList;
 @SpringBootTest
 public class AppTest {
     protected final Logger log = Logger.getLogger(AppTest.class);
-    @Autowired
-    UserRepo userRepo;
-
-    @Autowired
-    UserService userService;
 
     @Autowired
     QuesRepo quesRepo;
@@ -93,47 +88,6 @@ public class AppTest {
         gridFSUtil.getByFileName(fileName);
     }
 
-    @Test
-    public void testUser(){
-        userRepo.deleteAll();
-        User user1 = new User();
-        user1.setLoginName("songyue");
-        user1.setPassWord("123456");
-        user1.setUserName("宋悦");
-        user1.setCreateTime("20161226");
-
-        User user2 = new User();
-        user2.setLoginName("gaoxing");
-        user2.setPassWord("123456");
-        user2.setUserName("高兴");
-        user2.setCreateTime("20161226");
-
-        User user3 = new User();
-        user3.setLoginName("liming");
-        user3.setPassWord("123456");
-        user3.setUserName("李明");
-        user3.setCreateTime("20161226");
-
-        userRepo.save(user1);
-        userRepo.save(user2);
-        userRepo.save(user3);
-
-        long size = userRepo.count();
-
-        Assert.assertEquals(size,3);
-
-        System.out.println(userRepo.findAll());
-    }
-
-    @Test
-    public void testfindAllUser(){
-        User user = new User();
-        user.setLoginName("song");
-        userService.findAll(user,new PageRequest(0,10)).getDataList().forEach(o -> {
-            System.out.println(o.getLoginName());
-        });
-    }
-
     @Test
     public void testQuestion(){
         Question question = new Question();
@@ -236,25 +190,25 @@ public class AppTest {
         paperDetailRepo.deleteAll();
         quesRepo.deleteAll();
         paperDetailUnitRepo.deleteAll();
-        String inputFilePath = "/Users/songyue/docxImport/ceshi2.docx";
-        try {
-            File inputFile = new File(inputFilePath);
-            FileInputStream inputStream = new FileInputStream(inputFile);
-            System.out.println(inputFilePath);
-            long startTime = System.currentTimeMillis();    //获取开始时间
-
-            String errorInfo = importPaperService.ImportPaper(inputStream);
-            System.out.println("errorInfo:"+errorInfo);
-
-            long endTime = System.currentTimeMillis();    //获取结束时间
-
-            System.out.println("程序运行时间:" + (endTime - startTime)/1000 + "s");    //输出程序运行时间
-
-
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+//        String inputFilePath = "/Users/songyue/docxImport/ceshi2.docx";
+//        try {
+//            File inputFile = new File(inputFilePath);
+//            FileInputStream inputStream = new FileInputStream(inputFile);
+//            System.out.println(inputFilePath);
+//            long startTime = System.currentTimeMillis();    //获取开始时间
+//
+//            String errorInfo = importPaperService.ImportPaper("",inputFile);
+//            System.out.println("errorInfo:"+errorInfo);
+//
+//            long endTime = System.currentTimeMillis();    //获取结束时间
+//
+//            System.out.println("程序运行时间:" + (endTime - startTime)/1000 + "s");    //输出程序运行时间
+//
+//
+//
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
 
 
     }
@@ -262,7 +216,7 @@ public class AppTest {
     @Test
     public void testExport()throws Exception{
         long startTime = System.currentTimeMillis();    //获取开始时间
-        exportPaperService.exportPaper("58d0ef46aaa9a760080e2136");
+        exportPaperService.exportPaper("58d2249dcca40392c5782322");
         long endTime = System.currentTimeMillis();    //获取结束时间
         System.out.println("程序运行时间:" + (endTime - startTime)/1000 + "s");    //输出程序运行时间
     }
@@ -285,7 +239,17 @@ public class AppTest {
         } catch (Exception e) {
             e.printStackTrace();
         }
+    }
 
+    @Test
+    public void testCourse(){
+        Map<String,String> params = new HashMap<String,String>();
+        params.put("courseNo","03013750");
+        params.put("courseName","专升本《合同法》");
+//        List<Paper> papers = paperRepo.findByParams(params);
+        Page<Paper> papers = paperRepo.findByPaperType(PaperType.IMPORT,new PageRequest(0,10));
+        System.out.println(papers.getTotalElements());
+//        System.out.println(gson.toJson(papers));
     }
 
 }