Procházet zdrojové kódy

添加加密解密url

insomniaLee před 4 roky
rodič
revize
bde9d8fb74

+ 24 - 0
src/main/java/edu/nju/controller/AnalyzeController.java

@@ -13,6 +13,7 @@ import edu.nju.model.AnalyseVO;
 import edu.nju.model.AnalyseVO2;
 import edu.nju.model.BugDataVO;
 import edu.nju.model.HistoricalDataVO;
+import edu.nju.util.AESUtil;
 import edu.nju.util.BlockChainAspect;
 import org.json.JSONArray;
 import org.json.JSONObject;
@@ -371,6 +372,29 @@ public class AnalyzeController {
 		}
 	}
 
+	@RequestMapping(value = "/analyse/getTaskToken")
+	@ResponseBody
+	public String getAnalyseTaskToken(String caseId,String taskId,HttpServletResponse response ){
+		return AESUtil.encrypt("taskId="+taskId+"&caseId="+caseId);
+	}
+
+	@GetMapping(value = "/analyse/task")
+	public String analyseTask(String token, HttpServletResponse response ){
+		String realUrl = AESUtil.decrypt(token);
+		return "redirect:/analyseExam2?"+realUrl;
+	}
+
+	/**
+	 * todo 引进 guvva 来做缓存
+	 * @param workId
+	 * @param response
+	 */
+	@RequestMapping(value = "/analyse/people")
+	public String analyseSinglePeople(String token, String workId , HttpServletResponse response){
+		String realUrl = AESUtil.decrypt(token);
+		return "redirect:/analysePeople?"+realUrl+"&workId="+workId;
+	}
+
 	@RequestMapping(value = "/historicalData")
 	@ResponseBody
 	public HistoricalDataVO getHistoricalData(Long workerId,int caseTypeId){

+ 3 - 0
src/main/java/edu/nju/model/AnalysePeopleVO.java

@@ -1,10 +1,12 @@
 package edu.nju.model;
 
+import com.google.gson.JsonArray;
 import edu.nju.entities.Bug;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.json.JSONArray;
 
 import java.util.List;
 
@@ -13,6 +15,7 @@ import java.util.List;
 @NoArgsConstructor
 @Data
 public class AnalysePeopleVO {
+    JSONArray timeLine ;
     String taskName;
     String name;
     String school;

+ 44 - 10
src/main/java/edu/nju/service/AnalyzeService.java

@@ -10,6 +10,7 @@ import edu.nju.dao.*;
 import edu.nju.entities.*;
 import edu.nju.model.*;
 import edu.nju.util.HTTP;
+import edu.nju.util.TimeUtil;
 import org.apache.commons.lang3.EnumUtils;
 import org.json.JSONArray;
 import org.json.JSONObject;
@@ -588,21 +589,54 @@ public class AnalyzeService {
 		res.setLabels(getUserLabels(workerId));
 		Report userReport = extraService.findByWorker(caseTakeId,workerId);
 		List<Bug> bugList = extraService.getBugList(userReport.getId(),caseTakeId);
-		long firstActivate  = Long.MAX_VALUE ;
-		long lastActivate  = 0 ;
-		long cur ;
+		Collections.sort(bugList, Comparator.comparing(Bug::getCreate_time_millis));
+		JSONArray array=new JSONArray();
+		Map<String,Integer> severityCount = new HashMap<>();
+		int [] severityValueCount = new int[5];
 		for(Bug bug : bugList){
-			cur = Long.parseLong(bug.getCreate_time_millis());
-			if(firstActivate>cur)firstActivate = cur;
-			if(lastActivate<cur)lastActivate=cur;
-		}
-		if(firstActivate == Long.MAX_VALUE)firstActivate = 0 ;
-		res.setFirstActivate(firstActivate);
-		res.setLastActivate(lastActivate);
+			severityValueCount[bug.getSeverity()]++;
+			JSONObject object = new JSONObject();
+			object.put("content",bug.getTitle());
+			object.put("timestamp", TimeUtil.timestamp2DayHour(bug.getCreate_time_millis()));
+			array.put(object);
+		}
+		int severityMax = Arrays.stream(severityValueCount).max().getAsInt();
+		for(int i = 0 ;i<severityValueCount.length;i++){
+			severityCount.put(BugSeverity.getValue(i).toString(),severityValueCount[i]*100/severityMax);
+		}
+		res.setFirstActivate(bugList.size()==0?0:Long.parseLong(bugList.get(0).getCreate_time_millis()));
+		res.setLastActivate(bugList.size()==0?0:Long.parseLong(bugList.get(bugList.size()-1).getCreate_time_millis()));
 		res.setBugList(bugList);
+		res.setTimeLine(array);
 		return res;
 	}
 
+	private void getTimeDistribute(String workerId){
+		List<Report>reports=reportDao.findReportsByWorker(String.valueOf(workerId));
+		reports = reports.stream().filter(e->{
+			return Long.parseLong(e.getCreate_time_millis()) > monthAgoStart(5);
+		}).collect(Collectors.toList());
+		List<Bug> bugs = new ArrayList<>();
+		for(Report report : reports){
+			bugs.addAll(bdao.findByReport(report.getId(),report.getCase_take_id()));
+		}
+		Map<String,Integer> data = new HashMap<>(6);
+		for(Bug bug : bugs){
+
+		}
+	}
+
+	private long  monthAgoStart(int offset){
+		Calendar calendar = Calendar.getInstance();
+		calendar.set(Calendar.HOUR_OF_DAY, 0);
+		calendar.set(Calendar.MINUTE, 0);
+		calendar.set(Calendar.SECOND, 0);
+		calendar.set(Calendar.MILLISECOND, 0);
+		calendar.add(Calendar.MONTH, -offset);
+		calendar.set(Calendar.DAY_OF_MONTH,1);
+		return calendar.getTimeInMillis();
+	}
+
 	public AnalyseVO getReviewAnalyseVO(String caseId, String taskId){
 		Task task=taskDao.findById(taskId);
 		long startTime=0;

+ 49 - 0
src/main/java/edu/nju/util/AESUtil.java

@@ -0,0 +1,49 @@
+package edu.nju.util;
+
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.util.Base64;
+
+public class AESUtil {
+
+    //偏移量
+    private static String IV ="mooctestmooctest";
+    //钥匙
+    private static String KEY = "TESTMOOCTESTMOOC";
+
+    //加密
+    public static String encrypt(String str) {
+        try {
+            byte[] bytes = str.getBytes();
+            IvParameterSpec ivParameterSpec = new IvParameterSpec(IV.getBytes());
+            SecretKeySpec secretKeySpec = new SecretKeySpec(KEY.getBytes(), "AES");
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);
+            bytes = cipher.doFinal(bytes);
+            bytes = Base64.getEncoder().encode(bytes);
+            return new String(bytes);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    //解密
+    public static String decrypt(String str) {
+        try {
+            byte[] bytes = Base64.getDecoder().decode(str);
+            IvParameterSpec ivParameterSpec = new IvParameterSpec(IV.getBytes());
+            SecretKeySpec secretKeySpec = new SecretKeySpec(KEY.getBytes(), "AES");
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
+            bytes = cipher.doFinal(bytes);
+            return new String(bytes);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+}

+ 9 - 0
src/main/java/edu/nju/util/TimeUtil.java

@@ -7,7 +7,9 @@ import java.util.Date;
 public class TimeUtil {
 
     private static final String format  = "MM-dd HH:mm:ss";
+    private static final String dayHour  = "MM-dd HH:mm";
     private static final SimpleDateFormat sdf = new SimpleDateFormat(format);
+    private static final SimpleDateFormat dayHourFormat = new SimpleDateFormat(dayHour);
 
     public static Date StringToDate(String datetime){
         SimpleDateFormat sdFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -28,4 +30,11 @@ public class TimeUtil {
         return sdf.format(new Date(Long.valueOf(seconds)));
     }
 
+    public static String timestamp2DayHour(String timestamp) {
+        if (timestamp == null || timestamp.isEmpty() || timestamp.equals("null")) {
+            return "";
+        }
+        return dayHourFormat.format(new Date(Long.valueOf(timestamp)));
+    }
+
 }