From 09cd8ceadb62df23f14f1346e47ef09efc3f84da Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Mon, 27 Jan 2025 11:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/net/xnzn/utils/RedisCache.java | 269 ++++++++++++++++++ .../core/common/constant/LeMqConstant.java | 217 ++++++++++++++ .../java/net/xnzn/core/common/mq/MqUtil.java | 147 ++++++++++ .../core/customer/constants/CustConstant.java | 37 +++ .../constants/PersonalStatusEnum.java | 23 ++ .../customer/service/CustInfoBusiness.java | 10 + .../service/impl/CustInfoBusinessImpl.java | 103 +++++++ .../customer/vo/CustInfoAppIdLoginVO.java | 26 ++ .../core/merchant/dto/SmsCodeVerifyDTO.java | 14 + .../xnzn/core/notice/v2/api/SmsCodeApi.java | 87 ++++++ 10 files changed, 933 insertions(+) create mode 100644 bonus-common-biz/src/main/java/net/xnzn/utils/RedisCache.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/constant/LeMqConstant.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/mq/MqUtil.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/CustConstant.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/PersonalStatusEnum.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/CustInfoBusiness.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/impl/CustInfoBusinessImpl.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/vo/CustInfoAppIdLoginVO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/merchant/dto/SmsCodeVerifyDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/notice/v2/api/SmsCodeApi.java diff --git a/bonus-common-biz/src/main/java/net/xnzn/utils/RedisCache.java b/bonus-common-biz/src/main/java/net/xnzn/utils/RedisCache.java new file mode 100644 index 00000000..c2ed3662 --- /dev/null +++ b/bonus-common-biz/src/main/java/net/xnzn/utils/RedisCache.java @@ -0,0 +1,269 @@ +package net.xnzn.utils; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.BoundSetOperations; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * spring redis 工具类 + * + **/ +@Component +public class RedisCache +{ + @Autowired + public RedisTemplate redisTemplate; + + //添加分布式锁 + public Boolean setNxCacheObject(final String key, final T value,long lt,TimeUnit tu) + { + return redisTemplate.opsForValue().setIfAbsent(key,value,lt,tu); + } + + /** + * 缓存基本的对象,Integer、String、实体类等 + * + * @param key 缓存的键值 + * @param value 缓存的值 + */ + public void setCacheObject(final String key, final T value) + { + redisTemplate.opsForValue().set(key, value); + } + + /** + * 缓存基本的对象,Integer、String、实体类等 + * + * @param key 缓存的键值 + * @param value 缓存的值 + * @param timeout 时间 + * @param timeUnit 时间颗粒度 + */ + public void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) + { + redisTemplate.opsForValue().set(key, value, timeout, timeUnit); + } + + /** + * 设置有效时间 + * + * @param key Redis键 + * @param timeout 超时时间 + * @return true=设置成功;false=设置失败 + */ + public boolean expire(final String key, final long timeout) + { + return expire(key, timeout, TimeUnit.SECONDS); + } + + /** + * 设置有效时间 + * + * @param key Redis键 + * @param timeout 超时时间 + * @param unit 时间单位 + * @return true=设置成功;false=设置失败 + */ + public boolean expire(final String key, final long timeout, final TimeUnit unit) + { + return redisTemplate.expire(key, timeout, unit); + } + + /** + * 获取有效时间 + * + * @param key Redis键 + * @return 有效时间 + */ + public long getExpire(final String key) + { + return redisTemplate.getExpire(key); + } + + /** + * 判断 key是否存在 + * + * @param key 键 + * @return true 存在 false不存在 + */ + public Boolean hasKey(String key) + { + return redisTemplate.hasKey(key); + } + + /** + * 获得缓存的基本对象。 + * + * @param key 缓存键值 + * @return 缓存键值对应的数据 + */ + public T getCacheObject(final String key) + { + ValueOperations operation = redisTemplate.opsForValue(); + return operation.get(key); + } + + /** + * 删除单个对象 + * + * @param key + */ + public boolean deleteObject(final String key) + { + return redisTemplate.delete(key); + } + + /** + * 删除集合对象 + * + * @param collection 多个对象 + * @return + */ + public boolean deleteObject(final Collection collection) + { + return redisTemplate.delete(collection) > 0; + } + + /** + * 缓存List数据 + * + * @param key 缓存的键值 + * @param dataList 待缓存的List数据 + * @return 缓存的对象 + */ + public long setCacheList(final String key, final List dataList) + { + Long count = redisTemplate.opsForList().rightPushAll(key, dataList); + return count == null ? 0 : count; + } + + /** + * 获得缓存的list对象 + * + * @param key 缓存的键值 + * @return 缓存键值对应的数据 + */ + public List getCacheList(final String key) + { + return redisTemplate.opsForList().range(key, 0, -1); + } + + /** + * 缓存Set + * + * @param key 缓存键值 + * @param dataSet 缓存的数据 + * @return 缓存数据的对象 + */ + public BoundSetOperations setCacheSet(final String key, final Set dataSet) + { + BoundSetOperations setOperation = redisTemplate.boundSetOps(key); + Iterator it = dataSet.iterator(); + while (it.hasNext()) + { + setOperation.add(it.next()); + } + return setOperation; + } + + /** + * 获得缓存的set + * + * @param key + * @return + */ + public Set getCacheSet(final String key) + { + return redisTemplate.opsForSet().members(key); + } + + /** + * 缓存Map + * + * @param key + * @param dataMap + */ + public void setCacheMap(final String key, final Map dataMap) + { + if (dataMap != null) { + redisTemplate.opsForHash().putAll(key, dataMap); + } + } + + /** + * 获得缓存的Map + * + * @param key + * @return + */ + public Map getCacheMap(final String key) + { + return redisTemplate.opsForHash().entries(key); + } + + /** + * 往Hash中存入数据 + * + * @param key Redis键 + * @param hKey Hash键 + * @param value 值 + */ + public void setCacheMapValue(final String key, final String hKey, final T value) + { + redisTemplate.opsForHash().put(key, hKey, value); + } + + /** + * 获取Hash中的数据 + * + * @param key Redis键 + * @param hKey Hash键 + * @return Hash中的对象 + */ + public T getCacheMapValue(final String key, final String hKey) + { + HashOperations opsForHash = redisTemplate.opsForHash(); + return opsForHash.get(key, hKey); + } + + /** + * 获取多个Hash中的数据 + * + * @param key Redis键 + * @param hKeys Hash键集合 + * @return Hash对象集合 + */ + public List getMultiCacheMapValue(final String key, final Collection hKeys) + { + return redisTemplate.opsForHash().multiGet(key, hKeys); + } + + /** + * 删除Hash中的某条数据 + * + * @param key Redis键 + * @param hKey Hash键 + * @return 是否成功 + */ + public boolean deleteCacheMapValue(final String key, final String hKey) + { + return redisTemplate.opsForHash().delete(key, hKey) > 0; + } + + /** + * 获得缓存的基本对象列表 + * + * @param pattern 字符串前缀 + * @return 对象列表 + */ + public Collection keys(final String pattern) + { + return redisTemplate.keys(pattern); + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/constant/LeMqConstant.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/constant/LeMqConstant.java new file mode 100644 index 00000000..aeae7068 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/constant/LeMqConstant.java @@ -0,0 +1,217 @@ +package net.xnzn.core.common.constant; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public interface LeMqConstant { + public static enum DataChangeType { + ADD(1, "新增"), + UPDATE(2, "修改"), + REMOVE(3, "移除"); + + private final Integer key; + private final String desc; + + public Integer getKey() { + return this.key; + } + + public String getDesc() { + return this.desc; + } + + private DataChangeType(final Integer key, final String desc) { + this.key = key; + this.desc = desc; + } + + // $FF: synthetic method + private static DataChangeType[] $values() { + return new DataChangeType[]{ADD, UPDATE, REMOVE}; + } + } + + public static enum Topic { + DEVICE_UPDATE_BIND_DISHES("device-update-bind-dishes", "设备更新绑定菜品"), + DEVICE_UPDATE_DEVICE_BASICSETTING("update-device-basicsetting", "设备基础设置(商家)"), + DEVICE_UPDATE_DEVICE_METADATA("update-device-metadata", "设备基础设置(设备)"), + DEVICE_UPDATE_PERSON("update-person", "下发人员至设备(设备)"), + DEVICE_UPDATE_PERSON_BATCH("update-person-batch", "下发人员至设备(批量)(设备)"), + DEVICE_UPDATE_PERSONALFEATURE_BATCH("update-personalfeature-batch", "下发人员特征至设备(批量)(设备) "), + DEVICE_DOOR_OPERATOR("door_operator", "推送到web端"), + DEVICE_HAIQING_DEVICE_COMMUNICATION("haiqing", "推送海清设备"), + DEVICE_HAIQING_DEVICE_TRANSIT("device:haiqing_transit", "推送海清设备中间队列"), + DEVICE_PUSH_USER_DATA("device:push_user_data", "推送用户信息到设备"), + DEVICE_SBLS_DEVICE_TRANSIT("device:sbls_transit", "推送塞伯罗斯设备中间队列"), + DEVICE_SBLS_CR02EN_COMMUNICATION("sbls-send", "推送塞伯罗斯"), + DEVICE_DC_DEVICE_DELEAY("device:dc_delayed", "门禁延迟消息队列"), + DEVICE_LOCKER_STATUS("device-locker-status", "推送更新智能餐柜状态"), + DEVICE_NEW_MAKING_ORDER("device-new-making-order", "推送新的制作中订单"), + DEVICE_ATTENDANCE_ACCEPT_DOOR_CONTROL("device:attendance-accept-door-control", "门禁推送打卡信息至考勤模块"), + DEVICE_ATTENDANCE_ACCEPT_DOOR_CONTROL_VISITOR("device:attendance-accept-door-control-visitor", "门禁推送打卡信息至访客模块"), + CUSTOMER_VISITOR_INVITE("customer:visitor-invite", "访客邀约"), + CUSTOMER_VISITOR_AUDIT_PASS("customer:visitor-audit-pass", "访客审核通过"), + CUSTOMER_VISITOR_WAITING_AUDIT("customer:visitor-waiting-audit", "访客待审核"), + CUSTOMER_VISITOR_SIGN_IN("customer:visitor-sign-in", "访客签到"), + DATA_CHANGE_ORG("customer:data-change-org", "组织数据变更"), + DATA_CHANGE_CUSTOMER("customer:data-change-customer", "人员数据变更"), + CUSTOMER_CHANGE_DELAY("customer:customer-data-change-delay", "人员模块数据变更延迟队列"), + DATA_CHANGE_AREA("canteen:data-change-area", "区域数据变更"), + DATA_CHANGE_WAREHOUSE("drp:data-change-warehouse", "仓库数据变更"), + BACK_DEVICE_HAIQING_DEVICE_TRANSIT("backfield:back-haiqing-transit", "后场推送海清设备中间队列"), + BACK_DEVICE_HAIQING_DEVICE_COMMUNICATION("backhaiqing", "后场推送海清设备"), + BACK_DEVICE_SBLS_DEVICE_TRANSIT("backfield:back-sbls-transit", "后场推送塞伯罗斯设备中间队列"), + BACK_DEVICE_SBLS_CR02EN_COMMUNICATION("b-sbls-send", "后场推送塞伯罗斯"), + BACK_DEVICE_IOT_GATEWAY("back_device_iot_gateway", "后场推送网关设备信息"), + BACK_ATTENDANCE_CARD_DATA("backfield:back-attendance-card-data", "后场门禁考勤信息"), + BACK_TH_ALARM_DATA("backfield:back-th-alarm-data", "后场仓库温湿度告警"), + DATA_CHANGE_CANTEEN("canteen:data-change-canteen", "食堂数据变更"), + DATA_CHANGE_SHOP_STALL("canteen:data-change-shop-stall", "档口数据变更"), + DATA_CHANGE_DISHES("dishes:data-change-dishes", "菜品数据变更"), + DATA_CHANGE_RECIPE("dishes:data-change-recipe", "菜谱数据变更"), + DATA_CHANGE_RECIPE_RELEASE("dishes:data-change-recipe-release", "菜谱发布"), + DATA_CHANGE_ORDER("canteen:data-change-order", "食堂订单数据变更"), + DATA_CHANGE_SUPERMARKET("supermarket:data-change-market", "商超数据变更"), + DATA_CHANGE_SUPERMARKET_ORDER("supermarket:data-change-supermarket-order", "商超订单数据变更"), + DATA_CHANGE_SUPERMARKET_GOODS("supermarket:data-change-supermarket-goods", "超市商品数据变更"), + DATA_CHANGE_RULE("marketing:data-change-rule", "规则数据变更"), + DATA_CHANGE_SUPERMARKET_RULE("marketing:data-change-supermarket-rule", "规则数据变更"), + DATA_CHANGE_RECHARGE("acc:data-change-recharge", "充值数据变更"), + BUFFET_BIND_NOTIFY("order:buffet-bind", "用户绑盘/用户解绑"), + BUFFET_ORD_PAY("order:buffet-ord-pay", "定时自助餐支付"), + ORDER_V3_ASYNC_SAVE("order:order-v3-async-save", "订单异步保存"), + ORDER_V3_ASYNC_SAVE_WEIGHT("order:order-v3-async-save-weight", "订单异步保存自助餐缓存"), + ORDER_V3_ASYNC_PAY_RESULT("order:order-v3-async-pay-result", "订单异步处理支付结果"), + ORDER_V3_ASYNC_TIMEOUT("order:order-v3-async-timeout", "订单异步超时处理"), + ORDER_V3_ASYNC_IMAGE_UPDATE("order:order-v3-async-img-queue", "订单图片保存"), + ORDER_CHANGE("order:order-change", "订单变更"), + ORDER_V3_PLACED("order:order-v3-placed", "订单已下单"), + ORDER_V3_REFUNDED("order:order-v3-refunded", "订单已退款"), + ORDER_V3_CANCELED("order:order-v3-canceled", "订单已取消"), + ORDER_V3_DISHES_STATE_UPDATED("order:order-v3-dishes-state-updated", "订单制作配送更新状态(制作/配送/核销)"), + ORDER_V3_ADD_DISHES("order:order-v3-add-dishes", "未支付订单添加菜品"), + ORDER_V3_REMOVE_DISHES("order:order-v3-remove-dishes", "未支付订单移除菜品"), + PAY_ASYNC_PAY_QUERY("pay:order-v3-async-pay-query", "支付异步查询支付结果"), + PAY_ZHIFUFEN_ORDER_DELAY_CONFIRM("pay:zhifufen-delay-confirm", "创建支付分订单延时处理"), + PAY_RESULT("pay:pay-result", "支付结果"), + REFUND_RESULT("pay:pay-refund-result", "退款结果"), + PAY_ABC_NATIVE_RECHARGE_RESULT("pay:pay-abc-native-recharge-result", "农行掌银充值结果"), + PAY_ALI_ENTERPRISE_CODE_PAY_ASYNC("pay:ali-enterprise-code-pay-async", "支付宝企业码异步提交"), + DATA_CHANGE_CUSTOMER_DINING_PLACE("customer:data-change-customer-dining-place", "人员就餐地数据变更"), + ORDER_PRINT("order:order-print", "订单打印"), + ROOM_ORDER_PRINT("order:room-order-print", "包间餐桌订单打印"), + ACC_STATUS_CHANGE("acc:acc-status-change-queue", "账户状态变动记录"), + ACC_TRADE_REPORT("acc:acc-trade-report-queue", "账户交易记录"), + MENUAI_REGIST("menuai:menuai-regist", "菜品注册"), + NOTICE_SUMMARY_COLLECT("notice:notice-summary-collect", "消息统计收集"), + NOTICE_USER_BUSINESS_SEND("notice:notice-user-business-send", "通知发布"), + NOTICE_VERIFICATION_CODE("notice:notice-verification-code-send", "验证码消息"), + JIABO_PRINTER_FAIL("notice:jiabo-printer-fail", "佳博打印机失败队列"), + JIABO_PRINTER_SUCCESS("notice:jiabo-printer-success", "佳博打印机成功队列"), + AUTH_OPS_USER_EXPIRE("auth:auth-ops-user-expire", "临时运维账号过期队列"), + DEVICE_HEARTBEAT("device:device-heart-send", "设备心跳消息(兼容2.2.14前版本接口)"), + BACK_DEVICE_HEARTBEAT_DELAY("backfield:back-device-heart-delay", "后场设备心跳延迟队列"), + DASHBOARD_DATA_SEND("dashboard-data-send", "数据大屏下发数据"), + NOTICE_DRP_GENERAL("drp:drp-notice", "出入库发送短信通知"), + NOTICE_DRP_GENERAL_RESULT("drp:drp-notice-result", "出入库发送短信通知结果"), + DRP_INTO_AND_OUT_DETAIL("drp:drp-into-and-out-detail", "出入库详情"), + DRP_CANCEL_INTO_AND_OUT("drp:drp-cancel-into-and-out", "取消出入库"), + DRP_OUT_NOTICE_BACKFIELD_MATERIAL("drp:drp-out-notice-backfield-material", "出库告知后场货品信息"), + DRP_ALLOCATION_DETAIL("drp:drp-allocation-detail", "调拨详情"), + DRP_SYNC_MATERIAL("drp_sync_material", "同步货品"), + DRP_SYNC_MATERIAL_BIG_CATEGORY("drp_sync_material_big_category", "同步货品前10大类"), + BACK_STAFF_CHANGE("backfield:back-change-staff", "后场人员变更队列"), + BACK_DEVICE_CONTROL("back-device-control", "后场推送至设备端控制设备状态"), + BACK_ALARM_NOTICE("backfield:back-alarm-notice", "后场告警通知"), + BACK_ALARM_NOTICE_TO_DASHBOARD("back-device-alarm-to-dashboard", "告警通知推送到食安公示大屏"), + BACK_CABINET_STORAGE_STATUS("backfield:back-cabinet-storage-status", "后场留样柜自动离柜延迟队列"), + BACK_TRAIN_AUTO_FINISH("backfield:back-train-auto-finish", "后场培训签到后自动完成"), + BACK_EXAM_AUTO_FINISH("backfield:back-exam-auto-finish", "后场培训考试到点自动交卷"), + BACK_DISINFECT_MISSION_AUTO_FINISH("backfield:back-disinfect-mission-finish", "消毒任务超过最大消毒时长自动结束"), + BACK_DISINFECT_PHOTO("backfield:back-disinfect-photo", "自动获取消毒现场照片"), + BACK_FOLLOW_PHOTO("backfield:back-follow-photo", "自动获取晨检尾随照片"), + BACK_DH_BACK_ILLEGAL_WARNING("backfield:dh-back-illegal-warning", "处理dataBridge接受的大华盒子智能事件"), + BACK_DH_BACK_ILLEGAL_WARNING_STAFF("backfield:dh-back-illegal-warning-staff", "处理dataBridge接受的大华盒子智能事件关联的人员信息:编号-姓名"), + DEVICE_LOG_INFO_DELETE_v4("device:device-log-info-delete-v4", "设备日志定时处理"), + DEVICE_ORDER_DELAY("device:device-order-delay", "前场设备订单延迟消息"), + DEVICE_UPDATE_PERSONALINFO_V2("update-personinfo-v2", "下发跟新人员信息通知"), + DEVICE_ONLINE_REPORT_V2("device-online-report-v2", "通知商户下设备上下线"), + DEVICE_UPDATE_DEVICE_BASICSETTING_V2("update-device-basicsetting-v2", "下发设备商家层级基础设置"), + DEVICE_UPDATE_DEVICE_METADATASETTING_V2("update-device-metadatasetting-v2", "设备设置"), + DEVICE_TIME_CALIBRATION_V2("time-calibration-v2", "设备时间校准"), + DEVICE_DISTRIBUTE_RECIPE_V2("distribute-recipe-v2", "设备下发菜谱"), + DEVICE_SWITCH_DEVICE_MENU_V2("switch-device-menu-v2", "设备切菜主题"), + DEVICE_SWITCH_DEVICE_MENU_PRICE_V2("switch-device-menu-price-v2", "设备切价格主题"), + DEVICE_STALL_UPDATE_WEIGHTINFO_V2("device-stall-update-weightinfo-v2", "通知计量主机状态(余量看板)"), + DEVICE_TIME_CALIBRATION_V4("time-calibration-v4", "设备时间校准"), + DEVICE_UPDATE_PERSONAL_CONFIG_V4("device-update-person-config-v4", "通知设备人员和特征值更新"), + DEVICE_SYNC_ACCOUNT_BALANCE_V1("device-sync-acc-balance-v1", "设备实时同步账户余额v1"), + DEVICE_SYNC_ACCOUNT_BALANCE_V4("device-sync-acc-balance-v4", "设备实时同步账户余额v4"), + DEVICE_UPDATE_MENU_CONFIG_V4("device-update-menu-config-v4", "设备下发菜谱通知"), + DEVICE_UPDATE_INTERVAL_CONFIG_V4("device-update-interval-config-v4", "餐次变动通知"), + DEVICE_UPDATE_SYSTEM_CARD_V4("device-update-system-card-v4", "后台系统卡息更新"), + DEVICE_UPDATE_INFO_V4("device-update-info-v4", "后台设备信息(包含自定义)更新"), + DEVICE_ONLINE_REPORT_V4("device-online-report-v4", "通知商户下所有设备设备上下线"), + DEVICE_ORDER_DISHES_STATE_UPDATE_V4("device-order-dishes-state-update-v4", "推送订单制作配送状态更新"), + DEVICE_LOCKER_STATUS_V4("device-locker-status-v4", "推送更新智能餐柜状态"), + BACK_DEVICE_IOT_GATEWAY_V4("back-device-iot-gateway-v4", "后场推送网关设备信息"), + BACK_DEVICE_UPDATE_PERSONAL_CONFIG_V4("back-device-update-person-config-v4", "通知设备后场人员和特征值更新"), + BACK_CABINET_UPDATE_SETTING_CONFIG_V4("back-cabinet-update-setting-config-v4", "通知设备留样柜基础设置更新"), + BACK_CABINET_OPEN_V4("back-cabinet-open-v4", "通知留样柜开柜"), + DEVICE_UPDATE_BUFFET_MERCHANT_V4("device-update-buffet-merchant-config-v4", "自助餐商家层级设置"), + DEVICE_STALL_UPDATE_WEIGHTINFO_V4("device-stall-update-weightinfo-v4", "通知计量主机状态(余量看板)"), + DEVICE_PULL_LOG_NOTICE_V4("device-pull-log-notice-v4", "获取设备日志下发通知"), + DEVICE_SWITCH_DEVICE_MENU_V4("switch-device-menu-v4", "计量主机切菜"), + DEVICE_SWITCH_DEVICE_MENU_PRICE_V4("switch-device-menu-price-v4", "计量主机改价"), + DEVICE_STALL_BUFFET_ALARM_V4("device-stall-buffet-alarm-v4", "通知计量主机报警状态(余量看板)"), + DEVICE_PRICE_TAG_V4("device-price-tag-v4", "营养价签通知给设备"), + DEVICE_UPDATE_AD_V4("device-update-ad-config-v4", "设备更新广告菜品"), + DEVICE_UPDATE_APK_V4("device-update-apk-config-v4", "设备更新广告菜品"), + BACK_DEVICE_PASSENGER_FLOW("backfield:back-device-passenger-flow", "客流统计"), + DATA_BRIDGE_DEVICE_HEART("backfield:data-bridge-device-heart", "数据桥接设备心跳"), + DEVICE_CAMERA_CONTROL("data_bridge:device_camera_control", "摄像头云台控制"), + BACK_DEVICE_HEART("backfield:back_device_heart", "设备心跳"), + BACK_DEVICE_IOT("backfield:back_device_iot", "传感器数据"), + MERCHANT_LIMIT_FLAG_CHANGE("merchant:limit-flag-change", "商户人数限制标识变更"), + DEVICE_VOICE("voice", "发送MQTT消息给收银播报音箱"), + AI_GATEWAY_MQTT("ai_gateway_mqtt", "菜品识别"), + DEVICE_SYNC_PADDLE_FAISS("device_sync_paddle_faiss", "通知设备更新向量库"), + DEVICE_SYNC_PADDLE_PICODET("device_sync_paddle_picodet", "通知设备更新主体检测模型"); + + private final String key; + private final String value; + + private Topic(String key, String value) { + this.key = key; + this.value = value; + } + + public static Topic getTopic(String key) { + return (Topic)Arrays.stream(values()).filter((topic) -> { + return topic.getKey().equals(key); + }).findFirst().orElse((Topic) null); + } + + public static List deviceTopics() { + return (List)Arrays.stream(values()).filter((topic) -> { + return topic.name().startsWith("DEVICE_"); + }).collect(Collectors.toList()); + } + + public static List orderTopics() { + return (List)Arrays.stream(values()).filter((topic) -> { + return topic.name().startsWith("ORDER_") || topic.name().startsWith("MAC_ORDER_") || topic.name().startsWith("BUFFET_"); + }).collect(Collectors.toList()); + } + + public String getKey() { + return this.key; + } + + public String getValue() { + return this.value; + } + + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/mq/MqUtil.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/mq/MqUtil.java new file mode 100644 index 00000000..d5101f57 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/common/mq/MqUtil.java @@ -0,0 +1,147 @@ +//package net.xnzn.core.common.mq; +// +//import com.pig4cloud.pigx.common.core.util.SpringContextHolder; +//import com.pig4cloud.pigx.common.security.util.SecurityUtils; +//import lombok.extern.slf4j.Slf4j; +//import net.xnzn.core.common.constant.LeMqConstant; +//import net.xnzn.core.common.utils.JacksonUtil; +//import net.xnzn.core.common.utils.LogUtil; +//import net.xnzn.framework.data.tenant.TenantContextHolder; +//import net.xnzn.framework.mq.MQTemplate; +//import net.xnzn.framework.mq.tx.TxHolder; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.context.annotation.Lazy; +//import java.time.LocalDateTime; +// +//@Slf4j +//public class MqUtil { +// private static final Logger log = LoggerFactory.getLogger(MqUtil.class); +// @Lazy +// public static final MQTemplate mqTemplate = (MQTemplate)SpringContextHolder.getBean(MQTemplate.class); +// +// public static void send(T data, LeMqConstant.Topic topic) { +// try { +// log.info("发送消息,topic:{}", topic.getKey()); +// log.info("消息体", data); +// String routing = topic.getKey(); +// mqTemplate.send(routing, MqPayload.of(data, topic, routing)); +// } catch (Exception var3) { +// log.error("发送MQ消息失败", var3); +// } +// +// } +// +// public static void send(T data, LeMqConstant.Topic topic, String routing) { +// try { +// log.info("发送消息,topic:{},routing:{}", topic.getKey(), routing); +// LogUtil.printArgs("消息体", data); +// mqTemplate.send(routing, MqPayload.of(data, topic, routing)); +// } catch (Exception var4) { +// log.error("发送MQ消息失败", var4); +// } +// +// } +// +// public static TxHolder sendByTx(T data, LeMqConstant.Topic topic) { +// String routing = topic.getKey(); +// log.info("发送事务消息,topic:{}", topic.getKey()); +// LogUtil.printArgs("消息体", data); +// return mqTemplate.txBegin(routing, MqPayload.of(data, topic, routing)); +// } +// +// public static void sendByTxEnd(T data, LeMqConstant.Topic topic) { +// String routing = topic.getKey(); +// log.info("发送事务消息,topic:{}", topic.getKey()); +// LogUtil.printArgs("消息体", data); +// mqTemplate.txBegin(routing, MqPayload.of(data, topic, routing)).end(); +// } +// +// public static void sendByTxCommit(T data, LeMqConstant.Topic topic) { +// log.info("发送事务消息,topic:{}", topic.getKey()); +// LogUtil.printArgs("消息体", data); +// String routing = topic.getKey(); +// mqTemplate.txBegin(routing, MqPayload.of(data, topic, routing)).commit(); +// } +// +// public static void sendDelay(T data, LeMqConstant.Topic topic, int delayMileSecond) { +// try { +// log.info("发送延迟消息,topic:{},delayMileSecond:{}", topic.getKey(), delayMileSecond); +// LogUtil.printArgs("消息体", data); +// String routing = topic.getKey(); +// mqTemplate.sendDelay(routing, MqPayload.of(data, topic, routing), (long)delayMileSecond); +// } catch (Exception var4) { +// log.error("发送事务MQ消息失败", var4); +// } +// +// } +// +// public static void sendDataChange(T data, LeMqConstant.DataChangeType changeType, LeMqConstant.Topic topic) { +// Long userId = null; +// +// try { +// userId = SecurityUtils.getUser().getId(); +// } catch (Exception var5) { +// } +// +// MqDataChangeMessageDto dto = MqDataChangeMessageDto.of(TenantContextHolder.getTenantId(), JacksonUtil.valueToTree(data), changeType, topic, LocalDateTime.now(), SecurityUtils.getUser().getUsername(), userId); +// send(dto, topic); +// } +// +// public static void pushToSingleDevice(T data, LeMqConstant.Topic topic, String deviceSn) { +// String var10000 = topic.getKey(); +// String routing = var10000 + "/" + TenantContextHolder.getTenantId() + "/" + deviceSn; +// log.info("推送给单条设备,routing:{}", routing); +// LogUtil.printArgs("消息体", data); +// mqTemplate.sendMqtt(routing, data); +// } +// +// public static void pushToSingleDevice(T data, LeMqConstant.Topic topic, String deviceSn, Long merchantId) { +// String routing = topic.getKey() + "/" + merchantId + "/" + deviceSn; +// log.info("推送给单条设备,routing:{}", routing); +// LogUtil.printArgs("消息体", data); +// mqTemplate.sendMqtt(routing, data); +// } +// +// public static void pushToSingleTxDevice(T data, LeMqConstant.Topic topic, String deviceSn) { +// String var10000 = topic.getKey(); +// String routing = var10000 + "/" + TenantContextHolder.getTenantId() + "/" + deviceSn; +// log.info("推送给单条设备,routing:{}", routing); +// LogUtil.printArgs("消息体", data); +// mqTemplate.mqttTxBegin(routing, data).end(); +// } +// +// public static void pushToSingleDevice(T data, String routing, String deviceSn) { +// routing = routing + "/" + TenantContextHolder.getTenantId(); +// if (deviceSn != null) { +// routing = routing + "/" + deviceSn; +// } +// +// log.info("推送给单条设备,routing:{}", routing); +// LogUtil.printArgs("消息体", data); +// mqTemplate.sendMqtt(routing, data); +// } +// +// public static void pushToTenantAllDevice(T data, LeMqConstant.Topic topic) { +// String var10000 = topic.getKey(); +// String routing = var10000 + "/" + TenantContextHolder.getTenantId(); +// log.info("推送给商户下所有设备,routing:{}", routing); +// mqTemplate.sendMqtt(routing, data); +// } +// +// public static void pushToTenantAllDeviceWithTenantId(T data, LeMqConstant.Topic topic, Long tenantId) { +// String var10000 = topic.getKey(); +// String routing = var10000 + "/" + tenantId; +// log.info("推送给商户下所有设备,routing:{}", routing); +// LogUtil.printArgs("消息体", data); +// mqTemplate.sendMqtt(routing, data); +// } +// +// public static void pushToAllDevice(T data, LeMqConstant.Topic topic) { +// mqTemplate.sendMqtt(topic.getKey(), data); +// } +// +// public static void pushToSingleDeviceCustomed(T data, String routing) { +// mqTemplate.sendMqtt(routing, data); +// } +//} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/CustConstant.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/CustConstant.java new file mode 100644 index 00000000..b6fdb487 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/CustConstant.java @@ -0,0 +1,37 @@ +package net.xnzn.core.customer.constants; + +public interface CustConstant { + String DEFAULT_DATA_ERROR_MSG = "数据错误"; + Integer HEAD_ROW_NUMBER = 2; + String TRUE_CH = "是"; + Integer CUST_ALIPAY_NOT_AUTHORIZED = 53200; + Long DATA_DEFAULT_LONG = -1L; + Integer DATA_DEFAULT_INTEGER = -1; + String DATA_DEFAULT_STRING = ""; + String ASYNC_CUST_STATE = "yst:merchant-id:cust:async:state"; + Long TEMPORARY_CUST_ID = -1L; + String ASYNC_UPDATE_CUST_ORG_STATE = "yst:merchant-id:cust:async:updateorg:state"; + String ASYNC_UPDATE_CUST_STATE = "yst:merchant-id:cust:async:update:state"; + String ipRegex = "^(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]):([0-9]|[1-9]\\d|[1-9]\\d{2}|[1-9]\\d{3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$"; + Integer CUST_ACC_TEMP_DEFAULT_PSN_TYPE = -1; + Integer PLACE_REMARK_LENGTH = 255; + String PLACE_TREE_NODE_NAME_KEY = "text"; + String PLACE_TREE_PARENT_NODE_ID_KEY = "superId"; + int PLACE_EXCEL_IMPORT_FILE_SIZE_LIMIT = 1048576; + int PLACE_EXCEL_IMPORT_LOCK_EXPIRE_TIME_SECOND = 1200; + Long TEMPORARY_ORG_ID = 99999L; + String TEMPORARY_ORG_NUM = "letemporaryorg"; + String TEMPORARY_ORG_NAME = "临时部门"; + String ORG_FULL_NAME_SEPARATOR = "/"; + String ORG_FULL_ID_SEPARATOR = "/"; + int ORG_EXCEL_IMPORT_FILE_SIZE_LIMIT = 8388608; + Integer TEMPORARY_PSN_TYPE = 999; + String TEMPORARY_PSN_TYPE_NAME = "临时人员"; + Integer PSN_TYPE_MIN = 1; + Integer PSN_TYPE_MAX = 100; + String DEFAULT_PSN_TYPE_NAME_PREFIX = "类别"; + String CUSTOMER_DEFAULT_NUM = "888888"; + Integer FACE_ALGORITHM_VERSION = 1; + String DOWN_ZIP_BED_CODE_LOCK = "yunshitang:%s:cust:bed:down:zip"; + String DOWN_ZIP_PHOTO_LOCK = "yunshitang:%s:cust:photo:down:zip"; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/PersonalStatusEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/PersonalStatusEnum.java new file mode 100644 index 00000000..59ccf8b4 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/constants/PersonalStatusEnum.java @@ -0,0 +1,23 @@ +package net.xnzn.core.customer.constants; + +public enum PersonalStatusEnum { + NORMAL(1, "正常"), + CLOSE(2, "注销"); + + private final Integer key; + private final String desc; + + private PersonalStatusEnum(Integer key, String desc) { + this.key = key; + this.desc = desc; + } + + public Integer getKey() { + return this.key; + } + + public String getDesc() { + return this.desc; + } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/CustInfoBusiness.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/CustInfoBusiness.java new file mode 100644 index 00000000..8449c01a --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/CustInfoBusiness.java @@ -0,0 +1,10 @@ +package net.xnzn.core.customer.service; + +import net.xnzn.core.customer.vo.CustInfoAppIdLoginDTO; +import net.xnzn.core.customer.vo.CustInfoAppIdLoginVO; + +public interface CustInfoBusiness { + + CustInfoAppIdLoginVO customLoginWithAppId(CustInfoAppIdLoginDTO content, Integer sourceType); + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/impl/CustInfoBusinessImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/impl/CustInfoBusinessImpl.java new file mode 100644 index 00000000..a33fbee2 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/service/impl/CustInfoBusinessImpl.java @@ -0,0 +1,103 @@ +package net.xnzn.core.customer.service.impl; + +import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.bonus.common.core.exception.ServiceException; +import com.google.common.collect.Maps; +import net.xnzn.core.common.encrypt.SM4EncryptUtils; +import net.xnzn.core.common.utils.AesEncryptUtil; +import net.xnzn.core.customer.constants.CustConstant; +import net.xnzn.core.customer.constants.CustLoginTypeEnum; +import net.xnzn.core.customer.constants.PersonalStatusEnum; +import net.xnzn.core.customer.model.*; +import net.xnzn.core.customer.service.*; +import net.xnzn.core.customer.vo.CustInfoAppIdLoginDTO; +import net.xnzn.core.customer.vo.CustInfoAppIdLoginVO; +import net.xnzn.core.merchant.dto.SmsCodeVerifyDTO; +import net.xnzn.core.notice.v2.api.SmsCodeApi; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Service; + +@Service +public class CustInfoBusinessImpl implements CustInfoBusiness { + private static final Logger log = LoggerFactory.getLogger(CustInfoBusinessImpl.class); + private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); + @Autowired + private AesEncryptUtil aesEncryptUtil; + + @Autowired + private SmsCodeApi smsCodeApi; + + + + public CustInfoAppIdLoginVO customLoginWithAppId(CustInfoAppIdLoginDTO content, Integer sourceType) { + Integer loginType = content.getLoginType(); + if (loginType != null && CustLoginTypeEnum.contains(loginType)) { + Long merchantId = 1L; +// Long merchantId = (Long)Executors.readInSystem(() -> { +// return this.allocMerchantApi.getMerchantIdByAppid(LoginSourceTypeEnum.getAppIdKey(sourceType), content.getAppId()); +// }); + if (ObjectUtil.isEmpty(merchantId)) { + throw new ServiceException("商户appId不存在"); + } else { + //TenantContextHolder.setTenantId(merchantId); + if (CharSequenceUtil.isNotBlank(content.getMobile())) { + content.setMobile(this.aesEncryptUtil.aesDecode(content.getMobile())); + } + + LambdaQueryWrapper custInfoWrapper = (LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(CustInfo.class).eq(CustInfo::getCustState, PersonalStatusEnum.NORMAL.getKey())).and((wrapper) -> { + ((LambdaQueryWrapper)((LambdaQueryWrapper)wrapper.ne(CustInfo::getPsnType, CustConstant.TEMPORARY_PSN_TYPE)).or()).isNull(CustInfo::getPsnType); + }); + if (CustLoginTypeEnum.NAME_PWD.key().equals(content.getLoginType())) { + custInfoWrapper.eq(CustInfo::getCustName, SM4EncryptUtils.sm4Encryptbyconfig(content.getCustName())); + } else if (CustLoginTypeEnum.NAME_CUST_NUM_PWD.key().equals(content.getLoginType())) { + ((LambdaQueryWrapper)custInfoWrapper.eq(CustInfo::getCustName, SM4EncryptUtils.sm4Encryptbyconfig(content.getCustName()))).eq(CustInfo::getCustNum, content.getCustNum()); + } else if (CustLoginTypeEnum.TEL_PWD.key().equals(content.getLoginType())) { + custInfoWrapper.eq(CustInfo::getMobile, SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile())); + } else if (CustLoginTypeEnum.TEL_CODE.key().equals(content.getLoginType())) { + SmsCodeVerifyDTO smsCodeVerifyDTO = new SmsCodeVerifyDTO(); + smsCodeVerifyDTO.setCode(content.getCode()); + smsCodeVerifyDTO.setTelephoneNumber(content.getMobile()); + boolean flag = this.smsCodeApi.verifySmsCode(smsCodeVerifyDTO); + if (!flag) { + throw new ServiceException("验证码错误"); + } + + custInfoWrapper.eq(CustInfo::getMobile, SM4EncryptUtils.sm4Encryptbyconfig(content.getMobile())); + } else { + if (!CustLoginTypeEnum.ID_CARD_PWD.key().equals(content.getLoginType())) { + throw new ServiceException("参数错误"); + } + + custInfoWrapper.eq(CustInfo::getIdCard, SM4EncryptUtils.sm4Encryptbyconfig(content.getIdCard())); + } + + CustInfoAppIdLoginVO result = this.custInfoMapper.selectLoginInfo(custInfoWrapper); + if (ObjectUtil.isEmpty(result)) { + throw new ServiceException("未找到用户"); + } else { + if (CustLoginTypeEnum.getNeedPasswordLoginTypeToMap().containsKey(content.getLoginType())) { + content.setPassword(this.aesEncryptUtil.aesDecode(content.getPassword())); + log.info("输入密码:{}", content.getPassword()); + if (!encoder.matches(content.getPassword(), result.getPwd())) { + throw new ServiceException("密码错误"); + } + } + + return this.addOrUpdateCustCasual(sourceType, result); + } + } + } else { + throw new ServiceException("登录类型错误"); + } + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/vo/CustInfoAppIdLoginVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/vo/CustInfoAppIdLoginVO.java new file mode 100644 index 00000000..e7ea9da3 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/customer/vo/CustInfoAppIdLoginVO.java @@ -0,0 +1,26 @@ +package net.xnzn.core.customer.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@ApiModel("人员资料表") +@Data +public class CustInfoAppIdLoginVO implements Serializable { + @ApiModelProperty("人员id") + private Long custId; + @ApiModelProperty("人员姓名") + private String custName; + @ApiModelProperty("人员编号") + private String custNum; + @ApiModelProperty("人脸照片地址") + private String custPhotoUrl; + @ApiModelProperty("电话号码") + private String mobile; + @ApiModelProperty("openid") + private String openid; + @ApiModelProperty("登录密码") + private String pwd; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/merchant/dto/SmsCodeVerifyDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/merchant/dto/SmsCodeVerifyDTO.java new file mode 100644 index 00000000..c1e17cb3 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/merchant/dto/SmsCodeVerifyDTO.java @@ -0,0 +1,14 @@ +package net.xnzn.core.merchant.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SmsCodeVerifyDTO implements Serializable { + @ApiModelProperty("手机号") + private String telephoneNumber; + @ApiModelProperty("验证码") + private String code; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/notice/v2/api/SmsCodeApi.java b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/notice/v2/api/SmsCodeApi.java new file mode 100644 index 00000000..266f57d9 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/net/xnzn/core/notice/v2/api/SmsCodeApi.java @@ -0,0 +1,87 @@ +package net.xnzn.core.notice.v2.api; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.bonus.common.core.exception.ServiceException; +import net.xnzn.core.common.constant.LeMqConstant; +import net.xnzn.core.merchant.dto.SmsCodeVerifyDTO; +import net.xnzn.utils.RedisCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +@Service +public class SmsCodeApi { + private static final Logger log = LoggerFactory.getLogger(SmsCodeApi.class); + + @Autowired + private RedisCache redisCache; + + public void sendSmsCodePost(String telephoneNumber) { + this.sendSmsCodePost(telephoneNumber, "code_"); + } + + public void sendSmsCodePost(String telephoneNumber, String cacheKey) { + String limitKey = "limit_" + telephoneNumber; + LocalDateTime now = LocalDateTime.now(); + LocalDateTime endOfDay = now.with(LocalTime.MAX); + long expirTime = Math.max(1L, Duration.between(now, endOfDay).getSeconds()); + String lastSendTimeKey = "last_send_time_" + telephoneNumber; + String lastSendTime = redisCache.getCacheObject(lastSendTimeKey); + if (lastSendTime != null) { + long lastSendTimestamp = Long.parseLong(lastSendTime); + long currentTimestamp = System.currentTimeMillis(); + long timeElapsed = currentTimestamp - lastSendTimestamp; + if (timeElapsed < 60000L) { + throw new ServiceException("验证码重复"); + } + } + +// Integer times = RedisUtil.incr(limitKey, expirTime); +// if (times > 5) { +// throw new ServiceException("验证码时间超过限制"); +// } else { +// int code = (int)((Math.random() * 9.0 + 1.0) * 100000.0); +// String codeString = "" + code; +// Map maps = new HashMap(); +// maps.put("telephoneNumber", telephoneNumber); +// maps.put("sendCode", codeString); +// log.info("验证码发送code : {}", codeString); +// //MqUtil.send(JSON.toJSONString(maps), LeMqConstant.Topic.NOTICE_VERIFICATION_CODE); +// String key = cacheKey + telephoneNumber; +// redisCache.setNxCacheObject(key, codeString, 300L, TimeUnit.SECONDS); +// //redisCache.setNxCacheObject(lastSendTimeKey, String.valueOf(System.currentTimeMillis())); //TODO +// redisCache.setNxCacheObject(lastSendTimeKey, String.valueOf(System.currentTimeMillis()), 300L, TimeUnit.SECONDS); +// } + + int code = (int)((Math.random() * 9.0 + 1.0) * 100000.0); + String codeString = "" + code; + Map maps = new HashMap(); + maps.put("telephoneNumber", telephoneNumber); + maps.put("sendCode", codeString); + log.info("验证码发送code : {}", codeString); + //MqUtil.send(JSON.toJSONString(maps), LeMqConstant.Topic.NOTICE_VERIFICATION_CODE); + String key = cacheKey + telephoneNumber; + redisCache.setNxCacheObject(key, codeString, 300L, TimeUnit.SECONDS); + //redisCache.setNxCacheObject(lastSendTimeKey, String.valueOf(System.currentTimeMillis())); //TODO + redisCache.setNxCacheObject(lastSendTimeKey, String.valueOf(System.currentTimeMillis()), 300L, TimeUnit.SECONDS); + } + + public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO) { + return this.verifySmsCode(smsCodeVerifyDTO, "code_"); + } + + public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO, String cacheKey) { + String key = cacheKey + smsCodeVerifyDTO.getTelephoneNumber(); + String code = redisCache.getCacheObject(key); + log.info("redis缓存验证码code : {}", code); + return ObjectUtil.isNotEmpty(code) && ObjectUtil.equal(code, smsCodeVerifyDTO.getCode()); + } +}