fix(education): tighten entitlement integration contracts

This commit is contained in:
2026-07-31 16:26:39 +08:00
parent fce2c6bc4a
commit bd956bcb35
6 changed files with 22 additions and 3 deletions

View File

@@ -9,6 +9,9 @@ import java.time.LocalDateTime;
@Mapper
public interface EducationEntitlementMapper extends BaseMapperX<EducationEntitlementDO> {
@Select("SELECT 1 FROM pg_advisory_xact_lock(hashtextextended(#{subjectKey}, 0))")
Integer lockSubject(@Param("subjectKey") String subjectKey);
@Select("""
SELECT * FROM education_entitlement
WHERE tenant_id=#{tenantId} AND user_id=#{userId} AND resource_type=#{resourceType} AND resource_id=#{resourceId}

View File

@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.education.integration.member;
import cn.iocoder.yudao.module.member.api.point.MemberPointApi;
import cn.iocoder.yudao.module.member.api.point.MemberPointBizType;
import org.springframework.stereotype.Component;
/**
@@ -16,7 +17,8 @@ public class MemberPointAwardPort {
}
public void addLearningPoints(Long userId, Integer points, Long awardId) {
memberPointApi.addPoint(userId, points, 31, "education-learning-award:" + awardId);
memberPointApi.addPoint(userId, points, MemberPointBizType.EDUCATION_LEARNING,
"education-learning-award:" + awardId);
}
}

View File

@@ -42,6 +42,8 @@ public class EducationEntitlementServiceImpl implements EducationEntitlementServ
}
return existing.getEntitlementId();
}
entitlementMapper.lockSubject(tenantId + ":" + command.userId() + ":" + command.resourceType()
+ ":" + command.resourceId());
EducationEntitlementDO aggregate = entitlementMapper.selectForUpdate(tenantId, command.userId(), command.resourceType(), command.resourceId());
boolean applied;
if ("GRANT".equals(command.eventType())) {

View File

@@ -38,10 +38,11 @@ public class ResourceProductBindingService {
throw exception(PRODUCT_BINDING_CONFLICT);
} else if (!"ACTIVE".equals(existing.getStatus())) {
int version = existing.getVersion();
bindingMapper.update(null, new LambdaUpdateWrapper<EducationResourceProductBindingDO>()
int updated = bindingMapper.update(null, new LambdaUpdateWrapper<EducationResourceProductBindingDO>()
.eq(EducationResourceProductBindingDO::getId, existing.getId()).eq(EducationResourceProductBindingDO::getTenantId, tenantId)
.eq(EducationResourceProductBindingDO::getVersion, version).set(EducationResourceProductBindingDO::getStatus, "ACTIVE")
.set(EducationResourceProductBindingDO::getVersion, version + 1));
if (updated != 1) throw exception(PRODUCT_BINDING_CONFLICT);
existing.setStatus("ACTIVE"); existing.setVersion(version + 1);
}
return toResult(existing);

View File

@@ -0,0 +1,10 @@
package cn.iocoder.yudao.module.member.api.point;
/**
* Public Member point business types available to other modules.
*/
public interface MemberPointBizType {
int EDUCATION_LEARNING = 31;
}

View File

@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.member.enums.point;
import cn.hutool.core.util.EnumUtil;
import cn.iocoder.yudao.module.member.api.point.MemberPointBizType;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -27,7 +28,7 @@ public enum MemberPointBizTypeEnum implements ArrayValuable<Integer> {
ORDER_GIVE_CANCEL(22, "订单积分奖励(整单取消)", "订单取消,退还 {} 积分", false), // ORDER_GIVE 的取消
ORDER_GIVE_CANCEL_ITEM(23, "订单积分奖励(单个退款)", "订单退款,扣除赠送的 {} 积分", false), // ORDER_GIVE 的取消
EDUCATION_LEARNING(31, "教育学习奖励", "完成学习任务获得 {} 积分", true)
EDUCATION_LEARNING(MemberPointBizType.EDUCATION_LEARNING, "教育学习奖励", "完成学习任务获得 {} 积分", true)
;
/**