Commit 99c7f47671a134c2234a60014f5a7f703deaf857
1 parent
96b7db9e7b
Exists in
master
and in
6 other branches
孕妇学校
Showing 4 changed files with 69 additions and 7 deletions
- platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/SyncDataService.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientCourseFacade.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MysqlDataInterceptor.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/SendMysqlSyncDatUtil.java
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/SyncDataService.java
View file @
99c7f47
... | ... | @@ -68,7 +68,7 @@ |
68 | 68 | |
69 | 69 | SyncDataModel model = new SyncDataModel(); |
70 | 70 | model.setStatus(1); |
71 | - model.setJsonData(JsonUtil.obj2JsonString(model)); | |
71 | + model.setJsonData(JsonUtil.obj2JsonString(syncMysqlDataModel)); | |
72 | 72 | model.setAction("POSTMYSQL"); |
73 | 73 | model.setCreated(new Date()); |
74 | 74 | model.setClassName("syncmysql"); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientCourseFacade.java
View file @
99c7f47
... | ... | @@ -412,6 +412,19 @@ |
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
415 | + PatientCourseQuery patientCourseQuery = new PatientCourseQuery(); | |
416 | + patientCourseQuery.setYn(YnEnums.YES.getId()); | |
417 | + //状态 1预约,2签到 | |
418 | + patientCourseQuery.setStatus(1); | |
419 | + patientCourseQuery.setId(patientCourseId); | |
420 | + List<PatientCourseModel> patientCourseModels = patientCourseService.queryPatientCourseList(patientCourseQuery); | |
421 | + if (!CollectionUtils.isNotEmpty(patientCourseModels)) | |
422 | + { | |
423 | + objectResponse.setErrorcode(ErrorCodeConstants.DATA_EXPIRE); | |
424 | + objectResponse.setErrormsg("您签到的课程还没有预约,请预约后签到!"); | |
425 | + return objectResponse; | |
426 | + } | |
427 | + | |
415 | 428 | if (patientCourseId != null) |
416 | 429 | { |
417 | 430 | PatientCourseModel model = new PatientCourseModel(); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/MysqlDataInterceptor.java
View file @
99c7f47
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | |
4 | 4 | import com.lyms.platform.biz.service.SyncDataService; |
5 | 5 | import com.lyms.platform.common.utils.ExceptionUtils; |
6 | +import com.lyms.platform.operate.web.utils.SendMysqlSyncDatUtil; | |
6 | 7 | import org.apache.commons.collections.CollectionUtils; |
7 | 8 | import org.apache.commons.lang.StringUtils; |
8 | 9 | import org.apache.ibatis.executor.Executor; |
... | ... | @@ -15,6 +16,7 @@ |
15 | 16 | import org.apache.ibatis.session.Configuration; |
16 | 17 | import org.apache.ibatis.type.TypeHandlerRegistry; |
17 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | +import org.springframework.context.annotation.Lazy; | |
18 | 20 | |
19 | 21 | import java.sql.Statement; |
20 | 22 | import java.text.DateFormat; |
... | ... | @@ -24,6 +26,7 @@ |
24 | 26 | * 眼科和听筛执行的sql保存下来 然后把区域执行的这些sql同步到线上执行 |
25 | 27 | * Created by Administrator on 2017-04-24. |
26 | 28 | */ |
29 | +@Lazy | |
27 | 30 | @Intercepts({ |
28 | 31 | @Signature(type = Executor.class, method = "update", args = { MappedStatement.class,Object.class }), |
29 | 32 | @Signature(type= ResultSetHandler.class, method = "handleResultSets", args = {Statement.class}) |
... | ... | @@ -76,8 +79,8 @@ |
76 | 79 | sql = getSql(configuration, boundSql, sqlId); |
77 | 80 | if (isSyncTable(sql)) |
78 | 81 | { |
79 | - System.out.println("==============delete or update sync sql = " + sql); | |
80 | - //syncDataService.savePostMysql(sql,sqlId); | |
82 | + System.out.println("delete or update sync sql = " + sql); | |
83 | + SendMysqlSyncDatUtil.addSqlToQueue1(sql,sqlId); | |
81 | 84 | sql = null; |
82 | 85 | |
83 | 86 | } |
... | ... | @@ -101,8 +104,8 @@ |
101 | 104 | { |
102 | 105 | List<Integer> list = (ArrayList)returnValue; |
103 | 106 | if (CollectionUtils.isNotEmpty(list)) { |
104 | - System.out.println("============add sync sql = " + sql); | |
105 | -// syncDataService.savePostMysql(sql,sqlId); | |
107 | + System.out.println("add sync sql = " + sql); | |
108 | + SendMysqlSyncDatUtil.addSqlToQueue1(sql,sqlId); | |
106 | 109 | sql = null; |
107 | 110 | } |
108 | 111 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/SendMysqlSyncDatUtil.java
View file @
99c7f47
1 | 1 | package com.lyms.platform.operate.web.utils; |
2 | 2 | |
3 | +import com.lyms.platform.biz.service.SyncDataService; | |
3 | 4 | import com.lyms.platform.common.utils.ExceptionUtils; |
4 | 5 | import com.lyms.platform.common.utils.JsonUtil; |
5 | 6 | import com.lyms.platform.common.utils.PropertiesUtils; |
... | ... | @@ -8,6 +9,7 @@ |
8 | 9 | import org.apache.commons.codec.binary.Base64; |
9 | 10 | import org.apache.commons.collections.CollectionUtils; |
10 | 11 | import org.springframework.beans.factory.InitializingBean; |
12 | +import org.springframework.beans.factory.annotation.Autowired; | |
11 | 13 | import org.springframework.stereotype.Component; |
12 | 14 | |
13 | 15 | import java.util.HashSet; |
14 | 16 | |
... | ... | @@ -23,7 +25,12 @@ |
23 | 25 | public class SendMysqlSyncDatUtil implements InitializingBean { |
24 | 26 | |
25 | 27 | |
28 | + | |
29 | + @Autowired | |
30 | + private SyncDataService syncDataService; | |
31 | + | |
26 | 32 | private static BlockingQueue<SqlRequest> syncSqlQueue = new LinkedBlockingQueue(200); |
33 | + private static BlockingQueue<SqlRequest> syncSqlQueue1 = new LinkedBlockingQueue(200); | |
27 | 34 | |
28 | 35 | //配置文件中配置的要同步的区域的url地址 |
29 | 36 | private static Set<String> urls = new HashSet<>(); |
... | ... | @@ -54,6 +61,16 @@ |
54 | 61 | System.out.println("syncSqlQueue size = " + syncSqlQueue.size()); |
55 | 62 | } |
56 | 63 | |
64 | + | |
65 | + public static void addSqlToQueue1(String sql ,String sqlId) | |
66 | + { | |
67 | + SqlRequest request = new SqlRequest(); | |
68 | + request.setSql(Base64.encodeBase64String(sql.getBytes())); | |
69 | + request.setSqlId(sqlId); | |
70 | + syncSqlQueue1.add(request); | |
71 | + System.out.println("syncSqlQueue1 size = " + syncSqlQueue.size()); | |
72 | + } | |
73 | + | |
57 | 74 | /** |
58 | 75 | * 初始化启动发送sql的线程 |
59 | 76 | * 线上才启动 |
60 | 77 | |
61 | 78 | |
62 | 79 | |
63 | 80 | |
... | ... | @@ -61,14 +78,18 @@ |
61 | 78 | */ |
62 | 79 | @Override |
63 | 80 | public void afterPropertiesSet() throws Exception { |
64 | - System.out.println("init ........."); | |
81 | + System.out.println("init sync sql thread........."); | |
65 | 82 | Thread thread = new HandleThread(); |
83 | + Thread thread1 = new HandleThread1(); | |
66 | 84 | thread.setName("syncMysqlThread"); |
85 | + thread1.setName("syncMysqlThread1"); | |
67 | 86 | thread.start(); |
87 | + thread1.start(); | |
68 | 88 | } |
69 | 89 | |
70 | 90 | |
71 | 91 | /** |
92 | + * 线上往区域同步时sql | |
72 | 93 | * 从队列中取出一个个取出来发送 |
73 | 94 | */ |
74 | 95 | private class HandleThread extends Thread { |
... | ... | @@ -99,7 +120,32 @@ |
99 | 120 | } |
100 | 121 | } |
101 | 122 | } catch (Exception e) { |
102 | - ExceptionUtils.catchException(e, "HandleThread thread error." + request); | |
123 | + syncSqlQueue.add(request); | |
124 | + ExceptionUtils.catchException(e, "HandleThread syncSqlQueue thread error." + request); | |
125 | + } | |
126 | + } | |
127 | + } | |
128 | + } | |
129 | + | |
130 | + | |
131 | + /** | |
132 | + * 区域同步的sql保存到同步表 然后线上把sql获取到在线上执行 | |
133 | + */ | |
134 | + private class HandleThread1 extends Thread { | |
135 | + | |
136 | + @Override | |
137 | + public void run() { | |
138 | + SqlRequest request = null; | |
139 | + while (true) { | |
140 | + try { | |
141 | + Thread.sleep(3000); | |
142 | + request = syncSqlQueue1.take(); | |
143 | + System.out.println(request); | |
144 | + syncDataService.savePostMysql(request.getSql(),request.getSqlId()); | |
145 | + | |
146 | + } catch (Exception e) { | |
147 | + syncSqlQueue1.add(request); | |
148 | + ExceptionUtils.catchException(e, "HandleThread syncSqlQueue1 thread error." + request); | |
103 | 149 | } |
104 | 150 | } |
105 | 151 | } |