Commit 227dbfbb3c94beb71a591a99183a83078b7ac26b
1 parent
bda221f4
添加知识点id
Showing
7 changed files
with
122 additions
and
4 deletions
resources/mybatis1/sunvote/PaperQuestionMapper.xml
| @@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
| 15 | PART_SCORE, | 15 | PART_SCORE, |
| 16 | RANK, | 16 | RANK, |
| 17 | NO_NAME, | 17 | NO_NAME, |
| 18 | + KNOWLEDGE_ID, | ||
| 18 | PAPERQUESTION_ID | 19 | PAPERQUESTION_ID |
| 19 | </sql> | 20 | </sql> |
| 20 | 21 | ||
| @@ -26,6 +27,7 @@ | @@ -26,6 +27,7 @@ | ||
| 26 | #{PART_SCORE}, | 27 | #{PART_SCORE}, |
| 27 | #{RANK}, | 28 | #{RANK}, |
| 28 | #{NO_NAME}, | 29 | #{NO_NAME}, |
| 30 | + #{KNOWLEDGE_ID}, | ||
| 29 | #{PAPERQUESTION_ID} | 31 | #{PAPERQUESTION_ID} |
| 30 | </sql> | 32 | </sql> |
| 31 | 33 | ||
| @@ -59,6 +61,7 @@ | @@ -59,6 +61,7 @@ | ||
| 59 | PART_SCORE = #{PART_SCORE}, | 61 | PART_SCORE = #{PART_SCORE}, |
| 60 | RANK = #{RANK}, | 62 | RANK = #{RANK}, |
| 61 | NO_NAME = #{NO_NAME}, | 63 | NO_NAME = #{NO_NAME}, |
| 64 | + KNOWLEDGE_ID = #{KNOWLEDGE_ID}, | ||
| 62 | PAPERQUESTION_ID = PAPERQUESTION_ID | 65 | PAPERQUESTION_ID = PAPERQUESTION_ID |
| 63 | where | 66 | where |
| 64 | PAPERQUESTION_ID = #{PAPERQUESTION_ID} | 67 | PAPERQUESTION_ID = #{PAPERQUESTION_ID} |
resources/spring/ApplicationContext-main.xml
| @@ -35,5 +35,6 @@ | @@ -35,5 +35,6 @@ | ||
| 35 | </bean> | 35 | </bean> |
| 36 | 36 | ||
| 37 | <bean id="springBeanFactoryUtils" class="com.fh.util.SpringBeanFactoryUtils"/> | 37 | <bean id="springBeanFactoryUtils" class="com.fh.util.SpringBeanFactoryUtils"/> |
| 38 | + <bean id="progressListener" class="com.fh.controller.api.FileUploadProgressListener"/> | ||
| 38 | 39 | ||
| 39 | </beans> | 40 | </beans> |
resources/spring/ApplicationContext-mvc.xml
| @@ -36,10 +36,11 @@ | @@ -36,10 +36,11 @@ | ||
| 36 | 36 | ||
| 37 | <bean id="exceptionResolver" class="com.fh.resolver.MyExceptionResolver"></bean> | 37 | <bean id="exceptionResolver" class="com.fh.resolver.MyExceptionResolver"></bean> |
| 38 | 38 | ||
| 39 | - <!-- 上传拦截,如最大上传值及最小上传值 --> | ||
| 40 | - <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" > | 39 | + <!-- 上传拦截,如最大上传值及最小上传值 104857600 104857600 --> |
| 40 | + <!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" > --> | ||
| 41 | + <bean id="multipartResolver" class="com.fh.controller.api.CustomMultipartResolver" > | ||
| 41 | <property name="maxUploadSize"> | 42 | <property name="maxUploadSize"> |
| 42 | - <value>104857600</value> | 43 | + <value>10737418240</value> |
| 43 | </property> | 44 | </property> |
| 44 | <property name="maxInMemorySize"> | 45 | <property name="maxInMemorySize"> |
| 45 | <value>4096</value> | 46 | <value>4096</value> |
src/com/fh/bean/Question.java
| @@ -43,7 +43,7 @@ public class Question { | @@ -43,7 +43,7 @@ public class Question { | ||
| 43 | private String sug_part_score; | 43 | private String sug_part_score; |
| 44 | 44 | ||
| 45 | private String questionType ; | 45 | private String questionType ; |
| 46 | - | 46 | + |
| 47 | private List<Question> questions; | 47 | private List<Question> questions; |
| 48 | 48 | ||
| 49 | public void setSubject_id(String subject_id) { | 49 | public void setSubject_id(String subject_id) { |
src/com/fh/controller/api/CustomMultipartResolver.java
0 → 100644
| 1 | +package com.fh.controller.api; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import javax.servlet.http.HttpServletRequest; | ||
| 6 | + | ||
| 7 | +import org.apache.commons.fileupload.FileItem; | ||
| 8 | +import org.apache.commons.fileupload.FileUpload; | ||
| 9 | +import org.apache.commons.fileupload.FileUploadBase; | ||
| 10 | +import org.apache.commons.fileupload.FileUploadException; | ||
| 11 | +import org.apache.commons.fileupload.servlet.ServletFileUpload; | ||
| 12 | +import org.springframework.web.multipart.MaxUploadSizeExceededException; | ||
| 13 | +import org.springframework.web.multipart.MultipartException; | ||
| 14 | +import org.springframework.web.multipart.commons.CommonsMultipartResolver; | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +public class CustomMultipartResolver extends CommonsMultipartResolver { | ||
| 18 | + | ||
| 19 | + /*@Autowired | ||
| 20 | + private FileUploadProgressListener progressListener; | ||
| 21 | + | ||
| 22 | + public void setFileUploadProgressListener(FileUploadProgressListener progressListener){ | ||
| 23 | + this.progressListener=progressListener; | ||
| 24 | + }*/ | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + @SuppressWarnings("unchecked") | ||
| 28 | + public MultipartParsingResult parseRequest(HttpServletRequest request) | ||
| 29 | + throws MultipartException { | ||
| 30 | + String encoding = determineEncoding(request); | ||
| 31 | + FileUpload fileUpload = prepareFileUpload(encoding); | ||
| 32 | + FileUploadProgressListener progressListener = new FileUploadProgressListener(); | ||
| 33 | + String ip = ""; | ||
| 34 | + if (request.getHeader("x-forwarded-for") == null) { | ||
| 35 | + ip = request.getRemoteAddr(); | ||
| 36 | + } else { | ||
| 37 | + ip = request.getHeader("x-forwarded-for"); | ||
| 38 | + } | ||
| 39 | + progressListener.setIp(ip); | ||
| 40 | + fileUpload.setProgressListener(progressListener); | ||
| 41 | + try { | ||
| 42 | + List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request); | ||
| 43 | + return parseFileItems(fileItems, encoding); | ||
| 44 | + } | ||
| 45 | + catch (FileUploadBase.SizeLimitExceededException ex) { | ||
| 46 | + throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex); | ||
| 47 | + } | ||
| 48 | + catch (FileUploadException ex) { | ||
| 49 | + throw new MultipartException("Could not parse multipart servlet request", ex); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + | ||
| 55 | +} |
src/com/fh/controller/api/FileUploadProgressListener.java
0 → 100644
| 1 | +package com.fh.controller.api; | ||
| 2 | + | ||
| 3 | +import java.util.HashMap; | ||
| 4 | + | ||
| 5 | +import org.apache.commons.fileupload.ProgressListener; | ||
| 6 | + | ||
| 7 | +public class FileUploadProgressListener implements ProgressListener { | ||
| 8 | + | ||
| 9 | + public static HashMap<String,HashMap<String,String>> map = new HashMap(); | ||
| 10 | + private String ip ; | ||
| 11 | + private long last = 0 ; | ||
| 12 | + private HashMap<String,String> ipMap; | ||
| 13 | + private String key ; | ||
| 14 | + | ||
| 15 | + @Override | ||
| 16 | + public void update(long pBytesRead, long pContentLength, int pItems) { | ||
| 17 | + if(!"127.0.0.1".equals(ip)){ | ||
| 18 | + ipMap.put(key,"" + ((pBytesRead * 1000.0) / (System.currentTimeMillis() - last))); | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public void setIp(String ip) { | ||
| 23 | + this.ip = ip; | ||
| 24 | + last = System.currentTimeMillis(); | ||
| 25 | + if (map.get(ip) == null) { | ||
| 26 | + ipMap = new HashMap<String, String>(); | ||
| 27 | + map.put(ip, ipMap); | ||
| 28 | + } else { | ||
| 29 | + ipMap = map.get(ip); | ||
| 30 | + } | ||
| 31 | + for (int i = 0;; i++) { | ||
| 32 | + String tkey = "" + i; | ||
| 33 | + if (ipMap.get(tkey) == null) { | ||
| 34 | + key = tkey; | ||
| 35 | + break; | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | +} |
src/com/fh/controller/api/V1.java
| @@ -1397,6 +1397,7 @@ public class V1 extends BaseController { | @@ -1397,6 +1397,7 @@ public class V1 extends BaseController { | ||
| 1397 | pqPd.put("NO_NAME", question.getNo_name()); | 1397 | pqPd.put("NO_NAME", question.getNo_name()); |
| 1398 | pqPd.put("PAPERQUESTION_ID", this.get32UUID()); | 1398 | pqPd.put("PAPERQUESTION_ID", this.get32UUID()); |
| 1399 | pqPd.put("P_ID", "0"); | 1399 | pqPd.put("P_ID", "0"); |
| 1400 | + pqPd.put("KNOWLEDGE_ID", question.getKnowledge_id());// | ||
| 1400 | paperquestionService.save(pqPd); | 1401 | paperquestionService.save(pqPd); |
| 1401 | 1402 | ||
| 1402 | } | 1403 | } |
| @@ -2805,6 +2806,21 @@ public class V1 extends BaseController { | @@ -2805,6 +2806,21 @@ public class V1 extends BaseController { | ||
| 2805 | 2806 | ||
| 2806 | } | 2807 | } |
| 2807 | 2808 | ||
| 2809 | + /** | ||
| 2810 | + * 根据ID班级名称 | ||
| 2811 | + * @param id | ||
| 2812 | + * @return | ||
| 2813 | + * @throws Exception | ||
| 2814 | + */ | ||
| 2815 | + @RequestMapping(value = "/printmsg", produces = "application/json;charset=UTF-8") | ||
| 2816 | + @ResponseBody | ||
| 2817 | + public String printmsg() throws Exception { | ||
| 2818 | + ResponseGson<Map> res = new ResponseGson(); | ||
| 2819 | + res.setData(FileUploadProgressListener.map); | ||
| 2820 | + return res.toJson(); | ||
| 2821 | + | ||
| 2822 | + } | ||
| 2823 | + | ||
| 2808 | @RequestMapping(value = "/uploadfile", produces = "application/json;charset=UTF-8") | 2824 | @RequestMapping(value = "/uploadfile", produces = "application/json;charset=UTF-8") |
| 2809 | @ResponseBody | 2825 | @ResponseBody |
| 2810 | public String uploadFile(@RequestParam(value="file",required=false)MultipartFile file, HttpServletRequest request) throws Exception{ | 2826 | public String uploadFile(@RequestParam(value="file",required=false)MultipartFile file, HttpServletRequest request) throws Exception{ |
| @@ -2833,4 +2849,6 @@ public class V1 extends BaseController { | @@ -2833,4 +2849,6 @@ public class V1 extends BaseController { | ||
| 2833 | 2849 | ||
| 2834 | 2850 | ||
| 2835 | 2851 | ||
| 2852 | + | ||
| 2853 | + | ||
| 2836 | } | 2854 | } |