CommonService.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package cn.com.qmth.examcloud.tool.service;
  2. import cn.com.qmth.examcloud.tool.config.SysProperty;
  3. import cn.com.qmth.examcloud.tool.service.export_student_answer_and_score_detail.vo.CourseVO;
  4. import cn.com.qmth.examcloud.tool.utils.HttpHelper;
  5. import cn.com.qmth.examcloud.tool.utils.JsonMapper;
  6. import cn.com.qmth.examcloud.tool.vo.Pager;
  7. import cn.com.qmth.examcloud.tool.vo.User;
  8. import com.fasterxml.jackson.core.type.TypeReference;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Component;
  13. import java.util.ArrayList;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. @Component
  18. public class CommonService {
  19. private final static Logger log = LoggerFactory.getLogger(CommonService.class);
  20. @Autowired
  21. private SysProperty sysProperty;
  22. public User login(String domain, String loginName, String password) {
  23. Map<String, Object> params = new HashMap<>();
  24. // params.put("rootOrgId", 0L);
  25. params.put("domain", domain);
  26. params.put("accountType", "COMMON_LOGIN_NAME");
  27. params.put("accountValue", loginName);
  28. params.put("password", password);
  29. String url = sysProperty.getServerUrl() + "/api/ecs_core/auth/login";
  30. String result = HttpHelper.post(url, null, params);
  31. log.info("LOGIN_IN {}", result);
  32. return new JsonMapper().parseJson(result, User.class);
  33. }
  34. /**
  35. * 获取考试相关的课程列表
  36. */
  37. public List<CourseVO> getExamCourseList(String key, String token, Long examId) {
  38. Map<String, Object> params = new HashMap<>();
  39. params.put("examId", examId);
  40. params.put("pageNo", 1);
  41. params.put("pageSize", 1000);
  42. Map<String, String> headers = new HashMap<>();
  43. headers.put("key", key);
  44. headers.put("token", token);
  45. String url = sysProperty.getServerUrl() + "/api/ecs_exam_work/exam/course/list";
  46. String json = HttpHelper.post(url, headers, params);
  47. JsonMapper jsonMapper = new JsonMapper();
  48. Pager<CourseVO> page = jsonMapper.parseJson(json, new TypeReference<Pager<CourseVO>>() {
  49. });
  50. if (page != null && page.getContent() != null) {
  51. return page.getContent();
  52. }
  53. return new ArrayList<>();
  54. }
  55. }