wangwei hace 6 años
padre
commit
9fe1626ff7

+ 25 - 58
examcloud-task-api-provider/src/main/java/cn/com/qmth/examcloud/task/api/provider/DataSyncCloudServiceProvider.java

@@ -1,20 +1,11 @@
 package cn.com.qmth.examcloud.task.api.provider;
 
-import java.util.List;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import cn.com.qmth.examcloud.commons.api.HandleSyncCloudService;
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
-import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
-import cn.com.qmth.examcloud.commons.base.util.RegExpUtil;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncCourseReq;
@@ -29,8 +20,7 @@ import cn.com.qmth.examcloud.task.api.response.SyncExamStudentResp;
 import cn.com.qmth.examcloud.task.api.response.SyncOrgResp;
 import cn.com.qmth.examcloud.task.api.response.SyncSpecialtyResp;
 import cn.com.qmth.examcloud.task.api.response.SyncStudentResp;
-import cn.com.qmth.examcloud.task.dao.DataSyncRepo;
-import cn.com.qmth.examcloud.task.dao.entity.DataSyncEntity;
+import cn.com.qmth.examcloud.task.service.DataSyncService;
 
 /**
  * 数据同步
@@ -45,13 +35,10 @@ public class DataSyncCloudServiceProvider extends ControllerSupport
 		implements
 			DataSyncCloudService {
 
-	@Autowired
-	DataSyncRepo dataSyncRepo;
+	private static final long serialVersionUID = -2880611326177571371L;
 
 	@Autowired
-	HandleSyncCloudService handleSyncCloudService;
-
-	private static final long serialVersionUID = -2880611326177571371L;
+	DataSyncService dataSyncService;
 
 	@PostMapping("syncCourse")
 	@Override
@@ -71,47 +58,22 @@ public class DataSyncCloudServiceProvider extends ControllerSupport
 	@Override
 	public SyncStudentResp syncStudent(@RequestBody SyncStudentReq req) {
 
-		String group = PropertiesUtil.getString("$sync.syncStudent.group");
-		if (StringUtils.isBlank(group)) {
-			throw new StatusException("T-001001", "group is not configured");
-		}
-
-		List<String> componentList = RegExpUtil.findAll(group, "[^\\,]+");
-
-		if (CollectionUtils.isEmpty(componentList)) {
-			throw new StatusException("T-001001", "no component");
-		}
-
-		cn.com.qmth.examcloud.commons.api.request.SyncStudentReq request = new cn.com.qmth.examcloud.commons.api.request.SyncStudentReq();
-		request.setEnable(req.getEnable());
-		request.setId(req.getId());
-		request.setIdentityNumber(req.getIdentityNumber());
-		request.setName(req.getName());
-		request.setOrgCode(req.getOrgCode());
-		request.setOrgId(req.getOrgId());
-		request.setOrgName(req.getOrgName());
-		request.setPhoneNumber(req.getPhoneNumber());
-		request.setPhotoPath(req.getPhotoPath());
-		request.setRootOrgId(req.getRootOrgId());
-		request.setSecurityPhone(req.getSecurityPhone());
-		request.setStudentCode(req.getStudentCode());
-		request.setSyncType(req.getSyncType());
-
-		for (String component : componentList) {
-			String url = PropertiesUtil.getString("$sync.syncStudent.component." + component);
-			request.setUrl(url);
-			try {
-				handleSyncCloudService.syncStudent(request);
-			} catch (Exception e) {
-				DataSyncEntity entity = new DataSyncEntity();
-				entity.setMethodName("syncCourse");
-				entity.setParamType(
-						cn.com.qmth.examcloud.commons.api.request.SyncStudentReq.class.getName());
-				entity.setSyncNum(0);
-				entity.setParamJson(JsonUtil.toJson(request));
-				dataSyncRepo.saveAndFlush(entity);
-			}
-		}
+		cn.com.qmth.examcloud.commons.api.request.SyncStudentReq r = new cn.com.qmth.examcloud.commons.api.request.SyncStudentReq();
+		r.setEnable(req.getEnable());
+		r.setId(req.getId());
+		r.setIdentityNumber(req.getIdentityNumber());
+		r.setName(req.getName());
+		r.setOrgCode(req.getOrgCode());
+		r.setOrgId(req.getOrgId());
+		r.setOrgName(req.getOrgName());
+		r.setPhoneNumber(req.getPhoneNumber());
+		r.setPhotoPath(req.getPhotoPath());
+		r.setRootOrgId(req.getRootOrgId());
+		r.setSecurityPhone(req.getSecurityPhone());
+		r.setStudentCode(req.getStudentCode());
+		r.setSyncType(req.getSyncType());
+
+		dataSyncService.syncStudent(r);
 
 		SyncStudentResp resp = new SyncStudentResp();
 		return resp;
@@ -133,7 +95,12 @@ public class DataSyncCloudServiceProvider extends ControllerSupport
 	@PostMapping("syncExamStudent")
 	@Override
 	public SyncExamStudentResp syncExamStudent(@RequestBody SyncExamStudentReq req) {
-		return null;
+		cn.com.qmth.examcloud.commons.api.request.SyncExamStudentReq r = new cn.com.qmth.examcloud.commons.api.request.SyncExamStudentReq();
+		r.setSyncType(req.getSyncType());
+
+		dataSyncService.syncExamStudent(r);
+		SyncExamStudentResp resp = new SyncExamStudentResp();
+		return resp;
 	}
 
 }

+ 79 - 0
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/DataSyncService.java

@@ -0,0 +1,79 @@
+package cn.com.qmth.examcloud.task.service;
+
+import cn.com.qmth.examcloud.commons.api.request.SyncCourseReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncExamReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncExamStudentReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncOrgReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncSpecialtyReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncStudentReq;
+import cn.com.qmth.examcloud.commons.api.response.SyncCourseResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncExamResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncExamStudentResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncOrgResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncSpecialtyResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncStudentResp;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年9月19日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface DataSyncService {
+
+	/**
+	 * 同步课程
+	 *
+	 * @author WANGWEI
+	 * @param req
+	 * @return
+	 */
+	SyncCourseResp syncCourse(SyncCourseReq req);
+
+	/**
+	 * 同步机构
+	 *
+	 * @author WANGWEI
+	 * @param req
+	 * @return
+	 */
+	SyncOrgResp syncOrg(SyncOrgReq req);
+
+	/**
+	 * 同步学生
+	 *
+	 * @author WANGWEI
+	 * @param req
+	 * @return
+	 */
+	SyncStudentResp syncStudent(SyncStudentReq req);
+
+	/**
+	 * 同步考生
+	 *
+	 * @author WANGWEI
+	 * @param req
+	 * @return
+	 */
+	SyncExamStudentResp syncExamStudent(SyncExamStudentReq req);
+
+	/**
+	 * 同步专业
+	 *
+	 * @author WANGWEI
+	 * @param req
+	 * @return
+	 */
+	SyncSpecialtyResp syncSpecialty(SyncSpecialtyReq req);
+
+	/**
+	 * 同步考试
+	 *
+	 * @author WANGWEI
+	 * @param req
+	 * @return
+	 */
+	SyncExamResp syncExam(SyncExamReq req);
+
+}

