Commit dc0e3a8eaa7fae2399b6b05a4e2f041226a30703
1 parent
3a89cd6065
Exists in
master
and in
6 other branches
增加儿童精准推送
Showing 2 changed files with 107 additions and 56 deletions
platform-msg-generate/src/main/java/com/lyms/platform/msg/service/impl/MsgGenerateServiceImpl.java
View file @
dc0e3a8
... | ... | @@ -12,8 +12,10 @@ |
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.BasicConfig; | |
15 | 16 | import com.lyms.platform.pojo.CourseModel; |
16 | 17 | import com.lyms.platform.pojo.SmsConfigModel; |
18 | +import com.lyms.platform.query.BasicConfigQuery; | |
17 | 19 | import com.lyms.platform.query.CourseQuery; |
18 | 20 | import org.apache.commons.collections.CollectionUtils; |
19 | 21 | import org.apache.commons.lang.StringUtils; |
... | ... | @@ -73,6 +75,8 @@ |
73 | 75 | |
74 | 76 | @Autowired |
75 | 77 | private PostReviewService postReviewService; |
78 | + @Autowired | |
79 | + private BasicConfigService basicConfigService; | |
76 | 80 | |
77 | 81 | |
78 | 82 | /** |
79 | 83 | |
... | ... | @@ -108,9 +112,11 @@ |
108 | 112 | @Override |
109 | 113 | public void generateBabyAmsMsg(String generateHospitalId) { |
110 | 114 | List<SmsConfigModel> configModels = baseService.getHospitalConfigsByWeek(generateHospitalId); |
111 | - logger.info("The generateBabyAmsMsg configs hospital size is {}",configModels.size()); | |
115 | + logger.info("The generateBabyAmsMsg configs hospital size is {}", configModels.size()); | |
116 | + | |
112 | 117 | if (CollectionUtils.isNotEmpty(configModels)) |
113 | 118 | { |
119 | + Map<String,String> babyRiskMap = loadBabyRisk(); | |
114 | 120 | int end = 0; |
115 | 121 | for (int i = 0; i < configModels.size(); i += DEFAULT_BATCH_SIZE) { |
116 | 122 | end = (end + DEFAULT_BATCH_SIZE); |
117 | 123 | |
... | ... | @@ -118,11 +124,29 @@ |
118 | 124 | end = configModels.size(); |
119 | 125 | } |
120 | 126 | BabyAmsMsgGenerateWorker checkPointCountWorker = new BabyAmsMsgGenerateWorker(configModels.subList(i,end), |
121 | - baseService,babyBookbuildingService); | |
127 | + baseService,babyBookbuildingService,babyRiskMap); | |
122 | 128 | pool.execute(checkPointCountWorker); |
123 | 129 | } |
124 | 130 | |
125 | 131 | } |
132 | + } | |
133 | + | |
134 | + private Map loadBabyRisk(){ | |
135 | + BasicConfigQuery basicConfigQuery = new BasicConfigQuery(); | |
136 | + basicConfigQuery.setYn(YnEnums.YES.getId()); | |
137 | + basicConfigQuery.setEnable(1); | |
138 | + //出生时异常 | |
139 | + //新生儿期严重疾病 | |
140 | + //加载儿童的高危因素 | |
141 | + basicConfigQuery.setTypeId("5b18f8a7422b03d4ad2bf913"); | |
142 | + List<BasicConfig> data = basicConfigService.queryBasicConfig(basicConfigQuery); | |
143 | + Map<String,String> map =new HashMap<String,String>(); | |
144 | + if(CollectionUtils.isNotEmpty(data)){ | |
145 | + for(BasicConfig config:data){ | |
146 | + map.put(config.getId(),config.getName()); | |
147 | + } | |
148 | + } | |
149 | + return map; | |
126 | 150 | } |
127 | 151 | |
128 | 152 |
platform-msg-generate/src/main/java/com/lyms/platform/msg/worker/BabyAmsMsgGenerateWorker.java
View file @
dc0e3a8
... | ... | @@ -29,38 +29,33 @@ |
29 | 29 | private static final Logger logger = LoggerFactory.getLogger(BabyAmsMsgGenerateWorker.class); |
30 | 30 | |
31 | 31 | |
32 | - | |
33 | 32 | private List<SmsConfigModel> configs; |
34 | 33 | |
35 | 34 | private IBaseService baseService; |
36 | 35 | |
37 | 36 | private BabyBookbuildingService babyBookbuildingService; |
38 | 37 | |
38 | + private Map<String, String> babyRiskMap; | |
39 | 39 | |
40 | - | |
41 | 40 | public BabyAmsMsgGenerateWorker(List<SmsConfigModel> configs, IBaseService baseService, |
42 | - BabyBookbuildingService babyBookbuildingService) | |
43 | - { | |
41 | + BabyBookbuildingService babyBookbuildingService, Map<String, String> babyRiskMap) { | |
44 | 42 | this.configs = configs; |
45 | 43 | this.baseService = baseService; |
46 | 44 | this.babyBookbuildingService = babyBookbuildingService; |
45 | + this.babyRiskMap = babyRiskMap; | |
47 | 46 | } |
48 | 47 | |
49 | 48 | @Override |
50 | 49 | public void run() { |
51 | - if (CollectionUtils.isNotEmpty(configs)) | |
52 | - { | |
53 | - for (SmsConfigModel config : configs) | |
54 | - { | |
50 | + if (CollectionUtils.isNotEmpty(configs)) { | |
51 | + for (SmsConfigModel config : configs) { | |
55 | 52 | String hospitalId = config.getHospitalId(); |
56 | - if (StringUtils.isEmpty(hospitalId)) | |
57 | - { | |
53 | + if (StringUtils.isEmpty(hospitalId)) { | |
58 | 54 | continue; |
59 | 55 | } |
60 | 56 | |
61 | 57 | //判断医院是否运行 |
62 | - if (!baseService.isRunning(hospitalId)) | |
63 | - { | |
58 | + if (!baseService.isRunning(hospitalId)) { | |
64 | 59 | continue; |
65 | 60 | } |
66 | 61 | |
67 | 62 | |
68 | 63 | |
69 | 64 | |
... | ... | @@ -69,23 +64,21 @@ |
69 | 64 | |
70 | 65 | //判断消息服务是否启动 |
71 | 66 | //0服务不提供,1 推送服务, 2 短信服务,3推送和短信服务 |
72 | - int service = baseService.isStartService(SmsServiceEnums.YBZD.getId(), serviceStr,serviceType); | |
73 | - if (service == 0) | |
74 | - { | |
67 | + int service = baseService.isStartService(SmsServiceEnums.YBZD.getId(), serviceStr, serviceType); | |
68 | + if (service == 0) { | |
75 | 69 | continue; |
76 | 70 | } |
77 | 71 | |
78 | 72 | // 查询模板短信 从ams平台配置的短信通过医院IDa |
79 | - Map<String, List<MessageContent>> amsSmses = AmsMessageService | |
80 | - .getMessageTemplateMap(String.valueOf(hospitalId), | |
81 | - AmsServiceTypeEnum.CHILD_GUIDE); | |
73 | + Map<String, List<MessageContent>> amsSmses = AmsMessageService | |
74 | + .getMessageTemplateMap(String.valueOf(hospitalId), | |
75 | + AmsServiceTypeEnum.CHILD_GUIDE); | |
82 | 76 | |
83 | - if (amsSmses == null || amsSmses.size() == 0) | |
84 | - { | |
77 | + if (amsSmses == null || amsSmses.size() == 0) { | |
85 | 78 | continue; |
86 | 79 | } |
87 | 80 | |
88 | - logger.info("The BabyAmsMsgGenerate hospital id is "+hospitalId); | |
81 | + logger.info("The BabyAmsMsgGenerate hospital id is " + hospitalId); | |
89 | 82 | |
90 | 83 | |
91 | 84 | BabyModelQuery babyQuery = new BabyModelQuery(); |
92 | 85 | |
93 | 86 | |
94 | 87 | |
95 | 88 | |
96 | 89 | |
97 | 90 | |
98 | 91 | |
99 | 92 | |
... | ... | @@ -104,57 +97,91 @@ |
104 | 97 | babyQuery.setServiceType(ServiceTypeEnums.ADD_SERVICE.getId()); |
105 | 98 | babyQuery.setServiceStatus(ServiceStatusEnums.ADD_OPEN.getId()); |
106 | 99 | //查询符合条件儿童 |
107 | - List<BabyModel> babies = babyBookbuildingService.queryBabyBuildByCond(babyQuery); | |
100 | + List<BabyModel> babies = babyBookbuildingService.queryBabyBuildByCond(babyQuery); | |
108 | 101 | |
109 | 102 | |
110 | - if (CollectionUtils.isNotEmpty(babies)) | |
111 | - { | |
103 | + if (CollectionUtils.isNotEmpty(babies)) { | |
112 | 104 | |
113 | 105 | //发送短信集合 |
114 | 106 | MsgListRequest list = new MsgListRequest(); |
115 | 107 | List<MsgRequest> messages = new ArrayList<>(); |
116 | - for (BabyModel baby : babies) | |
117 | - { | |
118 | - if (baby == null || baby.getBirth() == null) | |
119 | - { | |
108 | + for (BabyModel baby : babies) { | |
109 | + if (baby == null || baby.getBirth() == null) { | |
120 | 110 | continue; |
121 | 111 | } |
122 | 112 | |
123 | - String messagePrefix = baseService.getSmsPrefix(config, baby.getBuildDoctor(),ServiceObjEnums.BABYOBJ.getId()); | |
113 | + String messagePrefix = baseService.getSmsPrefix(config, baby.getBuildDoctor(), ServiceObjEnums.BABYOBJ.getId()); | |
124 | 114 | |
125 | - int weeks = DateUtils.daysBetween(baby.getBirth(),new Date()) / 7; | |
126 | - String weekAge = String.valueOf(weeks)+"周"; | |
115 | + int weeks = DateUtils.daysBetween(baby.getBirth(), new Date()) / 7; | |
116 | + String weekAge = String.valueOf(weeks) + "周"; | |
127 | 117 | //得到符合当前周龄的短信条数 |
128 | - List<MessageContent> messageContents = amsSmses.get(weekAge); | |
118 | + List<MessageContent> messageContents = amsSmses.get(weekAge); | |
129 | 119 | |
130 | - if (CollectionUtils.isNotEmpty(messageContents)) | |
131 | - { | |
132 | - for(MessageContent message : messageContents) | |
133 | - { | |
134 | - //判断当前短信是否已经发送 通过短信ID和儿童ID | |
135 | - boolean isExist = SaveMessageService.isExistMsg(baby.getId(), message.getId()); | |
136 | - if (isExist) | |
137 | - { | |
138 | - continue; | |
139 | - } | |
120 | + String weekDay = weeks + "周"; | |
121 | + //生成儿童健康指导 | |
122 | + doHandlAndBuildMsg(messageContents,baby,messagePrefix,messages,service,0,weekDay); | |
140 | 123 | |
141 | - String weekDay = weeks+"周"; | |
142 | - String title = "儿童健康指导"; | |
143 | - | |
144 | - String messageContent = "【"+messagePrefix+"】" + message.getContent(); | |
145 | - MsgRequest request = HelperUtils.getMessageRequest(messageContent, baby.getMphone(), | |
146 | - ServiceObjEnums.BABYOBJ.getId(), SmsServiceEnums.YBZD.getId(), | |
147 | - baby.getHospitalId(), message.getId(), baby.getId(), weekDay, title, "", | |
148 | - WxTempleteIdEnums.BABY_YI_BAN_ZHI_DAO.getId(),service); | |
149 | - | |
150 | - messages.add(request); | |
151 | - break; | |
124 | + //判断儿童是否有高危因素 | |
125 | + if (CollectionUtils.isNotEmpty(baby.getHighRiskInfo())) { | |
126 | + for (Object riskId : baby.getHighRiskInfo()) { | |
127 | + String riskName = babyRiskMap.get(riskId.toString()); | |
128 | + if (StringUtils.isNotEmpty(riskName)) { | |
129 | + String riskKey = riskName + "&" + weekAge; | |
130 | + //得到符合当前周龄的短信条数 | |
131 | + List<MessageContent> messageContents1 = amsSmses.get(riskKey); | |
132 | + //生成儿童健康指导 | |
133 | + doHandlAndBuildMsg(messageContents1,baby,messagePrefix,messages,service,1,riskKey); | |
134 | + } | |
152 | 135 | } |
153 | 136 | } |
154 | 137 | } |
155 | 138 | list.setMessages(messages); |
156 | 139 | HelperUtils.sendMsg(list); |
157 | 140 | } |
141 | + } | |
142 | + } | |
143 | + } | |
144 | + | |
145 | + | |
146 | + /** | |
147 | + * 根据规则生成推送消息 | |
148 | + * | |
149 | + * @param messageContents 符合该条件的短信发送内容 | |
150 | + * @param baby | |
151 | + * @param messagePrefix | |
152 | + * @param messages | |
153 | + * @param service | |
154 | + * @param type | |
155 | + * @param weekDay | |
156 | + */ | |
157 | + private void doHandlAndBuildMsg(List<MessageContent> messageContents, | |
158 | + BabyModel baby, | |
159 | + String messagePrefix, | |
160 | + List messages, | |
161 | + int service, | |
162 | + int type, | |
163 | + String weekDay) { | |
164 | + if (CollectionUtils.isNotEmpty(messageContents)) { | |
165 | + for (MessageContent message : messageContents) { | |
166 | + //判断当前短信是否已经发送 通过短信ID和儿童ID | |
167 | + boolean isExist = SaveMessageService.isExistMsg(baby.getId(), message.getId()); | |
168 | + if (isExist) { | |
169 | + continue; | |
170 | + } | |
171 | + | |
172 | + String title = "儿童健康指导"; | |
173 | + if (type == 1) { | |
174 | + title = "儿童高危精准指导"; | |
175 | + } | |
176 | + | |
177 | + String messageContent = "【" + messagePrefix + "】" + message.getContent(); | |
178 | + MsgRequest request = HelperUtils.getMessageRequest(messageContent, baby.getMphone(), | |
179 | + ServiceObjEnums.BABYOBJ.getId(), SmsServiceEnums.YBZD.getId(), | |
180 | + baby.getHospitalId(), message.getId(), baby.getId(), weekDay, title, "", | |
181 | + WxTempleteIdEnums.BABY_YI_BAN_ZHI_DAO.getId(), service); | |
182 | + | |
183 | + messages.add(request); | |
184 | + break; | |
158 | 185 | } |
159 | 186 | } |
160 | 187 | } |