|
@@ -1,57 +1,82 @@
|
|
-package cn.com.qmth.examcloud.exchange.outer.service.impl;
|
|
|
|
-
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
-import com.thoughtworks.xstream.XStream;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
|
-import cn.com.qmth.examcloud.commons.base.helpers.XStreamBuilder;
|
|
|
|
-import cn.com.qmth.examcloud.commons.base.util.PathUtil;
|
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.service.CourseGroupService;
|
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.service.bean.Course;
|
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.service.bean.CourseGroup;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 类注释
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @date 2018年9月4日
|
|
|
|
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
|
- */
|
|
|
|
-@Service
|
|
|
|
-public class CourseGroupServiceImpl implements CourseGroupService {
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public List<Course> getCourseList(Long rootOrgId, String courseGroupName) {
|
|
|
|
-
|
|
|
|
- String resoucePath = PathUtil.getResoucePath("course-group/course-group-" + rootOrgId + ".xml");
|
|
|
|
- File file = new File(resoucePath);
|
|
|
|
-
|
|
|
|
- XStream xStream = XStreamBuilder.newInstance().build();
|
|
|
|
- xStream.allowTypes(new Class[] { CourseGroup.class, Course.class, List.class });
|
|
|
|
- xStream.alias("groups", List.class);
|
|
|
|
- xStream.alias("group", CourseGroup.class);
|
|
|
|
- xStream.alias("course", Course.class);
|
|
|
|
-
|
|
|
|
- List<CourseGroup> list = null;
|
|
|
|
- try {
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
- List<CourseGroup> obj = (List<CourseGroup>) xStream.fromXML(file);
|
|
|
|
- list = obj;
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw new StatusException("EX-620001", "配置文件错误", e);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (CourseGroup cur : list) {
|
|
|
|
- if (courseGroupName.equals(cur.getName())) {
|
|
|
|
- return cur.getCourseList();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- throw new StatusException("EX-860001", "课程组未配置");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+package cn.com.qmth.examcloud.exchange.outer.service.impl;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import com.thoughtworks.xstream.XStream;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.helpers.XStreamBuilder;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.PathUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.web.redis.RedisClient;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.outer.service.CourseGroupService;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.outer.service.bean.Course;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.outer.service.bean.CourseGroup;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 类注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @date 2018年9月4日
|
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class CourseGroupServiceImpl implements CourseGroupService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ RedisClient redisClient;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Course> getCourseList(Long rootOrgId, String courseGroupName) {
|
|
|
|
+
|
|
|
|
+ String key = "EX_COURSE_LIST:" + rootOrgId + "_" + courseGroupName;
|
|
|
|
+ List<Course> list = null;
|
|
|
|
+
|
|
|
|
+ String json = redisClient.get(key, String.class);
|
|
|
|
+ if (null != json) {
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ List<Course> obj = JsonUtil.fromJson(json, List.class);
|
|
|
|
+ list = obj;
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ list = getCourseListFromXml(rootOrgId, courseGroupName);
|
|
|
|
+ redisClient.set(key, JsonUtil.toJson(list), 60 * 5);
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<Course> getCourseListFromXml(Long rootOrgId, String courseGroupName) {
|
|
|
|
+
|
|
|
|
+ String resoucePath = PathUtil
|
|
|
|
+ .getResoucePath("course-group/course-group-" + rootOrgId + ".xml");
|
|
|
|
+ File file = new File(resoucePath);
|
|
|
|
+
|
|
|
|
+ XStream xStream = XStreamBuilder.newInstance().build();
|
|
|
|
+ xStream.allowTypes(new Class[]{CourseGroup.class, Course.class, List.class});
|
|
|
|
+ xStream.alias("groups", List.class);
|
|
|
|
+ xStream.alias("group", CourseGroup.class);
|
|
|
|
+ xStream.alias("course", Course.class);
|
|
|
|
+
|
|
|
|
+ List<CourseGroup> list = null;
|
|
|
|
+ try {
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ List<CourseGroup> obj = (List<CourseGroup>) xStream.fromXML(file);
|
|
|
|
+ list = obj;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new StatusException("EX-620001", "配置文件错误", e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (CourseGroup cur : list) {
|
|
|
|
+ if (courseGroupName.equals(cur.getName())) {
|
|
|
|
+ return cur.getCourseList();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ throw new StatusException("EX-860001", "课程组未配置");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|