Commit 7038dace122b467519605378f6cb1b9fb15ddb9b
1 parent
a29d200d96
Exists in
master
and in
6 other branches
孕妇学校
Showing 10 changed files with 292 additions and 8 deletions
- platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/IYunBookBuildingDao.java
- platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/impl/YunBookbuildingDaoImpl.java
- platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/YunBookbuildingService.java
- platform-common/src/main/java/com/lyms/platform/common/enums/SmsServiceEnums.java
- platform-common/src/main/java/com/lyms/platform/common/enums/WxTempleteIdEnums.java
- platform-dal/src/main/java/com/lyms/platform/pojo/CourseModel.java
- platform-dal/src/main/java/com/lyms/platform/query/CourseQuery.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/service/IMsgGenerateService.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/service/impl/MsgGenerateServiceImpl.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/CourseMsgGenerateWorker.java
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/IYunBookBuildingDao.java
View file @
7038dac
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/impl/YunBookbuildingDaoImpl.java
View file @
7038dac
... | ... | @@ -37,6 +37,11 @@ |
37 | 37 | } |
38 | 38 | |
39 | 39 | @Override |
40 | + public int queryPatientCount(MongoQuery query) { | |
41 | + return (int) count(query.convertToMongoQuery()); | |
42 | + } | |
43 | + | |
44 | + @Override | |
40 | 45 | public void updatePatient(Patients obj, String id) { |
41 | 46 | update(new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery(), obj); |
42 | 47 | } |
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/YunBookbuildingService.java
View file @
7038dac
... | ... | @@ -6,6 +6,7 @@ |
6 | 6 | import com.lyms.platform.pojo.AntExChuModel; |
7 | 7 | import com.lyms.platform.query.AntExChuQuery; |
8 | 8 | import com.lyms.platform.query.PatientsQuery; |
9 | +import org.apache.commons.lang.StringUtils; | |
9 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
10 | 11 | import org.springframework.data.domain.Sort; |
11 | 12 | import org.springframework.stereotype.Service; |
... | ... | @@ -58,8 +59,12 @@ |
58 | 59 | } |
59 | 60 | |
60 | 61 | public List<Patients> queryPregnantWithQuery(PatientsQuery patientsQuery) { |
61 | - MongoQuery query = patientsQuery.convertToQuery(); | |
62 | - return yunBookBuildingDao.queryPatientWithQuery(query.addOrder(Sort.Direction.DESC, "created")); | |
62 | + MongoQuery query = patientsQuery.convertToQuery(); | |
63 | + if (StringUtils.isNotEmpty(patientsQuery.getNeed())) { | |
64 | + patientsQuery.mysqlBuild(yunBookBuildingDao.queryPatientCount(query)); | |
65 | + query.start(patientsQuery.getOffset()).end(patientsQuery.getLimit()); | |
66 | + } | |
67 | + return yunBookBuildingDao.queryPatientWithQuery(query.addOrder(Sort.Direction.DESC, "created")); | |
63 | 68 | } |
64 | 69 | |
65 | 70 | public List<Patients> queryPregnantWithQuery(PatientsQuery patientsQuery,String sortkey,Sort.Direction sort) { |
platform-common/src/main/java/com/lyms/platform/common/enums/SmsServiceEnums.java
View file @
7038dac
... | ... | @@ -39,7 +39,8 @@ |
39 | 39 | YBYYTX(25,"儿童眼保键预约提醒",14,"2"), |
40 | 40 | TSYYTX(26,"儿童听力筛查预约提醒",14,"2"), |
41 | 41 | TYZDYYTX(27,"儿童听力诊断预约提醒",14,"2"), |
42 | - TLZDYYTX(28,"儿童听力随访预约提醒",14,"2"); | |
42 | + TLZDYYTX(28,"儿童听力随访预约提醒",14,"2"), | |
43 | + YFXXKCTX(29,"孕妇学校课程提醒",21,"1,3"); | |
43 | 44 | |
44 | 45 | private SmsServiceEnums(int id,String name,int pid,String serviceObj){ |
45 | 46 | this.id = id; |
platform-common/src/main/java/com/lyms/platform/common/enums/WxTempleteIdEnums.java
View file @
7038dac
... | ... | @@ -21,6 +21,7 @@ |
21 | 21 | YUN_YI_BAN_ZHI_DAO("98i1P6zh3slBxEKLftweaESnnem4w6SDmzvJIBWRXNE","孕妇一般指导"),//孕妇 |
22 | 22 | CHAN_YI_BAN_ZHI_DAO("H2_ucLqVEbsZAv-EZcmUDpD1Zul5NGqMoJktHT0u4gw","产妇一般指导"),//产妇 |
23 | 23 | BABY_YI_BAN_ZHI_DAO("dqvyESU8UXx1V3cIMQDqj4PLxI6T9-sgihQcs3ZGL9E","儿童一般指导"),//儿童 |
24 | + YUN_XUE_KE_CHEN_TX("","孕妇学校课程提醒"),//孕妇学校课程提醒 | |
24 | 25 | |
25 | 26 | YI_SHENG_ZHI_DAO("OggqiSHitLkCgSLCaCH72reCZzaw5NyG8iO56InQiQg","医生指导");//指导 |
26 | 27 | // WEI_JI_ZHI_DAO("fNkkLSp_gS-YWvzji6gwgdTddl4XBlk8SNP7FRksrfk","危急值提醒");//危急值提醒 |
platform-dal/src/main/java/com/lyms/platform/pojo/CourseModel.java
View file @
7038dac
... | ... | @@ -72,6 +72,17 @@ |
72 | 72 | //课程对象id 0全部/空 1孕期 2儿童 ,3产后 |
73 | 73 | private Integer courseObjId; |
74 | 74 | |
75 | + //是否发送过推送 字段不存在表示未推送,1已推送 | |
76 | + private Integer isSend; | |
77 | + | |
78 | + public Integer getIsSend() { | |
79 | + return isSend; | |
80 | + } | |
81 | + | |
82 | + public void setIsSend(Integer isSend) { | |
83 | + this.isSend = isSend; | |
84 | + } | |
85 | + | |
75 | 86 | public Integer getCourseObjId() { |
76 | 87 | return courseObjId; |
77 | 88 | } |
platform-dal/src/main/java/com/lyms/platform/query/CourseQuery.java
View file @
7038dac
... | ... | @@ -75,6 +75,8 @@ |
75 | 75 | private Date courseEndTime; |
76 | 76 | private String keyword; |
77 | 77 | |
78 | + private boolean isSend; | |
79 | + | |
78 | 80 | @Override |
79 | 81 | public MongoQuery convertToQuery() { |
80 | 82 | MongoCondition condition = MongoCondition.newInstance(); |
... | ... | @@ -114,6 +116,10 @@ |
114 | 116 | condition = condition.and("status", status, MongoOper.IS); |
115 | 117 | } |
116 | 118 | |
119 | + if (!isSend) { | |
120 | + condition = condition.and("isSend", false, MongoOper.EXISTS); | |
121 | + } | |
122 | + | |
117 | 123 | if (null != courseEndTime) { |
118 | 124 | condition = condition.and("courseEndTime", courseEndTime, MongoOper.LTE); |
119 | 125 | } |
... | ... | @@ -188,6 +194,13 @@ |
188 | 194 | return condition.toMongoQuery(); |
189 | 195 | } |
190 | 196 | |
197 | + public boolean isSend() { | |
198 | + return isSend; | |
199 | + } | |
200 | + | |
201 | + public void setIsSend(boolean isSend) { | |
202 | + this.isSend = isSend; | |
203 | + } | |
191 | 204 | |
192 | 205 | public String getKeyword() { |
193 | 206 | return keyword; |
platform-msg-generate/src/main/java/com/lyms/platform/msg/service/IMsgGenerateService.java
View file @
7038dac
platform-msg-generate/src/main/java/com/lyms/platform/msg/service/impl/MsgGenerateServiceImpl.java
View file @
7038dac
1 | 1 | package com.lyms.platform.msg.service.impl; |
2 | 2 | |
3 | 3 | import com.lyms.platform.biz.service.*; |
4 | +import com.lyms.platform.common.enums.CourseStatusEnums; | |
5 | +import com.lyms.platform.common.enums.YnEnums; | |
6 | +import com.lyms.platform.common.utils.DateUtil; | |
4 | 7 | import com.lyms.platform.msg.service.IBaseService; |
5 | 8 | import com.lyms.platform.msg.service.IMsgGenerateService; |
6 | 9 | import com.lyms.platform.msg.utils.DateUtils; |
7 | -import com.lyms.platform.msg.worker.BabyAmsMsgGenerateWorker; | |
8 | -import com.lyms.platform.msg.worker.ChanAmsMsgGenerateWorker; | |
9 | -import com.lyms.platform.msg.worker.TempleteMsgGenerateWorker; | |
10 | -import com.lyms.platform.msg.worker.YunAmsMsgGenerateWorker; | |
10 | +import com.lyms.platform.msg.worker.*; | |
11 | 11 | |
12 | 12 | import com.lyms.platform.permission.service.BabyPatientExtendEarFollowUpService; |
13 | 13 | import com.lyms.platform.permission.service.BabyPatientExtendEarHearingDiagnoseService; |
14 | 14 | import com.lyms.platform.permission.service.BabyPatientExtendEarScreenService; |
15 | +import com.lyms.platform.pojo.CourseModel; | |
15 | 16 | import com.lyms.platform.pojo.SmsConfigModel; |
17 | +import com.lyms.platform.query.CourseQuery; | |
16 | 18 | import org.apache.commons.collections.CollectionUtils; |
19 | +import org.apache.commons.lang.StringUtils; | |
17 | 20 | import org.slf4j.Logger; |
18 | 21 | import org.slf4j.LoggerFactory; |
19 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -40,6 +43,8 @@ |
40 | 43 | |
41 | 44 | @Autowired |
42 | 45 | private IBaseService baseService; |
46 | + @Autowired | |
47 | + private CourseService courseService; | |
43 | 48 | |
44 | 49 | @Autowired |
45 | 50 | private MongoTemplate mongoTemplate; |
... | ... | @@ -175,6 +180,51 @@ |
175 | 180 | pool.execute(worker); |
176 | 181 | } |
177 | 182 | |
183 | + } | |
184 | + } | |
185 | + | |
186 | + | |
187 | + /** | |
188 | + * isSend字段不存在表示未推送过 | |
189 | + * 并且取的课程只去当天时间范围内的来推送 | |
190 | + * 生成课程推送 | |
191 | + * @param generateHospitalId | |
192 | + */ | |
193 | + @Override | |
194 | + public void generateCourseMsg(String generateHospitalId) { | |
195 | + | |
196 | + CourseQuery query = new CourseQuery(); | |
197 | + query.setYn(YnEnums.YES.getId()); | |
198 | + query.setStatus(CourseStatusEnums.YFB.getId()); | |
199 | + query.setIsSend(false); | |
200 | + String currentDate = DateUtil.getyyyy_MM_dd(new Date()); | |
201 | + query.setCreatedStart(DateUtil.parseYMD(currentDate)); | |
202 | + query.setCreatedEnd(DateUtil.parseYMDHMS(currentDate + " 23:59:59")); | |
203 | + | |
204 | + if (StringUtils.isNotEmpty(generateHospitalId)) | |
205 | + { | |
206 | + query.setHospitalId(generateHospitalId); | |
207 | + } | |
208 | + | |
209 | + List<CourseModel> courseModels = courseService.queryCourseList(query); | |
210 | + | |
211 | + logger.info("The generateCourseMsg configs hospital size is {}",courseModels.size()); | |
212 | + if (CollectionUtils.isNotEmpty(courseModels)) | |
213 | + { | |
214 | + int end = 0; | |
215 | + for (int i = 0; i < courseModels.size(); i += 5) { | |
216 | + end = (end + 5); | |
217 | + if (end > courseModels.size()) { | |
218 | + end = courseModels.size(); | |
219 | + } | |
220 | + CourseMsgGenerateWorker worker = new CourseMsgGenerateWorker(courseModels.subList(i,end), | |
221 | + baseService, | |
222 | + yunBookbuildingService, | |
223 | + smsTemplateService, | |
224 | + babyBookbuildingService | |
225 | + ); | |
226 | + pool.execute(worker); | |
227 | + } | |
178 | 228 | } |
179 | 229 | } |
180 | 230 |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/CourseMsgGenerateWorker.java
View file @
7038dac
1 | +package com.lyms.platform.msg.worker; | |
2 | + | |
3 | +import com.lyms.platform.beans.MsgListRequest; | |
4 | +import com.lyms.platform.beans.MsgRequest; | |
5 | +import com.lyms.platform.biz.service.*; | |
6 | +import com.lyms.platform.common.enums.*; | |
7 | +import com.lyms.platform.common.utils.JsonUtil; | |
8 | +import com.lyms.platform.common.utils.StringUtils; | |
9 | +import com.lyms.platform.msg.model.MessageContent; | |
10 | +import com.lyms.platform.msg.remote.AmsMessageService; | |
11 | +import com.lyms.platform.msg.remote.SaveMessageService; | |
12 | +import com.lyms.platform.msg.service.IBaseService; | |
13 | +import com.lyms.platform.msg.utils.DateUtils; | |
14 | +import com.lyms.platform.msg.utils.HelperUtils; | |
15 | +import com.lyms.platform.permission.service.BabyPatientExtendEarFollowUpService; | |
16 | +import com.lyms.platform.permission.service.BabyPatientExtendEarHearingDiagnoseService; | |
17 | +import com.lyms.platform.permission.service.BabyPatientExtendEarScreenService; | |
18 | +import com.lyms.platform.pojo.CourseModel; | |
19 | +import com.lyms.platform.pojo.HighRiskSmsModel; | |
20 | +import com.lyms.platform.pojo.Patients; | |
21 | +import com.lyms.platform.pojo.SmsConfigModel; | |
22 | +import com.lyms.platform.query.HighRiskSmsQuery; | |
23 | +import com.lyms.platform.query.PatientsQuery; | |
24 | +import org.apache.commons.collections.CollectionUtils; | |
25 | +import org.slf4j.Logger; | |
26 | +import org.slf4j.LoggerFactory; | |
27 | +import org.springframework.data.mongodb.core.MongoTemplate; | |
28 | + | |
29 | +import java.util.ArrayList; | |
30 | +import java.util.Date; | |
31 | +import java.util.List; | |
32 | +import java.util.Map; | |
33 | + | |
34 | +/** | |
35 | + * Created by lqy on 2017-07-18. | |
36 | + */ | |
37 | +public class CourseMsgGenerateWorker implements Runnable { | |
38 | + | |
39 | + | |
40 | + private static final Logger logger = LoggerFactory.getLogger(CourseMsgGenerateWorker.class); | |
41 | + | |
42 | + private List<CourseModel> courseModels; | |
43 | + | |
44 | + private IBaseService baseService; | |
45 | + | |
46 | + private YunBookbuildingService yunBookbuildingService; | |
47 | + | |
48 | + | |
49 | + private SmsTemplateService smsTemplateService; | |
50 | + | |
51 | + private BabyBookbuildingService babyBookbuildingService; | |
52 | + | |
53 | + public CourseMsgGenerateWorker( List<CourseModel> courseModels, IBaseService baseService, | |
54 | + YunBookbuildingService yunBookbuildingService, | |
55 | + SmsTemplateService smsTemplateService, | |
56 | + BabyBookbuildingService babyBookbuildingService) | |
57 | + { | |
58 | + this.courseModels = courseModels; | |
59 | + this.baseService = baseService; | |
60 | + this.yunBookbuildingService = yunBookbuildingService; | |
61 | + this.smsTemplateService = smsTemplateService; | |
62 | + this.babyBookbuildingService = babyBookbuildingService; | |
63 | + } | |
64 | + | |
65 | + | |
66 | + @Override | |
67 | + public void run() { | |
68 | + if (CollectionUtils.isNotEmpty(courseModels)) | |
69 | + { | |
70 | + for (CourseModel course : courseModels) | |
71 | + { | |
72 | + List<SmsConfigModel> configModels = baseService.getHospitalConfigs(course.getHospitalId()); | |
73 | + if (CollectionUtils.isEmpty(configModels) && configModels.get(0) != null) | |
74 | + { | |
75 | + continue; | |
76 | + } | |
77 | + | |
78 | + SmsConfigModel config = configModels.get(0); | |
79 | + | |
80 | + String hospitalId = course.getHospitalId(); | |
81 | + | |
82 | + logger.info("genernate course hospital id = "+hospitalId); | |
83 | + if (StringUtils.isEmpty(hospitalId)) | |
84 | + { | |
85 | + continue; | |
86 | + } | |
87 | + | |
88 | + //判断医院是否运行 | |
89 | + if (!baseService.isRunning(hospitalId)) | |
90 | + { | |
91 | + continue; | |
92 | + } | |
93 | + | |
94 | + String serviceStr = config.getSmsService(); | |
95 | + String serviceType = config.getServiceType(); | |
96 | + | |
97 | + //判断消息服务是否启动 | |
98 | + //0服务不提供,1 推送服务, 2 短信服务,3推送和短信服务 | |
99 | + int service = baseService.isStartService(SmsServiceEnums.YBZD.getId(), serviceStr,serviceType); | |
100 | + if (service == 0) | |
101 | + { | |
102 | + continue; | |
103 | + } | |
104 | + //课程对象id 0全部/空 1孕期 2儿童 ,3产后 (儿童占时没有) | |
105 | + if (course.getCourseObjId() == null || course.getCourseObjId() == 1) | |
106 | + { | |
107 | + generateYun(course,config,service); | |
108 | + generateChan(course,config,service); | |
109 | + } | |
110 | + else if (course.getCourseObjId() == 1) | |
111 | + { | |
112 | + generateYun(course,config,service); | |
113 | + } | |
114 | + else if (course.getCourseObjId() == 3) | |
115 | + { | |
116 | + generateChan(course,config,service); | |
117 | + } | |
118 | + } | |
119 | + } | |
120 | + } | |
121 | + | |
122 | + private void generateYun(CourseModel course,SmsConfigModel config,int service) | |
123 | + { | |
124 | + //发送短信集合 | |
125 | + MsgListRequest list = new MsgListRequest(); | |
126 | + List<MsgRequest> messages = new ArrayList<>(); | |
127 | + PatientsQuery patientsQuery = new PatientsQuery(); | |
128 | + patientsQuery.setYn(YnEnums.YES.getId()); | |
129 | + patientsQuery.setHospitalId(course.getHospitalId()); | |
130 | + patientsQuery.setLimit(1000); | |
131 | + int count = 1; | |
132 | + while (true) | |
133 | + { | |
134 | + List buildType = new ArrayList(); | |
135 | + buildType.add(0); | |
136 | + buildType.add(2); | |
137 | + patientsQuery.setSmsBuildTypeList(buildType); | |
138 | + //1孕妇 3 产妇 | |
139 | + patientsQuery.setType(1); | |
140 | + //分娩状态 | |
141 | + patientsQuery.setDueStatus(0); | |
142 | + | |
143 | + //末次月经必须大于当前时间减去42周视为未分娩孕妇 | |
144 | + Date lastMenses = DateUtils.getNewDate(new Date(),-42, "周", 0); | |
145 | + Date lastMensesMax = DateUtils.formatDate(lastMenses,DateUtils.Y_M_D); | |
146 | + patientsQuery.setLastMensesStart(lastMensesMax); | |
147 | + | |
148 | + patientsQuery.setNeed("true"); | |
149 | + patientsQuery.setPage(count); | |
150 | + | |
151 | + //查询符合条件的孕妇 | |
152 | + List<Patients> patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); | |
153 | + if (CollectionUtils.isNotEmpty(patients)) | |
154 | + { | |
155 | + for (Patients pat : patients) | |
156 | + { | |
157 | + //消息前缀 | |
158 | + String messagePrefix = baseService.getSmsPrefix(config, pat.getBookbuildingDoctor(), ServiceObjEnums.YUNOBJ.getId()); | |
159 | + String courseTime = DateUtils.getDateStr(course.getCourseTime(),DateUtils.Y_M_D_H_M)+" ("+DateUtils.getWeekOfDate(course.getCourseTime())+")"; | |
160 | + | |
161 | + String messageContent = "【"+messagePrefix+"】"; | |
162 | + MsgRequest request = HelperUtils.getMessageRequest(messageContent, pat.getPhone(), | |
163 | + ServiceObjEnums.YUNOBJ.getId(), SmsServiceEnums.YFXXKCTX.getId(), | |
164 | + course.getHospitalId(), course.getId(), pat.getId(), course.getCourseName(), | |
165 | + course.getCourseSpeaker(), courseTime, | |
166 | + WxTempleteIdEnums.YUN_XUE_KE_CHEN_TX.getId(),service); | |
167 | + | |
168 | + messages.add(request); | |
169 | + } | |
170 | + } | |
171 | + else | |
172 | + { | |
173 | + break; | |
174 | + } | |
175 | + count++; | |
176 | + } | |
177 | + list.setMessages(messages); | |
178 | + HelperUtils.sendMsg(list); | |
179 | + } | |
180 | + | |
181 | + private void generateChan(CourseModel course,SmsConfigModel config,int service) | |
182 | + { | |
183 | + //发送短信集合 | |
184 | + MsgListRequest list = new MsgListRequest(); | |
185 | + List<MsgRequest> messages = new ArrayList<>(); | |
186 | + | |
187 | + list.setMessages(messages); | |
188 | + HelperUtils.sendMsg(list); | |
189 | + } | |
190 | +} |