Commit 92bca66521f6c42b04800883608d264a6ead11be
1 parent
6b03436d4f
Exists in
master
and in
6 other branches
短信修改
Showing 7 changed files with 264 additions and 271 deletions
- platform-msg-generate/src/main/java/com/lyms/platform/msg/model/MessageContent.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/model/MessageResponseEntity.java
- platform-msg-generate/src/main/java/com/lyms/platform/msg/remote/AmsMessageService.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/YunAmsMsgGenerateWorker.java
- platform-msg-generate/src/main/resources/config.properties
platform-msg-generate/src/main/java/com/lyms/platform/msg/model/MessageContent.java
View file @
92bca66
... | ... | @@ -9,11 +9,22 @@ |
9 | 9 | public class MessageContent implements Serializable { |
10 | 10 | private static final long serialVersionUID = 1L; |
11 | 11 | private String id; |
12 | - private String content; | |
13 | - private String title; | |
14 | - private List<Tag> tags; | |
12 | +// private String title; | |
13 | +// private List<Tag> tags; | |
15 | 14 | private String highRiskId; |
16 | 15 | |
16 | + private String content; | |
17 | + | |
18 | + private String riskName; | |
19 | + | |
20 | + public String getRiskName() { | |
21 | + return riskName; | |
22 | + } | |
23 | + | |
24 | + public void setRiskName(String riskName) { | |
25 | + this.riskName = riskName; | |
26 | + } | |
27 | + | |
17 | 28 | public String getHighRiskId() { |
18 | 29 | return highRiskId; |
19 | 30 | } |
20 | 31 | |
21 | 32 | |
... | ... | @@ -38,26 +49,12 @@ |
38 | 49 | this.content = content; |
39 | 50 | } |
40 | 51 | |
41 | - public String getTitle() { | |
42 | - return title; | |
43 | - } | |
44 | 52 | |
45 | - public void setTitle(String title) { | |
46 | - this.title = title; | |
47 | - } | |
48 | - | |
49 | - public List<Tag> getTags() { | |
50 | - return tags; | |
51 | - } | |
52 | - | |
53 | - public void setTags(List<Tag> tags) { | |
54 | - this.tags = tags; | |
55 | - } | |
56 | - | |
57 | 53 | @Override |
58 | 54 | public String toString() { |
59 | - return "MessageContent [content=" + content + ", id=" + id + ", Tags=" | |
60 | - + tags + ", title=" + title + "]"; | |
55 | + return "MessageContent{" + | |
56 | + "content='" + content + '\'' + | |
57 | + '}'; | |
61 | 58 | } |
62 | 59 | } |
platform-msg-generate/src/main/java/com/lyms/platform/msg/model/MessageResponseEntity.java
View file @
92bca66
1 | 1 | package com.lyms.platform.msg.model; |
2 | 2 | |
3 | 3 | import java.util.List; |
4 | +import java.util.Map; | |
4 | 5 | |
5 | 6 | /** |
6 | 7 | * Created by Administrator on 2016/7/5. |
... | ... | @@ -8,7 +9,8 @@ |
8 | 9 | public class MessageResponseEntity { |
9 | 10 | private String errormsg; |
10 | 11 | private PageInfo pageInfo; |
11 | - private List<MessageContent> list ; | |
12 | + private Map<String,List<MessageContent>> categories; | |
13 | + private List list; | |
12 | 14 | private int errorcode; |
13 | 15 | public String getErrormsg() { |
14 | 16 | return errormsg; |
15 | 17 | |
16 | 18 | |
... | ... | @@ -23,12 +25,23 @@ |
23 | 25 | public void setPageInfo(PageInfo pageInfo) { |
24 | 26 | this.pageInfo = pageInfo; |
25 | 27 | } |
26 | - public List<MessageContent> getList() { | |
28 | + | |
29 | + public Map<String, List<MessageContent>> getCategories() { | |
30 | + return categories; | |
31 | + } | |
32 | + | |
33 | + public void setCategories(Map<String, List<MessageContent>> categories) { | |
34 | + this.categories = categories; | |
35 | + } | |
36 | + | |
37 | + public List getList() { | |
27 | 38 | return list; |
28 | 39 | } |
29 | - public void setList(List<MessageContent> list) { | |
40 | + | |
41 | + public void setList(List list) { | |
30 | 42 | this.list = list; |
31 | 43 | } |
44 | + | |
32 | 45 | public int getErrorcode() { |
33 | 46 | return errorcode; |
34 | 47 | } |
... | ... | @@ -38,7 +51,7 @@ |
38 | 51 | @Override |
39 | 52 | public String toString() { |
40 | 53 | return "MessageResponseEntity [errorcode=" + errorcode + ", errormsg=" |
41 | - + errormsg + ", list=" + list + ", pageInfo=" + pageInfo + "]"; | |
54 | + + errormsg + ", categories=" + categories + ", pageInfo=" + pageInfo + "]"; | |
42 | 55 | } |
43 | 56 | } |
platform-msg-generate/src/main/java/com/lyms/platform/msg/remote/AmsMessageService.java
View file @
92bca66
... | ... | @@ -3,21 +3,16 @@ |
3 | 3 | import com.lyms.platform.common.enums.AmsServiceTypeEnum; |
4 | 4 | import com.lyms.platform.common.utils.ExceptionUtils; |
5 | 5 | import com.lyms.platform.common.utils.HttpRequest; |
6 | -import com.lyms.platform.common.utils.StringUtils; | |
6 | +import com.lyms.platform.common.utils.JsonUtil; | |
7 | 7 | |
8 | 8 | import com.lyms.platform.msg.constants.ConfigInterface; |
9 | 9 | import com.lyms.platform.msg.model.MessageContent; |
10 | 10 | import com.lyms.platform.msg.model.MessageResponseEntity; |
11 | -import com.lyms.platform.msg.model.Tag; | |
12 | 11 | import org.slf4j.Logger; |
13 | 12 | import org.slf4j.LoggerFactory; |
14 | -import org.codehaus.jackson.JsonParseException; | |
15 | -import org.codehaus.jackson.map.JsonMappingException; | |
16 | 13 | import org.codehaus.jackson.map.ObjectMapper; |
17 | 14 | |
18 | -import java.io.IOException; | |
19 | 15 | |
20 | -import java.util.ArrayList; | |
21 | 16 | import java.util.HashMap; |
22 | 17 | |
23 | 18 | import java.util.List; |
24 | 19 | |
25 | 20 | |
... | ... | @@ -34,15 +29,10 @@ |
34 | 29 | private static final Logger logger = LoggerFactory.getLogger(AmsMessageService.class); |
35 | 30 | public static final String AMS_URL= ConfigInterface.AMS_URL; |
36 | 31 | private static final String AUTHORIZATION = "healthbaby2015"; |
32 | + private static ObjectMapper om = new ObjectMapper(); | |
37 | 33 | |
38 | - /** | |
39 | - * 根据医院id和对象来获取ams短信 | |
40 | - * @param hospitalId | |
41 | - * @param serviceType | |
42 | - * @return | |
43 | - */ | |
44 | 34 | public static Map<String,List<MessageContent>> getMessageTemplateMap(String hospitalId,AmsServiceTypeEnum serviceType) { |
45 | - System.out.println("ams > hospitalId="+hospitalId+";serviceType="+serviceType); | |
35 | + System.out.println("ams > hospitalId=" + hospitalId + ";serviceType=" + serviceType); | |
46 | 36 | |
47 | 37 | Map<String, String> headers = new HashMap<String, String>(); |
48 | 38 | headers.put("Authorization", AUTHORIZATION); |
49 | 39 | |
50 | 40 | |
51 | 41 | |
52 | 42 | |
53 | 43 | |
54 | 44 | |
... | ... | @@ -52,109 +42,139 @@ |
52 | 42 | params.put("limit", "9999"); |
53 | 43 | String str = HttpRequest.sendGet(AMS_URL, |
54 | 44 | params, headers); |
55 | - | |
56 | - //调用https用这个 | |
57 | - // String str = HttpClientUtil.doGet(AMS_URL, params, "utf-8", AUTHORIZATION); | |
58 | - | |
59 | - ObjectMapper om = new ObjectMapper(); | |
45 | + System.out.print(str); | |
60 | 46 | MessageResponseEntity mre = null; |
61 | - Map<String,List<MessageContent>> map = new HashMap<String, List<MessageContent>>(); | |
62 | 47 | try { |
63 | - mre = om.readValue(str, MessageResponseEntity.class); | |
64 | - } catch (JsonParseException e) { | |
65 | - ExceptionUtils.catchException(e,"JsonParseException"); | |
66 | - } catch (JsonMappingException e) { | |
67 | - ExceptionUtils.catchException(e, "JsonMappingException"); | |
68 | - } catch (IOException e) { | |
69 | - ExceptionUtils.catchException(e, "IOException"); | |
48 | + mre = JsonUtil.jkstr2Obj(str, MessageResponseEntity.class); | |
49 | + return mre.getCategories(); | |
50 | + } catch (Exception e) { | |
51 | + ExceptionUtils.catchException(e,"getMessageTemplateMap exception"); | |
70 | 52 | } |
71 | - if(mre !=null){ | |
72 | - if(mre.getErrorcode()==0){//成功 | |
73 | - List<MessageContent> mcs=mre.getList(); | |
74 | - for(int i = 0;i<mcs.size();i++){ | |
75 | - MessageContent mc = mcs.get(i); | |
76 | - List<Tag> tags = mc.getTags(); | |
77 | - for (int j = 0; j < tags.size(); j++) { | |
78 | - Tag tag=tags.get(j); | |
79 | - String type = getTagType(tag, serviceType); | |
80 | - if(!StringUtils.isEmpty(type)){ | |
81 | - List<MessageContent> list = map.get(type); | |
82 | - if(list==null){ | |
83 | - list = new ArrayList<MessageContent>(); | |
84 | - } | |
85 | - list.add(mc); | |
86 | - map.put(type, list); | |
87 | - }else{ | |
88 | - String riskName = tag.getTagName(); | |
89 | - List<MessageContent> list = map.get(riskName); | |
90 | - if(list==null){ | |
91 | - list = new ArrayList<MessageContent>(); | |
92 | - } | |
93 | - list.add(mc); | |
94 | - map.put(riskName, list); | |
95 | - } | |
96 | - } | |
97 | - } | |
98 | - }else{//失败 | |
99 | - logger.error("The hospital id is {},and error code is {},and error message is {}" | |
100 | - ,new Object[]{hospitalId,mre.getErrorcode(),mre.getErrormsg()}); | |
101 | - } | |
102 | - }else{ | |
103 | - logger.error("The hospital id is {},and error code is {},and error message is {}" | |
104 | - ,new Object[]{hospitalId,mre.getErrorcode(),mre.getErrormsg()}); | |
105 | - } | |
106 | - return map; | |
53 | + return null; | |
107 | 54 | } |
108 | 55 | |
109 | - public static String getTagType(Tag tag,AmsServiceTypeEnum serviceType){ | |
110 | - String re = null; | |
111 | - if(tag==null) return re; | |
112 | - String tagName = tag.getTagName(); | |
113 | - switch (serviceType) { | |
114 | - case CHILD_GUIDE: | |
115 | - boolean boo = tagName.endsWith("周"); | |
116 | - if(boo) { | |
117 | - String str = tagName.substring(0,tagName.length()-1); | |
118 | - if(StringUtils.isNum(str)){ | |
119 | - re = str; | |
120 | - } | |
121 | - } | |
122 | - break; | |
123 | - case YUN_GUIDE: | |
124 | - boolean end = tagName.endsWith("周"); | |
125 | - boolean start = tagName.startsWith("孕"); | |
126 | - if(start&&end) { | |
127 | - String str = tagName.substring(1,tagName.length()-1); | |
128 | - if(StringUtils.isNum(str)){ | |
129 | - re = str; | |
130 | - } | |
131 | - } | |
132 | - break; | |
133 | - case CHAN_GUIDE: | |
134 | - end = tagName.endsWith("周"); | |
135 | - start = tagName.startsWith("产后"); | |
136 | - if(start&&end) { | |
137 | - String str = tagName.substring(2,tagName.length()-1); | |
138 | - if(StringUtils.isNum(str)){ | |
139 | - re = str; | |
140 | - } | |
141 | - } | |
142 | - break; | |
143 | - case YUN_WARN: | |
144 | - end = tagName.endsWith("周"); | |
145 | - start = tagName.startsWith("孕"); | |
146 | - if(!start && !end) { | |
147 | - re = tagName; | |
148 | - } | |
149 | - break; | |
150 | - default: | |
151 | - break; | |
152 | - } | |
153 | - return re; | |
154 | - } | |
155 | 56 | |
57 | + | |
58 | +// /** | |
59 | +// * 根据医院id和对象来获取ams短信 | |
60 | +// * @param hospitalId | |
61 | +// * @param serviceType | |
62 | +// * @return | |
63 | +// */ | |
64 | +// public static Map<String,List<MessageContent>> getMessageTemplateMap(String hospitalId,AmsServiceTypeEnum serviceType) { | |
65 | +// System.out.println("ams > hospitalId="+hospitalId+";serviceType="+serviceType); | |
66 | +// | |
67 | +// Map<String, String> headers = new HashMap<String, String>(); | |
68 | +// headers.put("Authorization", AUTHORIZATION); | |
69 | +// Map<String, String> params = new HashMap<String, String>(); | |
70 | +// params.put("hospitalId", hospitalId); | |
71 | +// params.put("page", "1"); | |
72 | +// params.put("limit", "9999"); | |
73 | +// String str = HttpRequest.sendGet(AMS_URL, | |
74 | +// params, headers); | |
75 | +// | |
76 | +// //调用https用这个 | |
77 | +// // String str = HttpClientUtil.doGet(AMS_URL, params, "utf-8", AUTHORIZATION); | |
78 | +// | |
79 | +// ObjectMapper om = new ObjectMapper(); | |
80 | +// MessageResponseEntity mre = null; | |
81 | +// Map<String,List<MessageContent>> map = new HashMap<String, List<MessageContent>>(); | |
82 | +// try { | |
83 | +// mre = om.readValue(str, MessageResponseEntity.class); | |
84 | +// } catch (JsonParseException e) { | |
85 | +// ExceptionUtils.catchException(e,"JsonParseException"); | |
86 | +// } catch (JsonMappingException e) { | |
87 | +// ExceptionUtils.catchException(e, "JsonMappingException"); | |
88 | +// } catch (IOException e) { | |
89 | +// ExceptionUtils.catchException(e, "IOException"); | |
90 | +// } | |
91 | +// if(mre !=null){ | |
92 | +// if(mre.getErrorcode()==0){//成功 | |
93 | +// List<MessageContent> mcs=mre.getList(); | |
94 | +// for(int i = 0;i<mcs.size();i++){ | |
95 | +// MessageContent mc = mcs.get(i); | |
96 | +// List<Tag> tags = mc.getTags(); | |
97 | +// for (int j = 0; j < tags.size(); j++) { | |
98 | +// Tag tag=tags.get(j); | |
99 | +// String type = getTagType(tag, serviceType); | |
100 | +// if(!StringUtils.isEmpty(type)){ | |
101 | +// List<MessageContent> list = map.get(type); | |
102 | +// if(list==null){ | |
103 | +// list = new ArrayList<MessageContent>(); | |
104 | +// } | |
105 | +// list.add(mc); | |
106 | +// map.put(type, list); | |
107 | +// }else{ | |
108 | +// String riskName = tag.getTagName(); | |
109 | +// List<MessageContent> list = map.get(riskName); | |
110 | +// if(list==null){ | |
111 | +// list = new ArrayList<MessageContent>(); | |
112 | +// } | |
113 | +// list.add(mc); | |
114 | +// map.put(riskName, list); | |
115 | +// } | |
116 | +// } | |
117 | +// } | |
118 | +// }else{//失败 | |
119 | +// logger.error("The hospital id is {},and error code is {},and error message is {}" | |
120 | +// ,new Object[]{hospitalId,mre.getErrorcode(),mre.getErrormsg()}); | |
121 | +// } | |
122 | +// }else{ | |
123 | +// logger.error("The hospital id is {},and error code is {},and error message is {}" | |
124 | +// ,new Object[]{hospitalId,mre.getErrorcode(),mre.getErrormsg()}); | |
125 | +// } | |
126 | +// return map; | |
127 | +// } | |
128 | +// | |
129 | +// public static String getTagType(Tag tag,AmsServiceTypeEnum serviceType){ | |
130 | +// String re = null; | |
131 | +// if(tag==null) return re; | |
132 | +// String tagName = tag.getTagName(); | |
133 | +// switch (serviceType) { | |
134 | +// case CHILD_GUIDE: | |
135 | +// boolean boo = tagName.endsWith("周"); | |
136 | +// if(boo) { | |
137 | +// String str = tagName.substring(0,tagName.length()-1); | |
138 | +// if(StringUtils.isNum(str)){ | |
139 | +// re = str; | |
140 | +// } | |
141 | +// } | |
142 | +// break; | |
143 | +// case YUN_GUIDE: | |
144 | +// boolean end = tagName.endsWith("周"); | |
145 | +// boolean start = tagName.startsWith("孕"); | |
146 | +// if(start&&end) { | |
147 | +// String str = tagName.substring(1,tagName.length()-1); | |
148 | +// if(StringUtils.isNum(str)){ | |
149 | +// re = str; | |
150 | +// } | |
151 | +// } | |
152 | +// break; | |
153 | +// case CHAN_GUIDE: | |
154 | +// end = tagName.endsWith("周"); | |
155 | +// start = tagName.startsWith("产后"); | |
156 | +// if(start&&end) { | |
157 | +// String str = tagName.substring(2,tagName.length()-1); | |
158 | +// if(StringUtils.isNum(str)){ | |
159 | +// re = str; | |
160 | +// } | |
161 | +// } | |
162 | +// break; | |
163 | +// case YUN_WARN: | |
164 | +// end = tagName.endsWith("周"); | |
165 | +// start = tagName.startsWith("孕"); | |
166 | +// if(!start && !end) { | |
167 | +// re = tagName; | |
168 | +// } | |
169 | +// break; | |
170 | +// default: | |
171 | +// break; | |
172 | +// } | |
173 | +// return re; | |
174 | +// } | |
175 | + | |
156 | 176 | public static void main(String[] args) { |
157 | - Map<String,List<MessageContent>> list = getMessageTemplateMap("204", | |
177 | + Map<String,List<MessageContent>> list = getMessageTemplateMap("216", | |
158 | 178 | AmsServiceTypeEnum.CHILD_GUIDE); |
159 | 179 | List<MessageContent> msgs = list.get("0周"); |
160 | 180 | System.out.println(list); |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/BabyAmsMsgGenerateWorker.java
View file @
92bca66
... | ... | @@ -123,7 +123,7 @@ |
123 | 123 | String messagePrefix = baseService.getSmsPrefix(config, baby.getBuildDoctor(),ServiceObjEnums.BABYOBJ.getId()); |
124 | 124 | |
125 | 125 | int weeks = DateUtils.daysBetween(baby.getBirth(),new Date()) / 7; |
126 | - String weekAge = String.valueOf(weeks); | |
126 | + String weekAge = String.valueOf(weeks)+"周"; | |
127 | 127 | //得到符合当前周龄的短信条数 |
128 | 128 | List<MessageContent> messageContents = amsSmses.get(weekAge); |
129 | 129 |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/ChanAmsMsgGenerateWorker.java
View file @
92bca66
... | ... | @@ -123,7 +123,7 @@ |
123 | 123 | |
124 | 124 | //计算产后多少周 按分娩日期计算 |
125 | 125 | int weeks = DateUtils.daysBetween(pat.getFmDate(),new Date()) / 7; |
126 | - String yunWeek = String.valueOf(weeks); | |
126 | + String yunWeek = "产后"+String.valueOf(weeks)+"周"; | |
127 | 127 | //得到符合当前孕周的短信条数 |
128 | 128 | List<MessageContent> messageContents = amsSmses.get(yunWeek); |
129 | 129 |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/YunAmsMsgGenerateWorker.java
View file @
92bca66
... | ... | @@ -22,10 +22,7 @@ |
22 | 22 | import org.slf4j.Logger; |
23 | 23 | import org.slf4j.LoggerFactory; |
24 | 24 | |
25 | -import java.util.ArrayList; | |
26 | -import java.util.Date; | |
27 | -import java.util.List; | |
28 | -import java.util.Map; | |
25 | +import java.util.*; | |
29 | 26 | |
30 | 27 | /** |
31 | 28 | * Created by lqy on 2017-07-18. |
32 | 29 | |
33 | 30 | |
34 | 31 | |
... | ... | @@ -87,30 +84,30 @@ |
87 | 84 | |
88 | 85 | String serviceStr = config.getSmsService(); |
89 | 86 | String serviceType = config.getServiceType(); |
90 | - | |
91 | - int weekNum = HelperUtils.getWeekNum(guideTimes, week); | |
92 | - | |
93 | - //判断消息服务是否启动 | |
94 | - int service = 0; | |
95 | - | |
87 | +// /** | |
88 | +// * 孕妇一周发送两次消息,第一次发送高危指导,一次发送一般指导 | |
89 | +// * 孕妇周二发送高危指导 周五发送一般指导,根据小的周号发送高危指导,大的周号发送一般指导 | |
90 | +// * 小周号判断高危指导是否开通 大周号判断一般指导是否开通 | |
91 | +// */ | |
96 | 92 | /** |
97 | - * 孕妇一周发送两次消息,第一次发送高危指导,一次发送一般指导 | |
98 | - * 孕妇周二发送高危指导 周五发送一般指导,根据小的周号发送高危指导,大的周号发送一般指导 | |
99 | - * 小周号判断高危指导是否开通 大周号判断一般指导是否开通 | |
93 | + *高危指导消息发送 | |
94 | + ①健康指导消息针对所有收费孕妇提供每周2条消息 | |
95 | + ②如果孕妇有高危因素的话,在健康指导基础上再另外提供对应的每周2条高危消息,几项风险因素对应几个2条。 | |
96 | + ③具体发送时间与孕产婴平台上配置的健康指导消息发送频率一致即可。例如平台配置的是每周二、五,那就是周二发一次, | |
97 | + 符合几项风险因素条件就发几条;周五发一次,符合吉祥风险因素条件就发几条。 | |
98 | + 例如一名孕妇孕20周有妊娠期糖尿病和梅毒两项风险因素。 | |
99 | + 平台配置周二周五发送消息。 | |
100 | + 周二时候给这名孕妇 发孕20周 健康指导1条 妊娠期糖尿病1条 梅毒1条 | |
101 | + 周五时候给这名孕妇 发孕20周另外的1条健康指导、妊娠糖尿病、梅毒消息。 | |
100 | 102 | */ |
101 | - if (weekNum > WeekEnums.getIdByName(week)) | |
102 | - { | |
103 | - //判断消息服务是否启动 | |
104 | - //0服务不提供,1 推送服务, 2 短信服务,3推送和短信服务 | |
105 | - service = baseService.isStartService(SmsServiceEnums.GWZD.getId(), serviceStr,serviceType); | |
106 | - } | |
107 | - else | |
108 | - { | |
109 | - //判断消息服务是否启动 | |
110 | - service = baseService.isStartService(SmsServiceEnums.YBZD.getId(), serviceStr,serviceType); | |
111 | - } | |
112 | 103 | |
113 | - if (service == 0) { | |
104 | + //判断消息服务是否启动 | |
105 | + //0服务不提供,1 推送服务, 2 短信服务,3推送和短信服务 | |
106 | + int serviceGwzd = baseService.isStartService(SmsServiceEnums.GWZD.getId(), serviceStr,serviceType); | |
107 | + //判断消息服务是否启动 | |
108 | + int serviceYbzd = baseService.isStartService(SmsServiceEnums.YBZD.getId(), serviceStr,serviceType); | |
109 | + | |
110 | + if (serviceGwzd == 0 && serviceYbzd == 0) { | |
114 | 111 | continue; |
115 | 112 | } |
116 | 113 | |
117 | 114 | |
118 | 115 | |
119 | 116 | |
120 | 117 | |
121 | 118 | |
122 | 119 | |
123 | 120 | |
124 | 121 | |
125 | 122 | |
126 | 123 | |
127 | 124 | |
128 | 125 | |
129 | 126 | |
130 | 127 | |
131 | 128 | |
132 | 129 | |
133 | 130 | |
134 | 131 | |
135 | 132 | |
136 | 133 | |
... | ... | @@ -149,149 +146,115 @@ |
149 | 146 | //查询符合条件的孕妇 |
150 | 147 | List<Patients> patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); |
151 | 148 | |
152 | - | |
153 | 149 | if (CollectionUtils.isNotEmpty(patients)) |
154 | 150 | { |
155 | 151 | |
156 | 152 | //发送短信集合 |
157 | 153 | MsgListRequest list = new MsgListRequest(); |
158 | 154 | List<MsgRequest> messages = new ArrayList<>(); |
159 | - for (Patients pat : patients) | |
160 | - { | |
161 | - if (pat == null || pat.getLastMenses() == null) | |
162 | - { | |
155 | + for (Patients pat : patients) { | |
156 | + if (pat == null || pat.getLastMenses() == null) { | |
163 | 157 | continue; |
164 | 158 | } |
165 | 159 | |
160 | + //计算出孕周 孕周计算方式 当前时间减去末次月经 除以7 的到孕周 | |
161 | + int weeks = DateUtils.daysBetween(pat.getLastMenses(), new Date()) / 7; | |
162 | + String yunWeek = "孕" + String.valueOf(weeks) + "周"; | |
163 | + | |
166 | 164 | //消息前缀 |
167 | - String messagePrefix = baseService.getSmsPrefix(config, pat.getBookbuildingDoctor(),ServiceObjEnums.YUNOBJ.getId()); | |
165 | + String messagePrefix = baseService.getSmsPrefix(config, pat.getBookbuildingDoctor(), ServiceObjEnums.YUNOBJ.getId()); | |
168 | 166 | |
169 | - boolean isRisk = false; | |
170 | - if (weekNum > WeekEnums.getIdByName(week)) | |
171 | - { | |
172 | - /** | |
173 | - * 高危短信 | |
174 | - * | |
175 | - */ | |
176 | - //获取最后一次高危因素 | |
177 | - List risks = baseService.findLastRisk(pat.getPid()); | |
178 | - if (baseService.isOnlyHealthy(risks)) | |
179 | - { | |
180 | - List<MessageContent> highRiskContents = new ArrayList(); | |
181 | - //把多种高危因素的短信合并在一起 | |
182 | - for (Object obj : risks) | |
183 | - { | |
184 | - Map<String,Object> riskMap = (Map<String,Object>)obj; | |
185 | - String name = String.valueOf(riskMap.get("name")); | |
186 | - List<MessageContent> messageContents = amsSmses.get(name); | |
187 | - if (CollectionUtils.isNotEmpty(messageContents)) | |
188 | - { | |
189 | - for (MessageContent message : messageContents) | |
190 | - { | |
191 | - message.setHighRiskId(String.valueOf(riskMap.get("id"))); | |
192 | - } | |
193 | - highRiskContents.addAll(messageContents); | |
194 | - } | |
167 | + /** | |
168 | + * 高危短信 | |
169 | + * | |
170 | + */ | |
171 | + //获取最后一次高危因素 | |
172 | + List risks = baseService.findLastRisk(pat.getPid()); | |
173 | + if (baseService.isOnlyHealthy(risks) && serviceGwzd > 0) { | |
195 | 174 | |
175 | + Map<String, MessageContent> highRiskContents = new HashMap<>(); | |
176 | + | |
177 | + //把多种高危因素的短信合并在一起 | |
178 | + for (Object obj : risks) { | |
179 | + Map<String, Object> riskMap = (Map<String, Object>) obj; | |
180 | + String riskName1 = yunWeek + "&" + String.valueOf(riskMap.get("name")); | |
181 | + String riskName2 = String.valueOf(riskMap.get("name")) + "&" + yunWeek; | |
182 | + List<MessageContent> messageContents = amsSmses.get(riskName1); | |
183 | + if (CollectionUtils.isEmpty(messageContents)) { | |
184 | + riskName1 = riskName2; | |
185 | + messageContents = amsSmses.get(riskName2); | |
196 | 186 | } |
197 | - if (CollectionUtils.isNotEmpty(highRiskContents)) | |
198 | - { | |
199 | - //可以发送的高危短信 | |
200 | - List<MessageContent> sendMessageContents = new ArrayList<>(); | |
201 | 187 | |
202 | - for (MessageContent message : highRiskContents) | |
203 | - { | |
204 | - | |
188 | + if (CollectionUtils.isNotEmpty(messageContents)) { | |
189 | + for (MessageContent message : messageContents) { | |
205 | 190 | HighRiskSmsQuery hquery = new HighRiskSmsQuery(); |
206 | 191 | hquery.setMessageId(message.getId()); |
207 | - hquery.setHighId(message.getHighRiskId()); | |
192 | + hquery.setHighId(String.valueOf(riskMap.get("id"))); | |
208 | 193 | hquery.setPhone(pat.getPhone()); |
209 | 194 | hquery.setPatientId(pat.getId()); |
210 | 195 | |
211 | - int count = highRiskService.queryHighRiskCount(hquery); | |
212 | - if (count > 0) | |
213 | - { | |
196 | + int count = highRiskService.queryHighRiskCount(hquery); | |
197 | + if (count > 0) { | |
214 | 198 | continue; |
215 | 199 | } |
216 | - //把未发送过的添加到集合中 | |
217 | - sendMessageContents.add(message); | |
218 | - } | |
219 | 200 | |
220 | - if (CollectionUtils.isNotEmpty(sendMessageContents)) { | |
221 | - | |
222 | - //根据集合的长度随机一个数字 | |
223 | - int index = (int)(Math.random()*sendMessageContents.size()); | |
224 | - | |
225 | - //从集合中随机取一个发送 | |
226 | - MessageContent message =sendMessageContents.get(index); | |
227 | - String weekDay = HelperUtils.getYunWeekDay(pat.getLastMenses()); | |
228 | - String title = ""; | |
229 | - if (message.getTags() != null && message.getTags().size() > 0) | |
230 | - { | |
231 | - title = message.getTags().get(0).getTagName(); | |
232 | - } | |
233 | - | |
234 | - String messageContent = "【"+messagePrefix+"】" + message.getContent(); | |
235 | - MsgRequest request = HelperUtils.getMessageRequest(messageContent, pat.getPhone(), | |
236 | - ServiceObjEnums.YUNOBJ.getId(), SmsServiceEnums.GWZD.getId(), | |
237 | - pat.getHospitalId(), message.getId(), pat.getId(), weekDay, title, "", | |
238 | - WxTempleteIdEnums.GAO_WEI_ZHI_DAO.getId(),service); | |
239 | - | |
240 | - messages.add(request); | |
241 | - | |
242 | - HighRiskSmsModel highRiskSmsModel = new HighRiskSmsModel(); | |
243 | - highRiskSmsModel.setPatientId(pat.getId()); | |
244 | - highRiskSmsModel.setHighId(message.getHighRiskId()); | |
245 | - highRiskSmsModel.setPhone(pat.getPhone()); | |
246 | - highRiskSmsModel.setHospitalId(pat.getHospitalId()); | |
247 | - highRiskSmsModel.setCreated(new Date()); | |
248 | - highRiskSmsModel.setModified(new Date()); | |
249 | - highRiskSmsModel.setMessageId(message.getId()); | |
250 | - highRiskService.addHighRiskSmsModel(highRiskSmsModel); | |
251 | - | |
252 | - isRisk = true; | |
253 | - | |
201 | + message.setRiskName(String.valueOf(riskMap.get("name"))); | |
202 | + highRiskContents.put(riskName1, message); | |
254 | 203 | } |
255 | 204 | } |
256 | - | |
257 | 205 | } |
258 | - } | |
259 | - //没有高危短信就发送指导短信 | |
260 | - if (!isRisk) | |
261 | - { | |
262 | - //计算出孕周 孕周计算方式 当前时间减去末次月经 除以7 的到孕周 | |
263 | - int weeks = DateUtils.daysBetween(pat.getLastMenses(),new Date()) / 7; | |
264 | - String yunWeek = String.valueOf(weeks); | |
265 | - //得到符合当前孕周的短信条数 | |
266 | - List<MessageContent> messageContents = amsSmses.get(yunWeek); | |
267 | - | |
268 | - if (CollectionUtils.isNotEmpty(messageContents)) | |
269 | - { | |
270 | - for(MessageContent message : messageContents) | |
271 | - { | |
272 | - //判断当前短信是否已经发送 通过短信ID和孕妇ID | |
273 | - boolean isExist = SaveMessageService.isExistMsg(pat.getId(), message.getId()); | |
274 | - if (isExist) | |
275 | - { | |
276 | - continue; | |
277 | - } | |
278 | - | |
206 | + if (highRiskContents.size() > 0) { | |
207 | + for (String riskName : highRiskContents.keySet()) { | |
208 | + MessageContent message = highRiskContents.get(riskName); | |
279 | 209 | String weekDay = HelperUtils.getYunWeekDay(pat.getLastMenses()); |
280 | - String title = "孕期健康指导"; | |
210 | + String title = message.getRiskName(); | |
281 | 211 | |
282 | - String messageContent = "【"+messagePrefix+"】" + message.getContent(); | |
212 | + String messageContent = "【" + messagePrefix + "】" + message.getContent(); | |
283 | 213 | MsgRequest request = HelperUtils.getMessageRequest(messageContent, pat.getPhone(), |
284 | - ServiceObjEnums.YUNOBJ.getId(), SmsServiceEnums.YBZD.getId(), | |
214 | + ServiceObjEnums.YUNOBJ.getId(), SmsServiceEnums.GWZD.getId(), | |
285 | 215 | pat.getHospitalId(), message.getId(), pat.getId(), weekDay, title, "", |
286 | - WxTempleteIdEnums.YUN_YI_BAN_ZHI_DAO.getId(),service); | |
216 | + WxTempleteIdEnums.GAO_WEI_ZHI_DAO.getId(), serviceGwzd); | |
287 | 217 | |
288 | 218 | messages.add(request); |
289 | - break; | |
219 | + | |
220 | + HighRiskSmsModel highRiskSmsModel = new HighRiskSmsModel(); | |
221 | + highRiskSmsModel.setPatientId(pat.getId()); | |
222 | + highRiskSmsModel.setHighId(message.getHighRiskId()); | |
223 | + highRiskSmsModel.setPhone(pat.getPhone()); | |
224 | + highRiskSmsModel.setHospitalId(pat.getHospitalId()); | |
225 | + highRiskSmsModel.setCreated(new Date()); | |
226 | + highRiskSmsModel.setModified(new Date()); | |
227 | + highRiskSmsModel.setMessageId(message.getId()); | |
228 | + highRiskService.addHighRiskSmsModel(highRiskSmsModel); | |
290 | 229 | } |
291 | 230 | } |
292 | 231 | } |
293 | - } | |
294 | 232 | |
233 | + //得到符合当前孕周的短信条数 | |
234 | + List<MessageContent> messageContents = amsSmses.get(yunWeek); | |
235 | + | |
236 | + if (CollectionUtils.isNotEmpty(messageContents) && serviceYbzd > 0) { | |
237 | + for (MessageContent message : messageContents) { | |
238 | + //判断当前短信是否已经发送 通过短信ID和孕妇ID | |
239 | + boolean isExist = SaveMessageService.isExistMsg(pat.getId(), message.getId()); | |
240 | + if (isExist) { | |
241 | + continue; | |
242 | + } | |
243 | + | |
244 | + String weekDay = HelperUtils.getYunWeekDay(pat.getLastMenses()); | |
245 | + String title = "孕期健康指导"; | |
246 | + | |
247 | + String messageContent = "【" + messagePrefix + "】" + message.getContent(); | |
248 | + MsgRequest request = HelperUtils.getMessageRequest(messageContent, pat.getPhone(), | |
249 | + ServiceObjEnums.YUNOBJ.getId(), SmsServiceEnums.YBZD.getId(), | |
250 | + pat.getHospitalId(), message.getId(), pat.getId(), weekDay, title, "", | |
251 | + WxTempleteIdEnums.YUN_YI_BAN_ZHI_DAO.getId(), serviceYbzd); | |
252 | + | |
253 | + messages.add(request); | |
254 | + break; | |
255 | + } | |
256 | + } | |
257 | + } | |
295 | 258 | list.setMessages(messages); |
296 | 259 | HelperUtils.sendMsg(list); |
297 | 260 | } |
platform-msg-generate/src/main/resources/config.properties
View file @
92bca66
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | |
5 | 5 | #AMS地址 线上:http://data.api.healthbaby.com.cn/v1/messages 测试:http://data.api.stage.healthbaby.com.cn/v1/messages |
6 | 6 | #演示地址 https://stage-rp-data-api.healthbaby.com.cn/v1/messages |
7 | -ams_url=http://data.api.healthbaby.com.cn/v1/messages | |
7 | +ams_url=http://data.api.stage.healthbaby.com.cn/v1/messages | |
8 | 8 | |
9 | 9 | #短信当天发送时间 如16:00 |
10 | 10 | send_time=16:00 |