Commit 5287c0627c63acb177406e6014d2a8309c60c243

Authored by 504987307@qq.com
1 parent bb8cc5dd
Exists in master

翼学云 数据同步到 慧校园

cloud/quartz/src/main/java/com/sincere/quartz/datasource/DataSourceConfig.java
... ... @@ -29,6 +29,12 @@ public class DataSourceConfig {
29 29 return DataSourceBuilder.create().build();
30 30 }
31 31  
  32 + @Bean(name = "yxy")
  33 + @ConfigurationProperties(prefix = "datasource.yxy")
  34 + public DataSource dataSource3() {
  35 + return DataSourceBuilder.create().build();
  36 + }
  37 +
32 38  
33 39 @Bean(name="dynamicDataSource")
34 40 @Primary //优先使用,多数据源
... ... @@ -36,12 +42,14 @@ public class DataSourceConfig {
36 42 DynamicDataSource dynamicDataSource = new DynamicDataSource();
37 43 DataSource master = dataSource1();
38 44 DataSource slave = dataSource2();
  45 + DataSource yxy = dataSource3();
39 46 //设置默认数据源
40 47 dynamicDataSource.setDefaultTargetDataSource(master);
41 48 //配置多数据源
42 49 Map<Object,Object> map = new HashMap<>();
43 50 map.put(DataSourceType.Master.getName(), master); //key需要跟ThreadLocal中的值对应
44 51 map.put(DataSourceType.Slave.getName(), slave);
  52 + map.put(DataSourceType.Yxy.getName(), yxy);
45 53 dynamicDataSource.setTargetDataSources(map);
46 54 return dynamicDataSource;
47 55 }
... ...
cloud/quartz/src/main/java/com/sincere/quartz/datasource/DataSourceType.java
... ... @@ -4,7 +4,9 @@ public enum DataSourceType {
4 4  
5 5 Master("master"),
6 6  
7   - Slave("slave");
  7 + Slave("slave"),
  8 +
  9 + Yxy("yxy");
8 10  
9 11  
10 12 private String name;
... ...
cloud/quartz/src/main/java/com/sincere/quartz/datasource/DynamicDataSource.java
1 1 package com.sincere.quartz.datasource;
2 2  
3   -import org.slf4j.Logger;
4   -import org.slf4j.LoggerFactory;
5 3 import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
6 4  
7 5 /**
... ... @@ -9,11 +7,8 @@ import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
9 7 */
10 8 public class DynamicDataSource extends AbstractRoutingDataSource {
11 9  
12   - private Logger logger = LoggerFactory.getLogger(this.getClass());
13   -
14 10 @Override
15 11 protected Object determineCurrentLookupKey() {
16   - logger.info("数据源为{}",JdbcContextHolder.getDataSource());
17 12 return JdbcContextHolder.getDataSource();
18 13 }
19 14  
... ...
cloud/quartz/src/main/java/com/sincere/quartz/job/BindPushJob.java
... ... @@ -28,7 +28,7 @@ import java.util.Map;
28 28 @Service
29 29 public class BindPushJob {
30 30  
31   - private Logger logger = LoggerFactory.getLogger(KQJob.class);
  31 + private Logger logger = LoggerFactory.getLogger(BindPushJob.class);
32 32  
33 33  
34 34 @Autowired
... ...
cloud/quartz/src/main/java/com/sincere/quartz/job/SyncJob.java
... ... @@ -23,7 +23,7 @@ public class SyncJob {
23 23 @Scheduled(cron = "0 0 23 * * ? ")
24 24 public void Sync(){
25 25 //翼校通的同步 之后还有钉钉的同步等等
26   - yxyWriteService.sync();
27   - //yxyReadService.sync();
  26 + yxyWriteService.sync();
  27 + yxyReadService.sync();
28 28 }
29 29 }
... ...
cloud/quartz/src/main/java/com/sincere/quartz/mapper/YxyMapper.java 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +package com.sincere.quartz.mapper;
  2 +
  3 +import com.sincere.quartz.model.YxyAgency;
  4 +import com.sincere.quartz.model.YxyStudent;
  5 +import com.sincere.quartz.model.YxyTeacher;
  6 +
  7 +public interface YxyMapper {
  8 +
  9 + int updateAgency() ;
  10 +
  11 + int updateTeacher() ;
  12 +
  13 + int updateStudent() ;
  14 +
  15 + int insertAgency(YxyAgency agency) ;
  16 +
  17 + int insertTeacher(YxyTeacher teacher) ;
  18 +
  19 + int insertStudent(YxyStudent student) ;
  20 +}
... ...
cloud/quartz/src/main/java/com/sincere/quartz/model/YxyAgency.java 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +package com.sincere.quartz.model;
  2 +
  3 +public class YxyAgency {
  4 +
  5 + private String deptId ;
  6 + private String deptName ;
  7 + private String superDeptId ;
  8 +
  9 + public String getDeptId() {
  10 + return deptId;
  11 + }
  12 +
  13 + public void setDeptId(String deptId) {
  14 + this.deptId = deptId;
  15 + }
  16 +
  17 + public String getDeptName() {
  18 + return deptName;
  19 + }
  20 +
  21 + public void setDeptName(String deptName) {
  22 + this.deptName = deptName;
  23 + }
  24 +
  25 + public String getSuperDeptId() {
  26 + return superDeptId;
  27 + }
  28 +
  29 + public void setSuperDeptId(String superDeptId) {
  30 + this.superDeptId = superDeptId;
  31 + }
  32 +}
... ...
cloud/quartz/src/main/java/com/sincere/quartz/model/YxyStudent.java 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +package com.sincere.quartz.model;
  2 +
  3 +public class YxyStudent {
  4 +
  5 + private String userId ;
  6 + private String classId ;
  7 + private String name ;
  8 + private String account ;
  9 +
  10 + public String getUserId() {
  11 + return userId;
  12 + }
  13 +
  14 + public void setUserId(String userId) {
  15 + this.userId = userId;
  16 + }
  17 +
  18 + public String getClassId() {
  19 + return classId;
  20 + }
  21 +
  22 + public void setClassId(String classId) {
  23 + this.classId = classId;
  24 + }
  25 +
  26 + public String getName() {
  27 + return name;
  28 + }
  29 +
  30 + public void setName(String name) {
  31 + this.name = name;
  32 + }
  33 +
  34 + public String getAccount() {
  35 + return account;
  36 + }
  37 +
  38 + public void setAccount(String account) {
  39 + this.account = account;
  40 + }
  41 +}
... ...
cloud/quartz/src/main/java/com/sincere/quartz/model/YxyTeacher.java 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +package com.sincere.quartz.model;
  2 +
  3 +public class YxyTeacher {
  4 +
  5 + private String userId ;
  6 + private String account ;
  7 + private String name ;
  8 + private String deptId ;
  9 +
  10 + public String getUserId() {
  11 + return userId;
  12 + }
  13 +
  14 + public void setUserId(String userId) {
  15 + this.userId = userId;
  16 + }
  17 +
  18 + public String getAccount() {
  19 + return account;
  20 + }
  21 +
  22 + public void setAccount(String account) {
  23 + this.account = account;
  24 + }
  25 +
  26 + public String getName() {
  27 + return name;
  28 + }
  29 +
  30 + public void setName(String name) {
  31 + this.name = name;
  32 + }
  33 +
  34 + public String getDeptId() {
  35 + return deptId;
  36 + }
  37 +
  38 + public void setDeptId(String deptId) {
  39 + this.deptId = deptId;
  40 + }
  41 +}
... ...
cloud/quartz/src/main/java/com/sincere/quartz/service/YxyService.java 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +package com.sincere.quartz.service;
  2 +
  3 +import com.sincere.quartz.model.YxyAgency;
  4 +import com.sincere.quartz.model.YxyStudent;
  5 +import com.sincere.quartz.model.YxyTeacher;
  6 +
  7 +public interface YxyService {
  8 +
  9 + int updateAgency() ;
  10 +
  11 + int updateTeacher() ;
  12 +
  13 + int updateStudent() ;
  14 +
  15 + int insertAgency(YxyAgency agency) ;
  16 +
  17 + int insertTeacher(YxyTeacher teacher) ;
  18 +
  19 + int insertStudent(YxyStudent student) ;
  20 +}
... ...
cloud/quartz/src/main/java/com/sincere/quartz/service/impl/YxyServiceImpl.java 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +package com.sincere.quartz.service.impl;
  2 +
  3 +import com.sincere.quartz.datasource.DataSourceType;
  4 +import com.sincere.quartz.datasource.MyDataSource;
  5 +import com.sincere.quartz.mapper.YxyMapper;
  6 +import com.sincere.quartz.model.YxyAgency;
  7 +import com.sincere.quartz.model.YxyStudent;
  8 +import com.sincere.quartz.model.YxyTeacher;
  9 +import com.sincere.quartz.service.YxyService;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Service;
  12 +
  13 +@Service
  14 +public class YxyServiceImpl implements YxyService {
  15 +
  16 + @Autowired
  17 + YxyMapper yxyMapper ;
  18 +
  19 + @Override
  20 + @MyDataSource(DataSourceType.Yxy)
  21 + public int updateAgency() {
  22 + return yxyMapper.updateAgency();
  23 + }
  24 +
  25 + @Override
  26 + @MyDataSource(DataSourceType.Yxy)
  27 + public int updateTeacher() {
  28 + return yxyMapper.updateTeacher();
  29 + }
  30 +
  31 + @Override
  32 + @MyDataSource(DataSourceType.Yxy)
  33 + public int updateStudent() {
  34 + return yxyMapper.updateStudent();
  35 + }
  36 +
  37 + @Override
  38 + @MyDataSource(DataSourceType.Yxy)
  39 + public int insertAgency(YxyAgency agency) {
  40 + return yxyMapper.insertAgency(agency);
  41 + }
  42 +
  43 + @Override
  44 + @MyDataSource(DataSourceType.Yxy)
  45 + public int insertTeacher(YxyTeacher teacher) {
  46 + return yxyMapper.insertTeacher(teacher);
  47 + }
  48 +
  49 + @Override
  50 + @MyDataSource(DataSourceType.Yxy)
  51 + public int insertStudent(YxyStudent student) {
  52 + return yxyMapper.insertStudent(student);
  53 + }
  54 +}
... ...
cloud/quartz/src/main/java/com/sincere/quartz/third/yixueyun/YXYReadService.java
... ... @@ -6,6 +6,10 @@ import com.sincere.common.util.DateUtils;
6 6 import com.sincere.common.util.HttpClientUtils;
7 7 import com.sincere.common.util.Xml2JsonUtils;
8 8 import com.sincere.quartz.feign.ScFeign;
  9 +import com.sincere.quartz.model.YxyAgency;
  10 +import com.sincere.quartz.model.YxyStudent;
  11 +import com.sincere.quartz.model.YxyTeacher;
  12 +import com.sincere.quartz.service.YxyService;
9 13 import org.apache.commons.lang3.StringUtils;
10 14 import org.springframework.beans.factory.annotation.Autowired;
11 15 import org.springframework.stereotype.Service;
... ... @@ -32,45 +36,113 @@ public class YXYReadService {
32 36 private static String getALlStudent_method = "getStudentInfo";
33 37 private static String getAddStudent = "http://122.229.30.149:8282/DataSynService/GetIncrementStudentInfo" ;
34 38 private static String getAddStudent_method = "getIncrementStudentInfo" ;
35   -
36 39 private static String getAllDept = "http://122.229.30.149:8282/DataSynService/GetDeptInfo" ;
37 40 private static String getALlDept_method = "getDeptInfo";
38 41  
39 42 @Autowired
40   - ScFeign scFeign ;
  43 + YxyService yxyService ;
41 44  
42 45 public void sync(){
  46 + List<String> areaCodeList = new ArrayList<>();
  47 + areaCodeList.add("0571") ;
  48 + areaCodeList.add("0572") ;
  49 + areaCodeList.add("0573") ;
  50 + areaCodeList.add("0574") ;
  51 + areaCodeList.add("0575") ;
  52 + areaCodeList.add("0576") ;
  53 + areaCodeList.add("0577") ;
  54 + areaCodeList.add("0578") ;
  55 + areaCodeList.add("0579") ;
  56 + areaCodeList.add("0580") ;
  57 +
  58 + yxyService.updateAgency();
  59 + yxyService.updateStudent();
  60 + yxyService.updateTeacher();
  61 + for(String areaCode : areaCodeList){
  62 + // 先获取学校,部门,年级 班级
  63 + // 再根据学校 获取老师 学生
  64 + List list = new ArrayList();
  65 + list.add(SI);
  66 + list.add(getPassword(SI_CODE));
  67 + list.add(areaCode);
  68 + String wsdl =getAllDept ;
  69 + String ns = nameSpace;
  70 + String method = getALlDept_method;
  71 + JSONArray jsonArray = getMessage(wsdl, ns, method, list);
  72 + if(jsonArray != null){
  73 + List<String> schoolList = new ArrayList<>();
  74 + for(int i = 0 ; i < jsonArray.size() ; i++){
  75 + JSONObject object = (JSONObject) jsonArray.get(i) ;
  76 + YxyAgency agency = new YxyAgency() ;
  77 + agency.setDeptId(object.get("deptID").toString());
  78 + agency.setDeptName(object.get("deptName").toString());
  79 + agency.setSuperDeptId(object.get("superDeptID").toString());
  80 + if(areaCode.equals(object.get("superDeptID").toString())){
  81 + schoolList.add(object.get("deptID").toString()) ;
  82 + }
  83 + yxyService.insertAgency(agency);
  84 + }
  85 + for(String schoolId : schoolList){
  86 + syncTeacher(schoolId) ;
  87 + syncStudent(schoolId) ;
  88 + }
  89 + }
  90 + }
  91 + }
  92 +
  93 +
  94 + private void syncStudent(String schoolId){
43 95 List list = new ArrayList();
44 96 list.add(SI);
45 97 list.add(getPassword(SI_CODE));
46   - list.add("05750400");
47   - String wsdl =getAllTeacher ;
  98 + list.add(schoolId);
  99 + String wsdl =getAllStudent ;
48 100 String ns = nameSpace;
49   - String method = getAllTeacher_method;
  101 + String method = getALlStudent_method;
50 102 JSONArray jsonArray = getMessage(wsdl, ns, method, list);
51   - System.out.println(jsonArray.toJSONString());
52   - }
53   -
54   - private void syncDept(){
55   -
56   - }
57   -
58   - private void syncTeacher(){
59   -
  103 + if(jsonArray != null){
  104 + for(int i = 0 ; i < jsonArray.size() ; i++){
  105 + JSONObject object = (JSONObject) jsonArray.get(i) ;
  106 + YxyStudent student = new YxyStudent();
  107 + student.setClassId(object.get("classID").toString());
  108 + student.setAccount(object.get("account").toString());
  109 + student.setName(object.get("name").toString());
  110 + student.setUserId(object.get("userID").toString());
  111 + yxyService.insertStudent(student);
  112 + }
  113 + }
60 114 }
61 115  
62   - private void syncStudent(){
63   -
  116 + private void syncTeacher(String schoolId){
  117 + List list = new ArrayList();
  118 + list.add(SI);
  119 + list.add(getPassword(SI_CODE));
  120 + list.add(schoolId);
  121 + String wsdl =getAllTeacher ;
  122 + String ns = nameSpace;
  123 + String method = getAllTeacher_method;
  124 + JSONArray jsonArray = getMessage(wsdl, ns, method, list);
  125 + if(jsonArray != null){
  126 + for(int i = 0 ; i < jsonArray.size() ; i++){
  127 + JSONObject object = (JSONObject) jsonArray.get(i) ;
  128 + YxyTeacher teacher = new YxyTeacher();
  129 + teacher.setDeptId(object.get("classID").toString());
  130 + teacher.setAccount(object.get("account").toString());
  131 + teacher.setName(object.get("name").toString());
  132 + teacher.setUserId(object.get("userID").toString());
  133 + yxyService.insertTeacher(teacher);
  134 + }
  135 + }
64 136 }
65 137  
66 138 private JSONArray getMessage(String wsdl, String ns, String method, List<String> list){
67 139 String resultXml = HttpClientUtils.invoiceWebService(wsdl,ns,method,list);
68 140 if(StringUtils.isNotBlank(resultXml)){
69   - int begin = resultXml.indexOf("&lt;JXT");
70   - int end = resultXml.indexOf("&lt;/JXT");
71   - String str = resultXml.substring(begin, end+9);
72   - str = str.replaceAll("&lt;", "<");
73   - str = str.replaceAll("&gt;", ">");
  141 + resultXml = resultXml.replaceAll("&lt;", "<");
  142 + resultXml = resultXml.replaceAll("&gt;", ">");
  143 + int begin = resultXml.indexOf("<JXT");
  144 + int end = resultXml.indexOf("</JXT");
  145 + String str = resultXml.substring(begin, end+6);
74 146 JSONObject json = Xml2JsonUtils.xml2Json(str);
75 147 if(json != null){
76 148 return (JSONArray)json.get("resultInfo") ;
... ...
cloud/quartz/src/main/resources/application.yaml
... ... @@ -16,6 +16,14 @@ datasource:
16 16 password: qaz!@#0401
17 17 jdbcUrl: jdbc:sqlserver://60.190.202.38:49469;database=XST
18 18 driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
  19 + yxy: ## 翼学云
  20 + username: szyxt
  21 + password: QWer123$%^
  22 + jdbcUrl: jdbc:sqlserver://47.110.50.251,33419;database=SZYXT
  23 +# username: SZJXTUSER
  24 +# password: xst200919
  25 +# jdbcUrl: jdbc:sqlserver://60.190.202.57:14333;database=SZYXT
  26 + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
19 27 ##mybatis
20 28 mybatis:
21 29 mapper-locations: classpath:mapper/*.xml
... ...
cloud/quartz/src/main/resources/mapper/YxyMapper.xml 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.sincere.quartz.mapper.YxyMapper">
  4 +
  5 + <update id="updateAgency" >
  6 + update Agency set state = 0 where state = 1
  7 + </update>
  8 +
  9 + <update id="updateTeacher">
  10 + update Teacher set state = 0 where state = 1
  11 + </update>
  12 +
  13 + <update id="updateStudent">
  14 + update Student set state = 0 where state = 1
  15 + </update>
  16 +
  17 +
  18 + <insert id="insertAgency" parameterType="com.sincere.quartz.model.YxyAgency" >
  19 + insert into Agency(deptID , deptName , superDeptID , intime , state)
  20 + values (#{deptId} , #{deptName} , #{superDeptId} , GETDATE() , 1)
  21 + </insert>
  22 +
  23 + <insert id="insertTeacher" parameterType="com.sincere.quartz.model.YxyTeacher" >
  24 + insert into Teacher(userID , account , name , deptID , intime , state)
  25 + values (#{userId} , #{account} , #{name} , #{deptId} , GETDATE() , 1)
  26 + </insert>
  27 +
  28 + <insert id="insertStudent" parameterType="com.sincere.quartz.model.YxyStudent" >
  29 + insert into Student(userID , account , name , classID , intime , state , isCard , isEquipment , card_crafts)
  30 + values (#{userId} , #{account} , #{name} , #{classId} , GETDATE() , 1 ,0,0,2)
  31 + </insert>
  32 +</mapper>
... ...