wangwei 6 år sedan
förälder
incheckning
bc8fbbd9d9

+ 54 - 44
examcloud-task-api-provider/src/main/java/cn/com/qmth/examcloud/task/api/provider/DataSyncCloudServiceProvider.java

@@ -1,12 +1,20 @@
 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;
@@ -21,11 +29,6 @@ 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;
-import cn.com.qmth.examcloud.task.service.bean.CourseInfo;
-import cn.com.qmth.examcloud.task.service.bean.OrgInfo;
-import cn.com.qmth.examcloud.task.service.bean.SpecialtyInfo;
-import cn.com.qmth.examcloud.task.service.bean.StudentInfo;
 
 /**
  * 数据同步
@@ -41,74 +44,81 @@ public class DataSyncCloudServiceProvider extends ControllerSupport
 			DataSyncCloudService {
 
 	@Autowired
-	DataSyncService dataSyncService;
+	DataSyncRepo dataSyncRepo;
 
 	@Autowired
-	DataSyncRepo dataSyncRepo;
+	HandleSyncCloudService handleSyncCloudService;
 
 	private static final long serialVersionUID = -2880611326177571371L;
 
 	@PostMapping("syncCourse")
 	@Override
 	public SyncCourseResp syncCourse(@RequestBody SyncCourseReq req) {
-		CourseInfo info = new CourseInfo();
 
-		DataSyncEntity entity = new DataSyncEntity();
-		entity.setMethodName("syncCourse");
-		entity.setParamType(CourseInfo.class.getName());
-		entity.setParam(JsonUtil.toJson(info));
-
-		dataSyncRepo.saveAndFlush(entity);
-
-		dataSyncService.syncCourse(info);
 		return null;
 	}
 
 	@PostMapping("syncOrg")
 	@Override
 	public SyncOrgResp syncOrg(@RequestBody SyncOrgReq req) {
-		OrgInfo info = new OrgInfo();
-
-		DataSyncEntity entity = new DataSyncEntity();
-		entity.setMethodName("syncOrg");
-		entity.setParamType(CourseInfo.class.getName());
-		entity.setParam(JsonUtil.toJson(info));
 
-		dataSyncRepo.saveAndFlush(entity);
-
-		dataSyncService.syncOrg(info);
 		return null;
 	}
 
 	@PostMapping("syncStudent")
 	@Override
 	public SyncStudentResp syncStudent(@RequestBody SyncStudentReq req) {
-		StudentInfo info = new StudentInfo();
-
-		DataSyncEntity entity = new DataSyncEntity();
-		entity.setMethodName("syncStudent");
-		entity.setParamType(CourseInfo.class.getName());
-		entity.setParam(JsonUtil.toJson(info));
-
-		dataSyncRepo.saveAndFlush(entity);
 
-		dataSyncService.syncStudent(info);
-		return null;
+		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);
+			}
+		}
+
+		SyncStudentResp resp = new SyncStudentResp();
+		return resp;
 	}
 
 	@PostMapping("syncSpecialty")
 	@Override
 	public SyncSpecialtyResp syncSpecialty(@RequestBody SyncSpecialtyReq req) {
-		SpecialtyInfo info = new SpecialtyInfo();
-
-		DataSyncEntity entity = new DataSyncEntity();
-		entity.setMethodName("syncSpecialty");
-		entity.setParamType(CourseInfo.class.getName());
-		entity.setParam(JsonUtil.toJson(info));
-
-		dataSyncRepo.saveAndFlush(entity);
 
-		dataSyncService.syncSpecialty(info);
 		return null;
 	}
 

+ 25 - 12
examcloud-task-dao/src/main/java/cn/com/qmth/examcloud/task/dao/entity/DataSyncEntity.java

@@ -1,8 +1,8 @@
 package cn.com.qmth.examcloud.task.dao.entity;
 
 import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.IdClass;
 import javax.persistence.Table;
 
 import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
@@ -16,31 +16,44 @@ import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
  */
 @Entity
 @Table(name = "EC_T_DATA_SYNC")
