support consume point
This commit is contained in:
@@ -17,7 +17,7 @@ public class GaoPointLedger extends UUIDEntity {
|
|||||||
/// 流水变化类型
|
/// 流水变化类型
|
||||||
public enum ChangeType {
|
public enum ChangeType {
|
||||||
|
|
||||||
/// 登记事件获得积分
|
/// 登记事件积分变化
|
||||||
EARN,
|
EARN,
|
||||||
|
|
||||||
/// 删除登记记录撤销积分
|
/// 删除登记记录撤销积分
|
||||||
|
|||||||
+2
-2
@@ -74,7 +74,7 @@ public class GaoPointLedgerServiceImplement extends AbstractEntityService<GaoPoi
|
|||||||
public GaoPointLedger earn(GaoEventRecord record, GaoPointRule rule, long pointDelta, JsonNode sourcePayload) {
|
public GaoPointLedger earn(GaoEventRecord record, GaoPointRule rule, long pointDelta, JsonNode sourcePayload) {
|
||||||
TimiException.required(record, "not found event record");
|
TimiException.required(record, "not found event record");
|
||||||
TimiException.required(rule, "not found point rule");
|
TimiException.required(rule, "not found point rule");
|
||||||
TimiException.requiredTrue(0 < pointDelta, "pointDelta invalid");
|
TimiException.requiredTrue(pointDelta != 0, "pointDelta invalid");
|
||||||
String idempotencyKey = "GAO_EVENT_RECORD:%s:RULE:%s:EARN".formatted(record.getId(), rule.getId());
|
String idempotencyKey = "GAO_EVENT_RECORD:%s:RULE:%s:EARN".formatted(record.getId(), rule.getId());
|
||||||
return apply(record.getStoreId(), record.getCustomerId(), GaoPointLedger.ChangeType.EARN, pointDelta, rule.getId(), record.getEventId(), record.getId(), sourcePayload, idempotencyKey, rule.getRemark(), record.getOperatorUserId(), record.getRegisteredAt());
|
return apply(record.getStoreId(), record.getCustomerId(), GaoPointLedger.ChangeType.EARN, pointDelta, rule.getId(), record.getEventId(), record.getId(), sourcePayload, idempotencyKey, rule.getRemark(), record.getOperatorUserId(), record.getRegisteredAt());
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ public class GaoPointLedgerServiceImplement extends AbstractEntityService<GaoPoi
|
|||||||
public GaoPointLedger revoke(GaoPointLedger originLedger, GaoEventRecord record) {
|
public GaoPointLedger revoke(GaoPointLedger originLedger, GaoEventRecord record) {
|
||||||
TimiException.required(originLedger, "not found origin ledger");
|
TimiException.required(originLedger, "not found origin ledger");
|
||||||
TimiException.required(record, "not found event record");
|
TimiException.required(record, "not found event record");
|
||||||
TimiException.requiredTrue(0 < originLedger.getPointDelta(), "origin ledger pointDelta invalid");
|
TimiException.requiredTrue(originLedger.getPointDelta() != 0, "origin ledger pointDelta invalid");
|
||||||
String idempotencyKey = "GAO_EVENT_RECORD:%s:LEDGER:%s:REVOKE".formatted(record.getId(), originLedger.getId());
|
String idempotencyKey = "GAO_EVENT_RECORD:%s:LEDGER:%s:REVOKE".formatted(record.getId(), originLedger.getId());
|
||||||
return apply(originLedger.getStoreId(), originLedger.getCustomerId(), GaoPointLedger.ChangeType.REVOKE, -originLedger.getPointDelta(), originLedger.getRuleId(), originLedger.getEventId(), originLedger.getEventRecordId(), originLedger.getSourcePayload(), idempotencyKey, "撤销登记记录积分", userLoginService.getRequireLoginUserId(), Time.now());
|
return apply(originLedger.getStoreId(), originLedger.getCustomerId(), GaoPointLedger.ChangeType.REVOKE, -originLedger.getPointDelta(), originLedger.getRuleId(), originLedger.getEventId(), originLedger.getEventRecordId(), originLedger.getSourcePayload(), idempotencyKey, "撤销登记记录积分", userLoginService.getRequireLoginUserId(), Time.now());
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -127,7 +127,7 @@ public class GaoPointRuleServiceImplement extends AbstractEntityService<GaoPoint
|
|||||||
|
|
||||||
TimiException.requiredTrue(rule.getPointMode() == GaoPointRule.PointMode.FIXED, "固定触发规则必须使用 FIXED 积分值模式");
|
TimiException.requiredTrue(rule.getPointMode() == GaoPointRule.PointMode.FIXED, "固定触发规则必须使用 FIXED 积分值模式");
|
||||||
TimiException.required(rule.getPointValue(), "not found rule.pointValue");
|
TimiException.required(rule.getPointValue(), "not found rule.pointValue");
|
||||||
TimiException.requiredTrue(0 < rule.getPointValue(), "rule.pointValue invalid");
|
TimiException.requiredTrue(rule.getPointValue() != 0, "rule.pointValue invalid");
|
||||||
if (rule.getTriggerType() == GaoPointRule.TriggerType.AFTER_COUNT_EVERY_TIME) {
|
if (rule.getTriggerType() == GaoPointRule.TriggerType.AFTER_COUNT_EVERY_TIME) {
|
||||||
JsonNode condition = requireObjectCondition(rule.getConditionJson());
|
JsonNode condition = requireObjectCondition(rule.getConditionJson());
|
||||||
JsonNode threshold = condition.get("threshold");
|
JsonNode threshold = condition.get("threshold");
|
||||||
@@ -192,7 +192,7 @@ public class GaoPointRuleServiceImplement extends AbstractEntityService<GaoPoint
|
|||||||
TimiException.requiredTrue(max == null, "最后一档 TIER.max 必须为空");
|
TimiException.requiredTrue(max == null, "最后一档 TIER.max 必须为空");
|
||||||
}
|
}
|
||||||
JsonNode pointValue = tier.get("pointValue");
|
JsonNode pointValue = tier.get("pointValue");
|
||||||
TimiException.requiredTrue(pointValue != null && pointValue.isIntegralNumber() && 0 <= pointValue.longValue(), "TIER.tiers[%d].pointValue invalid".formatted(i));
|
TimiException.requiredTrue(pointValue != null && pointValue.isIntegralNumber(), "TIER.tiers[%d].pointValue invalid".formatted(i));
|
||||||
previousMax = max;
|
previousMax = max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,9 +203,10 @@ public class GaoPointRuleServiceImplement extends AbstractEntityService<GaoPoint
|
|||||||
Long max = condition == null || condition.get("max") == null || condition.get("max").isNull() ? null : condition.get("max").isIntegralNumber() ? condition.get("max").longValue() : null;
|
Long max = condition == null || condition.get("max") == null || condition.get("max").isNull() ? null : condition.get("max").isIntegralNumber() ? condition.get("max").longValue() : null;
|
||||||
TimiException.requiredTrue(condition == null || min != null || condition.get("min") == null || condition.get("min").isNull(), "SOURCE_VALUE.min invalid");
|
TimiException.requiredTrue(condition == null || min != null || condition.get("min") == null || condition.get("min").isNull(), "SOURCE_VALUE.min invalid");
|
||||||
TimiException.requiredTrue(condition == null || max != null || condition.get("max") == null || condition.get("max").isNull(), "SOURCE_VALUE.max invalid");
|
TimiException.requiredTrue(condition == null || max != null || condition.get("max") == null || condition.get("max").isNull(), "SOURCE_VALUE.max invalid");
|
||||||
TimiException.requiredTrue(min == null || 0 < min, "SOURCE_VALUE.min invalid");
|
TimiException.requiredTrue(min == null || min != 0, "SOURCE_VALUE.min invalid");
|
||||||
TimiException.requiredTrue(max == null || 0 < max, "SOURCE_VALUE.max invalid");
|
TimiException.requiredTrue(max == null || max != 0, "SOURCE_VALUE.max invalid");
|
||||||
TimiException.requiredTrue(min == null || max == null || min <= max, "SOURCE_VALUE.min or SOURCE_VALUE.max invalid");
|
TimiException.requiredTrue(min == null || max == null || min <= max, "SOURCE_VALUE.min or SOURCE_VALUE.max invalid");
|
||||||
|
TimiException.requiredTrue(min == null || max == null || (min < 0) == (max < 0), "SOURCE_VALUE.min or SOURCE_VALUE.max direction invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonNode requireObjectCondition(JsonNode conditionJson) {
|
private JsonNode requireObjectCondition(JsonNode conditionJson) {
|
||||||
|
|||||||
+6
-6
@@ -62,7 +62,7 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
|||||||
|
|
||||||
List<GaoPointRule> ruleList = ruleService.listActive(record.getStoreId(), record.getEventId(), Time.now());
|
List<GaoPointRule> ruleList = ruleService.listActive(record.getStoreId(), record.getEventId(), Time.now());
|
||||||
Long count = null;
|
Long count = null;
|
||||||
long earnedPointValue = 0L;
|
long pointDeltaTotal = 0L;
|
||||||
for (GaoPointRule rule : ruleList) {
|
for (GaoPointRule rule : ruleList) {
|
||||||
RuleResolution resolution = resolveRule(record, rule, count);
|
RuleResolution resolution = resolveRule(record, rule, count);
|
||||||
if (resolution == null) {
|
if (resolution == null) {
|
||||||
@@ -72,16 +72,16 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
|||||||
count = count == null ? count(record) : count;
|
count = count == null ? count(record) : count;
|
||||||
}
|
}
|
||||||
long pointDelta = resolution.pointDelta();
|
long pointDelta = resolution.pointDelta();
|
||||||
if (0 < pointDelta) {
|
if (pointDelta != 0) {
|
||||||
ledgerService.earn(record, rule, pointDelta, resolution.sourcePayload());
|
ledgerService.earn(record, rule, pointDelta, resolution.sourcePayload());
|
||||||
earnedPointValue = Math.addExact(earnedPointValue, pointDelta);
|
pointDeltaTotal = Math.addExact(pointDeltaTotal, pointDelta);
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(rule.getExclusive())) {
|
if (Boolean.TRUE.equals(rule.getExclusive())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
record.setEarnedPointValue(earnedPointValue);
|
record.setEarnedPointValue(pointDeltaTotal);
|
||||||
eventRecordMapper.updateEarnedPointValue(record.getId(), earnedPointValue);
|
eventRecordMapper.updateEarnedPointValue(record.getId(), pointDeltaTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||||
@@ -140,7 +140,7 @@ public class GaoPointTriggerServiceImplement implements GaoPointTriggerService {
|
|||||||
}
|
}
|
||||||
permissionChecker.checkAny(ModuleCode.GAO, GaoPermissionCode.POINT_SOURCE_VALUE.getValue());
|
permissionChecker.checkAny(ModuleCode.GAO, GaoPermissionCode.POINT_SOURCE_VALUE.getValue());
|
||||||
long pointValue = record.getPointValue();
|
long pointValue = record.getPointValue();
|
||||||
TimiException.requiredTrue(0 < pointValue, "pointValue invalid");
|
TimiException.requiredTrue(pointValue != 0, "pointValue invalid");
|
||||||
JsonNode condition = rule.getConditionJson();
|
JsonNode condition = rule.getConditionJson();
|
||||||
if (condition != null) {
|
if (condition != null) {
|
||||||
JsonNode min = condition.get("min");
|
JsonNode min = condition.get("min");
|
||||||
|
|||||||
Reference in New Issue
Block a user