Commit 7656ff94a847b34406c6086db0c929856d1f3d0c
1 parent
185b1b2f71
Exists in
master
and in
6 other branches
update code
Showing 6 changed files with 211 additions and 14 deletions
- platform-common/src/main/java/com/lyms/platform/common/enums/WxTempleteIdEnums.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/utils/DateUtils.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/BabyAmsMsgGenerateWorker.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/ChanAmsMsgGenerateWorker.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/TempleteMsgGenerateWorker.java
platform-common/src/main/java/com/lyms/platform/common/enums/WxTempleteIdEnums.java
View file @
7656ff9
... | ... | @@ -19,7 +19,8 @@ |
19 | 19 | |
20 | 20 | GAO_WEI_ZHI_DAO("n6fSC1wYc3jOfGmuI1Vtbut6TlaBPlt5482SqJ8CE4o","高危提醒"), |
21 | 21 | |
22 | - ER_JIAN_KANG_ZHI_DAO("","儿童健康指导"); | |
22 | + ER_JIAN_KANG_ZHI_DAO("","儿童健康指导"), | |
23 | + CHAN_JIAN_KANG_ZHI_DAO("","产妇健康指导"); | |
23 | 24 | private WxTempleteIdEnums(String id, String name){ |
24 | 25 | this.name=name; |
25 | 26 | this.id =id; |
platform-msg-generate/src/main/java/com/lyms/platform/msg/service/impl/MsgGenerateServiceImpl.java
View file @
7656ff9
... | ... | @@ -49,6 +49,10 @@ |
49 | 49 | private BabyBookbuildingService babyBookbuildingService; |
50 | 50 | |
51 | 51 | |
52 | + @Autowired | |
53 | + private PostReviewService postReviewService; | |
54 | + | |
55 | + | |
52 | 56 | /** |
53 | 57 | * 生成孕妇的AMS推送消息 |
54 | 58 | * @param generateHospitalId 医院id |
... | ... | @@ -146,7 +150,7 @@ |
146 | 150 | end = configModels.size(); |
147 | 151 | } |
148 | 152 | TempleteMsgGenerateWorker worker = new TempleteMsgGenerateWorker(configModels.subList(i,end), |
149 | - baseService,yunBookbuildingService,smsTemplateService,babyBookbuildingService); | |
153 | + baseService,yunBookbuildingService,smsTemplateService,babyBookbuildingService,postReviewService); | |
150 | 154 | pool.submit(worker); |
151 | 155 | } |
152 | 156 |
platform-msg-generate/src/main/java/com/lyms/platform/msg/utils/DateUtils.java
View file @
7656ff9
... | ... | @@ -88,6 +88,18 @@ |
88 | 88 | } |
89 | 89 | |
90 | 90 | |
91 | + public static Date addYear(Date srcDate, int year) { | |
92 | + try { | |
93 | + lock.lock(); | |
94 | + Calendar rightNow = Calendar.getInstance(); | |
95 | + rightNow.setTime(srcDate); | |
96 | + rightNow.add(Calendar.YEAR, year); | |
97 | + return rightNow.getTime(); | |
98 | + }finally { | |
99 | + lock.unlock(); | |
100 | + } | |
101 | + } | |
102 | + | |
91 | 103 | /** |
92 | 104 | * 把时间格式化成对应格式的时间 |
93 | 105 | * @param date |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/BabyAmsMsgGenerateWorker.java
View file @
7656ff9
... | ... | @@ -96,7 +96,7 @@ |
96 | 96 | babyQuery.setSmsBuildTypeList(buildType); |
97 | 97 | |
98 | 98 | //儿童年龄满三岁就不在提供短信服务 |
99 | - Date birthdayMax = DateUtil.addYear(new Date(), -3); | |
99 | + Date birthdayMax = DateUtils.addYear(new Date(), -3); | |
100 | 100 | babyQuery.setBirthStart(birthdayMax); |
101 | 101 | //健康指导短信 只能是类型为 增值服务 开通状态 才发送 |
102 | 102 | babyQuery.setServiceType(ServiceTypeEnums.ADD_SERVICE.getId()); |
... | ... | @@ -127,7 +127,7 @@ |
127 | 127 | } |
128 | 128 | |
129 | 129 | |
130 | - int weeks = DateUtil.daysBetween(baby.getBirth(),new Date()) / 7; | |
130 | + int weeks = DateUtils.daysBetween(baby.getBirth(),new Date()) / 7; | |
131 | 131 | String weekAge = String.valueOf(weeks); |
132 | 132 | //得到符合当前周龄的短信条数 |
133 | 133 | List<MessageContent> messageContents = amsSmses.get(weekAge); |
134 | 134 | |
135 | 135 | |
... | ... | @@ -143,13 +143,13 @@ |
143 | 143 | continue; |
144 | 144 | } |
145 | 145 | |
146 | - String weekDay = DateUtil.getWeek(baby.getBirth(), new Date())+"周"; | |
147 | - String title = "儿童健康指导";//SmsServiceEnums.getSmsServiceById(SmsServiceEnums.YBZD.getId()); | |
146 | + String weekDay = weeks+"周"; | |
147 | + String title = "儿童健康指导"; | |
148 | 148 | |
149 | 149 | String messageContent = "【"+messagePrefix+"】" + message.getContent(); |
150 | - MessageRequest request = HelperUtils.getMessageRequest(title, baby.getMphone(), | |
150 | + MessageRequest request = HelperUtils.getMessageRequest(messageContent, baby.getMphone(), | |
151 | 151 | ServiceObjEnums.BABYOBJ.getId(), SmsServiceEnums.YBZD.getId(), |
152 | - baby.getHospitalId(), message.getId(), baby.getId(), weekDay, "", messageContent, WxTempleteIdEnums.ER_JIAN_KANG_ZHI_DAO.getId()); | |
152 | + baby.getHospitalId(), message.getId(), baby.getId(), weekDay, title, "", WxTempleteIdEnums.ER_JIAN_KANG_ZHI_DAO.getId()); | |
153 | 153 | |
154 | 154 | messages.add(request); |
155 | 155 | break; |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/ChanAmsMsgGenerateWorker.java
View file @
7656ff9
... | ... | @@ -59,7 +59,103 @@ |
59 | 59 | { |
60 | 60 | for(SmsConfigModel config : configs) { |
61 | 61 | |
62 | + String hospitalId = config.getHospitalId(); | |
63 | + if (StringUtils.isEmpty(hospitalId)) | |
64 | + { | |
65 | + continue; | |
66 | + } | |
62 | 67 | |
68 | + //判断医院是否运行 | |
69 | + if (!baseService.isRunning(hospitalId)) | |
70 | + { | |
71 | + continue; | |
72 | + } | |
73 | + | |
74 | + String serviceStr = config.getSmsService(); | |
75 | + | |
76 | + //判断消息服务是否启动 | |
77 | + boolean isStart = baseService.isStartService(SmsServiceEnums.YBZD.getId(),serviceStr); | |
78 | + if (!isStart) | |
79 | + { | |
80 | + continue; | |
81 | + } | |
82 | + // 查询模板短信 从ams平台配置的短信通过医院ID | |
83 | + Map<String, List<MessageContent>> amsSmses = AmsMessageService | |
84 | + .getMessageTemplateMap(String.valueOf(hospitalId), | |
85 | + AmsServiceTypeEnum.CHAN_GUIDE); | |
86 | + | |
87 | + | |
88 | + PatientsQuery patientsQuery = new PatientsQuery(); | |
89 | + patientsQuery.setYn(YnEnums.YES.getId()); | |
90 | + patientsQuery.setHospitalId(hospitalId); | |
91 | + //1孕妇 3 产妇 | |
92 | + patientsQuery.setType(3); | |
93 | + patientsQuery.setDueStatus(0); | |
94 | + | |
95 | + List buildType = new ArrayList(); | |
96 | + buildType.add(0); | |
97 | + buildType.add(2); | |
98 | + patientsQuery.setSmsBuildTypeList(buildType); | |
99 | + | |
100 | +// //末次月经必须大于当前时间减去42周视为为分娩孕妇 | |
101 | +// Date lastMensesMax = DateUtil.addDay(new Date(), -42); | |
102 | +// patientsQuery.setLastMensesStart(lastMensesMax); | |
103 | + //健康指导短信 只能是类型为 增值服务 开通状态 才发送 | |
104 | + patientsQuery.setServiceType(ServiceTypeEnums.ADD_SERVICE.getId()); | |
105 | + patientsQuery.setServiceStatus(ServiceStatusEnums.ADD_OPEN.getId()); | |
106 | + | |
107 | + | |
108 | + //查询符合条件的产妇 | |
109 | + List<Patients> patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); | |
110 | + if (CollectionUtils.isNotEmpty(patients)) | |
111 | + { | |
112 | + | |
113 | + //发送短信集合 | |
114 | + MessageListRequest list = new MessageListRequest(); | |
115 | + List<MessageRequest> messages = new ArrayList<>(); | |
116 | + for (Patients pat : patients) | |
117 | + { | |
118 | + if (pat == null || pat.getFmDate() == null) | |
119 | + { | |
120 | + continue; | |
121 | + } | |
122 | + | |
123 | + String messagePrefix = baseService.getSmsPrefix(config, pat.getBookbuildingDoctor()); | |
124 | + | |
125 | + //计算产后多少周 按分娩日期计算 | |
126 | + int weeks = DateUtils.daysBetween(pat.getFmDate(),new Date()) / 7; | |
127 | + String yunWeek = String.valueOf(weeks); | |
128 | + //得到符合当前孕周的短信条数 | |
129 | + List<MessageContent> messageContents = amsSmses.get(yunWeek); | |
130 | + | |
131 | + if (CollectionUtils.isNotEmpty(messageContents)) | |
132 | + { | |
133 | + for(MessageContent message : messageContents) | |
134 | + { | |
135 | + | |
136 | + //判断当前短信是否已经发送 通过短信ID和产妇ID | |
137 | + boolean isExist = SaveMessageService.isExistMsg(pat.getId(), message.getId()); | |
138 | + if (isExist) | |
139 | + { | |
140 | + continue; | |
141 | + } | |
142 | + | |
143 | + String weekDay = weeks+"周"; | |
144 | + String title = "产妇健康指导"; | |
145 | + | |
146 | + String messageContent = "【"+messagePrefix+"】" + message.getContent(); | |
147 | + MessageRequest request = HelperUtils.getMessageRequest(messageContent, pat.getPhone(), | |
148 | + ServiceObjEnums.CHANOBJ.getId(), SmsServiceEnums.YBZD.getId(), | |
149 | + pat.getHospitalId(), message.getId(), pat.getId(), weekDay, title, "", WxTempleteIdEnums.CHAN_JIAN_KANG_ZHI_DAO.getId()); | |
150 | + | |
151 | + messages.add(request); | |
152 | + break; | |
153 | + } | |
154 | + } | |
155 | + } | |
156 | + list.setMessages(messages); | |
157 | + HelperUtils.sendMsg(list); | |
158 | + } | |
63 | 159 | } |
64 | 160 | } |
65 | 161 | } |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/TempleteMsgGenerateWorker.java
View file @
7656ff9
... | ... | @@ -2,10 +2,7 @@ |
2 | 2 | |
3 | 3 | import com.lyms.platform.beans.MessageListRequest; |
4 | 4 | import com.lyms.platform.beans.MessageRequest; |
5 | -import com.lyms.platform.biz.service.BabyBookbuildingService; | |
6 | -import com.lyms.platform.biz.service.SmsConfigService; | |
7 | -import com.lyms.platform.biz.service.SmsTemplateService; | |
8 | -import com.lyms.platform.biz.service.YunBookbuildingService; | |
5 | +import com.lyms.platform.biz.service.*; | |
9 | 6 | import com.lyms.platform.common.enums.*; |
10 | 7 | import com.lyms.platform.common.utils.DateUtil; |
11 | 8 | import com.lyms.platform.common.utils.ExceptionUtils; |
... | ... | @@ -18,6 +15,7 @@ |
18 | 15 | import org.apache.commons.collections.CollectionUtils; |
19 | 16 | import org.slf4j.Logger; |
20 | 17 | import org.slf4j.LoggerFactory; |
18 | +import org.springframework.beans.factory.annotation.Autowired; | |
21 | 19 | |
22 | 20 | import java.util.*; |
23 | 21 | import java.util.concurrent.ExecutorService; |
24 | 22 | |
25 | 23 | |
... | ... | @@ -43,16 +41,20 @@ |
43 | 41 | |
44 | 42 | private BabyBookbuildingService babyBookbuildingService; |
45 | 43 | |
44 | + private PostReviewService postReviewService; | |
45 | + | |
46 | 46 | public TempleteMsgGenerateWorker(List<SmsConfigModel> configs, IBaseService baseService, |
47 | 47 | YunBookbuildingService yunBookbuildingService, |
48 | 48 | SmsTemplateService smsTemplateService, |
49 | - BabyBookbuildingService babyBookbuildingService) | |
49 | + BabyBookbuildingService babyBookbuildingService, | |
50 | + PostReviewService postReviewService) | |
50 | 51 | { |
51 | 52 | this.configs = configs; |
52 | 53 | this.baseService = baseService; |
53 | 54 | this.yunBookbuildingService = yunBookbuildingService; |
54 | 55 | this.smsTemplateService = smsTemplateService; |
55 | 56 | this.babyBookbuildingService = babyBookbuildingService; |
57 | + this.postReviewService = postReviewService; | |
56 | 58 | } |
57 | 59 | |
58 | 60 | @Override |
... | ... | @@ -137,7 +139,7 @@ |
137 | 139 | //产妇 |
138 | 140 | else if (serviceObj == ServiceObjEnums.CHANOBJ.getId()) |
139 | 141 | { |
140 | - | |
142 | + generateChanTempMsg(template, config); | |
141 | 143 | } |
142 | 144 | } |
143 | 145 | catch (Exception e) |
... | ... | @@ -539,6 +541,88 @@ |
539 | 541 | |
540 | 542 | list.setMessages(messages); |
541 | 543 | HelperUtils.sendMsg(list); |
544 | + } | |
545 | + | |
546 | + | |
547 | + /** | |
548 | + * 产妇模板消息生成 | |
549 | + * @param template | |
550 | + * @param config | |
551 | + */ | |
552 | + private void generateChanTempMsg(SmsTemplateModel template, SmsConfigModel config) { | |
553 | + | |
554 | + //模板属于的医院id | |
555 | + String tempHid = template.getHospitalId(); | |
556 | + | |
557 | + //服务类型 | |
558 | + Integer serviceType = template.getServiceType(); | |
559 | + //服务状态 | |
560 | + Integer serviceStatus = template.getServiceStatus(); | |
561 | + //消息类型 | |
562 | + Integer smsType = template.getSmsType(); | |
563 | + | |
564 | + //发送时间 SendTimeEnums DT(0,"当天"),QYT(1,"前一天"),QLT(2,"前两天"),QST(3,"前三天"); | |
565 | + Integer sendTimeType = template.getSendTimeType(); | |
566 | + | |
567 | + | |
568 | + PatientsQuery patientsQuery = new PatientsQuery(); | |
569 | + patientsQuery.setYn(YnEnums.YES.getId()); | |
570 | + patientsQuery.setHospitalId(tempHid); | |
571 | + | |
572 | + List buildType = new ArrayList(); | |
573 | + buildType.add(0); | |
574 | + buildType.add(2); | |
575 | + patientsQuery.setSmsBuildTypeList(buildType); | |
576 | + //1孕妇 3产妇 | |
577 | + patientsQuery.setType(3); | |
578 | + //0未终止妊娠的产妇 | |
579 | + patientsQuery.setDueStatus(0); | |
580 | + | |
581 | + HelperUtils.getServicePatientQuery(serviceType, serviceStatus, patientsQuery); | |
582 | + | |
583 | + //发送短信集合 | |
584 | + MessageListRequest list = new MessageListRequest(); | |
585 | + List<MessageRequest> messages = new ArrayList<>(); | |
586 | + | |
587 | + //产妇预约短信 | |
588 | + if (smsType == SmsServiceEnums.CHFCYUTX.getId()) | |
589 | + { | |
590 | + //把时间格式成yyyy_MM_dd | |
591 | + String currentDate = DateUtil.getyyyy_MM_dd(new Date()); | |
592 | + Date actualSendDate = DateUtil.addDay(DateUtil.parseYMD(currentDate), sendTimeType); | |
593 | + | |
594 | + //查询出产妇预约 | |
595 | + List<PostReviewModel> orderModels = postReviewService.queryPostOrder(actualSendDate, tempHid); | |
596 | + | |
597 | + if(CollectionUtils.isNotEmpty(orderModels)) | |
598 | + { | |
599 | + for(PostReviewModel orderModel : orderModels) | |
600 | + { | |
601 | + PatientsQuery query = new PatientsQuery(); | |
602 | + query.setYn(YnEnums.YES.getId()); | |
603 | + query.setId(orderModel.getId()); //id就是parentId | |
604 | + | |
605 | + //查询符合条件的产妇 | |
606 | + List<Patients> patients = yunBookbuildingService.queryPregnantWithQuery(query); | |
607 | + if (CollectionUtils.isNotEmpty(patients)) | |
608 | + { | |
609 | + for (Patients pat : patients) | |
610 | + { | |
611 | + //短信前缀 | |
612 | + String messagePrefix = baseService.getSmsPrefix(config, pat.getBookbuildingDoctor()); | |
613 | + String messageContent = "【"+messagePrefix+"】"+template.getContent(); | |
614 | + String title = "产后复查"; | |
615 | + messageContent = HelperUtils.replaceEL(pat.getUsername(), actualSendDate, messageContent); | |
616 | + MessageRequest request = HelperUtils.getMessageRequest(messageContent, pat.getPhone(), | |
617 | + ServiceObjEnums.CHANOBJ.getId(), template.getSmsType(), | |
618 | + pat.getHospitalId(), template.getId(), pat.getId(), title, DateUtils.getDateStr(actualSendDate,DateUtils.Y_M_D), "", WxTempleteIdEnums.CHAN_JIAN_TI_XING.getId()); | |
619 | + | |
620 | + messages.add(request); | |
621 | + } | |
622 | + } | |
623 | + } | |
624 | + } | |
625 | + } | |
542 | 626 | } |
543 | 627 | } |