Merge branch 'feat/nongxin-notifications' of http://git.infoloop.cn/jiujian/clie…
…nt-customer-order-api into feat/nongxin-notifications # Conflicts: # src/main/java/com/infoloop/tianting/logic/task/OrderReminderTask.java # src/main/java/com/infoloop/tianting/service/OrderReminderService.java # src/main/java/com/infoloop/tianting/service/impl/OrderReminderServiceImpl.java
Showing
3 changed files
with
52 additions
and
83 deletions
| 1 | package com.infoloop.tianting.logic.task; | 1 | package com.infoloop.tianting.logic.task; |
| 2 | 2 | ||
| 3 | -import com.infoloop.tianting.deliveryruleservice.Rule; | ||
| 4 | import com.infoloop.tianting.mealorderservice.PendingOrderSubscriptionMessageRpcResponse; | 3 | import com.infoloop.tianting.mealorderservice.PendingOrderSubscriptionMessageRpcResponse; |
| 5 | import com.infoloop.tianting.mealorderservice.SingleMpAccountRpcResponse; | 4 | import com.infoloop.tianting.mealorderservice.SingleMpAccountRpcResponse; |
| 6 | import com.infoloop.tianting.model.dto.WxUserDto.SendSubscriptionMessageResponse; | 5 | import com.infoloop.tianting.model.dto.WxUserDto.SendSubscriptionMessageResponse; |
| ... | @@ -13,8 +12,6 @@ import org.springframework.beans.factory.annotation.Qualifier; | ... | @@ -13,8 +12,6 @@ import org.springframework.beans.factory.annotation.Qualifier; |
| 13 | import org.springframework.scheduling.annotation.Scheduled; | 12 | import org.springframework.scheduling.annotation.Scheduled; |
| 14 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
| 15 | 14 | ||
| 16 | -import java.time.DayOfWeek; | ||
| 17 | -import java.time.LocalDate; | ||
| 18 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
| 19 | import java.util.Collections; | 16 | import java.util.Collections; |
| 20 | import java.util.List; | 17 | import java.util.List; |
| ... | @@ -46,14 +43,19 @@ public class OrderReminderTask { | ... | @@ -46,14 +43,19 @@ public class OrderReminderTask { |
| 46 | private static final int ENTERPRISE_ID = 449; | 43 | private static final int ENTERPRISE_ID = 449; |
| 47 | 44 | ||
| 48 | /** | 45 | /** |
| 46 | + * 用餐类型 | ||
| 47 | + */ | ||
| 48 | + private static final String MEAL_TYPE = "下次订餐即将开启"; | ||
| 49 | + | ||
| 50 | + /** | ||
| 49 | * 温馨提醒内容 | 51 | * 温馨提醒内容 |
| 50 | */ | 52 | */ |
| 51 | private static final String TIPS = "请点击卡片,准时进入小程序完成预订"; | 53 | private static final String TIPS = "请点击卡片,准时进入小程序完成预订"; |
| 52 | 54 | ||
| 53 | /** | 55 | /** |
| 54 | - * 订餐时间配置 | 56 | + * 订餐时间配置(格式:HH:mm~HH:mm) |
| 55 | */ | 57 | */ |
| 56 | - private record OrderTimeConfig(String startTime, String endTime) {} | 58 | + private record OrderTimeConfig(String orderTime) {} |
| 57 | 59 | ||
| 58 | private final MealOrderServiceRpcClient mealOrderServiceRpcClient; | 60 | private final MealOrderServiceRpcClient mealOrderServiceRpcClient; |
| 59 | private final DeliveryRuleServiceRpcClient deliveryRuleServiceRpcClient; | 61 | private final DeliveryRuleServiceRpcClient deliveryRuleServiceRpcClient; |
| ... | @@ -83,9 +85,9 @@ public class OrderReminderTask { | ... | @@ -83,9 +85,9 @@ public class OrderReminderTask { |
| 83 | OrderTimeConfig orderTimeConfig = getOrderTimeConfigFromRule(); | 85 | OrderTimeConfig orderTimeConfig = getOrderTimeConfigFromRule(); |
| 84 | if (orderTimeConfig == null) { | 86 | if (orderTimeConfig == null) { |
| 85 | log.warn("Failed to get order time config from rule, using default"); | 87 | log.warn("Failed to get order time config from rule, using default"); |
| 86 | - orderTimeConfig = new OrderTimeConfig("请查看小程序", "请查看小程序"); | 88 | + orderTimeConfig = new OrderTimeConfig("请查看小程序"); |
| 87 | } | 89 | } |
| 88 | - log.info("Order time config: startTime={}, endTime={}", orderTimeConfig.startTime(), orderTimeConfig.endTime()); | 90 | + log.info("Order time config: orderTime={}", orderTimeConfig.orderTime()); |
| 89 | 91 | ||
| 90 | // 2. 查询所有待发送的订阅消息(未删除的记录) | 92 | // 2. 查询所有待发送的订阅消息(未删除的记录) |
| 91 | List<PendingOrderSubscriptionMessageRpcResponse> pendingMessages = | 93 | List<PendingOrderSubscriptionMessageRpcResponse> pendingMessages = |
| ... | @@ -176,7 +178,7 @@ public class OrderReminderTask { | ... | @@ -176,7 +178,7 @@ public class OrderReminderTask { |
| 176 | 178 | ||
| 177 | /** | 179 | /** |
| 178 | * 从配送规则配置中获取订餐时间配置 | 180 | * 从配送规则配置中获取订餐时间配置 |
| 179 | - * 返回开始时间和结束时间,格式:周x xx:xx | 181 | + * 返回订餐时间,格式:yyyy年MM月dd日 HH:mm~HH:mm |
| 180 | */ | 182 | */ |
| 181 | private OrderTimeConfig getOrderTimeConfigFromRule() { | 183 | private OrderTimeConfig getOrderTimeConfigFromRule() { |
| 182 | try { | 184 | try { |
| ... | @@ -195,37 +197,19 @@ public class OrderReminderTask { | ... | @@ -195,37 +197,19 @@ public class OrderReminderTask { |
| 195 | return null; | 197 | return null; |
| 196 | } | 198 | } |
| 197 | 199 | ||
| 198 | - // 获取启用的日期 | ||
| 199 | - List<DayOfWeek> enabledDays = getEnabledDays(cfg); | ||
| 200 | - if (enabledDays.isEmpty()) { | ||
| 201 | - log.warn("No enabled days in delivery rule"); | ||
| 202 | - return null; | ||
| 203 | - } | ||
| 204 | - | ||
| 205 | // 格式化时间(去掉秒) | 200 | // 格式化时间(去掉秒) |
| 206 | String startTime = formatTime(startTimeStr); | 201 | String startTime = formatTime(startTimeStr); |
| 207 | String endTime = formatTime(endTimeStr); | 202 | String endTime = formatTime(endTimeStr); |
| 208 | 203 | ||
| 209 | - // 获取第一个和最后一个启用日 | 204 | + // 获取当前日期,格式化为 yyyy年MM月dd日 HH:mm |
| 210 | - DayOfWeek firstDay = enabledDays.get(0); | 205 | + java.time.LocalDate today = java.time.LocalDate.now(); |
| 211 | - DayOfWeek lastDay = enabledDays.get(enabledDays.size() - 1); | ||
| 212 | - | ||
| 213 | - // 计算本周的实际日期(微信time类型需要具体日期格式) | ||
| 214 | - LocalDate today = LocalDate.now(); | ||
| 215 | - LocalDate startDate = today.with(java.time.temporal.TemporalAdjusters.nextOrSame(firstDay)); | ||
| 216 | - LocalDate endDate = today.with(java.time.temporal.TemporalAdjusters.nextOrSame(lastDay)); | ||
| 217 | - | ||
| 218 | - // 如果结束日期在开始日期之前,说明跨周了,结束日期加一周 | ||
| 219 | - if (endDate.isBefore(startDate)) { | ||
| 220 | - endDate = endDate.plusWeeks(1); | ||
| 221 | - } | ||
| 222 | - | ||
| 223 | - // 格式化为微信接受的格式:yyyy年MM月dd日 HH:mm | ||
| 224 | java.time.format.DateTimeFormatter dateFormatter = java.time.format.DateTimeFormatter.ofPattern("yyyy年MM月dd日"); | 206 | java.time.format.DateTimeFormatter dateFormatter = java.time.format.DateTimeFormatter.ofPattern("yyyy年MM月dd日"); |
| 225 | - String formattedStartTime = startDate.format(dateFormatter) + " " + startTime; | 207 | + String dateStr = today.format(dateFormatter); |
| 226 | - String formattedEndTime = endDate.format(dateFormatter) + " " + endTime; | 208 | + |
| 209 | + // 返回订餐时间,格式:yyyy年MM月dd日 HH:mm~yyyy年MM月dd日 HH:mm | ||
| 210 | + String orderTime = dateStr + " " + startTime + "~" + dateStr + " " + endTime; | ||
| 227 | 211 | ||
| 228 | - return new OrderTimeConfig(formattedStartTime, formattedEndTime); | 212 | + return new OrderTimeConfig(orderTime); |
| 229 | 213 | ||
| 230 | } catch (Exception e) { | 214 | } catch (Exception e) { |
| 231 | log.error("Failed to get order time config from rule", e); | 215 | log.error("Failed to get order time config from rule", e); |
| ... | @@ -234,21 +218,6 @@ public class OrderReminderTask { | ... | @@ -234,21 +218,6 @@ public class OrderReminderTask { |
| 234 | } | 218 | } |
| 235 | 219 | ||
| 236 | /** | 220 | /** |
| 237 | - * 获取启用的日期列表(按周一到周日排序) | ||
| 238 | - */ | ||
| 239 | - private List<DayOfWeek> getEnabledDays(Rule cfg) { | ||
| 240 | - List<DayOfWeek> enabledDays = new ArrayList<>(); | ||
| 241 | - if (Boolean.TRUE.equals(cfg.getMonday())) enabledDays.add(DayOfWeek.MONDAY); | ||
| 242 | - if (Boolean.TRUE.equals(cfg.getTuesday())) enabledDays.add(DayOfWeek.TUESDAY); | ||
| 243 | - if (Boolean.TRUE.equals(cfg.getWednesday())) enabledDays.add(DayOfWeek.WEDNESDAY); | ||
| 244 | - if (Boolean.TRUE.equals(cfg.getThursday())) enabledDays.add(DayOfWeek.THURSDAY); | ||
| 245 | - if (Boolean.TRUE.equals(cfg.getFriday())) enabledDays.add(DayOfWeek.FRIDAY); | ||
| 246 | - if (Boolean.TRUE.equals(cfg.getSaturday())) enabledDays.add(DayOfWeek.SATURDAY); | ||
| 247 | - if (Boolean.TRUE.equals(cfg.getSunday())) enabledDays.add(DayOfWeek.SUNDAY); | ||
| 248 | - return enabledDays; | ||
| 249 | - } | ||
| 250 | - | ||
| 251 | - /** | ||
| 252 | * 格式化时间字符串(HH:mm:ss -> HH:mm) | 221 | * 格式化时间字符串(HH:mm:ss -> HH:mm) |
| 253 | */ | 222 | */ |
| 254 | private String formatTime(String timeStr) { | 223 | private String formatTime(String timeStr) { |
| ... | @@ -275,10 +244,10 @@ public class OrderReminderTask { | ... | @@ -275,10 +244,10 @@ public class OrderReminderTask { |
| 275 | /** | 244 | /** |
| 276 | * 发送单条提醒消息 | 245 | * 发送单条提醒消息 |
| 277 | * | 246 | * |
| 278 | - * 小程序模板字段: | 247 | + * 小程序模板字段(模板ID: BCROwaS_oj1_b0fzc_qrgvtSeCtfxctghcLMu-Obkfw): |
| 279 | - * - time4: 开始时间(周x xx:xx) | 248 | + * - thing8: 用餐类型(如:下次订单即将开始) |
| 280 | - * - time5: 结束时间(周x xx:xx) | 249 | + * - time1: 订餐时间(如:13:00~21:00) |
| 281 | - * - thing1: 温馨提醒 | 250 | + * - thing2: 温馨提示 |
| 282 | */ | 251 | */ |
| 283 | private boolean sendReminderMessage(String openId, PendingOrderSubscriptionMessageRpcResponse message, OrderTimeConfig orderTimeConfig) { | 252 | private boolean sendReminderMessage(String openId, PendingOrderSubscriptionMessageRpcResponse message, OrderTimeConfig orderTimeConfig) { |
| 284 | String jumpPath = message.getJumpPath(); | 253 | String jumpPath = message.getJumpPath(); |
| ... | @@ -287,9 +256,9 @@ public class OrderReminderTask { | ... | @@ -287,9 +256,9 @@ public class OrderReminderTask { |
| 287 | SendSubscriptionMessageResponse response = orderReminderService.sendOrderReminder( | 256 | SendSubscriptionMessageResponse response = orderReminderService.sendOrderReminder( |
| 288 | openId, | 257 | openId, |
| 289 | jumpPath, | 258 | jumpPath, |
| 290 | - orderTimeConfig.startTime(), // time4: 开始时间 | 259 | + MEAL_TYPE, // thing8: 用餐类型 |
| 291 | - orderTimeConfig.endTime(), // time5: 结束时间 | 260 | + orderTimeConfig.orderTime(), // time1: 订餐时间 |
| 292 | - TIPS // thing1: 温馨提醒 | 261 | + TIPS // thing2: 温馨提示 |
| 293 | ); | 262 | ); |
| 294 | 263 | ||
| 295 | // 判断发送结果 | 264 | // 判断发送结果 | ... | ... |
| ... | @@ -10,18 +10,18 @@ public interface OrderReminderService { | ... | @@ -10,18 +10,18 @@ public interface OrderReminderService { |
| 10 | /** | 10 | /** |
| 11 | * 发送订餐提醒消息 | 11 | * 发送订餐提醒消息 |
| 12 | * | 12 | * |
| 13 | - * 小程序模板字段(模板ID: LtCsW7ciF0edUwNwt3h5C_ZCIRzOeO7MnvozRl2CxlE): | 13 | + * 小程序模板字段(模板ID: BCROwaS_oj1_b0fzc_qrgvtSeCtfxctghcLMu-Obkfw): |
| 14 | - * - time4: 开始时间 | 14 | + * - thing8: 用餐类型(如:下次订单即将开始) |
| 15 | - * - time5: 结束时间 | 15 | + * - time1: 订餐时间(如:13:00~21:00) |
| 16 | - * - thing1: 温馨提醒 | 16 | + * - thing2: 温馨提示(如:为了保证您明日正常用餐,立即订餐!) |
| 17 | * | 17 | * |
| 18 | * @param openId 用户 OpenID(小程序的 openId) | 18 | * @param openId 用户 OpenID(小程序的 openId) |
| 19 | * @param page 点击跳转小程序页面路径 | 19 | * @param page 点击跳转小程序页面路径 |
| 20 | - * @param startTime 开始时间,例如:"周一 09:00" | 20 | + * @param mealType 用餐类型,例如:"下次订单即将开始" |
| 21 | - * @param endTime 结束时间,例如:"周四 18:00" | 21 | + * @param orderTime 订餐时间,例如:"13:00~21:00" |
| 22 | - * @param tips 温馨提醒,例如:"请点击卡片,准时进入小程序完成预订" | 22 | + * @param tips 温馨提示,例如:"为了保证您明日正常用餐,立即订餐!" |
| 23 | * @return 发送结果 | 23 | * @return 发送结果 |
| 24 | */ | 24 | */ |
| 25 | SendSubscriptionMessageResponse sendOrderReminder(String openId, String page, | 25 | SendSubscriptionMessageResponse sendOrderReminder(String openId, String page, |
| 26 | - String startTime, String endTime, String tips); | 26 | + String mealType, String orderTime, String tips); |
| 27 | } | 27 | } | ... | ... |
| ... | @@ -18,10 +18,10 @@ import static com.infoloop.tianting.constant.ConfigConstants.MINI_PROGRAM_ORDER_ | ... | @@ -18,10 +18,10 @@ import static com.infoloop.tianting.constant.ConfigConstants.MINI_PROGRAM_ORDER_ |
| 18 | * 订餐提醒服务实现 | 18 | * 订餐提醒服务实现 |
| 19 | * 使用小程序订阅消息接口发送提醒 | 19 | * 使用小程序订阅消息接口发送提醒 |
| 20 | * | 20 | * |
| 21 | - * 小程序模板字段(模板ID: LtCsW7ciF0edUwNwt3h5C_ZCIRzOeO7MnvozRl2CxlE): | 21 | + * 小程序模板字段(模板ID: BCROwaS_oj1_b0fzc_qrgvtSeCtfxctghcLMu-Obkfw): |
| 22 | - * - time4: 开始时间 | 22 | + * - thing8: 用餐类型(如:下次订单即将开始) |
| 23 | - * - time5: 结束时间 | 23 | + * - time1: 订餐时间(如:13:00~21:00) |
| 24 | - * - thing1: 温馨提醒 | 24 | + * - thing2: 温馨提示(如:为了保证您明日正常用餐,立即订餐!) |
| 25 | * | 25 | * |
| 26 | * 注意: | 26 | * 注意: |
| 27 | * 1. 使用的是小程序的 access_token 和 template_id | 27 | * 1. 使用的是小程序的 access_token 和 template_id |
| ... | @@ -40,29 +40,29 @@ public class OrderReminderServiceImpl implements OrderReminderService { | ... | @@ -40,29 +40,29 @@ public class OrderReminderServiceImpl implements OrderReminderService { |
| 40 | @Override | 40 | @Override |
| 41 | public SendSubscriptionMessageResponse sendOrderReminder(String openId, | 41 | public SendSubscriptionMessageResponse sendOrderReminder(String openId, |
| 42 | String page, | 42 | String page, |
| 43 | - String startTime, | 43 | + String mealType, |
| 44 | - String endTime, | 44 | + String orderTime, |
| 45 | String tips) { | 45 | String tips) { |
| 46 | - log.info("Sending order reminder via MiniProgram to openId: {}, page: {}, startTime: {}, endTime: {}, tips: {}", | 46 | + log.info("Sending order reminder via MiniProgram to openId: {}, page: {}, mealType: {}, orderTime: {}, tips: {}", |
| 47 | - openId, page, startTime, endTime, tips); | 47 | + openId, page, mealType, orderTime, tips); |
| 48 | 48 | ||
| 49 | // 构建小程序订阅消息模板数据 | 49 | // 构建小程序订阅消息模板数据 |
| 50 | Map<String, Object> data = new HashMap<>(); | 50 | Map<String, Object> data = new HashMap<>(); |
| 51 | 51 | ||
| 52 | - // time4: 开始时间 | 52 | + // thing8: 用餐类型(如:下次订单即将开始) |
| 53 | - Map<String, String> time4Value = new HashMap<>(); | 53 | + Map<String, String> thing8Value = new HashMap<>(); |
| 54 | - time4Value.put("value", startTime); | 54 | + thing8Value.put("value", mealType); |
| 55 | - data.put("time4", time4Value); | 55 | + data.put("thing8", thing8Value); |
| 56 | 56 | ||
| 57 | - // time5: 结束时间 | 57 | + // time1: 订餐时间(如:13:00~21:00) |
| 58 | - Map<String, String> time5Value = new HashMap<>(); | 58 | + Map<String, String> time1Value = new HashMap<>(); |
| 59 | - time5Value.put("value", endTime); | 59 | + time1Value.put("value", orderTime); |
| 60 | - data.put("time5", time5Value); | 60 | + data.put("time1", time1Value); |
| 61 | 61 | ||
| 62 | - // thing1: 温馨提醒 | 62 | + // thing2: 温馨提示 |
| 63 | - Map<String, String> thing1Value = new HashMap<>(); | 63 | + Map<String, String> thing2Value = new HashMap<>(); |
| 64 | - thing1Value.put("value", tips); | 64 | + thing2Value.put("value", tips); |
| 65 | - data.put("thing1", thing1Value); | 65 | + data.put("thing2", thing2Value); |
| 66 | 66 | ||
| 67 | try { | 67 | try { |
| 68 | // 使用小程序订阅消息接口 | 68 | // 使用小程序订阅消息接口 | ... | ... |
-
Please register or login to post a comment