+ 110 - 0
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/DataSyncServiceImpl.java

@@ -0,0 +1,110 @@
+package cn.com.qmth.examcloud.task.service.impl;
+
+import java.util.List;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.commons.api.HandleSyncCloudService;
+import cn.com.qmth.examcloud.commons.api.request.SyncCourseReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncExamReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncExamStudentReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncOrgReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncSpecialtyReq;
+import cn.com.qmth.examcloud.commons.api.request.SyncStudentReq;
+import cn.com.qmth.examcloud.commons.api.response.SyncCourseResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncExamResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncExamStudentResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncOrgResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncSpecialtyResp;
+import cn.com.qmth.examcloud.commons.api.response.SyncStudentResp;
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.base.util.JsonUtil;
+import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
+import cn.com.qmth.examcloud.commons.base.util.RegExpUtil;
+import cn.com.qmth.examcloud.task.dao.DataSyncRepo;
+import cn.com.qmth.examcloud.task.dao.entity.DataSyncEntity;
+import cn.com.qmth.examcloud.task.service.DataSyncService;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年9月19日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Service
+public class DataSyncServiceImpl implements DataSyncService {
+
+	@Autowired
+	DataSyncRepo dataSyncRepo;
+
+	@Autowired
+	HandleSyncCloudService handleSyncCloudService;
+
+	@Override
+	public SyncCourseResp syncCourse(SyncCourseReq req) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public SyncOrgResp syncOrg(SyncOrgReq req) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public SyncStudentResp syncStudent(SyncStudentReq req) {
+		String group = PropertiesUtil.getString("$sync.syncStudent.group");
+		if (StringUtils.isBlank(group)) {
+			throw new StatusException("T-001001", "group is not configured");
+		}
+
+		List<String> componentList = RegExpUtil.findAll(group, "[^\\,]+");
+
+		if (CollectionUtils.isEmpty(componentList)) {
+			throw new StatusException("T-001001", "no component");
+		}
+
+		for (String component : componentList) {
+			String url = PropertiesUtil.getString("$sync.syncStudent.component." + component);
+			req.setUrl(url);
+			try {
+				handleSyncCloudService.syncStudent(req);
+			} catch (Exception e) {
+				DataSyncEntity entity = new DataSyncEntity();
+				entity.setMethodName("syncStudent");
+				entity.setParamType(
+						cn.com.qmth.examcloud.commons.api.request.SyncStudentReq.class.getName());
+				entity.setSyncNum(0);
+				entity.setParamJson(JsonUtil.toJson(req));
+				dataSyncRepo.saveAndFlush(entity);
+			}
+		}
+
+		SyncStudentResp resp = new SyncStudentResp();
+		return resp;
+	}
+
+	@Override
+	public SyncExamStudentResp syncExamStudent(SyncExamStudentReq req) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public SyncSpecialtyResp syncSpecialty(SyncSpecialtyReq req) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public SyncExamResp syncExam(SyncExamReq req) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+}