+@IdClass(DataSyncPK.class)
 public class DataSyncEntity extends JpaEntity {
 
 	private static final long serialVersionUID = 1066874132817953168L;
 
+	/**
+	 * 同步请求组件
+	 */
 	@Id
-	@GeneratedValue
-	private Long id;
+	private String component;
 
+	/**
+	 * 方法(反射调用)
+	 */
+	@Id
 	private String methodName;
 
+	/**
+	 * 参数类型
+	 */
 	private String paramType;
 
-	private String param;
+	/**
+	 * 参数json
+	 */
+	private String paramJson;
 
 	/**
 	 * 同步次数
 	 */
 	private int syncNum;
 
-	public Long getId() {
-		return id;
+	public String getComponent() {
+		return component;
 	}
 
-	public void setId(Long id) {
-		this.id = id;
+	public void setComponent(String component) {
+		this.component = component;
 	}
 
 	public String getMethodName() {
@@ -59,12 +72,12 @@ public class DataSyncEntity extends JpaEntity {
 		this.paramType = paramType;
 	}
 
-	public String getParam() {
-		return param;
+	public String getParamJson() {
+		return paramJson;
 	}
 
-	public void setParam(String param) {
-		this.param = param;
+	public void setParamJson(String paramJson) {
+		this.paramJson = paramJson;
 	}
 
 	public int getSyncNum() {

+ 42 - 0
examcloud-task-dao/src/main/java/cn/com/qmth/examcloud/task/dao/entity/DataSyncPK.java

@@ -0,0 +1,42 @@
+package cn.com.qmth.examcloud.task.dao.entity;
+
+import java.io.Serializable;
+
+/**
+ * 数据同步PK
+ *
+ * @author WANGWEI
+ * @date 2018年8月2日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class DataSyncPK implements Serializable {
+
+	private static final long serialVersionUID = 1066874132817953168L;
+
+	/**
+	 * 同步请求组件
+	 */
+	private String component;
+
+	/**
+	 * 方法(反射调用)
+	 */
+	private String methodName;
+
+	public String getComponent() {
+		return component;
+	}
+
+	public void setComponent(String component) {
+		this.component = component;
+	}
+
+	public String getMethodName() {
+		return methodName;
+	}
+
+	public void setMethodName(String methodName) {
+		this.methodName = methodName;
+	}
+
+}

+ 5 - 0
examcloud-task-service/pom.xml

@@ -24,6 +24,11 @@
 			<artifactId>examcloud-core-examwork-api-client</artifactId>
 			<version>${examcloud.version}</version>
 		</dependency>
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.rmi</groupId>
+			<artifactId>examcloud-commons-api-client</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
 
 	</dependencies>
 </project>

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

@@ -1,53 +0,0 @@
-package cn.com.qmth.examcloud.task.service;
-
-import cn.com.qmth.examcloud.task.service.bean.CourseInfo;
-import cn.com.qmth.examcloud.task.service.bean.OrgInfo;
-import cn.com.qmth.examcloud.task.service.bean.SpecialtyInfo;
-import cn.com.qmth.examcloud.task.service.bean.StudentInfo;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年8月2日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public interface DataSyncService {
-
-	/**
-	 * 同步课程
-	 *
-	 * @author WANGWEI
-	 * @param info
-	 * @return
-	 */
-	void syncCourse(CourseInfo info);
-
-	/**
-	 * 同步机构
-	 *
-	 * @author WANGWEI
-	 * @param info
-	 * @return
-	 */
-	void syncOrg(OrgInfo info);
-
-	/**
-	 * 同步学生
-	 *
-	 * @author WANGWEI
-	 * @param info
-	 * @return
-	 */
-	void syncStudent(StudentInfo info);
-
-	/**
-	 * 同步专业
-	 *
-	 * @author WANGWEI
-	 * @param info
-	 * @return
-	 */
-	void syncSpecialty(SpecialtyInfo info);
-
-}

+ 0 - 76
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/bean/CourseInfo.java

@@ -1,76 +0,0 @@
-package cn.com.qmth.examcloud.task.service.bean;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年8月2日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class CourseInfo implements JsonSerializable {
-
-	private static final long serialVersionUID = -1031140605770551820L;
-
-	private Long id;
-
-	private String code;
-
-	private String name;
-
-	private Long rootOrgId;
-
-	private String level;
-
-	private Boolean enable;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public String getCode() {
-		return code;
-	}
-
-	public void setCode(String code) {
-		this.code = code;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-
-	public String getLevel() {
-		return level;
-	}
-
-	public void setLevel(String level) {
-		this.level = level;
-	}
-
-	public Boolean getEnable() {
-		return enable;
-	}
-
-	public void setEnable(Boolean enable) {
-		this.enable = enable;
-	}
-
-}

+ 0 - 69
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/bean/OrgInfo.java

@@ -1,69 +0,0 @@
-package cn.com.qmth.examcloud.task.service.bean;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
-
-public class OrgInfo implements JsonSerializable {
-
-	private static final long serialVersionUID = -2104134978729044084L;
-
-	private Long id;
-
-	private Long rootId;
-
-	private Long parentId;
-
-	private Integer level;
-
-	private String name;
-
-	private Boolean enable;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public Long getRootId() {
-		return rootId;
-	}
-
-	public void setRootId(Long rootId) {
-		this.rootId = rootId;
-	}
-
-	public Long getParentId() {
-		return parentId;
-	}
-
-	public void setParentId(Long parentId) {
-		this.parentId = parentId;
-	}
-
-	public Integer getLevel() {
-		return level;
-	}
-
-	public void setLevel(Integer level) {
-		this.level = level;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public Boolean getEnable() {
-		return enable;
-	}
-
-	public void setEnable(Boolean enable) {
-		this.enable = enable;
-	}
-
-}

+ 0 - 59
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/bean/SpecialtyInfo.java

@@ -1,59 +0,0 @@
-package cn.com.qmth.examcloud.task.service.bean;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.BaseRequest;
-
-public class SpecialtyInfo extends BaseRequest {
-
-	private static final long serialVersionUID = 1668418232494824050L;
-
-	private Long id;
-
-	private String code;
-
-	private String name;
-
-	private Long rootOrgId;
-
-	private Boolean enable;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public String getCode() {
-		return code;
-	}
-
-	public void setCode(String code) {
-		this.code = code;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-
-	public Boolean getEnable() {
-		return enable;
-	}
-
-	public void setEnable(Boolean enable) {
-		this.enable = enable;
-	}
-
-}

+ 0 - 165
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/bean/StudentInfo.java

@@ -1,165 +0,0 @@
-package cn.com.qmth.examcloud.task.service.bean;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
-
-public class StudentInfo implements JsonSerializable  {
-
-	private static final long serialVersionUID = -8613202479412809385L;
-
-	/**
-	 * 学生ID
-	 */
-	private Long id;
-
-	/**
-	 * 学生姓名
-	 */
-	private String name;
-
-	/**
-	 * 顶级机构ID
-	 */
-	private Long rootOrgId;
-
-	/**
-	 * 机构ID
-	 */
-	private Long orgId;
-
-	/**
-	 * 学习中心编码
-	 */
-	private String orgCode;
-
-	/**
-	 * 学习中心名称
-	 */
-	private String orgName;
-
-	/**
-	 * 学生code
-	 */
-	private String studentCode;
-
-	/**
-	 * 身份证号码
-	 */
-	private String identityNumber;
-
-	/**
-	 * 图片地址
-	 */
-	private String photoPath;
-
-	/**
-	 * 手机号码
-	 */
-	private String phoneNumber;
-
-	/**
-	 * 是否可用
-	 */
-	private Boolean enable;
-
-	/**
-	 * 安全手机号码(用于登录)
-	 */
-	private String securityPhone;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-
-	public Long getOrgId() {
-		return orgId;
-	}
-
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-
-	public String getOrgCode() {
-		return orgCode;
-	}
-
-	public void setOrgCode(String orgCode) {
-		this.orgCode = orgCode;
-	}
-
-	public String getOrgName() {
-		return orgName;
-	}
-
-	public void setOrgName(String orgName) {
-		this.orgName = orgName;
-	}
-
-	public String getStudentCode() {
-		return studentCode;
-	}
-
-	public void setStudentCode(String studentCode) {
-		this.studentCode = studentCode;
-	}
-
-	public String getIdentityNumber() {
-		return identityNumber;
-	}
-
-	public void setIdentityNumber(String identityNumber) {
-		this.identityNumber = identityNumber;
-	}
-
-	public String getPhotoPath() {
-		return photoPath;
-	}
-
-	public void setPhotoPath(String photoPath) {
-		this.photoPath = photoPath;
-	}
-
-	public String getPhoneNumber() {
-		return phoneNumber;
-	}
-
-	public void setPhoneNumber(String phoneNumber) {
-		this.phoneNumber = phoneNumber;
-	}
-
-	public Boolean getEnable() {
-		return enable;
-	}
-
-	public void setEnable(Boolean enable) {
-		this.enable = enable;
-	}
-
-	public String getSecurityPhone() {
-		return securityPhone;
-	}
-
-	public void setSecurityPhone(String securityPhone) {
-		this.securityPhone = securityPhone;
-	}
-
-}

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

@@ -1,45 +0,0 @@
-package cn.com.qmth.examcloud.task.service.impl;
-
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.task.service.DataSyncService;
-import cn.com.qmth.examcloud.task.service.bean.CourseInfo;
-import cn.com.qmth.examcloud.task.service.bean.OrgInfo;
-import cn.com.qmth.examcloud.task.service.bean.SpecialtyInfo;
-import cn.com.qmth.examcloud.task.service.bean.StudentInfo;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年8月2日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Service("dataSyncService")
-public class DataSyncServiceImpl implements DataSyncService {
-
-	@Override
-	public void syncCourse(CourseInfo info) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void syncOrg(OrgInfo info) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void syncStudent(StudentInfo info) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void syncSpecialty(SpecialtyInfo info) {
-		// TODO Auto-generated method stub
-
-	}
-
-}

+ 30 - 0
examcloud-task-starter/src/main/java/cn/com/qmth/examcloud/task/starter/config/PropertiesConfig.java

@@ -0,0 +1,30 @@
+package cn.com.qmth.examcloud.task.starter.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.event.ContextRefreshedEvent;
+
+import cn.com.qmth.examcloud.commons.base.util.PathUtil;
+import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
+
+/**
+ * 属性配置
+ *
+ * @author WANGWEI
+ * @date 2018年6月21日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Configuration
+public class PropertiesConfig implements ApplicationListener<ContextRefreshedEvent> {
+
+	@Value("${spring.profiles.active}")
+	private String springProfilesActive;
+
+	@Override
+	public void onApplicationEvent(ContextRefreshedEvent event) {
+		String resourceName = "application-" + springProfilesActive + ".properties";
+		PropertiesUtil.configureAndWatch(PathUtil.getResoucePath(resourceName));
+	}
+
+}

+ 5 - 1
examcloud-task-starter/src/main/resources/application-dev.properties

@@ -9,4 +9,8 @@ eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
 
 
 $tempDir=D:/Temp/tempDir
-$dir=D:/Temp/dir
+$dir=D:/Temp/dir
+
+
+$sync.syncStudent.group=EXAMWORK
+$sync.syncStudent.component.EXAMWORK=http://EC-CORE-EXAMWORK/api/core/examwork/sync/syncStudent