Commit ede6deca8c860cb9ca958e578bb4fa6ae513f9bf
1 parent
508b247535
Exists in
master
and in
6 other branches
服务同步
Showing 2 changed files with 31 additions and 16 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java
View file @
ede6dec
... | ... | @@ -45,7 +45,6 @@ |
45 | 45 | import java.io.File; |
46 | 46 | import java.io.IOException; |
47 | 47 | import java.util.*; |
48 | -import java.util.concurrent.Future; | |
49 | 48 | |
50 | 49 | /** |
51 | 50 | * Created by Zhang.Rui on 2016/4/8. |
52 | 51 | |
53 | 52 | |
54 | 53 | |
55 | 54 | |
... | ... | @@ -148,23 +147,27 @@ |
148 | 147 | //排查本院隐藏建档 |
149 | 148 | patientsQuery.setExtEnable(false); |
150 | 149 | patientsQuery.setBuildTypeNot(1); |
150 | + // patientsQuery.setServiceType(ServiceTypeEnums.ADD_SERVICE.getId()); | |
151 | 151 | patientsQuery.setYn(YnEnums.YES.getId()); |
152 | 152 | patientsQuery.setType(1); |
153 | 153 | |
154 | 154 | int patientCount = patientsService.queryPatientCount(patientsQuery); |
155 | 155 | System.out.println("一共需要处理数据量:"+patientCount); |
156 | 156 | |
157 | - //预计开启5个线程处理,计算每个线程需要处理的数据量 | |
158 | - int batchSize = patientCount/5; | |
157 | + //计算每个线程需要处理的数据量,默认1000,必须是分页条数的倍数,不然多线程处理的数据会重复 | |
158 | + int batchSize = 1000; | |
159 | + if(patientCount>10000){ | |
160 | + batchSize = 10000; | |
161 | + } | |
162 | + | |
159 | 163 | int end = 0; |
160 | - List<Future> listFuture = new ArrayList<>(); | |
161 | 164 | for (int i = 0; i < patientCount; i += batchSize) { |
162 | 165 | end = (end + batchSize); |
163 | 166 | if (end > patientCount) { |
164 | - end = patientCount+1; | |
167 | + end = patientCount; | |
165 | 168 | } |
166 | 169 | System.out.println("线程处理数据量:"+i+"--至--"+end); |
167 | - listFuture.add(commonThreadPool.submit(new BuildSerToPatientSerWorker(i, end,patientsService,patientServiceService,isSkip,isZjzx,batchSize,patientCount))); | |
170 | + commonThreadPool.submit(new BuildSerToPatientSerWorker(i, end,patientsService,patientServiceService,isSkip,isZjzx,batchSize,patientCount)); | |
168 | 171 | } |
169 | 172 | |
170 | 173 | // for (Future f : listFuture) { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/BuildSerToPatientSerWorker.java
View file @
ede6dec
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | import com.lyms.platform.common.enums.ServiceStatusEnums; |
6 | 6 | import com.lyms.platform.common.enums.ServiceTypeEnums; |
7 | 7 | import com.lyms.platform.common.enums.YnEnums; |
8 | +import com.lyms.platform.common.utils.StringUtils; | |
8 | 9 | import com.lyms.platform.operate.web.utils.CollectionUtils; |
9 | 10 | import com.lyms.platform.permission.model.PatientService; |
10 | 11 | import com.lyms.platform.permission.model.PatientServiceQuery; |
11 | 12 | |
... | ... | @@ -12,7 +13,9 @@ |
12 | 13 | import com.lyms.platform.pojo.Patients; |
13 | 14 | import com.lyms.platform.query.PatientsQuery; |
14 | 15 | |
16 | +import java.util.HashMap; | |
15 | 17 | import java.util.List; |
18 | +import java.util.Map; | |
16 | 19 | import java.util.UUID; |
17 | 20 | import java.util.concurrent.Callable; |
18 | 21 | |
19 | 22 | |
20 | 23 | |
... | ... | @@ -54,16 +57,15 @@ |
54 | 57 | @Override |
55 | 58 | public Object call() { |
56 | 59 | try { |
60 | + Map<String,Integer> patientsMap = new HashMap<>(); | |
61 | + | |
57 | 62 | for (int i = startIndex; i < endIndex; i += batchSize) { |
58 | 63 | PatientsQuery patientsQuery = new PatientsQuery(); |
59 | - if(i+batchSize>endIndex){ | |
60 | - patientsQuery.setLimit(endIndex-i); | |
61 | - }else{ | |
62 | - patientsQuery.setLimit(batchSize); | |
63 | - } | |
64 | - System.out.println("总数据量:"+allCount+",正在处理第:" + i+"--到--"+(i+batchSize)+",limit:"+patientsQuery.getLimit()); | |
65 | - | |
64 | + patientsQuery.setLimit(batchSize); | |
66 | 65 | patientsQuery.setPage((i + batchSize) / batchSize); |
66 | + | |
67 | + System.out.println("总数据量:"+allCount+",正在处理第:" + i+"--到--"+(i+batchSize)+",page:"+patientsQuery.getPage()+",limit:"+patientsQuery.getLimit()); | |
68 | + | |
67 | 69 | //排查本院隐藏建档 |
68 | 70 | patientsQuery.setExtEnable(false); |
69 | 71 | patientsQuery.setBuildTypeNot(1); |
... | ... | @@ -73,6 +75,13 @@ |
73 | 75 | |
74 | 76 | List<Patients> patients = patientsService.queryPatient(patientsQuery); |
75 | 77 | for (Patients pt : patients) { |
78 | + if(StringUtils.isEmpty(pt.getId())){ | |
79 | + System.out.println("建档主键id为空:"+pt.getId()); | |
80 | + }else if(patientsMap.containsKey(pt.getId())){//存在 | |
81 | + System.out.println("重复的主键:"+pt.getId()); | |
82 | + }else{ | |
83 | + patientsMap.put(pt.getId(),1); | |
84 | + } | |
76 | 85 | if (pt.getServiceType() == null) { |
77 | 86 | System.out.println("跳过数据:"+pt.getId()); |
78 | 87 | continue; |
79 | 88 | |
... | ... | @@ -115,13 +124,13 @@ |
115 | 124 | convertPatient(pt, pser2); |
116 | 125 | //增值服务有服务医生 |
117 | 126 | pser2.setSerDoct(pt.getBookbuildingDoctor()); |
118 | - patientServiceService.addPatientService(pser2); | |
127 | + // patientServiceService.addPatientService(pser2); | |
119 | 128 | } |
120 | 129 | } else { |
121 | 130 | convertPatient(pt, pser2); |
122 | 131 | //增值服务有服务医生 |
123 | 132 | pser2.setSerDoct(pt.getBookbuildingDoctor()); |
124 | - patientServiceService.addPatientService(pser2); | |
133 | + // patientServiceService.addPatientService(pser2); | |
125 | 134 | } |
126 | 135 | } |
127 | 136 | } |
128 | 137 | |
129 | 138 | |
... | ... | @@ -134,14 +143,17 @@ |
134 | 143 | |
135 | 144 | List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery); |
136 | 145 | if (CollectionUtils.isNotEmpty(patientServices)) { |
146 | + System.out.println("增量查询数据存在:"+pt.getId()); | |
137 | 147 | continue; |
138 | 148 | } |
139 | 149 | } |
140 | 150 | //老数据服务标记 |
141 | - patientServiceService.addPatientService(pser); | |
151 | + // patientServiceService.addPatientService(pser); | |
142 | 152 | } |
143 | 153 | // System.out.println("endIndex:" + endIndex + "," + i + ":" + patients.size()); |
144 | 154 | } |
155 | + | |
156 | + System.out.println("线程处理数据完成,开始条数:"+startIndex+",结束条数:"+endIndex+",map:"+ patientsMap.size()); | |
145 | 157 | } catch (Exception e) { |
146 | 158 | e.printStackTrace(); |
147 | 159 | } |