|
@@ -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;
|
|
|
}
|
|
|
|