浏览代码

修改bug

宋悦 8 年之前
父节点
当前提交
026ee91bb5

+ 6 - 0
exam-work-api/pom.xml

@@ -64,6 +64,12 @@
             <artifactId>reflectasm</artifactId>
             <version>1.11.3</version>
         </dependency>
+
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+            <version>1.3.2</version>
+        </dependency>
     </dependencies>
     
 	<build>

+ 5 - 5
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/api/ExamCourseApi.java

@@ -26,10 +26,10 @@ public class ExamCourseApi {
 
 
     @GetMapping
-    public Page<ExamCourseDTO> query(@RequestParam("exam_id") Long examId,
-                                     @RequestParam(value = "course_code", required = false) String courseCode,
-                                     @RequestParam("cur_page") Integer curPage,
-                                     @RequestParam("page_size") Integer pageSize) {
+    public Page<ExamCourseDTO> findCourse(@RequestParam("exam_id") Long examId,
+                                          @RequestParam(value = "course_code", required = false) String courseCode,
+                                          @RequestParam("cur_page") Integer curPage,
+                                          @RequestParam("page_size") Integer pageSize) {
 
 
         Page<ExamStudent> examStudentPage;
@@ -54,7 +54,7 @@ public class ExamCourseApi {
     }
 
     @GetMapping("/marking")
-    public List<ExamCourseDTO> query(@RequestParam(value="exam_id",required = true) Long examId) {
+    public List<ExamCourseDTO> findCourse(@RequestParam(value="exam_id",required = true) Long examId) {
 
         List<ExamStudent> examStudents = examStudentRepo.findDistinctCourseCode(examId);
 

+ 28 - 9
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/api/ExamStudentApi.java

@@ -3,8 +3,12 @@ package cn.com.qmth.examcloud.service.examwork.api;
 import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.service.examwork.entity.Exam;
+import cn.com.qmth.examcloud.service.examwork.service.rpc.OeService;
+import cn.com.qmth.examcloud.service.examwork.util.ImportUtils;
 import io.swagger.annotations.ApiOperation;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -38,6 +42,7 @@ import cn.com.qmth.examcloud.service.examwork.dto.ExamStudentDTO;
 import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
 import cn.com.qmth.examcloud.service.examwork.service.ExamStudentService;
 import cn.com.qmth.examcloud.service.examwork.util.ExportUtils;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 /**
  * 考生服务API
@@ -97,7 +102,7 @@ public class ExamStudentApi {
     @ApiOperation(value = "按ID查询考试学生", notes = "ID查询")
     @GetMapping("/{id}")
     public ResponseEntity<ExamStudent> getExamStudentById(@PathVariable Long id) {
-        return new ResponseEntity<ExamStudent>(examStudentService.getExamStudentById(id), HttpStatus.OK);
+        return new ResponseEntity<ExamStudent>(examStudentRepo.findOne(id), HttpStatus.OK);
     }
 
     @ApiOperation(value = "新增考试学生", notes = "新增")
@@ -143,25 +148,39 @@ public class ExamStudentApi {
 
     @ApiOperation(value = "按ID删除考试学生", notes = "删除")
     @DeleteMapping("/{id}")
-    public ResponseEntity deleteExamStudent(@PathVariable String id) {
-        List<Long> examStuIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
-                .collect(Collectors.toList());
-        examStudentRepo.deleteInBatch(examStudentRepo.findByIdIn(examStuIds));
-        return new ResponseEntity(HttpStatus.OK);
+    public ResponseEntity deleteExamStudent(@PathVariable Long id) {
+//        List<Long> examStuIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
+//                .collect(Collectors.toList());
+//        examStudentRepo.deleteInBatch(examStudentRepo.findByIdIn(examStuIds));
+        try {
+            examStudentService.deleteExamStudent(id);
+            return new ResponseEntity(HttpStatus.OK);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity(new ErrorMsg(e.getMessage()),HttpStatus.INTERNAL_SERVER_ERROR);
+        }
     }
 
     @ApiOperation(value = "导入考试学生", notes = "导入")
     @PostMapping("/import")
-    public ResponseEntity importExamStudent(@RequestParam Long examId, @RequestParam MultipartFile file) {
+    public ResponseEntity importExamStudent(@RequestParam Long examId, @RequestParam CommonsMultipartFile file) {
         try {
-            List<ExcelError> excelErrors = examStudentService.importExamStudent(examId, file.getInputStream());
+            File tempFile = ImportUtils.getUploadFile(file);
+            List<ExcelError> excelErrors = examStudentService.importExamStudent(examId, new FileInputStream(tempFile));
             return new ResponseEntity(excelErrors, HttpStatus.OK);
-        } catch (IOException e) {
+        } catch (Exception e) {
             e.printStackTrace();
             return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
         }
     }
 
+    @ApiOperation(value="下载导入模板",notes = "下载导入模板")
+    @GetMapping("/download")
+    public void importFileTemplate(HttpServletResponse response){
+        List<ExamStudentDTO> list= new ArrayList<ExamStudentDTO>();
+        ExportUtils.exportEXCEL("考生导入模板", ExamStudentDTO.class, list, response);
+    }
+
 //    @ApiOperation(value="导入学生照片",notes = "导入")
 //    @PostMapping("/exam_student/import_photo")
 //    public ResponseEntity importPhoto(@RequestParam Long examId,@RequestParam MultipartFile file){

+ 38 - 29
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/ExamStudentService.java

@@ -6,6 +6,8 @@ import java.util.List;
 
 import javax.persistence.criteria.Predicate;
 
+import cn.com.qmth.examcloud.common.util.BeanCopierUtil;
+import cn.com.qmth.examcloud.service.examwork.service.rpc.OeService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -45,16 +47,24 @@ public class ExamStudentService {
 
     @Autowired
     ExamStudentRepo examStudentRepo;
+
     @Autowired
     ExamRepo examRepo;
+
     @Autowired
     ExamStudentAssembler examStudentAssembler;
+
     @Autowired
     StudentService studentService;
+
     @Autowired
     CourseService courseService;
+
     @Autowired
     OrgService orgService;
+
+	@Autowired
+	OeService oeService;
     
 //    @Value("${app.em.photo.path}")
 //    private String PHOTO_PATH ;
@@ -95,15 +105,6 @@ public class ExamStudentService {
         return examStudentRepo.findAll(specification);
     }
 
-    /**
-     * 按ID获取考试学生
-     * @param studentId
-     * @return
-     */
-    public ExamStudent getExamStudentById(Long studentId){
-        return examStudentRepo.findOne(studentId);
-    }
-
     /**
      * 按考试批次获取学生
      * @param examId
@@ -124,23 +125,6 @@ public class ExamStudentService {
         return saveStudent(examStudent);
     }
 
-    /**
-     * 删除考试学生
-     * @param examId
-     * @return
-     */
-    public void deleteExamStudent(Long examId){
-        examStudentRepo.delete(examId);
-    }
-
-    /**
-     * 删除所有考试学生
-     * @return
-     */
-    public void deleteAllExamStudent(){
-        examStudentRepo.deleteAll();
-    }
-    
     /**
      * 导入考试学生
      * @return
@@ -206,6 +190,18 @@ public class ExamStudentService {
 			student.setUser(user);
 			student = studentService.addStudent(student);
 			examStudent.setStudentId(student.getId());
+		}else{
+			Student student = studentService.getStudent(examStudent.getStudentId());
+			student.setOrgId(examStudent.getOrgId());
+			student.setName(examStudent.getName());
+			student.setRootOrgId(examStudent.getRootOrgId());
+			student.setStudentCode(examStudent.getStudentCode());
+			student.setIdentityNumber(examStudent.getIdentityNumber());
+			examStudentRepo.updateById(examStudent.getIdentityNumber(),
+					examStudent.getName(),
+					examStudent.getSpecialtyName(),
+					examStudent.getExamSite());
+			studentService.updateStudent(student);
 		}
 		examStudent.setFinished(false);
 		examStudent.setGraduated(false);
@@ -390,11 +386,24 @@ public class ExamStudentService {
      */
 	public void copyExamStudent(Long sourceExamId,Long targetExamId){
 		List<ExamStudent> sourceExamStudents = examStudentRepo.findByExamId(sourceExamId);
+		List<ExamStudent> targetExamStudents = new ArrayList<ExamStudent>();
 		Exam targetExam = examRepo.findOne(targetExamId);
 		sourceExamStudents.stream().forEach(examStudent -> {
-			examStudent.setId(null);
-			examStudent.setExam(targetExam);
+			ExamStudent tempStudent = BeanCopierUtil.copyProperties(examStudent,ExamStudent.class);
+			tempStudent.setId(null);
+			tempStudent.setExam(targetExam);
+			targetExamStudents.add(tempStudent);
 		});
-		examStudentRepo.save(sourceExamStudents);
+		examStudentRepo.save(targetExamStudents);
+	}
+
+	public void deleteExamStudent(Long id)throws Exception{
+		ExamStudent examStudent = examStudentRepo.findOne(id);
+		int examRecordCount = oeService.checkExamRecord(examStudent.getExam().getId(), examStudent.getIdentityNumber());
+		if(examRecordCount > 0){
+			throw new RuntimeException("该考生已有考试记录,不能删除");
+		}else{
+			examStudentRepo.delete(id);
+		}
 	}
 }

+ 23 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/rpc/OeService.java

@@ -0,0 +1,23 @@
+package cn.com.qmth.examcloud.service.examwork.service.rpc;
+
+import cn.com.qmth.examcloud.service.examwork.service.rpc.client.OeClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Created by songyue on 17/7/20.
+ */
+@Service
+public class OeService {
+
+    @Autowired
+    OeClient oeClient;
+
+    public int checkExamRecord(Long examId,String identityNumber){
+        return oeClient.checkExamRecord(examId,identityNumber);
+    }
+
+    public int checkExamRecord(Long examId){
+        return oeClient.checkExamRecord(examId);
+    }
+}

+ 12 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/rpc/StudentService.java

@@ -30,4 +30,16 @@ public class StudentService {
 		return domain;
 	}
 
+	public Student updateStudent(Student student) {
+		String json = studentClient.updateStudent(student);
+		Student domain = GsonUtil.getInstanceByJson(json, Student.class);
+		return domain;
+	}
+
+	public Student getStudent(Long id) {
+		String json = studentClient.getStudent(id);
+		Student domain = GsonUtil.getInstanceByJson(json, Student.class);
+		return domain;
+	}
+
 }

+ 19 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/rpc/client/OeClient.java

@@ -0,0 +1,19 @@
+package cn.com.qmth.examcloud.service.examwork.service.rpc.client;
+
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Created by songyue on 17/7/20.
+ */
+@FeignClient(value = "ExamCloud-SERVICE-OE")
+public interface OeClient {
+
+    @RequestMapping(method = RequestMethod.GET, value = "/api/exam_record/count")
+    int checkExamRecord(@RequestParam("examId") Long examId, @RequestParam(value = "identityNumber", required = false) String identityNumber);
+
+    @RequestMapping(method = RequestMethod.GET, value = "/api/exam_record/count")
+    int checkExamRecord(@RequestParam("examId") Long examId);
+}

+ 7 - 4
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/rpc/client/StudentClient.java

@@ -1,10 +1,7 @@
 package cn.com.qmth.examcloud.service.examwork.service.rpc.client;
 
 import org.springframework.cloud.netflix.feign.FeignClient;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
 
 import cn.com.qmth.examcloud.common.dto.core.Student;
 
@@ -22,4 +19,10 @@ public interface StudentClient {
 	@RequestMapping(method = RequestMethod.POST, value = "${app.api.core}/student")
 	String addStudent(@RequestBody Student student);
 
+	@RequestMapping(method = RequestMethod.GET, value = "${app.api.core}/student/{id}")
+	String getStudent(@PathVariable("id") Long id);
+
+	@RequestMapping(method = RequestMethod.PUT, value = "${app.api.core}/student")
+	String updateStudent(@RequestBody Student student);
+
 }

+ 0 - 120
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/util/BeanCopierUtil.java

@@ -1,120 +0,0 @@
-package cn.com.qmth.examcloud.service.examwork.util;
-
-import com.esotericsoftware.reflectasm.ConstructorAccess;
-import org.springframework.cglib.beans.BeanCopier;
-import org.springframework.util.CollectionUtils;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static java.lang.String.format;
-
-/**
- * Created by songyue on 17/3/15.
- */
-public class BeanCopierUtil {
-    private static final Map<String, BeanCopier> beanCopierCache = new ConcurrentHashMap<>();
-    private static final Map<String,ConstructorAccess> constructorAccessCache = new ConcurrentHashMap<>();
-
-    private static void copyProperties(Object source, Object target) {
-        BeanCopier copier = getBeanCopier(source.getClass(), target.getClass());
-        copier.copy(source, target, null);
-    }
-
-    /**
-     * 获取BeanCopier实例
-     * @param sourceClass
-     * @param targetClass
-     * @return
-     */
-    private static BeanCopier getBeanCopier(Class sourceClass, Class targetClass) {
-        String beanKey = generateKey(sourceClass, targetClass);
-        BeanCopier copier = null;
-        if (!beanCopierCache.containsKey(beanKey)) {
-            copier = BeanCopier.create(sourceClass, targetClass, false);
-            beanCopierCache.put(beanKey, copier);
-        } else {
-            copier = beanCopierCache.get(beanKey);
-        }
-        return copier;
-    }
-
-    /**
-     * 生成key
-     * @param class1
-     * @param class2
-     * @return
-     */
-    private static String generateKey(Class<?> class1, Class<?> class2) {
-        return class1.toString() + class2.toString();
-    }
-
-    /**
-     * 拷贝对象
-     * @param source
-     * @param targetClass
-     * @param <T>
-     * @return
-     */
-    public static <T> T copyProperties(Object source, Class<T> targetClass) {
-        T t = null;
-        try {
-            t = targetClass.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
-            throw new RuntimeException(format("Create new instance of %s failed: %s", targetClass, e.getMessage()));
-        }
-        copyProperties(source, t);
-        return t;
-    }
-
-    /**
-     * 拷贝List
-     * @param sourceList
-     * @param targetClass
-     * @param <T>
-     * @return
-     */
-    public static <T> List<T> copyPropertiesOfList(List<?> sourceList, Class<T> targetClass) {
-        if (CollectionUtils.isEmpty(sourceList)) {
-            return Collections.emptyList();
-        }
-        ConstructorAccess<T> constructorAccess = getConstructorAccess(targetClass);
-        List<T> resultList = new ArrayList<>(sourceList.size());
-        for (Object o : sourceList) {
-            T t = null;
-            try {
-                t = constructorAccess.newInstance();
-                copyProperties(o, t);
-                resultList.add(t);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        }
-        return resultList;
-    }
-
-    /**
-     * 获取集合包装类
-     * @param targetClass
-     * @param <T>
-     * @return
-     */
-    private static <T> ConstructorAccess<T> getConstructorAccess(Class<T> targetClass) {
-        ConstructorAccess<T> constructorAccess = constructorAccessCache.get(targetClass.toString());
-        if(constructorAccess != null) {
-            return constructorAccess;
-        }
-        try {
-            constructorAccess = ConstructorAccess.get(targetClass);
-            constructorAccess.newInstance();
-            constructorAccessCache.put(targetClass.toString(),constructorAccess);
-        } catch (Exception e) {
-            throw new RuntimeException(format("Create new instance of %s failed: %s", targetClass, e.getMessage()));
-        }
-        return constructorAccess;
-    }
-
-}

+ 58 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/util/ImportUtils.java

@@ -0,0 +1,58 @@
+package cn.com.qmth.examcloud.service.examwork.util;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+/**
+ * Created by songyue on 17/7/14.
+ */
+public final class ImportUtils {
+
+    protected static final Logger logger = LoggerFactory.getLogger(ImportUtils.class);
+
+    public static final String TEMP_FILE_IMP = "fileImport/";
+
+    public static final String TEMP_FILE_EXP = "fileExport/";
+
+    static {
+        init();
+    }
+
+    /**
+     * 初始化文件夹
+     */
+    public static void init() {
+        File temp_file_exp = new File(TEMP_FILE_EXP);
+        File temp_file_imp = new File(TEMP_FILE_IMP);
+        // 如果输出目标文件夹不存在,则创建
+        if (!temp_file_imp.exists()) {
+            temp_file_imp.mkdirs();
+        }
+        if (!temp_file_exp.exists()) {
+            temp_file_exp.mkdirs();
+        }
+    }
+
+    /**
+     * 获取上传文件
+     *
+     * @param file
+     * @return
+     */
+    public static File getUploadFile(MultipartFile file) throws Exception {
+        String fileName = file.getOriginalFilename();
+        File tempFile = new File(TEMP_FILE_IMP + fileName);
+        OutputStream os = new FileOutputStream(tempFile);
+        IOUtils.copyLarge(file.getInputStream(), os);
+        IOUtils.closeQuietly(os);
+        return tempFile;
+    }
+
+}

+ 11 - 3
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/dao/ExamStudentRepo.java

@@ -6,23 +6,26 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
+import org.springframework.transaction.annotation.Transactional;
 
 public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, QueryByExampleExecutor<ExamStudent>, JpaSpecificationExecutor<ExamStudent> {
     Page<ExamStudent> findByExamId(Long examId, Pageable pageable);
 
     List<ExamStudent> findByExamId(Long examId);
 
-    @Query("select s from ExamStudent s where s.exam.id=?1 group by s.courseCode")
+    @Query("select s from ExamStudent s where s.exam.id=?1 group by s.courseCode order by s.courseCode")
     List<ExamStudent> findDistinctCourseCode(Long examId);
 
-    @Query("select s from ExamStudent s where s.exam.id=?1 group by s.courseCode")
+    @Query("select s from ExamStudent s where s.exam.id=?1 group by s.courseCode order by s.courseCode")
     Page<ExamStudent> findDistinctCourseCode(Long examId, Pageable pageable);
 
-    @Query("select s from ExamStudent s where s.exam.id=?1 and s.courseCode = ?2 group by s.courseCode")
+    @Query("select s from ExamStudent s where s.exam.id=?1 and s.courseCode = ?2 group by s.courseCode order by s.courseCode")
     Page<ExamStudent> findDistinctCourseCode(Long examId,String courseCode, Pageable pageable);
 
     List<ExamStudent> findByIdIn(List<Long> ids);
@@ -38,4 +41,9 @@ public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, Query
 
     @Query("select count(s) from ExamStudent s where s.exam.id = ?1 and s.rootOrgId=?2 and s.identityNumber=?3 and s.courseCode=?4")
     int checkExamStu(Long examId,Long rootOrgId,String identityNumber,String courseCode);
+
+    @Transactional
+    @Modifying
+    @Query("update ExamStudent s set s.name = ?2,s.specialtyName  = ?3,s.examSite = ?4  where s.identityNumber = ?1")
+    void updateById(String identityNumber,String name,String specialtyName,String examSite);
 }

+ 52 - 0
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/Exam.java

@@ -120,6 +120,26 @@ public class Exam implements Serializable {
 	@Enumerated(EnumType.STRING)
 	private PracticeType practiceType;
 
+	/**
+	 * 单选题补充说明是否可填
+	 */
+	private Boolean singleEdit;
+
+	/**
+	 * 多选题补充说明是否可填
+	 */
+	private Boolean mutipleEdit;
+
+	/**
+	 * 判断题补充说明是否可填
+	 */
+	private Boolean boolEdit;
+
+	/**
+	 * 填空题补充说明是否可填
+	 */
+	private Boolean fillBlankEdit;
+
 	/**
 	 * 单选题补充说明
      */
@@ -417,6 +437,38 @@ public class Exam implements Serializable {
 		this.enable = enable;
 	}
 
+	public Boolean getSingleEdit() {
+		return singleEdit;
+	}
+
+	public void setSingleEdit(Boolean singleEdit) {
+		this.singleEdit = singleEdit;
+	}
+
+	public Boolean getMutipleEdit() {
+		return mutipleEdit;
+	}
+
+	public void setMutipleEdit(Boolean mutipleEdit) {
+		this.mutipleEdit = mutipleEdit;
+	}
+
+	public Boolean getBoolEdit() {
+		return boolEdit;
+	}
+
+	public void setBoolEdit(Boolean boolEdit) {
+		this.boolEdit = boolEdit;
+	}
+
+	public Boolean getFillBlankEdit() {
+		return fillBlankEdit;
+	}
+
+	public void setFillBlankEdit(Boolean fillBlankEdit) {
+		this.fillBlankEdit = fillBlankEdit;
+	}
+
 	public Exam() {
 	}
 }

+ 1 - 1
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamStudent.java

@@ -21,7 +21,7 @@ public class ExamStudent implements Serializable {
 	@NotNull
 	private String name;
 
-	@ManyToOne(cascade = { CascadeType.ALL })
+	@ManyToOne(cascade = { CascadeType.REFRESH })
 	@JoinColumn(name = "examId")
 	private Exam exam;
 	/**

+ 17 - 0
exam-work-main/src/main/java/cn/com/qmth/examcloud/service/examwork/Application.java

@@ -1,18 +1,35 @@
 package cn.com.qmth.examcloud.service.examwork;
 
 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.cloud.netflix.eureka.EnableEurekaClient;
 import org.springframework.cloud.netflix.feign.EnableFeignClients;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.multipart.MultipartResolver;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 
 @SpringBootApplication
 @EnableEurekaClient
 @EnableFeignClients
+@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
 public class Application {
 
 	public static void main(String[] args) throws Exception {
 		SpringApplication.run(Application.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);// 上传文件大小 200M 50*1024*1024
+		return resolver;
+	}
 }