|
@@ -1,24 +1,91 @@
|
|
|
package cn.iselab.mooctest.site.common.acyncTask;
|
|
|
|
|
|
+import cn.iselab.mooctest.site.common.constant.MutationResultType;
|
|
|
+import cn.iselab.mooctest.site.models.Grade;
|
|
|
+import cn.iselab.mooctest.site.rpc.dev.data.MutationDTO;
|
|
|
+import cn.iselab.mooctest.site.service.AssignedTaskService;
|
|
|
+import cn.iselab.mooctest.site.service.CalculateScoreService;
|
|
|
import cn.iselab.mooctest.site.service.UserService;
|
|
|
+import cn.iselab.mooctest.site.service.common.MongoAPIService;
|
|
|
+import cn.iselab.mooctest.site.service.fromDev.AnalysisService;
|
|
|
+import cn.iselab.mooctest.site.web.data.forMongo.MutationForMongoDTO;
|
|
|
+import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO;
|
|
|
+import cn.iselab.mooctest.site.web.data.fromDev.MutationResult;
|
|
|
+import cn.iselab.mooctest.site.web.logic.CalculateSocreLogic;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* Created by tangshanshan on 2018/3/6.
|
|
|
*/
|
|
|
@Component
|
|
|
@Scope("prototype")
|
|
|
public class MutationCallBack extends AsyncTaskCallBack {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AssignedTaskService assignedTaskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CalculateScoreService calculateScoreService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CalculateSocreLogic calculateSocreLogic;
|
|
|
+
|
|
|
@Autowired
|
|
|
- UserService userService; //我就试试能不能注入
|
|
|
+ MongoAPIService mongoAPIService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AnalysisService analysisService;
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(String result) {
|
|
|
- //TODO mutation 结果处理
|
|
|
- userService.findByUserId(7L);
|
|
|
LOG.info("mutation onSuccess");
|
|
|
+ String type=this.context.get("type");
|
|
|
+ Long userId=Long.parseLong(this.context.get("userId"));
|
|
|
+ Long examId=Long.parseLong(this.context.get("examId"));
|
|
|
+ Long caseId=Long.parseLong(this.context.get("caseId"));
|
|
|
+ if(type == MutationResultType.MUTAION_NODE) {
|
|
|
+ JSONArray array = new JSONArray(result);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ List<CaughtNodeDTO> dtos = new ArrayList<>();
|
|
|
+ for (int i = 0; i < array.length(); i++) {
|
|
|
+ JSONObject object = array.getJSONObject(i);
|
|
|
+ CaughtNodeDTO dto = gson.fromJson(object.toString(), CaughtNodeDTO.class);
|
|
|
+ dtos.add(dto);
|
|
|
+ }
|
|
|
+ long catchNum = dtos.stream().filter(caughtNodeDTO -> caughtNodeDTO.getIfCatch() == true).count();
|
|
|
+ double mutationScore = dtos.size() == 0 ? 0 : (double) catchNum / dtos.size();
|
|
|
+ List<Grade> grades = analysisService.saveMutationScore(userId, examId, caseId, mutationScore);
|
|
|
+ if (grades != null && !grades.isEmpty()) {
|
|
|
+ calculateScoreService.calculatePersonalDevScore(examId, caseId, userId);
|
|
|
+ calculateSocreLogic.calculateExamScoreAuto(examId, userId);
|
|
|
+ }
|
|
|
+ calculateSocreLogic.catchNode(examId, caseId, userId, String.valueOf(System.currentTimeMillis()), dtos);
|
|
|
+ }else if(type == MutationResultType.MUTAION_RESULT){
|
|
|
+ MutationDTO dto=new Gson().fromJson(result,MutationDTO.class);
|
|
|
+ try {
|
|
|
+ List<MutationForMongoDTO> list = mongoAPIService.getMutationFromMongo(userId, examId, caseId);
|
|
|
+ if (list != null) {
|
|
|
+ MutationForMongoDTO mutationForMongoDTO = list.get(0);
|
|
|
+ mutationForMongoDTO.setMutationDTO(dto);
|
|
|
+ mongoAPIService.updateMutationToMongo(mutationForMongoDTO);
|
|
|
+ } else {
|
|
|
+ mongoAPIService.saveMutationToMongo(userId, examId, caseId, dto);
|
|
|
+ }
|
|
|
+ }catch (IOException e){
|
|
|
+ LOG.info("fail to save"+userId+"'s mutation result");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|