From 4963988ec2ff3cc403856fc2a0466e7690d75589 Mon Sep 17 00:00:00 2001 From: Timi Date: Fri, 21 Aug 2026 15:25:04 +0800 Subject: [PATCH] v1.0.20 --- .../common/config/NotifyQueueConfig.java | 13 +++ .../modules/common/service/SmsService.java | 30 +++++++ .../implement/SmsServiceImplement.java | 82 +++++++++++++++++++ .../api/modules/gao/entity/GaoCustomer.java | 6 +- .../modules/gao/entity/GaoPointLedger.java | 5 +- .../gao/mapper/GaoPointLedgerMapper.java | 6 +- .../gao/service/GaoPointLedgerService.java | 6 +- .../GaoPointLedgerServiceImplement.java | 5 +- .../GaoPointTriggerServiceImplement.java | 4 +- ...V37__fix_gao_point_consume_change_type.sql | 4 + .../timi-server/gao/GaoPointLedgerMapper.xml | 4 +- 11 files changed, 149 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/imyeyu/api/modules/common/service/SmsService.java create mode 100644 src/main/java/com/imyeyu/api/modules/common/service/implement/SmsServiceImplement.java create mode 100644 src/main/resources/db/migration/timiserver/V37__fix_gao_point_consume_change_type.sql diff --git a/src/main/java/com/imyeyu/api/modules/common/config/NotifyQueueConfig.java b/src/main/java/com/imyeyu/api/modules/common/config/NotifyQueueConfig.java index 3f35403..9427413 100644 --- a/src/main/java/com/imyeyu/api/modules/common/config/NotifyQueueConfig.java +++ b/src/main/java/com/imyeyu/api/modules/common/config/NotifyQueueConfig.java @@ -42,6 +42,19 @@ public class NotifyQueueConfig { private String secretId; private String secretKey; + + private Captcha captcha; + + /// 短信验证码 + @Data + public static class Captcha { + + private String templateId; + + private int ttlMinute; + + private int argIndex; + } } /// 微信队列配置 diff --git a/src/main/java/com/imyeyu/api/modules/common/service/SmsService.java b/src/main/java/com/imyeyu/api/modules/common/service/SmsService.java new file mode 100644 index 0000000..282e1c5 --- /dev/null +++ b/src/main/java/com/imyeyu/api/modules/common/service/SmsService.java @@ -0,0 +1,30 @@ +//package com.imyeyu.api.modules.common.service; +// +//import com.e2ins.ms.notify.entity.Notify; +//import com.e2ins.ms.notify.entity.NotifyDetail; +// +///** +// * +// * +// * @author 夜雨 +// * @since 2026-05-14 12:12 +// */ +//public interface SmsService { +// +// /** +// * 创建短信验证码通知 +// * +// * @param detail 通知 +// * @return 通知详情 ID +// */ +// String captchaCreate(Notify detail); +// +// /** +// * 校验短信验证码 +// * +// * @param detailId 通知详情 ID +// * @param captcha 请求验证码 +// * @return 通知详情 +// */ +// NotifyDetail captchaVerify(String detailId, String captcha); +//} diff --git a/src/main/java/com/imyeyu/api/modules/common/service/implement/SmsServiceImplement.java b/src/main/java/com/imyeyu/api/modules/common/service/implement/SmsServiceImplement.java new file mode 100644 index 0000000..8cabbd0 --- /dev/null +++ b/src/main/java/com/imyeyu/api/modules/common/service/implement/SmsServiceImplement.java @@ -0,0 +1,82 @@ +//package com.imyeyu.api.modules.common.service.implement; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.fasterxml.jackson.databind.node.ArrayNode; +//import com.imyeyu.api.modules.common.config.NotifyQueueConfig; +//import com.imyeyu.api.modules.common.entity.Notify; +//import com.imyeyu.api.modules.common.entity.NotifyDetail; +//import com.imyeyu.api.modules.common.service.NotifyDetailService; +//import com.imyeyu.api.modules.common.service.NotifyService; +//import com.imyeyu.api.modules.common.service.SmsService; +//import com.imyeyu.java.bean.timi.TimiException; +//import com.imyeyu.utils.Regex; +//import com.imyeyu.utils.Text; +//import com.imyeyu.utils.Time; +//import lombok.RequiredArgsConstructor; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.stereotype.Service; +// +//import java.util.List; +// +///** +// * +// * +// * @author 夜雨 +// * @since 2026-05-14 12:12 +// */ +//@Slf4j +//@Service +//@RequiredArgsConstructor +//public class SmsServiceImplement implements SmsService { +// +// @Value("${spring.profiles.active}") +// private String env; +// +// private final NotifyQueueConfig config; +// private final ObjectMapper jackson; +// +// private final NotifyService notifyService; +// private final NotifyDetailService notifyDetailService; +// +// @Override +// public String captchaCreate(Notify notify) { +// NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha(); +// TimiException.required(notify.getAppId(), "not found appId"); +// +// NotifyDetail detail = notify.getDetailList().getFirst(); +// +// TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, detail.getSendTo()), "invalid mobilePhone", "captcha.sms.invalid_mobile_phone"); +// +// String code = Text.randomString("0123456789", 6); +// if (!env.equalsIgnoreCase("prod")) { +// code = "123456"; +// } +// detail.setMsgType(NotifyDetail.MsgType.SMS); +// detail.setTemplateId(captchaConf.getTemplateId()); +// detail.setArgs(jackson.valueToTree(List.of(code, captchaConf.getTtlMinute()))); +// +// notifyService.create(notify); +// return notifyDetailService.listByNotifyId(notify.getId()).getFirst().getId(); +// } +// +// @Override +// public NotifyDetail captchaVerify(String detailId, String captcha) { +// AppConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha(); +// +// NotifyDetail detail = notifyDetailService.get(detailId); +// if (Time.M * captchaConf.getTtlMinute() < Time.now() - detail.getSendAt()) { +// throw new AppException(ResultCode.ARG_EXPIRED).msgKey("captcha.expired"); +// } +// if (detail.getArgs() instanceof ArrayNode array) { +// String dbCaptcha = array.get(captchaConf.getArgIndex()).asText(); +// if (!dbCaptcha.equalsIgnoreCase(captcha)) { +// throw new AppException(ResultCode.RESULT_BAD).msgKey("captcha.invalid"); +// } +// } else { +// throw new AppException(ResultCode.ERROR, "not array args"); +// } +// detail.setNotify(notifyService.get(detail.getNotifyId())); +// return detail; +// } +//} diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoCustomer.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoCustomer.java index d472e94..9c31870 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoCustomer.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoCustomer.java @@ -61,15 +61,15 @@ public class GaoCustomer extends UUIDEntity { /// 姓名 private String name; - @Column("zh_cn_pinyin_full") + @Column("name_pinyin_full") @JsonIgnore private String namePinyinFull; - @Column("zh_cn_pinyin_initial") + @Column("name_pinyin_initial") @JsonIgnore private String namePinyinInitial; - @Column("zh_cn_pinyin_mixed") + @Column("name_pinyin_mixed") @JsonIgnore private String namePinyinMixed; diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointLedger.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointLedger.java index 00ab9ab..f0e6826 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointLedger.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoPointLedger.java @@ -17,9 +17,12 @@ public class GaoPointLedger extends UUIDEntity { /// 流水变化类型 public enum ChangeType { - /// 登记事件积分变化 + /// 登记事件发放积分 EARN, + /// 登记事件消费积分 + CONSUME, + /// 删除登记记录撤销积分 REVOKE, diff --git a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointLedgerMapper.java b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointLedgerMapper.java index e1934fd..197349d 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointLedgerMapper.java +++ b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointLedgerMapper.java @@ -19,11 +19,11 @@ public interface GaoPointLedgerMapper extends BaseMapper /// @return 流水 GaoPointLedger selectByIdempotencyKey(@Param("idempotencyKey") String idempotencyKey); - /// 查询登记记录产生的原始获得积分流水 + /// 查询登记记录产生的原始规则积分流水 /// /// @param eventRecordId 登记记录 ID - /// @return 获得积分流水 - List selectEarnByEventRecordId(@Param("eventRecordId") String eventRecordId); + /// @return 原始规则积分流水 + List selectRuleChangeByEventRecordId(@Param("eventRecordId") String eventRecordId); /// 批量查询幂等键对应的流水 /// diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointLedgerService.java b/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointLedgerService.java index e544369..442d9b9 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointLedgerService.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/GaoPointLedgerService.java @@ -15,18 +15,18 @@ import com.imyeyu.spring.service.BaseService; /// @since 2026-08-11 public interface GaoPointLedgerService extends BaseService { - /// 写入登记获得积分流水 + /// 写入登记规则积分流水 /// /// @param record 登记记录 /// @param rule 命中规则 /// @param pointDelta 积分变化 /// @param sourcePayload 来源快照 /// @return 积分流水 - GaoPointLedger earn(GaoEventRecord record, GaoPointRule rule, long pointDelta, JsonNode sourcePayload); + GaoPointLedger applyRule(GaoEventRecord record, GaoPointRule rule, long pointDelta, JsonNode sourcePayload); /// 写入删除登记记录的撤销流水 /// - /// @param originLedger 原始获得积分流水 + /// @param originLedger 原始规则积分流水 /// @param record 登记记录 /// @return 撤销流水 GaoPointLedger revoke(GaoPointLedger originLedger, GaoEventRecord record); diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoPointLedgerServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoPointLedgerServiceImplement.java index e5f2098..a7cdd40 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoPointLedgerServiceImplement.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoPointLedgerServiceImplement.java @@ -71,12 +71,13 @@ public class GaoPointLedgerServiceImplement extends AbstractEntityService originLedgerList = ledgerMapper.selectEarnByEventRecordId(record.getId()); + List originLedgerList = ledgerMapper.selectRuleChangeByEventRecordId(record.getId()); if (originLedgerList.isEmpty()) { return; } diff --git a/src/main/resources/db/migration/timiserver/V37__fix_gao_point_consume_change_type.sql b/src/main/resources/db/migration/timiserver/V37__fix_gao_point_consume_change_type.sql new file mode 100644 index 0000000..84b44fa --- /dev/null +++ b/src/main/resources/db/migration/timiserver/V37__fix_gao_point_consume_change_type.sql @@ -0,0 +1,4 @@ +UPDATE `gao_point_ledger` +SET `change_type` = 'CONSUME' +WHERE `change_type` = 'EARN' + AND `point_delta` < 0; diff --git a/src/main/resources/mapper/timi-server/gao/GaoPointLedgerMapper.xml b/src/main/resources/mapper/timi-server/gao/GaoPointLedgerMapper.xml index 3a4d6ac..1589b75 100644 --- a/src/main/resources/mapper/timi-server/gao/GaoPointLedgerMapper.xml +++ b/src/main/resources/mapper/timi-server/gao/GaoPointLedgerMapper.xml @@ -9,11 +9,11 @@ LIMIT 1 - SELECT * FROM `gao_point_ledger` WHERE `event_record_id` = #{eventRecordId} - AND `change_type` = 'EARN' + AND `change_type` IN ('EARN', 'CONSUME') AND `deleted_at` IS NULL ORDER BY `created_at` ASC, `id` ASC -- 2.54.0