Commit e5f07457ee7613c2a523b657c13b6bcae836fbe5
1 parent
ed2713a12c
Exists in
master
and in
6 other branches
oracle 数据源
Showing 4 changed files with 435 additions and 108 deletions
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/SaveByV2ThreadPoolFacade.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/FixedThreadPoolUtil.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/CorrectDataWorker2.java
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
View file @
e5f0745
... | ... | @@ -21,6 +21,8 @@ |
21 | 21 | import com.lyms.platform.operate.web.result.*; |
22 | 22 | import com.lyms.platform.operate.web.service.ITrackDownService; |
23 | 23 | import com.lyms.platform.operate.web.utils.JdbcUtil; |
24 | +import com.lyms.platform.operate.web.worker.CorrectDataWorker; | |
25 | +import com.lyms.platform.operate.web.worker.CorrectDataWorker2; | |
24 | 26 | import com.lyms.platform.permission.dao.master.CouponMapper; |
25 | 27 | import com.lyms.platform.permission.model.Organization; |
26 | 28 | import com.lyms.platform.permission.model.OrganizationQuery; |
... | ... | @@ -32,6 +34,8 @@ |
32 | 34 | import com.lyms.platform.pojo.*; |
33 | 35 | import com.lyms.platform.query.*; |
34 | 36 | import org.apache.commons.collections.CollectionUtils; |
37 | +import org.apache.commons.dbutils.QueryRunner; | |
38 | +import org.apache.commons.dbutils.handlers.BeanListHandler; | |
35 | 39 | import org.slf4j.Logger; |
36 | 40 | import org.slf4j.LoggerFactory; |
37 | 41 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -54,6 +58,7 @@ |
54 | 58 | import java.sql.*; |
55 | 59 | import java.util.*; |
56 | 60 | import java.util.Date; |
61 | +import java.util.concurrent.atomic.AtomicLong; | |
57 | 62 | |
58 | 63 | /** |
59 | 64 | * |
... | ... | @@ -171,6 +176,8 @@ |
171 | 176 | |
172 | 177 | @Autowired |
173 | 178 | private CdfyHisService cdfyHisService; |
179 | + @Autowired | |
180 | + private SaveByV2ThreadPoolFacade saveByV2ThreadPoolFacade; | |
174 | 181 | |
175 | 182 | public static final String syncToV2Url = PropertiesUtils.getPropertyValue("sync_to_v2_url"); |
176 | 183 | |
177 | 184 | |
178 | 185 | |
179 | 186 | |
... | ... | @@ -2362,33 +2369,42 @@ |
2362 | 2369 | * @return BaseResponse |
2363 | 2370 | */ |
2364 | 2371 | public BaseResponse saveByV2(SyncV2HistoryRequest param) { |
2365 | - | |
2366 | - | |
2367 | - // TODO 2019/6/5 15:01 dongqing 数据的效验,整理 | |
2368 | - RestTemplate restTemplate = new RestTemplate(); | |
2369 | - HttpHeaders headers = new HttpHeaders(); | |
2370 | - headers.setContentType(MediaType.APPLICATION_JSON); | |
2371 | - String startTime = param.getStartTime(); | |
2372 | - String endTime = param.getEndTime(); | |
2373 | - // TODO 2019/6/5 15:39 dongqing 分批次请求保存 | |
2374 | - | |
2372 | + //获取2.0历史建档数据 | |
2373 | + String startTime = param.getStartTime(); | |
2374 | + String endTime = param.getEndTime(); | |
2375 | 2375 | Connection connection = null; |
2376 | 2376 | try { |
2377 | 2377 | connection = getConnection(); |
2378 | - String sql = ""; | |
2379 | - PreparedStatement statement = connection.prepareStatement(sql); | |
2380 | - ResultSet resultSet = statement.executeQuery(); | |
2381 | - while (resultSet.next()) { | |
2382 | - String id = resultSet.getString("id"); | |
2383 | - String name = resultSet.getString("stu_name"); | |
2384 | - String gender = resultSet.getString("gender"); | |
2385 | - String age = resultSet.getString("age"); | |
2386 | - String address = resultSet.getString("address"); | |
2378 | + String sql = getSqlString(startTime, endTime); | |
2379 | + QueryRunner queryRunner = new QueryRunner(true); | |
2380 | + List<SyncV2HistoryRequest> lists = queryRunner.query(connection, sql, new BeanListHandler<SyncV2HistoryRequest>(SyncV2HistoryRequest.class)); | |
2381 | + // TODO 2019/6/5 15:39 dongqing 分批次请求保存,明天加上 | |
2382 | + | |
2383 | + | |
2384 | + if(CollectionUtils.isNotEmpty(lists)){ | |
2385 | + int batchSize = 400; | |
2386 | + int end = 0; | |
2387 | + java.util.concurrent.atomic.AtomicLong counter=new AtomicLong(); | |
2388 | + for (int i = 0; i < lists.size(); i += batchSize) { | |
2389 | + end = (end + batchSize); | |
2390 | + if (end > lists.size()) { | |
2391 | + end = lists.size(); | |
2392 | + } | |
2393 | +// commonThreadPool.submit(new CorrectDataWorker2(lists.subList(i, end),postReviewService,patientsService,anExService,antExFacade,counter)); | |
2394 | + } | |
2395 | +// logger.info("hand hospitalId :" +hospitalId+", update count "+counter.get()); | |
2387 | 2396 | } |
2388 | - }catch (Exception e){ | |
2389 | 2397 | |
2390 | - }finally { | |
2391 | - if (connection != null){ | |
2398 | +// for (SyncV2HistoryRequest list : lists) { | |
2399 | +// BaseObjectResponse p = addPregnantBookbuilding(list, null, false);//Integer.parseInt(list.getBookbuildingDoctor() | |
2400 | +// System.out.println(p.getData()); | |
2401 | +// } | |
2402 | + | |
2403 | + } catch (Exception e) { | |
2404 | + logger.info(e.getMessage()); | |
2405 | + return new BaseResponse().setErrorcode(ErrorCodeConstants.SYSTEM_ERROR).setErrormsg("系统异常"); | |
2406 | + } finally { | |
2407 | + if (connection != null) { | |
2392 | 2408 | try { |
2393 | 2409 | connection.close(); |
2394 | 2410 | } catch (SQLException e) { |
2395 | 2411 | |
2396 | 2412 | |
2397 | 2413 | |
... | ... | @@ -2396,95 +2412,58 @@ |
2396 | 2412 | } |
2397 | 2413 | } |
2398 | 2414 | } |
2415 | + return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); | |
2399 | 2416 | |
2400 | - // 孕妇体验类型 | |
2401 | - param.setExpType(-1); | |
2402 | - // 服务信息 | |
2403 | - param.setSerInfos(new ArrayList<Map<String, String>>()); | |
2404 | - // 证件类型 | |
2405 | - param.setPregnantCertificateTypeId(null); | |
2406 | - // 居住地 | |
2407 | - param.setPregnantCensusProvinceId(null); | |
2408 | - param.setPregnantCensusCityId(null); | |
2409 | - param.setPregnantCensusCityId(null); | |
2410 | - param.setPregnantCensusStreetId(null); | |
2417 | + } | |
2411 | 2418 | |
2412 | - // 国籍 | |
2413 | - param.setPregnantCountryId(null); | |
2414 | - // 丈夫国籍 | |
2415 | - param.setHusbandCountryId(null); | |
2416 | - // 丈夫 证件类型 | |
2417 | - param.setHusbandCertificateTypeId(null); | |
2418 | - // 民族 | |
2419 | - param.setPregnantNationId(null); | |
2420 | - // 丈夫民族 | |
2421 | - param.setHusbandNationId(null); | |
2422 | - // 建档医生 | |
2423 | - param.setBookbuildingDoctor(null); | |
2424 | - // 孕妇证件号 | |
2425 | - param.setPregnantCertificateNum(null); | |
2426 | - // 孕妇民族 | |
2427 | - param.setPregnantName(null); | |
2428 | - // 孕妇手机号 | |
2429 | - param.setPregnantPhone(null); | |
2430 | - | |
2431 | - param.setPregnantCensusAddr("这是居住地"); | |
2432 | - | |
2433 | - param.setPregnantLiveProvinceId(null); | |
2434 | - param.setPregnantLiveCityId(null); | |
2435 | - param.setPregnantLiveAreaId(null); | |
2436 | - param.setPregnantLiveStreetId(null); | |
2437 | - param.setPregnantLiveAddr("户籍地址"); | |
2438 | - | |
2439 | - param.setChildbirthProvinceId(null); | |
2440 | - param.setChildbirthCityId(null); | |
2441 | - param.setChildbirthAreaId(null); | |
2442 | - param.setChildbirthStreetId(null); | |
2443 | - param.setChildExtAddrs(new ArrayList<String>()); | |
2444 | - param.setChildbirthAddr("产后 休养地"); | |
2445 | - | |
2446 | - param.setHusbandName("产后大幅度"); | |
2447 | - // 丈夫证件号 | |
2448 | - param.setHusbandCertificateNum(null); | |
2449 | - // 丈夫生日 | |
2450 | - param.setHusbandBirth(null); | |
2451 | - | |
2452 | - // 丈夫户籍地址 | |
2453 | - param.setHusbandProvinceRegisterId(null); | |
2454 | - param.setHusbandCityRegisterId(null); | |
2455 | - param.setHusbandAreaRegisterId(null); | |
2456 | - param.setHusbandStreetRegisterId(null); | |
2457 | - param.setHusbandAddressRegister(null); | |
2458 | - | |
2459 | - // 就诊卡号 | |
2460 | - param.setVcCardNo(null); | |
2461 | - // 乡镇卫生机构id | |
2462 | - param.setTownOrgId(null); | |
2463 | - // 孕妇生日 | |
2464 | - param.setBirthday(null); | |
2465 | - // 末次月经 | |
2466 | - param.setLastMenstrualPeriod(null); | |
2467 | - // 预产期 | |
2468 | - param.setDueDate(null); | |
2469 | - // 建档日期 | |
2470 | - param.setBookbuildingDate(null); | |
2471 | - // 医院Id | |
2472 | - param.setHospitalId(null); | |
2473 | - // 服务状态 | |
2474 | - param.setServiceStatus(null); | |
2475 | - param.setServiceType(null); | |
2476 | - | |
2477 | - | |
2478 | - JSONObject jsonObject = new JSONObject(); | |
2479 | - String result = restTemplate.postForObject(syncToV2Url + "/wx/babyMeasureInfo/saveOrUpdate", jsonObject, String.class); | |
2480 | - | |
2481 | - | |
2482 | - | |
2483 | - | |
2484 | - return null; | |
2419 | + private String getSqlString(String startTime, String endTime) { | |
2420 | + return "SELECT " + | |
2421 | + "P_CARDTYPE as pregnantCertificateTypeId," +//证件类型 | |
2422 | + "P_ADDRESSPROVINCE as pregnantCensusProvinceId," +//居住地-省 | |
2423 | + "P_ADDRESSCITY as pregnantCensusCityId," +//居住地 -城市 | |
2424 | + "P_ADDRESSCOUNTY as pregnantCensusAreaId," +//居住地区 | |
2425 | + "P_ADDRESSSTREET as pregnantCensusStreetId," +//居住地 -街道 | |
2426 | + "P_COUNTRY as pregnantCountryId," +//国籍 | |
2427 | + "P_HUSBANDCOUNTRY as husbandCountryId," +//丈夫国籍 | |
2428 | + "P_HUSBANDCARDTYPE as husbandCertificateTypeId," +//丈夫证件类型 | |
2429 | + "P_NATION as pregnantNationId," +//民族 | |
2430 | + "P_HUSBANDNATION as husbandNationId," +//丈夫民族 | |
2431 | + "P_DOCID as bookbuildingDoctor," +//建档医生 | |
2432 | + "P_CARDNO as pregnantCertificateNum," +//证件号 | |
2433 | + "P_CARDNO as pregnantNationId," +// 孕妇民族 | |
2434 | + "P_CARDNO as pregnantPhone," +// 孕妇手机号 | |
2435 | + "P_RRPROVINCE as pregnantLiveProvinceId," +//户口——省 | |
2436 | + "P_RRCITY as pregnantLiveCityId," +//户口——市 | |
2437 | + "P_RRCOUNTY as pregnantLiveAreaId," +//户口——区县 | |
2438 | + "P_RRSTREET as pregnantLiveStreetId," +//户口——街道 | |
2439 | + "P_POSTPARTUMPROVINCE as childbirthProvinceId," +//产后——省 | |
2440 | + "P_POSTPARTUMCITY as childbirthCityId," +//产后——市 | |
2441 | + "P_POSTPARTUMCOUNTY as childbirthAreaId," +//产后——区县 | |
2442 | + "P_POSTPARTUMSTREET as childbirthStreetId," +//产后——街道 | |
2443 | + "P_HUSBANDNAME as husbandName," +//丈夫姓名 | |
2444 | + "P_HUSBANDCARDNO as husbandCertificateNum," +//丈夫证件号码 | |
2445 | + "P_HUSBANDBIRTHDAY as husbandBirth," +//丈夫出生日期 | |
2446 | + "P_HUSBANDRRPROVINCE as husbandProvinceRegisterId," +//丈夫户口所在地 省 | |
2447 | + "P_HUSBANDRRCITY as husbandCityRegisterId," +//丈夫户口所在地 市 | |
2448 | + "P_HUSBANDRRCOUNTY as husbandAreaRegisterId," +//丈夫户口所在地 县 | |
2449 | + "P_HUSBANDRRSTREET as husbandStreetRegisterId," +//丈夫户口所在地 街道 | |
2450 | + "VC_CARDNO as vcCardNo, " +//就诊卡号 条码号 | |
2451 | + "P_BIRTHDAY as birthday, " +//孕妇生日 | |
2452 | + "P_LASTMENSTRUALPERIOD as lastMenstrualPeriod," +//末次月经 | |
2453 | + "YCQ as dueDate," +//预产期 | |
2454 | + "P_FILINGTIME as bookbuildingDate," +//建档日期 | |
2455 | + "P_HOSPITALID as hospitalId " +//医院Id | |
2456 | + " FROM V_SYNC_TO_V3_PATIENT T " + | |
2457 | + "LEFT join v_sync_to_v3_pdr pdr on pdr.p_no = t.p_no "+ | |
2458 | + "WHERE TRUNC(T.P_FILINGTIME) between TO_DATE('" + startTime + "','YYYY-MM-DD') AND TO_DATE('" + endTime + "','YYYY-MM-DD') " + | |
2459 | + "and pdr.p_no is null " + | |
2460 | + "and ( P_ADDRESSCOUNTY='160' " +//居住地区(桃城区) | |
2461 | + "OR P_POSTPARTUMCOUNTY='160' " +//产后区县(桃城区) | |
2462 | + "OR P_RRCOUNTY ='160')"; | |
2485 | 2463 | } |
2486 | 2464 | |
2487 | - private static Connection getConnection() { | |
2465 | + | |
2466 | + public static Connection getConnection() { | |
2488 | 2467 | Connection connection; |
2489 | 2468 | try { |
2490 | 2469 | Class.forName("oracle.jdbc.OracleDriver"); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/SaveByV2ThreadPoolFacade.java
View file @
e5f0745
1 | +package com.lyms.platform.operate.web.facade; | |
2 | + | |
3 | +import com.lyms.platform.common.result.BaseObjectResponse; | |
4 | +import com.lyms.platform.operate.web.request.SyncV2HistoryRequest; | |
5 | +import org.springframework.beans.factory.annotation.Autowired; | |
6 | +import org.springframework.stereotype.Component; | |
7 | + | |
8 | +import java.util.List; | |
9 | +import java.util.concurrent.CountDownLatch; | |
10 | +import java.util.concurrent.ExecutorService; | |
11 | +import java.util.concurrent.Executors; | |
12 | + | |
13 | +@Component | |
14 | +public class SaveByV2ThreadPoolFacade { | |
15 | + | |
16 | + @Autowired | |
17 | + private BookbuildingFacade bookbuildingFacade; | |
18 | + | |
19 | + public void exec(List<SyncV2HistoryRequest> list) throws InterruptedException { | |
20 | + //初始化线程处理500条数据 | |
21 | + int count = 500; | |
22 | + int listSize = list.size(); | |
23 | + int runSize = (listSize / count) + 1; | |
24 | + //线程数最大设置10个 | |
25 | + if (runSize>10){ | |
26 | + runSize=10; | |
27 | + count= listSize/runSize; | |
28 | + } | |
29 | + List<SyncV2HistoryRequest> newlist = null; | |
30 | + //创建一个线程池,数量和开启线程的数量一样 | |
31 | + ExecutorService executor = Executors.newFixedThreadPool(runSize); | |
32 | + CountDownLatch begin = new CountDownLatch(1); | |
33 | + CountDownLatch end = new CountDownLatch(runSize); | |
34 | + for (int i = 0; i < runSize; i++) { | |
35 | + //计算每个线程执行的数据 | |
36 | + if ((i + 1) == runSize) { | |
37 | + int startIndex = (i * count); | |
38 | + int endIndex = list.size(); | |
39 | + newlist = list.subList(startIndex, endIndex); | |
40 | + } else { | |
41 | + int startIndex = (i * count); | |
42 | + int endIndex = (i + 1) * count; | |
43 | + newlist = list.subList(startIndex, endIndex); | |
44 | + } | |
45 | + MyThread mythead = new MyThread(newlist, begin, end,bookbuildingFacade); | |
46 | + MyThread2 mythead2 = new MyThread2(bookbuildingFacade, newlist, begin, end); | |
47 | + executor.execute(mythead2); | |
48 | +// executor.execute(mythead); | |
49 | + } | |
50 | + | |
51 | + begin.countDown(); | |
52 | + end.await(); | |
53 | + executor.shutdown(); | |
54 | + } | |
55 | + | |
56 | +} | |
57 | + | |
58 | +class MyThread implements Runnable { | |
59 | + private BookbuildingFacade bookbuildingFacade; | |
60 | + private List<SyncV2HistoryRequest> list; | |
61 | + private CountDownLatch begin; | |
62 | + private CountDownLatch end; | |
63 | + | |
64 | + public MyThread(List<SyncV2HistoryRequest> list, CountDownLatch begin, CountDownLatch end,BookbuildingFacade bookbuildingFacade) { | |
65 | + this.list = list; | |
66 | + this.begin = begin; | |
67 | + this.end = end; | |
68 | + this.bookbuildingFacade = bookbuildingFacade; | |
69 | + } | |
70 | + | |
71 | + @Override | |
72 | + public void run() { | |
73 | + try { | |
74 | + for (int i = 0; i < list.size(); i++) { | |
75 | + /* | |
76 | + 2: 具体插入实现在这里写 | |
77 | + */ | |
78 | + BaseObjectResponse p = bookbuildingFacade.addPregnantBookbuilding(list.get(i), null, false);//Integer.parseInt(list.getBookbuildingDoctor() | |
79 | + System.out.println(p.getData()); | |
80 | + System.out.println("当前线程名称:"+Thread.currentThread().getName()+"======存储的数据内容:"+p.getData() | |
81 | + ); | |
82 | + } | |
83 | + //执行完让线程直接进入等待 | |
84 | + begin.await(); | |
85 | + } catch (InterruptedException e) { | |
86 | + e.printStackTrace(); | |
87 | + } finally { | |
88 | + end.countDown(); | |
89 | + } | |
90 | + } | |
91 | + | |
92 | + | |
93 | +} | |
94 | +class MyThread2 implements Runnable { | |
95 | + private BookbuildingFacade bookbuildingFacade; | |
96 | + private List<SyncV2HistoryRequest> list; | |
97 | + private CountDownLatch begin; | |
98 | + private CountDownLatch end; | |
99 | + | |
100 | + public MyThread2(BookbuildingFacade bookbuildingFacade, List<SyncV2HistoryRequest> list, CountDownLatch begin, CountDownLatch end) { | |
101 | + this.bookbuildingFacade = bookbuildingFacade; | |
102 | + this.list = list; | |
103 | + this.begin = begin; | |
104 | + this.end = end; | |
105 | + } | |
106 | + | |
107 | + @Override | |
108 | + public void run() { | |
109 | + System.out.println("123456"); | |
110 | + | |
111 | + try { | |
112 | + for (int i = 0; i < list.size(); i++) { | |
113 | + /* | |
114 | + 2: 具体插入实现在这里写 | |
115 | + */ | |
116 | + BaseObjectResponse p = bookbuildingFacade.addPregnantBookbuilding(list.get(i), null, false);//Integer.parseInt(list.getBookbuildingDoctor() | |
117 | + System.out.println(p.getData()); | |
118 | + System.out.println("当前线程名称:"+Thread.currentThread().getName()+"======存储的数据内容:"+p.getData() | |
119 | + ); | |
120 | + } | |
121 | + //执行完让线程直接进入等待 | |
122 | + begin.await(); | |
123 | + } catch (InterruptedException e) { | |
124 | + e.printStackTrace(); | |
125 | + } finally { | |
126 | + end.countDown(); | |
127 | + } | |
128 | + } | |
129 | +} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/FixedThreadPoolUtil.java
View file @
e5f0745
1 | +package com.lyms.platform.operate.web.utils; | |
2 | + | |
3 | +import java.util.ArrayList; | |
4 | +import java.util.List; | |
5 | +import java.util.concurrent.CountDownLatch; | |
6 | +import java.util.concurrent.ExecutorService; | |
7 | +import java.util.concurrent.Executors; | |
8 | + | |
9 | +public class FixedThreadPoolUtil { | |
10 | + | |
11 | + public static void exec(List<Object> list) throws InterruptedException { | |
12 | + int count = 30000; //一个线程处理300条数据 | |
13 | + int listSize = list.size(); //数据集合大小 | |
14 | + int runSize = (listSize / count) + 1; //开启的线程数 | |
15 | + if (runSize>10){//线程数最大设置30个,自己定义的 | |
16 | + runSize=10; | |
17 | + count= listSize/runSize; | |
18 | + } | |
19 | + List<Object> newlist = null; //存放每个线程的执行数据 | |
20 | + ExecutorService executor = Executors.newFixedThreadPool(runSize); //创建一个线程池,数量和开启线程的数量一样 | |
21 | + //创建两个个计数器 | |
22 | + CountDownLatch begin = new CountDownLatch(1); | |
23 | + CountDownLatch end = new CountDownLatch(runSize); | |
24 | + //循环创建线程 | |
25 | + for (int i = 0; i < runSize; i++) { | |
26 | + //计算每个线程执行的数据 | |
27 | + if ((i + 1) == runSize) { | |
28 | + int startIndex = (i * count); | |
29 | + int endIndex = list.size(); | |
30 | + newlist = list.subList(startIndex, endIndex); | |
31 | + } else { | |
32 | + int startIndex = (i * count); | |
33 | + int endIndex = (i + 1) * count; | |
34 | + newlist = list.subList(startIndex, endIndex); | |
35 | + } | |
36 | + //线程类 | |
37 | + MyThread mythead = new MyThread(newlist, begin, end); | |
38 | + //这里执行线程的方式是调用线程池里的executor.execute(mythead)方法。 | |
39 | + executor.execute(mythead); | |
40 | + } | |
41 | + | |
42 | + begin.countDown(); | |
43 | + end.await(); | |
44 | + //执行完关闭线程池 | |
45 | + executor.shutdown(); | |
46 | + } | |
47 | + | |
48 | + //测试 | |
49 | +// public static void main(String[] args) { | |
50 | +// List<Object> list = new ArrayList<Object>(); | |
51 | +// long start=System.currentTimeMillis(); | |
52 | +// System.out.println("start==" + start); | |
53 | +// Strtest strtest=new Strtest("王明",1); | |
54 | +// //数据越大线程越多 | |
55 | +// for (int i = 0; i < 3000; i++) { | |
56 | +//// list.add("hello" + i); | |
57 | +// list.add(new Strtest(i+"王明",1+i)); | |
58 | +// } | |
59 | +// try { | |
60 | +// FixedThreadPoolUtil.exec(list); | |
61 | +// long end=System.currentTimeMillis(); | |
62 | +// System.out.println("end=="+end); | |
63 | +// System.out.println("end-start="+(end-start)); | |
64 | +// } catch (InterruptedException e) { | |
65 | +// e.printStackTrace(); | |
66 | +// } | |
67 | +// } | |
68 | +} | |
69 | + | |
70 | +class MyThread implements Runnable { | |
71 | + private List<Object> list; | |
72 | + private CountDownLatch begin; | |
73 | + private CountDownLatch end; | |
74 | + | |
75 | + //创建个构造函数初始化 list,和其他用到的参数 | |
76 | + public MyThread(List<Object> list, CountDownLatch begin, CountDownLatch end) { | |
77 | + this.list = list; | |
78 | + this.begin = begin; | |
79 | + this.end = end; | |
80 | + } | |
81 | + | |
82 | + @Override | |
83 | + public void run() { | |
84 | + try { | |
85 | + for (int i = 0; i < list.size(); i++) { | |
86 | + /* | |
87 | + 2: 具体插入实现在这里写 | |
88 | + */ | |
89 | + //这里还要说一下,,由于在实质项目中,当处理的数据存在等待超时和出错会使线程一直处于等待状态 | |
90 | + //这里只是处理简单的, | |
91 | + //分批 批量插入 | |
92 | +// Thread.sleep(3000); | |
93 | + System.out.println("当前线程名称:"+Thread.currentThread().getName()+"======存储的数据内容:"+i | |
94 | + ); | |
95 | + } | |
96 | + //执行完让线程直接进入等待 | |
97 | + begin.await(); | |
98 | + } catch (InterruptedException e) { | |
99 | + // TODO Auto-generated catch block | |
100 | + e.printStackTrace(); | |
101 | + } finally { | |
102 | + //这里要主要了,当一个线程执行完 了计数要减一不然这个线程会被一直挂起 | |
103 | + // ,end.countDown(),这个方法就是直接把计数器减一的 | |
104 | + end.countDown(); | |
105 | + } | |
106 | + } | |
107 | + | |
108 | + | |
109 | +} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/CorrectDataWorker2.java
View file @
e5f0745
1 | +package com.lyms.platform.operate.web.worker; | |
2 | + | |
3 | +import com.lyms.platform.biz.service.AntenatalExaminationService; | |
4 | +import com.lyms.platform.biz.service.PatientsService; | |
5 | +import com.lyms.platform.biz.service.PostReviewService; | |
6 | +import com.lyms.platform.common.enums.YnEnums; | |
7 | +import com.lyms.platform.common.utils.ExceptionUtils; | |
8 | +import com.lyms.platform.operate.web.facade.AntenatalExaminationFacade; | |
9 | +import com.lyms.platform.pojo.AntExChuModel; | |
10 | +import com.lyms.platform.pojo.AntenatalExaminationModel; | |
11 | +import com.lyms.platform.pojo.Patients; | |
12 | +import com.lyms.platform.query.AntExChuQuery; | |
13 | +import com.lyms.platform.query.AntExQuery; | |
14 | +import com.lyms.platform.query.PostReviewQuery; | |
15 | +import org.apache.commons.collections.CollectionUtils; | |
16 | +import org.springframework.data.domain.Sort; | |
17 | + | |
18 | +import java.util.Date; | |
19 | +import java.util.List; | |
20 | +import java.util.concurrent.atomic.AtomicLong; | |
21 | + | |
22 | +/** | |
23 | + * 纠正数据线程 | |
24 | + * <p/> | |
25 | + * Created by Administrator on 2016/10/25 0025. | |
26 | + */ | |
27 | +public class CorrectDataWorker2 extends Thread { | |
28 | + | |
29 | + private PostReviewService postReviewService; | |
30 | + | |
31 | + private PatientsService patientsService; | |
32 | + | |
33 | + private AntenatalExaminationService antExService; | |
34 | + | |
35 | + private AntenatalExaminationFacade antExFacade; | |
36 | + | |
37 | + private List<Patients> patientses; | |
38 | + | |
39 | + private AtomicLong counter; | |
40 | + | |
41 | + public CorrectDataWorker2(List<Patients> patientses, | |
42 | + PostReviewService postReviewService, | |
43 | + PatientsService patientsService, | |
44 | + AntenatalExaminationService antExService, | |
45 | + AntenatalExaminationFacade antExFacade, | |
46 | + AtomicLong counter) { | |
47 | + this.patientses = patientses; | |
48 | + this.patientsService = patientsService; | |
49 | + this.postReviewService = postReviewService; | |
50 | + this.antExService = antExService; | |
51 | + this.antExFacade = antExFacade; | |
52 | + this.counter = counter; | |
53 | + } | |
54 | + | |
55 | + @Override | |
56 | + public void run() { | |
57 | + //最后一次高危时间 | |
58 | + // Date lastRhTime; | |
59 | + //本院最后一次产检时间 | |
60 | + //Date lastCTime; | |
61 | + //本院产后复查次数 | |
62 | + //Integer postViewTimes; | |
63 | + try { | |
64 | + for (Patients patients : patientses) { | |
65 | + Patients patients1 = new Patients(); | |
66 | + patients1.setId(patients.getId()); | |
67 | + //产后复查次数 | |
68 | + PostReviewQuery postReviewQuery = new PostReviewQuery(); | |
69 | + postReviewQuery.setHospitalId(patients.getHospitalId()); | |
70 | + postReviewQuery.setYn(YnEnums.YES.getId()); | |
71 | + postReviewQuery.setParentId(patients.getId()); | |
72 | + //产后复查次数 | |
73 | + patients1.setPostViewTimes(postReviewService.count(postReviewQuery)); | |
74 | + //最后产检时间 | |
75 | + patients1.setLastCTime(findLastCTime(patients.getId())); | |
76 | + | |
77 | + patientsService.updatePatient(patients1); | |
78 | + //修改最后一次定义高危时间 | |
79 | + antExFacade.updateLastRhTime(patients.getId(), patients.getHospitalId()); | |
80 | + //修改高危 | |
81 | + antExFacade.updateLastRisk(patients.getId()); | |
82 | + | |
83 | + counter.incrementAndGet(); | |
84 | + } | |
85 | + } catch (Exception e) { | |
86 | + ExceptionUtils.catchException(e, "CorrectDataWorker Error."); | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + | |
91 | + private Date findLastCTime(String id) { | |
92 | + AntExQuery antExQuery = new AntExQuery(); | |
93 | + antExQuery.setParentId(id); | |
94 | + antExQuery.setYn(YnEnums.YES.getId()); | |
95 | + | |
96 | + List<AntenatalExaminationModel> antEx = antExService.queryAntenatalExamination(antExQuery.convertToQuery().addOrder(Sort.Direction.DESC, "checkDate")); | |
97 | + if (CollectionUtils.isNotEmpty(antEx)) { | |
98 | + return antEx.get(0).getCheckDate(); | |
99 | + } else { | |
100 | + AntExChuQuery antExChuQuery = new AntExChuQuery(); | |
101 | + antExChuQuery.setParentId(id); | |
102 | + antExChuQuery.setYn(YnEnums.YES.getId()); | |
103 | + List<AntExChuModel> antExChu = antExService.queryAntExChu(antExChuQuery); | |
104 | + if (CollectionUtils.isNotEmpty(antExChu)) { | |
105 | + return antExChu.get(0).getCheckTime(); | |
106 | + } | |
107 | + } | |
108 | + return null; | |
109 | + } | |
110 | +} |