fix(education): tighten entitlement integration contracts
This commit is contained in:
@@ -9,6 +9,9 @@ import java.time.LocalDateTime;
|
|||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface EducationEntitlementMapper extends BaseMapperX<EducationEntitlementDO> {
|
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("""
|
||||||
SELECT * FROM education_entitlement
|
SELECT * FROM education_entitlement
|
||||||
WHERE tenant_id=#{tenantId} AND user_id=#{userId} AND resource_type=#{resourceType} AND resource_id=#{resourceId}
|
WHERE tenant_id=#{tenantId} AND user_id=#{userId} AND resource_type=#{resourceType} AND resource_id=#{resourceId}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.education.integration.member;
|
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.MemberPointApi;
|
||||||
|
import cn.iocoder.yudao.module.member.api.point.MemberPointBizType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +17,8 @@ public class MemberPointAwardPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addLearningPoints(Long userId, Integer points, Long awardId) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ public class EducationEntitlementServiceImpl implements EducationEntitlementServ
|
|||||||
}
|
}
|
||||||
return existing.getEntitlementId();
|
return existing.getEntitlementId();
|
||||||
}
|
}
|
||||||
|
entitlementMapper.lockSubject(tenantId + ":" + command.userId() + ":" + command.resourceType()
|
||||||
|
+ ":" + command.resourceId());
|
||||||
EducationEntitlementDO aggregate = entitlementMapper.selectForUpdate(tenantId, command.userId(), command.resourceType(), command.resourceId());
|
EducationEntitlementDO aggregate = entitlementMapper.selectForUpdate(tenantId, command.userId(), command.resourceType(), command.resourceId());
|
||||||
boolean applied;
|
boolean applied;
|
||||||
if ("GRANT".equals(command.eventType())) {
|
if ("GRANT".equals(command.eventType())) {
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ public class ResourceProductBindingService {
|
|||||||
throw exception(PRODUCT_BINDING_CONFLICT);
|
throw exception(PRODUCT_BINDING_CONFLICT);
|
||||||
} else if (!"ACTIVE".equals(existing.getStatus())) {
|
} else if (!"ACTIVE".equals(existing.getStatus())) {
|
||||||
int version = existing.getVersion();
|
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::getId, existing.getId()).eq(EducationResourceProductBindingDO::getTenantId, tenantId)
|
||||||
.eq(EducationResourceProductBindingDO::getVersion, version).set(EducationResourceProductBindingDO::getStatus, "ACTIVE")
|
.eq(EducationResourceProductBindingDO::getVersion, version).set(EducationResourceProductBindingDO::getStatus, "ACTIVE")
|
||||||
.set(EducationResourceProductBindingDO::getVersion, version + 1));
|
.set(EducationResourceProductBindingDO::getVersion, version + 1));
|
||||||
|
if (updated != 1) throw exception(PRODUCT_BINDING_CONFLICT);
|
||||||
existing.setStatus("ACTIVE"); existing.setVersion(version + 1);
|
existing.setStatus("ACTIVE"); existing.setVersion(version + 1);
|
||||||
}
|
}
|
||||||
return toResult(existing);
|
return toResult(existing);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.member.enums.point;
|
package cn.iocoder.yudao.module.member.enums.point;
|
||||||
|
|
||||||
import cn.hutool.core.util.EnumUtil;
|
import cn.hutool.core.util.EnumUtil;
|
||||||
|
import cn.iocoder.yudao.module.member.api.point.MemberPointBizType;
|
||||||
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
|
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -27,7 +28,7 @@ public enum MemberPointBizTypeEnum implements ArrayValuable<Integer> {
|
|||||||
ORDER_GIVE_CANCEL(22, "订单积分奖励(整单取消)", "订单取消,退还 {} 积分", false), // ORDER_GIVE 的取消
|
ORDER_GIVE_CANCEL(22, "订单积分奖励(整单取消)", "订单取消,退还 {} 积分", false), // ORDER_GIVE 的取消
|
||||||
ORDER_GIVE_CANCEL_ITEM(23, "订单积分奖励(单个退款)", "订单退款,扣除赠送的 {} 积分", false), // ORDER_GIVE 的取消
|
ORDER_GIVE_CANCEL_ITEM(23, "订单积分奖励(单个退款)", "订单退款,扣除赠送的 {} 积分", false), // ORDER_GIVE 的取消
|
||||||
|
|
||||||
EDUCATION_LEARNING(31, "教育学习奖励", "完成学习任务获得 {} 积分", true)
|
EDUCATION_LEARNING(MemberPointBizType.EDUCATION_LEARNING, "教育学习奖励", "完成学习任务获得 {} 积分", true)
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user