Explorar o código

Merge remote-tracking branch 'origin/dev0410' into dev0410

宋悦 %!s(int64=8) %!d(string=hai) anos
pai
achega
5ae03a37c9

+ 7 - 19
cqb-base/src/main/java/com/qmth/cqb/base/service/SettingService.java

@@ -1,35 +1,23 @@
 package com.qmth.cqb.base.service;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
-import com.qmth.cqb.base.dao.CourseRepo;
 import com.qmth.cqb.base.dao.SettingRepo;
-import com.qmth.cqb.base.model.Course;
 import com.qmth.cqb.base.model.Setting;
 import com.qmth.cqb.utils.enums.Switch;
-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.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.query.Criteria;
-import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
 
 /**
  * Created by songyue on 16/12/28.
  */
 @Service
 public class SettingService {
-	
-	@Autowired
+
+    @Autowired
     SettingRepo settingRepo;
-	
-    public void initData(){
-        if(settingRepo.count() == 0){
+
+    public void initData() {
+        if (settingRepo.count() == 0) {
             Setting importSetting = new Setting();
             Setting genSetting = new Setting();
             importSetting.setCode("import");

+ 271 - 252
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/StringSimilarityUtils.java

@@ -1,276 +1,295 @@
 package com.qmth.cqb.utils;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.ansj.domain.Result;
 import org.ansj.domain.Term;
 import org.ansj.splitWord.analysis.ToAnalysis;
 
-import java.util.*;
-
 /**
  * 计算相似度工具包:
+ * 
  * @author songyue
  * @date 2016-05-11
  */
 public class StringSimilarityUtils {
 
-	/**
-	 * 对输入字符串分词
-	 * @param str
-	 * @return ArrayList
-	 * @author songyue
-	 */
-	public static List<String> segmentText(String str) {
-		List<String> segResult = new ArrayList<String>();// 分词结果
-		Result result = ToAnalysis.parse(str);
-		List<Term> terms = result.getTerms();
-		for(Term term:terms){
-			segResult.add(term.getName());
-		}
-		return segResult;
-	}
+    /**
+     * 对输入字符串分词
+     * 
+     * @param str
+     * @return ArrayList
+     * @author songyue
+     */
+    public static List<String> segmentText(String str) {
+        List<String> segResult = new ArrayList<String>();// 分词结果
+        Result result = ToAnalysis.parse(str);
+        List<Term> terms = result.getTerms();
+        for (Term term : terms) {
+            segResult.add(term.getName());
+        }
+        return segResult;
+    }
+
+    /**
+     * 计算相似度(两个分词集合,分词匹配,算法为余弦定理)
+     * 
+     * @param seg1
+     * @param seg2
+     * @return
+     */
+    public static double getSimilarityWithCosinesBySeg(String seg1, String seg2) {
+        double similarity = 0;
+        int size1 = 0;
+        int size2 = 0;
+        seg1 = stringFilter(seg1);
+        seg2 = stringFilter(seg2);
+        List<String> w1 = segmentText(seg1);
+        List<String> w2 = segmentText(seg2);
+        if (w1 != null && (size1 = w1.size()) != 0 && w2 != null && (size2 = w2.size()) != 0) {
+            Map<String, int[]> countMap = new HashMap<String, int[]>();
+            String index = null;
+            // 将w1与w2分词出现频次统计入coutMap中
+            for (int i = 0; i < size1; i++) {
+                index = w1.get(i);
+                if (index != null) {
+                    int[] c = countMap.get(index);
+                    if (c != null && c.length == 2) {
+                        c[0]++;
+                    } else {
+                        c = new int[2];
+                        c[0] = 1;
+                        c[1] = 0;
+                        countMap.put(index, c);
+                    }
+                }
+            }
+            for (int i = 0; i < size2; i++) {
+                index = w2.get(i);
+                if (index != null) {
+                    int[] c = countMap.get(index);
+                    if (c != null && c.length == 2) {
+                        c[1]++;
+                    } else {
+                        c = new int[2];
+                        c[0] = 0;
+                        c[1] = 1;
+                        countMap.put(index, c);
+                    }
+                }
+            }
+            // 根据余弦定理计算相似度
+            Iterator<String> it = countMap.keySet().iterator();
+            double sum = 0;
+            double s1 = 0;
+            double s2 = 0;
+            while (it.hasNext()) {
+                int[] c = countMap.get(it.next());
+                sum += c[0] * c[1];
+                s1 += c[0] * c[0];
+                s2 += c[1] * c[1];
+            }
+            similarity = sum / Math.sqrt(s1 * s2);
+        } else {
+            return 0;
+        }
+        return similarity;
+    }
 
-	/**
-	 * 计算相似度(两个分词集合,分词匹配,算法为余弦定理)
-	 * @param seg1
-	 * @param seg2
-	 * @return
-	 */
-	public static double getSimilarityWithCosinesBySeg(String seg1, String seg2) {
-		double similarity = 0;
-		int size1 = 0;
-		int size2 = 0;
-		seg1 = stringFilter(seg1);
-		seg2 = stringFilter(seg2);
-		List<String> w1 = segmentText(seg1);
-		List<String> w2 = segmentText(seg2);
-		if (w1 != null && (size1 = w1.size()) != 0 && w2 != null && (size2 = w2.size()) != 0) {
-			Map<String, int[]> countMap = new HashMap<String, int[]>();
-			String index = null;
-			// 将w1与w2分词出现频次统计入coutMap中
-			for (int i = 0; i < size1; i++) {
-				index = w1.get(i);
-				if (index != null) {
-					int[] c = countMap.get(index);
-					if (c != null && c.length == 2) {
-						c[0]++;
-					} else {
-						c = new int[2];
-						c[0] = 1;
-						c[1] = 0;
-						countMap.put(index, c);
-					}
-				}
-			}
-			for (int i = 0; i < size2; i++) {
-				index = w2.get(i);
-				if (index != null) {
-					int[] c = countMap.get(index);
-					if (c != null && c.length == 2) {
-						c[1]++;
-					} else {
-						c = new int[2];
-						c[0] = 0;
-						c[1] = 1;
-						countMap.put(index, c);
-					}
-				}
-			}
-			// 根据余弦定理计算相似度
-			Iterator<String> it = countMap.keySet().iterator();
-			double sum = 0;
-			double s1 = 0;
-			double s2 = 0;
-			while (it.hasNext()) {
-				int[] c = countMap.get(it.next());
-				sum += c[0] * c[1];
-				s1 += c[0] * c[0];
-				s2 += c[1] * c[1];
-			}
-			similarity = sum / Math.sqrt(s1 * s2);
-		} else {
-			return 0;
-		}
-		return similarity;
-	}
+    /**
+     * 计算相似度(两个字符串,全字匹配,算法为余弦定理)
+     * 
+     * @param w1
+     * @param w2
+     * @return
+     */
+    public static double getSimilarityWithCosinesByWords(String w1, String w2) {
+        double similarity = 0;
+        int size1 = 0;
+        int size2 = 0;
+        w1 = stringFilter(w1);
+        w2 = stringFilter(w2);
+        if (w1 != null && (size1 = w1.length()) != 0 && w2 != null && (size2 = w2.length()) != 0) {
+            Map<Character, int[]> countMap = new HashMap<Character, int[]>();
+            char index;
+            // 将w1与w2所有字符出现频次统计入countMap中
+            for (int i = 0; i < size1; i++) {
+                index = w1.charAt(i);
+                int[] c = countMap.get(index);
+                if (c != null && c.length == 2) {
+                    c[0]++;
+                } else {
+                    c = new int[2];
+                    c[0] = 1;
+                    c[1] = 0;
+                    countMap.put(index, c);
+                }
+            }
+            for (int i = 0; i < size2; i++) {
+                index = w2.charAt(i);
+                int[] c = countMap.get(index);
+                if (c != null && c.length == 2) {
+                    c[1]++;
+                } else {
+                    c = new int[2];
+                    c[0] = 0;
+                    c[1] = 1;
+                    countMap.put(index, c);
+                }
+            }
+            // 根据余弦定理计算相似度
+            Iterator<Character> it = countMap.keySet().iterator();
+            double sum = 0;
+            double s1 = 0;
+            double s2 = 0;
+            while (it.hasNext()) {
+                int[] c = countMap.get(it.next());
+                sum += c[0] * c[1];
+                s1 += c[0] * c[0];
+                s2 += c[1] * c[1];
+            }
+            similarity = sum / Math.sqrt(s1 * s2);
+        } else {
+            throw new NullPointerException("传入的参数为空");
+        }
+        return similarity;
+    }
 
-	/**
-	 * 计算相似度(两个字符串,全字匹配,算法为余弦定理)
-	 * @param w1
-	 * @param w2
-	 * @return
-	 */
-	public static double getSimilarityWithCosinesByWords(String w1, String w2) {
-		double similarity = 0;
-		int size1 = 0;
-		int size2 = 0;
-		w1 = stringFilter(w1);
-		w2 = stringFilter(w2);
-		if (w1 != null && (size1 = w1.length()) != 0 && w2 != null && (size2 = w2.length()) != 0) {
-			Map<Character, int[]> countMap = new HashMap<Character, int[]>();
-			char index;
-			// 将w1与w2所有字符出现频次统计入countMap中
-			for (int i = 0; i < size1; i++) {
-				index = w1.charAt(i);
-				int[] c = countMap.get(index);
-				if (c != null && c.length == 2) {
-					c[0]++;
-				} else {
-					c = new int[2];
-					c[0] = 1;
-					c[1] = 0;
-					countMap.put(index, c);
-				}
-			}
-			for (int i = 0; i < size2; i++) {
-				index = w2.charAt(i);
-				int[] c = countMap.get(index);
-				if (c != null && c.length == 2) {
-					c[1]++;
-				} else {
-					c = new int[2];
-					c[0] = 0;
-					c[1] = 1;
-					countMap.put(index, c);
-				}
-			}
-			// 根据余弦定理计算相似度
-			Iterator<Character> it = countMap.keySet().iterator();
-			double sum = 0;
-			double s1 = 0;
-			double s2 = 0;
-			while (it.hasNext()) {
-				int[] c = countMap.get(it.next());
-				sum += c[0] * c[1];
-				s1 += c[0] * c[0];
-				s2 += c[1] * c[1];
-			}
-			similarity = sum / Math.sqrt(s1 * s2);
-		} else {
-			throw new NullPointerException("传入的参数为空");
-		}
-		return similarity;
-	}
+    /**
+     * 计算相似度(两个字符串,采用优化Dice算法)
+     * 
+     * @param w1
+     * @param w2
+     * @return
+     */
+    public static double getSimilarityWithDiceOptByWords(String w1, String w2) {
+        if (w1 == null || w2 == null || w1.length() == 0 || w2.length() == 0)
+            return 0;
+        if (w1 == w2)
+            return 1;
+        if (w1.length() == 1 || w2.length() == 1) {
+            if (w1.equals(w2)) {
+                return 1;
+            } else {
+                return 0;
+            }
+        }
+        w1 = stringFilter(w1);
+        w2 = stringFilter(w2);
+        final int n = w1.length() - 1;
+        final int[] sPairs = new int[n];
+        for (int i = 0; i <= n; i++)
+            if (i == 0)
+                sPairs[i] = w1.charAt(i) << 16;
+            else if (i == n)
+                sPairs[i - 1] |= w1.charAt(i);
+            else
+                sPairs[i] = (sPairs[i - 1] |= w1.charAt(i)) << 16;
 
-	/**
-	 * 计算相似度(两个字符串,采用优化Dice算法)
-	 * @param w1
-	 * @param w2
-	 * @return
-	 */
-	public static double getSimilarityWithDiceOptByWords(String w1, String w2) {
-		if (w1 == null || w2 == null || w1.length() == 0 || w2.length() == 0)
-			return 0;
-		if (w1 == w2)
-			return 1;
-		if (w1.length() == 1 || w2.length() == 1){
-			if (w1.equals(w2)) {
-				return 1;
-			} else {
-				return 0;
-			}
-		}
-		w1 = stringFilter(w1);
-		w2 = stringFilter(w2);
-		final int n = w1.length() - 1;
-		final int[] sPairs = new int[n];
-		for (int i = 0; i <= n; i++)
-			if (i == 0)
-				sPairs[i] = w1.charAt(i) << 16;
-			else if (i == n)
-				sPairs[i - 1] |= w1.charAt(i);
-			else
-				sPairs[i] = (sPairs[i - 1] |= w1.charAt(i)) << 16;
+        final int m = w2.length() - 1;
+        final int[] tPairs = new int[m];
+        for (int i = 0; i <= m; i++)
+            if (i == 0)
+                tPairs[i] = w2.charAt(i) << 16;
+            else if (i == m)
+                tPairs[i - 1] |= w2.charAt(i);
+            else
+                tPairs[i] = (tPairs[i - 1] |= w2.charAt(i)) << 16;
 
-		final int m = w2.length() - 1;
-		final int[] tPairs = new int[m];
-		for (int i = 0; i <= m; i++)
-			if (i == 0)
-				tPairs[i] = w2.charAt(i) << 16;
-			else if (i == m)
-				tPairs[i - 1] |= w2.charAt(i);
-			else
-				tPairs[i] = (tPairs[i - 1] |= w2.charAt(i)) << 16;
+        Arrays.sort(sPairs);
+        Arrays.sort(tPairs);
 
-		Arrays.sort(sPairs);
-		Arrays.sort(tPairs);
+        int matches = 0, i = 0, j = 0;
+        while (i < n && j < m) {
+            if (sPairs[i] == tPairs[j]) {
+                matches += 2;
+                i++;
+                j++;
+            } else if (sPairs[i] < tPairs[j])
+                i++;
+            else
+                j++;
+        }
+        return (double) matches / (n + m);
+    }
 
-		int matches = 0, i = 0, j = 0;
-		while (i < n && j < m) {
-			if (sPairs[i] == tPairs[j]) {
-				matches += 2;
-				i++;
-				j++;
-			} else if (sPairs[i] < tPairs[j])
-				i++;
-			else
-				j++;
-		}
-		return (double) matches / (n + m);
-	}
+    /**
+     * 计算相似度(两个字符串,采用一般Dice算法)
+     * 
+     * @param w1
+     * @param w2
+     * @return
+     */
+    public static double getSimilarityWithDiceByWords(String w1, String w2) {
+        double similarity = 0;
+        if (w1 != null && w1.length() != 0 && w2 != null && w2.length() != 0) {
+            if (w1.length() == 1 || w2.length() == 1) {
+                if (w1.equals(w2)) {
+                    return 1;
+                } else {
+                    return 0;
+                }
+            }
+            w1 = stringFilter(w1);
+            w2 = stringFilter(w2);
+            Set<String> nx = new HashSet<String>();
+            Set<String> ny = new HashSet<String>();
 
-	/**
-	 * 计算相似度(两个字符串,采用一般Dice算法)
-	 * @param w1
-	 * @param w2
-	 * @return
-	 */
-	public static double getSimilarityWithDiceByWords(String w1, String w2) {
-		double similarity = 0;
-		if (w1 != null && w1.length() != 0 && w2 != null && w2.length() != 0) {
-			if (w1.length() == 1 || w2.length() == 1){
-				if (w1.equals(w2)) {
-					return 1;
-				} else {
-					return 0;
-				}
-			}
-			w1 = stringFilter(w1);
-			w2 = stringFilter(w2);
-			Set<String> nx = new HashSet<String>();
-			Set<String> ny = new HashSet<String>();
+            for (int i = 0; i < w1.length() - 1; i++) {
+                char x1 = w1.charAt(i);
+                char x2 = w1.charAt(i + 1);
+                String tmp = "" + x1 + x2;
+                nx.add(tmp);
+            }
+            for (int j = 0; j < w2.length() - 1; j++) {
+                char y1 = w2.charAt(j);
+                char y2 = w2.charAt(j + 1);
+                String tmp = "" + y1 + y2;
+                ny.add(tmp);
+            }
+            Set<String> intersection = new HashSet<String>(nx);
+            intersection.retainAll(ny);
+            double totcombigrams = intersection.size();
+            similarity = (2 * totcombigrams) / (nx.size() + ny.size());
+        }
+        return similarity;
+    }
 
-			for (int i = 0; i < w1.length() - 1; i++) {
-				char x1 = w1.charAt(i);
-				char x2 = w1.charAt(i + 1);
-				String tmp = "" + x1 + x2;
-				nx.add(tmp);
-			}
-			for (int j = 0; j < w2.length() - 1; j++) {
-				char y1 = w2.charAt(j);
-				char y2 = w2.charAt(j + 1);
-				String tmp = "" + y1 + y2;
-				ny.add(tmp);
-			}
-			Set<String> intersection = new HashSet<String>(nx);
-			intersection.retainAll(ny);
-			double totcombigrams = intersection.size();
-			similarity = (2 * totcombigrams) / (nx.size() + ny.size());
-		}
-		return similarity;
-	}
+    /**
+     * 过滤特殊字符
+     * 
+     * @param str
+     * @return
+     */
+    public static String stringFilter(String str) {
+        String regEx = "[_`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
+        return str.replaceAll("\\s*", "").replaceAll(regEx, "");
 
-	/**
-	 * 过滤特殊字符
-	 * @param str
-	 * @return
-	 */
-	public static String stringFilter(String str) {
-		String regEx = "[_`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
-		return str.replaceAll("\\s*", "").replaceAll(regEx, "");
-	}
+    }
 
-	public static void main(String[] args) {
-		String str1 = "秦汉以    来的公文程式构   成有  :::::\n    <><>_________________ !!!!!";
-		String str2 = "明清以来的公文程式构成有";
-//		System.out.println(StringSimilarityUtils.stringFilter(str1));
-//		System.out.println(StringSimilarityUtils.stringFilter(str2));
-//		//double similarity1 = StringSimilarityUtils.getSimilarityWithCosinesBySeg(str1, str2);
-//		double similarity_cos = StringSimilarityUtils.getSimilarityWithCosinesByWords(str1, str2);
-//		double similarity_dice = StringSimilarityUtils.getSimilarityWithDiceByWords(str1, str2);
-//		double similarity_diceopt = StringSimilarityUtils.getSimilarityWithDiceOptByWords(str1, str2);
-//		System.out.println(similarity_cos);
-//		System.out.println(similarity_dice);
-//		System.out.println(similarity_diceopt);
-		System.out.println(segmentText(str2));
-	}
+    public static void main(String[] args) {
+        String str1 = "秦汉以    来的公文程式构   成有  :::::\n    <><>_________________ !!!!!";
+        String str2 = "明清以来的公文程式构成有";
+        // System.out.println(StringSimilarityUtils.stringFilter(str1));
+        // System.out.println(StringSimilarityUtils.stringFilter(str2));
+        // //double similarity1 =
+        // StringSimilarityUtils.getSimilarityWithCosinesBySeg(str1, str2);
+        // double similarity_cos =
+        // StringSimilarityUtils.getSimilarityWithCosinesByWords(str1, str2);
+        // double similarity_dice =
+        // StringSimilarityUtils.getSimilarityWithDiceByWords(str1, str2);
+        // double similarity_diceopt =
+        // StringSimilarityUtils.getSimilarityWithDiceOptByWords(str1, str2);
+        // System.out.println(similarity_cos);
+        // System.out.println(similarity_dice);
+        // System.out.println(similarity_diceopt);
+        System.out.println(segmentText(str2));
+    }
 }

+ 3 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/dao/PaperRepo.java

@@ -21,8 +21,9 @@ public interface PaperRepo extends MongoRepository<Paper, String>, QueryByExampl
 
     Page<Paper> findByPaperStatus(PaperStatus paperStatus, Pageable pageable);
 
-    Paper findByName(String name);
+    List<Paper> findByNameAndOrgId(String name, String orgId);
 
-    Page<Paper> findByIdNotInAndCourseNoAndOrgId(Set<String> idSet, String courseNo, String orgId, Pageable page);
+    Page<Paper> findByIdNotInAndCourseNoAndOrgIdAndPaperType(Set<String> idSet, String courseNo, String orgId,
+            PaperType paperType, Pageable page);
 
 }

+ 55 - 42
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperDetailService.java

@@ -3,90 +3,103 @@ package com.qmth.cqb.paper.service;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 
 import com.qmth.cqb.paper.dao.PaperDetailRepo;
+import com.qmth.cqb.paper.dao.PaperRepo;
 import com.qmth.cqb.paper.model.Paper;
 import com.qmth.cqb.paper.model.PaperDetail;
 import com.qmth.cqb.paper.model.PaperDetailUnit;
 
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+
 @Service
 public class PaperDetailService {
-	
-	
-	@Autowired
-	PaperDetailRepo paperDetailRepo;
-	
-	@Autowired
-	PaperDetailUnitService unitService;
-	
-	
-	/**
-	 * 根据Id获得对应所有小题
-	 * @param id
-	 * @return
-	 */
-	public List<PaperDetailUnit> getUnitsByPaperDetailId(String id){	
-		return unitService.getUnitsByPaperDetail(paperDetailRepo.findOne(id));
-	}
+
+    @Autowired
+    PaperDetailRepo paperDetailRepo;
+
+    @Autowired
+    PaperDetailUnitService unitService;
+
+    @Autowired
+    PaperRepo paperRepo;
+
+    /**
+     * 根据Id获得对应所有小题
+     * 
+     * @param id
+     * @return
+     */
+    public List<PaperDetailUnit> getUnitsByPaperDetailId(String id) {
+        return unitService.getUnitsByPaperDetail(paperDetailRepo.findOne(id));
+    }
 
     /**
      * 按ID查询大题
+     * 
      * @param id
      * @return
      */
-    public PaperDetail findById(String id){
+    public PaperDetail findById(String id) {
         return paperDetailRepo.findOne(id);
     }
 
     /**
      * 保存大题
+     * 
      * @param pd
      * @return
      */
-    public PaperDetail savePaperDetail(PaperDetail pd){
+    public PaperDetail savePaperDetail(PaperDetail pd, String paperId, AccessUser user) {
+        Paper paper = paperRepo.findOne(paperId);
+        paper.setLastModifyName(user.getName());
+        paper = paperRepo.save(paper);
+        pd.setPaper(paper);
         return paperDetailRepo.save(pd);
     }
 
     /**
      * 删除大题
+     * 
      * @param id
      * @return
      */
-    public void deletePaperDetail(String id){
-    	paperDetailRepo.delete(id);
+    public void deletePaperDetail(String id) {
+        paperDetailRepo.delete(id);
     }
-    
+
     /**
      * 查询同一个试卷对象对应大题
+     * 
      * @param paper
      * @return
      */
-    public List<PaperDetail> getPaperDetailsByPaper(Paper paper){
-    	return paperDetailRepo.findByPaper(paper);
+    public List<PaperDetail> getPaperDetailsByPaper(Paper paper) {
+        return paperDetailRepo.findByPaper(paper);
     }
-    
+
     /**
      * 删除试卷大题
+     * 
      * @param paper
      */
-     public void deletePaperDetailsByPaper(Paper paper){
-    	List<PaperDetail> details = getPaperDetailsByPaper(paper);
-    	unitService.deleteUnitsByPaperDetails(details);
-    	paperDetailRepo.delete(details);
+    public void deletePaperDetailsByPaper(Paper paper) {
+        List<PaperDetail> details = getPaperDetailsByPaper(paper);
+        unitService.deleteUnitsByPaperDetails(details);
+        paperDetailRepo.delete(details);
     }
 
-	/**
-	 * 批量删除试卷大题
-	 * @param papers
-	 */
-	public void deletePaperDetailsByPapers(List<Paper> papers){
-		for(Paper paper:papers){
-			List<PaperDetail> details = getPaperDetailsByPaper(paper);
-			unitService.deleteUnitsByPaperDetails(details);
-			paperDetailRepo.delete(details);
-		}
-	}
+    /**
+     * 批量删除试卷大题
+     * 
+     * @param papers
+     */
+    public void deletePaperDetailsByPapers(List<Paper> papers) {
+        for (Paper paper : papers) {
+            List<PaperDetail> details = getPaperDetailsByPaper(paper);
+            unitService.deleteUnitsByPaperDetails(details);
+            paperDetailRepo.delete(details);
+        }
+    }
 }
-

+ 20 - 6
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java

@@ -151,15 +151,29 @@ public class PaperService {
      * @param paperExp
      * @return
      */
-    public Paper savePaper(PaperExp paperExp, AccessUser user) {
+    public Map<String, Object> savePaper(PaperExp paperExp, AccessUser user) {
+        Map<String, Object> msgMap = new HashMap<String, Object>();
         Paper oldPaper = paperRepo.findOne(paperExp.getId());
         if (oldPaper != null) {
+            String oldName = oldPaper.getName();
             oldPaper.setTitle(paperExp.getTitle());
             oldPaper.setName(paperExp.getName());
-            oldPaper.setLastModifyName(user.getLoginName());
-            return paperRepo.save(oldPaper);
+            oldPaper.setLastModifyName(user.getName());
+            if (!oldName.equals(paperExp.getName())) {// 假如改变了试卷名称 则要效验试卷名称唯一性
+                String msg = this.checkPaperName(paperExp.getName(), user.getOrgId().toString());
+                if (msg == null) {
+                    paperRepo.save(oldPaper);
+                    msgMap.put("msg", "success");
+                } else {
+                    msgMap.put("msg", msg);
+                }
+            } else {
+                paperRepo.save(oldPaper);
+                msgMap.put("msg", "success");
+            }
+
         }
-        return null;
+        return msgMap;
     }
 
     /**
@@ -695,8 +709,8 @@ public class PaperService {
             selectedIds.add(id);
         }
         Pageable page = new PageRequest(curPage - 1, pageSize);
-        return paperRepo.findByIdNotInAndCourseNoAndOrgId(selectedIds, paperSearchInfo.getCourseNo(),
-                paperSearchInfo.getOrgId(), page);
+        return paperRepo.findByIdNotInAndCourseNoAndOrgIdAndPaperType(selectedIds, paperSearchInfo.getCourseNo(),
+                paperSearchInfo.getOrgId(), PaperType.IMPORT, page);
     }
 
 }

+ 8 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperController.java

@@ -89,7 +89,13 @@ public class PaperController {
     public ResponseEntity savePaperById(HttpServletRequest request,
                                         @RequestBody PaperExp paper) {
         AccessUser user = (AccessUser) request.getAttribute("accessUser");
-        return new ResponseEntity(paperService.savePaper(paper,user), HttpStatus.OK);
+        Map<String,Object> msgMap = paperService.savePaper(paper,user);
+        if("success".equals(msgMap.get("msg"))){
+            return new ResponseEntity(msgMap, HttpStatus.OK);
+        } else {
+            return new ResponseEntity(msgMap, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+      
     }
 
     /**
@@ -464,7 +470,7 @@ public class PaperController {
         if(ids !=null && ids.length > 0){
             return new ResponseEntity(paperService.getImportPapersNotInIds(paperSearchInfo,ids,curPage, pageSize), HttpStatus.OK);
         } else {
-            return new ResponseEntity(paperService.getImportPapersNotSuccess(paperSearchInfo, curPage, pageSize), HttpStatus.OK);
+            return new ResponseEntity(paperService.getImportPapers(paperSearchInfo, curPage, pageSize), HttpStatus.OK);
         }
       
     }

+ 12 - 6
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperDetailController.java

@@ -2,6 +2,8 @@ package com.qmth.cqb.paper.web;
 
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -13,12 +15,14 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.qmth.cqb.paper.dao.PaperDetailRepo;
 import com.qmth.cqb.paper.dao.PaperRepo;
 import com.qmth.cqb.paper.model.PaperDetail;
 import com.qmth.cqb.paper.model.PaperDetailUnit;
 import com.qmth.cqb.paper.service.PaperDetailService;
 import com.qmth.cqb.paper.service.PaperService;
 
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -33,9 +37,9 @@ public class PaperDetailController {
 
     @Autowired
     PaperService paperService;
-
+    
     @Autowired
-    PaperRepo paperRepo;
+    PaperDetailRepo paperDetailRepo;
 
     /**
      * 获取大题对应的小题
@@ -69,9 +73,11 @@ public class PaperDetailController {
      */
     @ApiOperation(value = "更新试卷中的大题", notes = "更新试卷中的大题")
     @PostMapping(value = "/updatePaperDetail/{paperId}")
-    public ResponseEntity updatePaperDetail(@PathVariable String paperId, @RequestBody PaperDetail pd) {
-        pd.setPaper(paperRepo.findOne(paperId));
-        PaperDetail paperDetail = paperDetailService.savePaperDetail(pd);
+    public ResponseEntity updatePaperDetail( HttpServletRequest request,
+                                             @PathVariable String paperId, 
+                                             @RequestBody PaperDetail pd) {
+        AccessUser user = (AccessUser) request.getAttribute("accessUser");
+        PaperDetail paperDetail = paperDetailService.savePaperDetail(pd,paperId,user);
         return new ResponseEntity(paperDetail, HttpStatus.OK);
 
     }
@@ -85,7 +91,7 @@ public class PaperDetailController {
     @ApiOperation(value = "新增大题", notes = "新增大题")
     @PostMapping(value = "/paperDetail")
     public ResponseEntity addPaperDetail(@RequestBody PaperDetail pd) {
-        PaperDetail paperDetail = paperDetailService.savePaperDetail(pd);
+        PaperDetail paperDetail = paperDetailRepo.save(pd);
         return new ResponseEntity(paperDetail, HttpStatus.OK);
     }
 

+ 6 - 7
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/QuesService.java

@@ -71,7 +71,7 @@ public class QuesService {
             } else {
                 for (int i = 0; i < quesOptions.size(); i++) {
                     saveQuesOptions.get(i).setOptionBody(quesOptions.get(i).getOptionBody());
-                    //设置正确答案(chenken-2017.4.24)
+                    // 设置正确答案(chenken-2017.4.24)
                     saveQuesOptions.get(i).setIsCorrect(quesOptions.get(i).getIsCorrect());
                 }
             }
@@ -127,8 +127,7 @@ public class QuesService {
             updateQuesWord(saveQues);
             return quesRepo.save(saveQues);
         }
-        
-        
+
     }
 
     /**
@@ -249,7 +248,8 @@ public class QuesService {
             question.setQuesAnswerWord(null);
             question.setQuesAnswerAnalysisWord(null);
             question.setQuesPkg(new byte[0]);
-            String newQuesBody = question.getQuesBody().replaceAll("<span>", "").replaceAll("</span>", "").replaceAll("###", "______");
+            String newQuesBody = question.getQuesBody().replaceAll("<span>", "").replaceAll("</span>", "")
+                    .replaceAll("###", "______");
             question.setQuesBody(newQuesBody);
             if (question.getQuesOptions() != null && question.getQuesOptions().size() > 0) {
                 question.getQuesOptions().stream().forEach(quesOption -> {
@@ -309,18 +309,17 @@ public class QuesService {
      */
     public String getExtractText(Question question) {
         StringBuilder quesText = new StringBuilder();
-        if(!StringUtils.isEmpty(question.getQuesBody())){
+        if (question != null && !StringUtils.isEmpty(question.getQuesBody())) {
             quesText.append(DocxProcessUtil.getTextInHtml(question.getQuesBody()));
         }
         List<QuesOption> quesOptionList = question.getQuesOptions();
         if (quesOptionList != null && quesOptionList.size() > 0) {
             for (QuesOption quesOption : quesOptionList) {
-                if(!StringUtils.isEmpty(quesOption.getOptionBody())){
+                if (!StringUtils.isEmpty(quesOption.getOptionBody())) {
                     quesText.append(DocxProcessUtil.getTextInHtml(quesOption.getOptionBody()));
                 }
             }
         }
         return quesText.toString();
     }
-
 }