Commit 823484a40237b3e7efb88f591687c6be6fce7050
1 parent
fdfa231356
Exists in
master
and in
6 other branches
同步历史数据添加锁机制
Showing 3 changed files with 39 additions and 46 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/MatDeliverFacade.java
View file @
823484a
... | ... | @@ -2951,8 +2951,19 @@ |
2951 | 2951 | System.out.println("没有建档数据"); |
2952 | 2952 | continue; |
2953 | 2953 | } |
2954 | + String patientsId = patients.getId(); | |
2955 | + String pid = patients.getPid(); | |
2956 | + if (com.lyms.platform.common.utils.StringUtils.isEmpty(patientsId) || com.lyms.platform.common.utils.StringUtils.isEmpty(pid)) { | |
2957 | + System.out.println("pid 或 parentId为null"); | |
2958 | + continue; | |
2959 | + } | |
2954 | 2960 | matDeliverAddRequest.setParentId(patients.getId()); |
2955 | 2961 | matDeliverAddRequest.setPid(patients.getPid()); |
2962 | + MaternalDeliverModel one = mongoTemplate.findOne(Query.query(Criteria.where("parentId").is(patientsId).and("pid").is(pid)), MaternalDeliverModel.class); | |
2963 | + if (one != null) { | |
2964 | + System.out.println("分娩记录已存在"); | |
2965 | + continue; | |
2966 | + } | |
2956 | 2967 | Date childbirthday = rs.getDate("PDR_CHILDBIRTHDAY"); |
2957 | 2968 | String pdrGestationalweeks = rs.getString("PDR_GESTATIONALWEEKS"); |
2958 | 2969 | int pdrIrenum = rs.getInt("PDR_IRENUM"); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/SaveByV2ThreadPoolFacade.java
View file @
823484a
... | ... | @@ -25,6 +25,8 @@ |
25 | 25 | import java.util.concurrent.Executors; |
26 | 26 | import java.util.concurrent.Future; |
27 | 27 | import java.util.concurrent.atomic.AtomicInteger; |
28 | +import java.util.concurrent.locks.Lock; | |
29 | +import java.util.concurrent.locks.ReentrantLock; | |
28 | 30 | |
29 | 31 | @Component |
30 | 32 | public class SaveByV2ThreadPoolFacade { |
... | ... | @@ -53,11 +55,6 @@ |
53 | 55 | |
54 | 56 | String startTime = param.getStartTime(); |
55 | 57 | String endTime = param.getEndTime(); |
56 | - // 同步计数器 | |
57 | - AtomicInteger okSize=new AtomicInteger(0); | |
58 | - AtomicInteger existSize=new AtomicInteger(0); | |
59 | - AtomicInteger errorSize=new AtomicInteger(0); | |
60 | - | |
61 | 58 | Connection connection = null; |
62 | 59 | List<SyncV2HistoryRequest> lists=null; |
63 | 60 | try { |
64 | 61 | |
65 | 62 | |
... | ... | @@ -81,15 +78,16 @@ |
81 | 78 | if (CollectionUtils.isNotEmpty(lists)) { |
82 | 79 | int batchSize = 2; |
83 | 80 | int end = 0; |
81 | + Lock lock = new ReentrantLock(false); | |
84 | 82 | for (int i = 0; i < lists.size(); i += batchSize) { |
85 | 83 | end = (end + batchSize); |
86 | 84 | if (end > lists.size()) { |
87 | 85 | end = lists.size(); |
88 | 86 | } |
89 | - Future f = commonThreadPool.submit(new SyncV2HistoryWorkerx(bookbuildingFacade, lists.subList(i, end), mongoTemplate, okSize, existSize, errorSize,basicConfigDao)); | |
87 | + Future f = commonThreadPool.submit(new SyncV2HistoryWorkerx(bookbuildingFacade, lists.subList(i, end), mongoTemplate, lock, basicConfigDao)); | |
90 | 88 | } |
91 | 89 | } |
92 | - return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("同步结果: ok ===>" + okSize + "exist===>" + existSize + "error===>" + errorSize); | |
90 | + return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("同步结果: ok ===>" + lists.size()); | |
93 | 91 | } |
94 | 92 | |
95 | 93 | private String getSqlString(String startTime, String endTime) { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/SyncV2HistoryWorkerx.java
View file @
823484a
1 | 1 | package com.lyms.platform.operate.web.worker; |
2 | 2 | |
3 | -import com.lyms.platform.common.constants.ErrorCodeConstants; | |
4 | 3 | import com.lyms.platform.biz.dal.IBasicConfigDao; |
5 | -import com.lyms.platform.biz.service.AntenatalExaminationService; | |
6 | -import com.lyms.platform.biz.service.PatientsService; | |
7 | -import com.lyms.platform.biz.service.PostReviewService; | |
8 | 4 | import com.lyms.platform.common.dao.operator.MongoCondition; |
9 | 5 | import com.lyms.platform.common.dao.operator.MongoOper; |
10 | 6 | import com.lyms.platform.common.enums.YnEnums; |
11 | 7 | |
... | ... | @@ -13,16 +9,8 @@ |
13 | 9 | import com.lyms.platform.operate.web.facade.BookbuildingFacade; |
14 | 10 | import com.lyms.platform.operate.web.request.SyncV2HistoryRequest; |
15 | 11 | import com.lyms.platform.operate.web.request.YunBookbuildingAddRequest; |
16 | -import com.lyms.platform.pojo.AntExChuModel; | |
17 | -import com.lyms.platform.pojo.AntenatalExaminationModel; | |
18 | 12 | import com.lyms.platform.pojo.BasicConfig; |
19 | 13 | import com.lyms.platform.pojo.Patients; |
20 | -import com.lyms.platform.query.AntExChuQuery; | |
21 | -import com.lyms.platform.query.AntExQuery; | |
22 | -import com.lyms.platform.query.PostReviewQuery; | |
23 | -import org.apache.commons.collections.CollectionUtils; | |
24 | -import org.springframework.beans.factory.annotation.Autowired; | |
25 | -import org.springframework.data.domain.Sort; | |
26 | 14 | import org.springframework.data.mongodb.core.MongoTemplate; |
27 | 15 | import org.springframework.data.mongodb.core.query.Criteria; |
28 | 16 | import org.springframework.data.mongodb.core.query.Query; |
... | ... | @@ -30,7 +18,7 @@ |
30 | 18 | import java.util.Date; |
31 | 19 | import java.util.List; |
32 | 20 | import java.util.concurrent.Callable; |
33 | -import java.util.concurrent.atomic.AtomicInteger; | |
21 | +import java.util.concurrent.locks.Lock; | |
34 | 22 | |
35 | 23 | /** |
36 | 24 | * 纠正数据线程 |
37 | 25 | |
38 | 26 | |
39 | 27 | |
... | ... | @@ -42,24 +30,18 @@ |
42 | 30 | private BookbuildingFacade bookbuildingFacade; |
43 | 31 | private List<SyncV2HistoryRequest> lists; |
44 | 32 | private MongoTemplate mongoTemplate; |
45 | - private AtomicInteger okSize; | |
46 | - private AtomicInteger existSize; | |
47 | - private AtomicInteger errorSize; | |
48 | 33 | private IBasicConfigDao basicConfigDao; |
34 | + private Lock lock; | |
49 | 35 | |
50 | 36 | public SyncV2HistoryWorkerx(BookbuildingFacade bookbuildingFacade, |
51 | 37 | List<SyncV2HistoryRequest> lists, |
52 | 38 | MongoTemplate mongoTemplate, |
53 | - AtomicInteger okSize, | |
54 | - AtomicInteger existSize, | |
55 | - AtomicInteger errorSize, | |
39 | + Lock lock , | |
56 | 40 | IBasicConfigDao basicConfigDao) { |
57 | 41 | this.bookbuildingFacade = bookbuildingFacade; |
58 | 42 | this.lists = lists; |
59 | 43 | this.mongoTemplate = mongoTemplate; |
60 | - this.okSize = okSize; | |
61 | - this.existSize = existSize; | |
62 | - this.errorSize = errorSize; | |
44 | + this.lock = lock; | |
63 | 45 | this.basicConfigDao = basicConfigDao; |
64 | 46 | } |
65 | 47 | |
66 | 48 | |
67 | 49 | |
68 | 50 | |
... | ... | @@ -67,28 +49,30 @@ |
67 | 49 | public BaseObjectResponse call() throws Exception { |
68 | 50 | BaseObjectResponse p=null; |
69 | 51 | for (YunBookbuildingAddRequest list : lists) { |
70 | - Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("cardNo").is(list.getPregnantCertificateNum())), Patients.class); | |
71 | - if (patients != null) { | |
72 | - existSize.incrementAndGet(); | |
73 | - continue; | |
74 | - } | |
52 | + try { | |
53 | + lock.lock(); | |
54 | + Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("cardNo").is(list.getPregnantCertificateNum())), Patients.class); | |
55 | + if (patients != null) { | |
56 | + System.out.println("该证件号已存在"); | |
57 | + continue; | |
58 | + } | |
75 | 59 | |
76 | - list.setHospitalId("216");//todo | |
77 | - list.setBookbuildingDoctor("1000000185");//todo | |
78 | - list.setBookbuildingDate(DateUtil.getyyyy_MM_dd(new Date())); | |
79 | - list.setHusbandNationId(queryParentConfig(list.getHusbandNationId())); | |
80 | - list.setPregnantNationId(queryParentConfig(list.getPregnantNationId())); | |
81 | - p = bookbuildingFacade.addPregnantBookbuilding(list, null, false); | |
82 | - if (ErrorCodeConstants.SUCCESS == p.getErrorcode()) { | |
83 | - okSize.incrementAndGet(); | |
84 | - } else { | |
85 | - errorSize.incrementAndGet(); | |
60 | + list.setHospitalId("216");//todo | |
61 | + list.setBookbuildingDoctor("1000000185");//todo | |
62 | + list.setBookbuildingDate(DateUtil.getyyyy_MM_dd(new Date())); | |
63 | + list.setHusbandNationId(queryParentConfig(list.getHusbandNationId())); | |
64 | + list.setPregnantNationId(queryParentConfig(list.getPregnantNationId())); | |
65 | + p = bookbuildingFacade.addPregnantBookbuilding(list, null, false); | |
66 | + }catch (Exception e){ | |
67 | + e.printStackTrace(); | |
68 | + }finally { | |
69 | + lock.unlock(); | |
86 | 70 | } |
71 | + | |
72 | + | |
87 | 73 | } |
88 | 74 | return p; |
89 | 75 | } |
90 | - | |
91 | - | |
92 | 76 | |
93 | 77 | public String queryParentConfig(String name) { |
94 | 78 | List<BasicConfig> basicConfigs = basicConfigDao.queryBasicConfig( |