ToolsService.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.qxgmat.service.extend;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.qxgmat.data.constants.enums.SettingKey;
  4. import com.qxgmat.data.dao.entity.QuestionNo;
  5. import com.qxgmat.data.dao.entity.Setting;
  6. import com.qxgmat.data.relation.entity.QuestionNoRelation;
  7. import com.qxgmat.service.inline.SettingService;
  8. import org.springframework.stereotype.Service;
  9. import javax.annotation.Resource;
  10. import java.util.List;
  11. @Service
  12. public class ToolsService {
  13. @Resource
  14. private SettingService settingService;
  15. /**
  16. * 根据练习或者模考时间设置计算考题考试时间
  17. * setting: {struct: {difficult: ""}}
  18. * @param settingKey
  19. * @param relationList
  20. * @return
  21. */
  22. public Integer computerTime(SettingKey settingKey, List<QuestionNoRelation> relationList){
  23. Setting setting = settingService.getByKey(settingKey);
  24. JSONObject value = setting.getValue();
  25. Integer time = 0;
  26. for(QuestionNoRelation relation:relationList){
  27. JSONObject difficultMap = null;
  28. for (Integer struct : relation.getModuleStruct()){
  29. // 判断结构体
  30. difficultMap = value.getJSONObject(String.valueOf(struct));
  31. if (difficultMap != null) break;
  32. }
  33. if (difficultMap == null) continue;
  34. // 判断难度
  35. String t = difficultMap.getString(relation.getQuestion().getDifficult());
  36. if (t == null || t.isEmpty()) continue;
  37. time += Integer.valueOf(t);
  38. }
  39. return time;
  40. }
  41. }