update point rule groovy script
This commit is contained in:
@@ -58,6 +58,14 @@ public class NotifyController {
|
||||
@RequiredToken
|
||||
@PostMapping("/create")
|
||||
public Notify create(@RequestBody Notify notify) {
|
||||
String sendFrom = userLoginService.isLogged() ? userLoginService.getRequireLoginUserId() : null;
|
||||
notify.setCreatedBy(sendFrom);
|
||||
for (NotifyDetail detail : notify.getDetailList()) {
|
||||
detail.setNotifyId(notify.getId());
|
||||
if (TimiJava.isNotEmpty(sendFrom)) {
|
||||
detail.setSendFrom(sendFrom);
|
||||
}
|
||||
}
|
||||
service.create(notify);
|
||||
return notify;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -39,4 +40,7 @@ public class GroovyScript extends UUIDEntity {
|
||||
|
||||
/// 当前发布版本 ID
|
||||
private String publishedVersionId;
|
||||
|
||||
@Transient
|
||||
private GroovyScriptVersion latest;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@ package com.imyeyu.api.modules.common.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/// Groovy 脚本版本 Mapper
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-09-04
|
||||
public interface GroovyScriptVersionMapper extends BaseMapper<GroovyScriptVersion, String> {
|
||||
|
||||
@Select("SELECT * FROM `groovy_script_version` WHERE `script_id` = #{scriptId} " + NOT_DELETE + " ORDER BY `version` DESC " + LIMIT_1)
|
||||
GroovyScriptVersion selectLatest(String scriptId);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||
import com.imyeyu.spring.service.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,6 +16,12 @@ import java.util.Map;
|
||||
/// @since 2026-09-04
|
||||
public interface GroovyScriptService extends BaseService<GroovyScript, String> {
|
||||
|
||||
/// 按业务归属查询脚本列表
|
||||
///
|
||||
/// @param bizType 业务归属
|
||||
/// @return 脚本列表
|
||||
List<GroovyScript> listByBizType(GroovyScript.BizType bizType);
|
||||
|
||||
/// 按业务归属和代码查询脚本
|
||||
///
|
||||
/// @param bizType 业务归属
|
||||
@@ -23,26 +29,14 @@ public interface GroovyScriptService extends BaseService<GroovyScript, String> {
|
||||
/// @return 脚本,不存在时返回 null
|
||||
GroovyScript getByCode(GroovyScript.BizType bizType, String code);
|
||||
|
||||
/// 创建脚本元数据
|
||||
///
|
||||
/// 新建脚本默认停用,且没有已发布版本
|
||||
///
|
||||
/// @param script 脚本元数据
|
||||
void create(GroovyScript script);
|
||||
|
||||
/// 更新脚本元数据
|
||||
///
|
||||
/// 业务归属和代码是脚本稳定标识,创建后不可变更
|
||||
///
|
||||
/// @param script 脚本元数据
|
||||
void update(GroovyScript script);
|
||||
|
||||
/// 设置脚本启用状态
|
||||
///
|
||||
/// @param id 脚本 ID
|
||||
/// @param enabled true 为允许执行已发布版本
|
||||
void setEnabled(String id, boolean enabled);
|
||||
|
||||
GroovyScriptVersion getLatestVersion(String scriptId);
|
||||
|
||||
/// 创建不可变的脚本版本
|
||||
///
|
||||
/// @param scriptId 脚本 ID
|
||||
@@ -67,11 +61,6 @@ public interface GroovyScriptService extends BaseService<GroovyScript, String> {
|
||||
/// @param scriptId 脚本 ID
|
||||
void unpublish(String scriptId);
|
||||
|
||||
/// 删除脚本
|
||||
///
|
||||
/// @param id 脚本 ID
|
||||
void delete(String id);
|
||||
|
||||
/// 执行已发布且启用的脚本
|
||||
///
|
||||
/// @param bizType 业务归属
|
||||
|
||||
+15
-9
@@ -1,9 +1,9 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||
import com.imyeyu.api.modules.common.entity.GroovyScriptVersion;
|
||||
import com.imyeyu.api.modules.common.bean.GroovyScriptExecutionResult;
|
||||
import com.imyeyu.api.modules.common.mapper.GroovyScriptMapper;
|
||||
import com.imyeyu.api.modules.common.mapper.GroovyScriptVersionMapper;
|
||||
import com.imyeyu.api.modules.common.service.GroovyScriptService;
|
||||
@@ -52,6 +52,14 @@ public class GroovyScriptServiceImplement extends AbstractEntityService<GroovySc
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GroovyScript> listByBizType(GroovyScript.BizType bizType) {
|
||||
TimiException.required(bizType, "未找到脚本业务归属");
|
||||
GroovyScript example = new GroovyScript();
|
||||
example.setBizType(bizType);
|
||||
return mapper.selectAllByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroovyScript getByCode(GroovyScript.BizType bizType, String code) {
|
||||
GroovyScript example = new GroovyScript();
|
||||
@@ -95,6 +103,11 @@ public class GroovyScriptServiceImplement extends AbstractEntityService<GroovySc
|
||||
invalidateAfterCommit(script.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroovyScriptVersion getLatestVersion(String scriptId) {
|
||||
return versionMapper.selectLatest(scriptId);
|
||||
}
|
||||
|
||||
@Transactional(TimiServerDBConfig.ROLLBACKER)
|
||||
@Override
|
||||
public GroovyScriptVersion createVersion(String scriptId, String content) {
|
||||
@@ -104,7 +117,7 @@ public class GroovyScriptServiceImplement extends AbstractEntityService<GroovySc
|
||||
|
||||
GroovyScriptVersion version = new GroovyScriptVersion();
|
||||
version.setScriptId(scriptId);
|
||||
version.setVersion(nextVersion(scriptId));
|
||||
version.setVersion(versionMapper.selectLatest(scriptId).getVersion() + 1);
|
||||
version.setContent(content);
|
||||
version.setChecksum(checksum(content));
|
||||
versionMapper.insert(version);
|
||||
@@ -218,13 +231,6 @@ public class GroovyScriptServiceImplement extends AbstractEntityService<GroovySc
|
||||
return version;
|
||||
}
|
||||
|
||||
private int nextVersion(String scriptId) {
|
||||
return listVersion(scriptId).stream()
|
||||
.map(GroovyScriptVersion::getVersion)
|
||||
.max(Integer::compareTo)
|
||||
.orElse(0) + 1;
|
||||
}
|
||||
|
||||
private String cacheKey(GroovyScriptVersion version) {
|
||||
return "%s:%s".formatted(version.getId(), version.getChecksum());
|
||||
}
|
||||
|
||||
+4
-6
@@ -6,9 +6,9 @@ import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.mapper.NotifyMapper;
|
||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||
import com.imyeyu.api.modules.system.entity.Logger;
|
||||
import com.imyeyu.api.modules.system.service.LoggerService;
|
||||
import com.imyeyu.api.modules.common.vo.NotifyManagementItem;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
@@ -61,15 +61,13 @@ public class NotifyServiceImplement extends AbstractEntityService<Notify, String
|
||||
try {
|
||||
TimiException.required(notify, "未找到通知");
|
||||
TimiException.required(notify.getDetailList(), "未找到通知详情列表");
|
||||
String sendFrom = userLoginService.isLogged() ? userLoginService.getRequireLoginUserId() : null;
|
||||
notify.setCreatedBy(sendFrom);
|
||||
|
||||
notify.setCreatedBy(TimiJava.defaultIfEmpty(notify.getCreatedBy(), TimiJava.ZERO_UUID));
|
||||
super.create(notify);
|
||||
|
||||
for (NotifyDetail detail : notify.getDetailList()) {
|
||||
detail.setNotifyId(notify.getId());
|
||||
if (TimiJava.isNotEmpty(sendFrom)) {
|
||||
detail.setSendFrom(sendFrom);
|
||||
}
|
||||
detail.setSendFrom(TimiJava.defaultIfEmpty(detail.getSendFrom(), TimiJava.ZERO_UUID));
|
||||
detailService.create(detail);
|
||||
}
|
||||
logger.setLevel(Logger.Level.INFO);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.imyeyu.api.modules.gao.controller;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||
import com.imyeyu.api.modules.common.service.GroovyScriptService;
|
||||
import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission;
|
||||
import com.imyeyu.api.modules.gao.bean.GaoPermissionCode;
|
||||
import com.imyeyu.api.modules.gao.entity.GaoPointRule;
|
||||
@@ -31,6 +33,7 @@ public class GaoPointRuleController {
|
||||
|
||||
private final GaoStoreScopeService storeScopeService;
|
||||
private final GaoPointRuleService ruleService;
|
||||
private final GroovyScriptService groovyScriptService;
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@@ -54,9 +57,22 @@ public class GaoPointRuleController {
|
||||
GaoPointRule rule = ruleService.get(id);
|
||||
TimiException.required(rule, "not found point rule");
|
||||
storeScopeService.checkStoreId(rule.getStoreId());
|
||||
if (rule.getRuleMode() == GaoPointRule.RuleMode.GROOVY) {
|
||||
GroovyScript script = groovyScriptService.get(rule.getGroovyScriptId());
|
||||
script.setLatest(groovyScriptService.getLatestVersion(script.getId()));
|
||||
rule.setGroovyScript(script);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_READ)
|
||||
@PostMapping("/rule/script/list")
|
||||
public List<GroovyScript> scriptList() {
|
||||
return groovyScriptService.listByBizType(GroovyScript.BizType.GAO_POINT_RULE);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireGaoPermission(GaoPermissionCode.POINT_RULE_CREATE)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.imyeyu.api.modules.gao.entity;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.GroovyScript;
|
||||
import com.imyeyu.spring.annotation.table.Transient;
|
||||
import com.imyeyu.spring.entity.UUIDEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -96,4 +98,7 @@ public class GaoPointRule extends UUIDEntity {
|
||||
|
||||
/// 备注
|
||||
private String remark;
|
||||
|
||||
@Transient
|
||||
private GroovyScript groovyScript;
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
-- 积分规则已迁移到 trigger_source_type、trigger_ref_type、trigger_ref_id 模型。
|
||||
-- 删除旧模型字段,避免实体未赋值时触发非空约束。
|
||||
ALTER TABLE `gao_point_rule`
|
||||
DROP KEY `idx_gao_point_rule_match`,
|
||||
DROP KEY `idx_gao_point_rule_type`,
|
||||
DROP COLUMN `event_id`,
|
||||
DROP COLUMN `trigger_type`,
|
||||
DROP COLUMN `point_mode`,
|
||||
DROP COLUMN `condition_json`;
|
||||
Reference in New Issue
Block a user