insomniaLee пре 4 година
родитељ
комит
0aea80e0f7

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

@@ -8,6 +8,7 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
 
+import edu.nju.model.AnalysePeopleVO;
 import edu.nju.model.AnalyseVO;
 import edu.nju.model.BugDataVO;
 import edu.nju.model.HistoricalDataVO;
@@ -348,6 +349,27 @@ public class AnalyzeController {
 		}
 	}
 
+	/**
+	 * todo 引进 guvva 来做缓存
+	 * @param caseId
+	 * @param taskId
+	 * @param workId
+	 * @param response
+	 */
+	@RequestMapping(value = "/analysePeople")
+	@ResponseBody
+	public void analyseTask(String caseId, String taskId, String workId , HttpServletResponse response){
+		try {
+			PrintWriter out = response.getWriter();
+			AnalysePeopleVO analyseVO=aservice.getReviewAnalysePeopleVO(caseId, taskId,workId);
+			out.print(new JSONObject(analyseVO));
+			out.flush();
+			out.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
 	@RequestMapping(value = "/historicalData")
 	@ResponseBody
 	public HistoricalDataVO getHistoricalData(Long workerId,int caseTypeId){

+ 40 - 0
src/main/java/edu/nju/dao/UserLabelDao.java

@@ -0,0 +1,40 @@
+package edu.nju.dao;
+
+import edu.nju.entities.ReviewItem;
+import edu.nju.entities.UserLabel;
+import org.apache.catalina.User;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Queue;
+
+@Repository
+public class UserLabelDao {
+
+    @Autowired
+    private MongoOperations mongoOperations;
+
+    public String saveItem(UserLabel item){
+        mongoOperations.save(item);
+        return item.getId();
+    }
+
+//    public List<ReviewItem>findItemsByJob(String job_id){
+//        Query query = new Query();
+//        query.addCriteria(Criteria.where("job_id").is(job_id));
+//        return mongoOperations.find(query, ReviewItem.class);
+//    }
+
+    public List<UserLabel> findLabelsByWorkerId(String workerId){
+        Query query = new Query();
+        query.addCriteria(Criteria.where("workerId").is(workerId));
+        List<UserLabel> labels = mongoOperations.find(query,UserLabel.class);
+        return  labels;
+    }
+
+
+}

+ 27 - 0
src/main/java/edu/nju/entities/UserLabel.java

@@ -0,0 +1,27 @@
+package edu.nju.entities;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.Id;
+
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class UserLabel implements java.io.Serializable{
+
+    private static final long serialVersionUID = -4445308752903947027L;
+
+    @Id
+    private String id;
+
+    private String workerId;
+
+    private String label;
+
+    private String type; // 用来表示用 标签的类型
+
+
+}

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

@@ -0,0 +1,28 @@
+package edu.nju.model;
+
+import edu.nju.entities.Bug;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class AnalysePeopleVO {
+    String taskName;
+    String name;
+    String school;
+    String photoUrl;
+    String province;
+    String city;
+    long registerTime;
+    long crowdTime;
+    List<Bug> bugList ; //= extraService.getBugList(report_id, case_take_id);
+    long firstActivate ;
+    long lastActivate ;
+    List<String> labels ; // 用户标签
+}

+ 65 - 0
src/main/java/edu/nju/service/AnalyzeService.java

@@ -2,11 +2,13 @@ package edu.nju.service;
 
 import java.nio.charset.StandardCharsets;
 import java.util.*;
+import java.util.stream.Collectors;
 
 import edu.nju.dao.*;
 import edu.nju.entities.*;
 import edu.nju.model.*;
 import edu.nju.util.HTTP;
+import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.EnumUtils;
 import org.json.JSONArray;
 import org.json.JSONObject;
@@ -60,6 +62,12 @@ public class AnalyzeService {
 	@Autowired
 	TestCaseDao testCaseDao;
 
+	@Autowired
+	UserLabelDao userLabelDao;
+
+	@Autowired
+	ExtraService extraService;
+
 
 	Logger logger= LoggerFactory.getLogger(RecommendService.class);
 	
@@ -541,6 +549,53 @@ public class AnalyzeService {
 		return true;
 	}
 
+	public AnalysePeopleVO getReviewAnalysePeopleVO(String caseId,String taskId,String workerId) {
+		Task task=taskDao.findById(taskId);
+		AnalysePeopleVO res = new AnalysePeopleVO();
+		if(task!=null)res.setTaskName(task.getName());
+		String caseTakeId = caseId+"-"+taskId;
+		// 部分数据从主战接口中取得
+		String result = HTTP.sendGet("http://114.55.91.83:8191/api/user/" + workerId, "");
+		if (result != null && !result.equals("")) {
+			JSONObject json = new JSONObject(result);
+			if (json.has("name") && !json.isNull("name")) {
+				res.setName(json.getString("name"));
+			}
+			if (json.has("school") && !json.isNull("school")) {
+				res.setSchool( json.getString("school"));
+			}
+			if (json.has("province") && !json.isNull("province")) {
+				res.setProvince(json.getString("province"));
+			}
+			if (json.has("city") && !json.isNull("city")) {
+				res.setCity(json.getString("city"));
+			}
+			if (json.has("createTime") && !json.isNull("createTime")) {
+				res.setRegisterTime(json.getLong("createTime"));
+			}
+			if (json.has("photoUrl") && !json.isNull("photoUrl")) {
+				res.setPhotoUrl(json.getString("photoUrl"));
+			}
+		}
+		//用户lebels
+		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 ;
+		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);
+		res.setBugList(bugList);
+		return res;
+	}
+
 	public AnalyseVO getReviewAnalyseVO(String caseId, String taskId){
 		Task task=taskDao.findById(taskId);
 		long startTime=0;
@@ -680,5 +735,15 @@ public class AnalyzeService {
 		return historicalDataVO;
 	}
 
+	/**
+	 * 根据用户信息获取用户的labels
+	 * @param wordkId
+	 * @return
+	 */
+	private List<String> getUserLabels(String wordkId){
+		List<UserLabel> labels = userLabelDao.findLabelsByWorkerId(wordkId);
+		return labels.stream().map(UserLabel::getLabel).collect(Collectors.toList());
+	}
+
 
 }