Commit 3690b06b624d63bf2f84797032b924b26276773a

Authored by 陶汉栋
2 parents e92e5a92 88152d7c
Exists in master

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	cloud/quartz/src/main/java/com/sincere/quartz/job/SyncJob.java
#	cloud/quartz/src/main/java/com/sincere/quartz/mapper/YxyMapper.java
#	cloud/quartz/src/main/java/com/sincere/quartz/service/YxyService.java
#	cloud/quartz/src/main/java/com/sincere/quartz/third/yixueyun/YXYReadService.java
#	cloud/quartz/src/main/resources/mapper/YxyMapper.xml
cloud/quartz/src/main/java/com/sincere/quartz/job/SyncJob.java
... ... @@ -20,8 +20,8 @@ public class SyncJob {
20 20 @Autowired
21 21 YXYReadService yxyReadService;
22 22  
23   - @Scheduled(cron = "30 10 22 * * ? ")
24   - public void Sync() {
  23 + @Scheduled(cron = "30 1 22 * * ? ")
  24 + public void Sync(){
25 25 //翼校通的同步 之后还有钉钉的同步等等
26 26 yxyReadService.sync();
27 27 yxyWriteService.sync();
... ...
cloud/quartz/src/main/java/com/sincere/quartz/mapper/YxyMapper.java
... ... @@ -6,15 +6,19 @@ import com.sincere.quartz.model.YxyTeacher;
6 6  
7 7 public interface YxyMapper {
8 8  
9   - int updateAgency();
  9 + int selectCount(String date);
10 10  
11   - int updateTeacher();
  11 + int deleteWeekBefore();
12 12  
13   - int updateStudent();
  13 + int updateAgency() ;
14 14  
15   - int insertAgency(YxyAgency agency);
  15 + int updateTeacher() ;
16 16  
17   - int insertTeacher(YxyTeacher teacher);
  17 + int updateStudent() ;
18 18  
19   - int insertStudent(YxyStudent student);
  19 + int insertAgency(YxyAgency agency) ;
  20 +
  21 + int insertTeacher(YxyTeacher teacher) ;
  22 +
  23 + int insertStudent(YxyStudent student) ;
20 24 }
... ...
cloud/quartz/src/main/java/com/sincere/quartz/service/YxyService.java
... ... @@ -6,15 +6,19 @@ import com.sincere.quartz.model.YxyTeacher;
6 6  
7 7 public interface YxyService {
8 8  
9   - int updateAgency();
  9 + int selectCount(String date);
10 10  
11   - int updateTeacher();
  11 + int deleteWeekBefore();
12 12  
13   - int updateStudent();
  13 + int updateAgency() ;
14 14  
15   - int insertAgency(YxyAgency agency);
  15 + int updateTeacher() ;
16 16  
17   - int insertTeacher(YxyTeacher teacher);
  17 + int updateStudent() ;
18 18  
19   - int insertStudent(YxyStudent student);
  19 + int insertAgency(YxyAgency agency) ;
  20 +
  21 + int insertTeacher(YxyTeacher teacher) ;
  22 +
  23 + int insertStudent(YxyStudent student) ;
20 24 }
... ...
cloud/quartz/src/main/java/com/sincere/quartz/service/impl/YxyServiceImpl.java
... ... @@ -18,6 +18,18 @@ public class YxyServiceImpl implements YxyService {
18 18  
19 19 @Override
20 20 @MyDataSource(DataSourceType.Yxy)
  21 + public int selectCount(String date) {
  22 + return yxyMapper.selectCount(date);
  23 + }
  24 +
  25 + @Override
  26 + @MyDataSource(DataSourceType.Yxy)
  27 + public int deleteWeekBefore() {
  28 + return yxyMapper.deleteWeekBefore();
  29 + }
  30 +
  31 + @Override
  32 + @MyDataSource(DataSourceType.Yxy)
21 33 public int updateAgency() {
22 34 return yxyMapper.updateAgency();
23 35 }
... ...
cloud/quartz/src/main/java/com/sincere/quartz/third/yixueyun/YXYReadService.java
... ... @@ -27,75 +27,72 @@ import java.util.concurrent.TimeUnit;
27 27 @Service
28 28 public class YXYReadService {
29 29  
30   - private static String SI = "SZ";
31   - private static int SI_CODE = 12345678;
  30 + private static String SI = "SZ" ;
  31 + private static int SI_CODE = 12345678 ;
32 32  
33   - private static String nameSpace = "http://service.pubinfo.com.cn";
  33 + private static String nameSpace = "http://service.pubinfo.com.cn" ;
34 34 private static String getAllTeacher = "http://122.229.30.149:8282/DataSynService/GetTeacherInfo";
35   - private static String getAllTeacher_method = "getTeacherInfo";
36   - private static String getAddTeacher = "http://122.229.30.149:8282/DataSynService/GetIncrementTeacherInfo";
37   - private static String getAddTeacher_method = "getIncrementTeacherInfo";
  35 + private static String getAllTeacher_method = "getTeacherInfo" ;
  36 + private static String getAddTeacher = "http://122.229.30.149:8282/DataSynService/GetIncrementTeacherInfo" ;
  37 + private static String getAddTeacher_method = "getIncrementTeacherInfo" ;
38 38  
39   - private static String getAllStudent = "http://122.229.30.149:8282/DataSynService/GetStudentInfo";
  39 + private static String getAllStudent = "http://122.229.30.149:8282/DataSynService/GetStudentInfo" ;
40 40 private static String getALlStudent_method = "getStudentInfo";
41   - private static String getAddStudent = "http://122.229.30.149:8282/DataSynService/GetIncrementStudentInfo";
42   - private static String getAddStudent_method = "getIncrementStudentInfo";
43   - private static String getAllDept = "http://122.229.30.149:8282/DataSynService/GetDeptInfo";
  41 + private static String getAddStudent = "http://122.229.30.149:8282/DataSynService/GetIncrementStudentInfo" ;
  42 + private static String getAddStudent_method = "getIncrementStudentInfo" ;
  43 + private static String getAllDept = "http://122.229.30.149:8282/DataSynService/GetDeptInfo" ;
44 44 private static String getALlDept_method = "getDeptInfo";
45 45  
46 46 @Autowired
47   - YxyService yxyService;
  47 + YxyService yxyService ;
48 48  
49 49 private Logger logger = LoggerFactory.getLogger(YXYReadService.class);
50 50  
51   - public void sync() {
  51 + public void sync(){
52 52 ExecutorService pool = ThreadUtils.newFixedThreadPool(8);
53   - yxyService.updateAgency();
54   - yxyService.updateStudent();
55   - yxyService.updateTeacher();
56 53 List<String> areaCodeList = new ArrayList<>();
57   - areaCodeList.add("0571");
58   - areaCodeList.add("0572");
59   - areaCodeList.add("0573");
60   - areaCodeList.add("0574");
61   - areaCodeList.add("0575");
62   - areaCodeList.add("0576");
63   - areaCodeList.add("0577");
64   - areaCodeList.add("0578");
65   - areaCodeList.add("0579");
  54 + areaCodeList.add("0571") ;
  55 + areaCodeList.add("0572") ;
  56 + areaCodeList.add("0573") ;
  57 + areaCodeList.add("0574") ;
  58 + areaCodeList.add("0575") ;
  59 + areaCodeList.add("0576") ;
  60 + areaCodeList.add("0577") ;
  61 + areaCodeList.add("0578") ;
  62 + areaCodeList.add("0579") ;
66 63 List<String> schoolList = new ArrayList<>();
67   - for (String areaCode : areaCodeList) {
68   - try {
  64 + for(String areaCode : areaCodeList){
  65 + try{
69 66 // 先获取学校,部门,年级 班级
70 67 // 再根据学校 获取老师 学生
71 68 List list = new ArrayList();
72 69 list.add(SI);
73 70 list.add(getPassword(SI_CODE));
74 71 list.add(areaCode);
75   - String wsdl = getAllDept;
  72 + String wsdl =getAllDept ;
76 73 String ns = nameSpace;
77 74 String method = getALlDept_method;
78 75 JSONArray jsonArray = getMessage(wsdl, ns, method, list);
79   - if (jsonArray != null) {
  76 + if(jsonArray != null){
80 77 logger.info("市编码:" + areaCode);
81   - for (int i = 0; i < jsonArray.size(); i++) {
82   - JSONObject object = (JSONObject) jsonArray.get(i);
83   - YxyAgency agency = new YxyAgency();
  78 + for(int i = 0 ; i < jsonArray.size() ; i++){
  79 + JSONObject object = (JSONObject) jsonArray.get(i) ;
  80 + YxyAgency agency = new YxyAgency() ;
84 81 agency.setDeptId(object.get("deptID").toString());
85 82 agency.setDeptName(object.get("deptName").toString());
86 83 agency.setSuperDeptId(object.get("superDeptID").toString());
87   - if (areaCode.equals(object.get("superDeptID").toString())) {
88   - logger.info("学校:" + object.get("deptName").toString() + ";编码" + object.get("deptID").toString());
89   - schoolList.add(object.get("deptID").toString());
  84 + if(areaCode.equals(object.get("superDeptID").toString())){
  85 + logger.info("学校:" + object.get("deptName").toString() +";编码"+object.get("deptID").toString());
  86 + schoolList.add(object.get("deptID").toString()) ;
90 87 }
91 88 yxyService.insertAgency(agency);
92 89 }
93 90 }
94   - } catch (Exception e) {
  91 + }catch (Exception e){
95 92 e.printStackTrace();
96 93 }
97 94 }
98   - for (String schoolId : schoolList) {
  95 + for(String schoolId : schoolList){
99 96 pool.execute(initSchool(schoolId));
100 97 }
101 98 pool.shutdown();
... ... @@ -103,97 +100,108 @@ public class YXYReadService {
103 100 // 等待所有子线程结束,才退出主线程
104 101 }
105 102 logger.info("------------------当天更新完成");
  103 + try{
  104 + String today = DateUtils.getToday(DateUtils.format1)+" 22:00:00" ;
  105 + if(yxyService.selectCount(today) > 400000){
  106 + yxyService.deleteWeekBefore();
  107 + yxyService.updateAgency();
  108 + yxyService.updateStudent();
  109 + yxyService.updateTeacher();
  110 + }
  111 + }catch (Exception e){
  112 +
  113 + }
106 114 }
107 115  
108 116  
109   - private Runnable initSchool(String schoolId) {
  117 + private Runnable initSchool(String schoolId){
110 118 Runnable runnable = () -> {
111 119 syncStudent(schoolId);
112 120 syncTeacher(schoolId);
113 121 };
114   - return runnable;
  122 + return runnable ;
115 123 }
116 124  
117 125  
118   - public void syncStudent(String schoolId) {
119   - List list = new ArrayList();
120   - list.add(SI);
121   - list.add(getPassword(SI_CODE));
122   - list.add(schoolId);
123   - String wsdl = getAllStudent;
124   - String ns = nameSpace;
125   - String method = getALlStudent_method;
126   - JSONArray jsonArray = getMessage(wsdl, ns, method, list);
127   - try {
128   - logger.info("学校ID为:" + schoolId + "共有学生" + jsonArray.size() + "人");
129   - if (jsonArray != null) {
130   - for (int i = 0; i < jsonArray.size(); i++) {
131   - JSONObject object = (JSONObject) jsonArray.get(i);
  126 + public void syncStudent(String schoolId){
  127 + try{
  128 + List list = new ArrayList();
  129 + list.add(SI);
  130 + list.add(getPassword(SI_CODE));
  131 + list.add(schoolId);
  132 + String wsdl =getAllStudent ;
  133 + String ns = nameSpace;
  134 + String method = getALlStudent_method;
  135 + JSONArray jsonArray = getMessage(wsdl, ns, method, list);
  136 + logger.info("学校ID为:"+schoolId + "共有学生" + jsonArray.size() +"人");
  137 + if(jsonArray != null){
  138 + for(int i = 0 ; i < jsonArray.size() ; i++){
  139 + JSONObject object = (JSONObject) jsonArray.get(i) ;
132 140 YxyStudent student = new YxyStudent();
133   - try {
  141 + try{
134 142 student.setClassId(object.get("classID").toString());
135 143 student.setAccount(object.get("account").toString());
136 144 student.setName(object.get("name").toString());
137 145 student.setUserId(object.get("userID").toString());
138   - } catch (Exception e) {
  146 + }catch (Exception e){
139 147 }
140   - try {
  148 + try{
141 149 student.setCardID(object.get("cardID").toString());
142   - } catch (Exception e) {
  150 + }catch (Exception e){
143 151 }
144   - try {
  152 + try{
145 153 student.setCardID2(object.get("cardID2").toString());
146   - } catch (Exception e) {
  154 + }catch (Exception e){
147 155 }
148   - try {
  156 + try{
149 157 student.setCardID3(object.get("cardID3").toString());
150   - } catch (Exception e) {
  158 + }catch (Exception e){
151 159 }
152 160 yxyService.insertStudent(student);
153 161 }
154 162 }
155   - } catch (Exception e) {
  163 + }catch (Exception e){
156 164 logger.info(e.toString());
157   - logger.info("学校ID为:" + schoolId + "学生数据没返回");
  165 + logger.info("学校ID为:"+schoolId + "学生数据没返回");
158 166 }
159 167  
160 168 }
161 169  
162   - public void syncTeacher(String schoolId) {
163   - List list = new ArrayList();
164   - list.add(SI);
165   - list.add(getPassword(SI_CODE));
166   - list.add(schoolId);
167   - String wsdl = getAllTeacher;
168   - String ns = nameSpace;
169   - String method = getAllTeacher_method;
170   - JSONArray jsonArray = getMessage(wsdl, ns, method, list);
171   - try {
172   - logger.info("学校ID为:" + schoolId + "共有老师" + jsonArray.size() + "人");
173   - if (jsonArray != null) {
174   - for (int i = 0; i < jsonArray.size(); i++) {
175   - JSONObject object = (JSONObject) jsonArray.get(i);
  170 + public void syncTeacher(String schoolId){
  171 + try{
  172 + List list = new ArrayList();
  173 + list.add(SI);
  174 + list.add(getPassword(SI_CODE));
  175 + list.add(schoolId);
  176 + String wsdl =getAllTeacher ;
  177 + String ns = nameSpace;
  178 + String method = getAllTeacher_method;
  179 + JSONArray jsonArray = getMessage(wsdl, ns, method, list);
  180 + logger.info("学校ID为:"+schoolId + "共有老师" + jsonArray.size() +"人");
  181 + if(jsonArray != null){
  182 + for(int i = 0 ; i < jsonArray.size() ; i++){
  183 + JSONObject object = (JSONObject) jsonArray.get(i) ;
176 184 YxyTeacher teacher = new YxyTeacher();
177 185 try {
178 186 teacher.setDeptId(object.get("classID").toString());
179 187 teacher.setAccount(object.get("account").toString());
180 188 teacher.setName(object.get("name").toString());
181 189 teacher.setUserId(object.get("userID").toString());
182   - } catch (Exception e) {
  190 + }catch (Exception e){
183 191 }
184 192 yxyService.insertTeacher(teacher);
185 193 }
186 194 }
187   - } catch (Exception e) {
  195 + }catch (Exception e){
188 196 logger.info(e.toString());
189   - logger.info("学校ID为:" + schoolId + "老师数据没返回");
  197 + logger.info("学校ID为:"+schoolId + "老师数据没返回");
190 198 }
191 199  
192 200 }
193 201  
194   - private JSONArray getMessage(String wsdl, String ns, String method, List<String> list) {
195   - String resultXml = HttpClientUtils.invoiceWebService(wsdl, ns, method, list);
  202 + private JSONArray getMessage(String wsdl, String ns, String method, List<String> list){
196 203 try {
  204 + String resultXml = HttpClientUtils.invoiceWebService(wsdl,ns,method,list);
197 205 if (StringUtils.isNotBlank(resultXml)) {
198 206 resultXml = resultXml.replaceAll("&lt;", "<");
199 207 resultXml = resultXml.replaceAll("&gt;", ">");
... ... @@ -205,17 +213,17 @@ public class YXYReadService {
205 213 return (JSONArray) json.get("resultInfo");
206 214 }
207 215 }
208   - } catch (Exception e) {
209   - logger.info("获取信息报错" + e.getMessage());
  216 + }catch (Exception e){
  217 + logger.info("获取信息报错"+e.getMessage());
210 218 }
211   - return null;
  219 + return null ;
212 220 }
213 221  
214   - private String getPassword(int si) {
215   - int date = Integer.valueOf(DateUtils.date2String(new Date(), DateUtils.format5));
216   - String pwd = String.valueOf(si & date);
217   - while (pwd.length() < 6) {
218   - pwd = "0" + pwd;
  222 + private String getPassword(int si){
  223 + int date = Integer.valueOf(DateUtils.date2String(new Date(),DateUtils.format5));
  224 + String pwd = String.valueOf(si&date) ;
  225 + while (pwd.length() < 6){
  226 + pwd = "0" + pwd ;
219 227 }
220 228 pwd = pwd.substring(pwd.length() - 6);
221 229 return EncodeByMD5(pwd);
... ... @@ -237,9 +245,9 @@ public class YXYReadService {
237 245 }
238 246 }
239 247  
240   - private String fillMD5(String md5) {
  248 + private String fillMD5(String md5){
241 249 //如果不够32位则回调自身补零,最后返回32位长度的签名
242   - return md5.length() == 32 ? md5 : fillMD5("0" + md5);
  250 + return md5.length()==32?md5:fillMD5("0"+md5);
243 251 }
244 252  
245 253 }
246 254 \ No newline at end of file
... ...
cloud/quartz/src/main/resources/mapper/YxyMapper.xml
... ... @@ -2,32 +2,41 @@
2 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3 3 <mapper namespace="com.sincere.quartz.mapper.YxyMapper">
4 4  
5   - <update id="updateAgency">
6   - update Agency set state = 0 where state = 1
  5 +
  6 + <delete id="deleteWeekBefore" >
  7 + delete Agency where DATEDIFF(d,intime,GETDATE())>7;
  8 + delete Teacher where DATEDIFF(d,intime,GETDATE())>7;
  9 + delete Student where DATEDIFF(d,intime,GETDATE())>7;
  10 + </delete>
  11 +
  12 + <update id="updateAgency" >
  13 + update Agency set state = 0 where DATEDIFF(n , intime, getdate()) > 240
7 14 </update>
8 15  
9 16 <update id="updateTeacher">
10   - update Teacher set state = 0 where state = 1
  17 + update Teacher set state = 0 where DATEDIFF(n , intime, getdate()) > 240
11 18 </update>
12 19  
13 20 <update id="updateStudent">
14   - update Student set state = 0 where state = 1
  21 + update Student set state = 0 where DATEDIFF(n , intime, getdate()) > 240
15 22 </update>
16 23  
  24 + <select id="selectCount" parameterType="java.lang.String" resultType="java.lang.Integer">
  25 + select count(0) from Student where intime > #{date}
  26 + </select>
17 27  
18   - <insert id="insertAgency" parameterType="com.sincere.quartz.model.YxyAgency">
  28 + <insert id="insertAgency" parameterType="com.sincere.quartz.model.YxyAgency" >
19 29 insert into Agency(deptID , deptName , superDeptID , intime , state)
20   - values (#{deptId} , #{deptName} , #{superDeptId} , GETDATE() , 1)
  30 + values (#{deptId} , #{deptName} , #{superDeptId} , GETDATE() , 1)
21 31 </insert>
22 32  
23   - <insert id="insertTeacher" parameterType="com.sincere.quartz.model.YxyTeacher">
  33 + <insert id="insertTeacher" parameterType="com.sincere.quartz.model.YxyTeacher" >
24 34 insert into Teacher(userID , account , name , deptID , intime , state)
25   - values (#{userId} , #{account} , #{name} , #{deptId} , GETDATE() , 1)
  35 + values (#{userId} , #{account} , #{name} , #{deptId} , GETDATE() , 1)
26 36 </insert>
27 37  
28   - <insert id="insertStudent" parameterType="com.sincere.quartz.model.YxyStudent">
29   - insert into Student(userID , account , name , classID , intime , state , isCard , isEquipment ,
30   - card_crafts,cardID,cardid2,cardid3)
31   - values (#{userId} , #{account} , #{name} , #{classId} , GETDATE() , 1 ,0,0,2,#{cardID},#{cardID2},#{cardID3})
  38 + <insert id="insertStudent" parameterType="com.sincere.quartz.model.YxyStudent" >
  39 + insert into Student(userID , account , name , classID , intime , state , isCard , isEquipment , card_crafts,cardID,cardid2,cardid3)
  40 + values (#{userId} , #{account} , #{name} , #{classId} , GETDATE() , 1 ,0,0,2,#{cardID},#{cardID2},#{cardID3})
32 41 </insert>
33 42 </mapper>
... ...
cloud/search_xiaoan/src/main/resources/mapper/FingerMapper.xml
... ... @@ -9,7 +9,7 @@
9 9 </insert>
10 10  
11 11 <select id="selectFinger" parameterType="java.lang.Integer" resultType="java.lang.String">
12   - select order_msg from zk_finger where student_id = #{studentId}
  12 + select top 1 order_msg from zk_finger where student_id = #{studentId}
13 13 </select>
14 14  
15 15 </mapper>
16 16 \ No newline at end of file
... ...