mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
support query rule management (#853)
This commit is contained in:
@@ -264,4 +264,25 @@ CREATE TABLE IF NOT EXISTS s2_tag(
|
||||
`updated_by` varchar(100) DEFAULT NULL ,
|
||||
`ext` text DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--20240321
|
||||
CREATE TABLE IF NOT EXISTS `s2_query_rule` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`data_set_id` INT ,
|
||||
`priority` INT NOT NULL DEFAULT '1' ,
|
||||
`rule_type` varchar(255) NOT NULL ,
|
||||
`name` varchar(255) NOT NULL ,
|
||||
`biz_name` varchar(255) NOT NULL ,
|
||||
`description` varchar(500) DEFAULT NULL ,
|
||||
`rule` LONGVARCHAR DEFAULT NULL ,
|
||||
`action` LONGVARCHAR DEFAULT NULL ,
|
||||
`status` INT NOT NULL DEFAULT '1' ,
|
||||
`created_at` TIMESTAMP NOT NULL ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
`updated_at` TIMESTAMP DEFAULT NULL ,
|
||||
`updated_by` varchar(100) DEFAULT NULL ,
|
||||
`ext` LONGVARCHAR DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_query_rule IS 'tag query rule table';
|
||||
@@ -603,4 +603,24 @@ CREATE TABLE IF NOT EXISTS `s2_tag_object` (
|
||||
`ext` LONGVARCHAR DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_tag IS 'tag object information';
|
||||
COMMENT ON TABLE s2_tag IS 'tag object information';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `s2_query_rule` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`data_set_id` INT ,
|
||||
`priority` INT NOT NULL DEFAULT '1' ,
|
||||
`rule_type` varchar(255) NOT NULL ,
|
||||
`name` varchar(255) NOT NULL ,
|
||||
`biz_name` varchar(255) NOT NULL ,
|
||||
`description` varchar(500) DEFAULT NULL ,
|
||||
`rule` LONGVARCHAR DEFAULT NULL ,
|
||||
`action` LONGVARCHAR DEFAULT NULL ,
|
||||
`status` INT NOT NULL DEFAULT '1' ,
|
||||
`created_at` TIMESTAMP NOT NULL ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
`updated_at` TIMESTAMP DEFAULT NULL ,
|
||||
`updated_by` varchar(100) DEFAULT NULL ,
|
||||
`ext` LONGVARCHAR DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_query_rule IS 'tag query rule table';
|
||||
@@ -526,4 +526,23 @@ CREATE TABLE IF NOT EXISTS `s2_tag_object`
|
||||
`ext` text DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8 COMMENT ='标签表对象';
|
||||
DEFAULT CHARSET = utf8 COMMENT ='标签对象表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `s2_query_rule` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`data_set_id` bigint(20) ,
|
||||
`priority` int(10) NOT NULL DEFAULT '1' ,
|
||||
`rule_type` varchar(255) NOT NULL ,
|
||||
`name` varchar(255) NOT NULL ,
|
||||
`biz_name` varchar(255) NOT NULL ,
|
||||
`description` varchar(500) DEFAULT NULL ,
|
||||
`rule` text DEFAULT NULL ,
|
||||
`action` text DEFAULT NULL ,
|
||||
`status` INT NOT NULL DEFAULT '1' ,
|
||||
`created_at` datetime NOT NULL ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
`updated_at` datetime DEFAULT NULL ,
|
||||
`updated_by` varchar(100) DEFAULT NULL ,
|
||||
`ext` text DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8 COMMENT ='查询规则表';
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.tencent.supersonic.headless;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.headless.api.pojo.ActionInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.RuleInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.QueryRuleType;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryRuleFilter;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryRuleReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryRuleResp;
|
||||
import com.tencent.supersonic.headless.server.service.QueryRuleService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class QueryRuleTest extends BaseTest {
|
||||
|
||||
@Autowired
|
||||
private QueryRuleService queryRuleService;
|
||||
|
||||
private User user = User.getFakeUser();
|
||||
|
||||
public QueryRuleReq addSystemRule() {
|
||||
QueryRuleReq queryRuleReq = new QueryRuleReq();
|
||||
queryRuleReq.setPriority(0);
|
||||
queryRuleReq.setRuleType(QueryRuleType.ADD_DATE);
|
||||
queryRuleReq.setName("全局默认时间设置");
|
||||
queryRuleReq.setBizName("global date config");
|
||||
RuleInfo rule = new RuleInfo();
|
||||
rule.setMode(RuleInfo.Mode.BEFORE);
|
||||
List parameters = new ArrayList(Arrays.asList(3));
|
||||
rule.setParameters(parameters);
|
||||
queryRuleReq.setRule(rule);
|
||||
return queryRuleReq;
|
||||
}
|
||||
|
||||
public QueryRuleReq addUserRule1() {
|
||||
QueryRuleReq queryRuleReq = new QueryRuleReq();
|
||||
queryRuleReq.setDataSetId(2L);
|
||||
queryRuleReq.setPriority(1);
|
||||
queryRuleReq.setRuleType(QueryRuleType.ADD_DATE);
|
||||
queryRuleReq.setName("规则_1");
|
||||
queryRuleReq.setBizName("rule_1");
|
||||
|
||||
RuleInfo rule = new RuleInfo();
|
||||
rule.setMode(RuleInfo.Mode.BEFORE);
|
||||
List parameters = new ArrayList(Arrays.asList(4));
|
||||
rule.setParameters(parameters);
|
||||
queryRuleReq.setRule(rule);
|
||||
return queryRuleReq;
|
||||
}
|
||||
|
||||
public QueryRuleReq addUserRule2() {
|
||||
QueryRuleReq queryRuleReq = new QueryRuleReq();
|
||||
queryRuleReq.setDataSetId(2L);
|
||||
queryRuleReq.setPriority(1);
|
||||
queryRuleReq.setRuleType(QueryRuleType.ADD_SELECT);
|
||||
queryRuleReq.setName("规则_2");
|
||||
queryRuleReq.setBizName("rule_2");
|
||||
|
||||
RuleInfo rule = new RuleInfo();
|
||||
rule.setMode(RuleInfo.Mode.EXIST);
|
||||
rule.setParameters(Arrays.asList("singer_id"));
|
||||
queryRuleReq.setRule(rule);
|
||||
|
||||
ActionInfo action = new ActionInfo();
|
||||
List parameters = new ArrayList(Arrays.asList("c1", "c2"));
|
||||
action.setOut(parameters);
|
||||
queryRuleReq.setAction(action);
|
||||
return queryRuleReq;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddQueryRule() {
|
||||
QueryRuleReq queryRuleReqSys = addSystemRule();
|
||||
QueryRuleResp queryRuleResp = queryRuleService.addQueryRule(queryRuleReqSys, user);
|
||||
QueryRuleResp queryRule = queryRuleService.getQueryRuleById(1L, user);
|
||||
Assert.assertEquals(queryRuleResp.getPriority().intValue(), 0);
|
||||
Assert.assertEquals(queryRule.getPriority().intValue(), 0);
|
||||
|
||||
QueryRuleReq queryRuleReq1 = addUserRule1();
|
||||
QueryRuleResp queryRuleResp1 = queryRuleService.addQueryRule(queryRuleReq1, user);
|
||||
queryRuleResp1.setName("规则_1_1");
|
||||
QueryRuleReq queryRuleReq11 = new QueryRuleReq();
|
||||
BeanUtils.copyProperties(queryRuleResp1, queryRuleReq11);
|
||||
queryRuleService.updateQueryRule(queryRuleReq11, user);
|
||||
|
||||
QueryRuleReq queryRuleReq2 = addUserRule2();
|
||||
queryRuleService.addQueryRule(queryRuleReq2, user);
|
||||
|
||||
QueryRuleFilter queryRuleFilter = new QueryRuleFilter();
|
||||
List<QueryRuleResp> queryRuleList = queryRuleService.getQueryRuleList(queryRuleFilter, user);
|
||||
queryRuleList.size();
|
||||
}
|
||||
}
|
||||
@@ -606,3 +606,23 @@ CREATE TABLE IF NOT EXISTS `s2_tag_object` (
|
||||
);
|
||||
COMMENT ON TABLE s2_tag IS 'tag object information';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `s2_query_rule` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`data_set_id` INT ,
|
||||
`priority` INT NOT NULL DEFAULT '1' ,
|
||||
`rule_type` varchar(255) NOT NULL ,
|
||||
`name` varchar(255) NOT NULL ,
|
||||
`biz_name` varchar(255) NOT NULL ,
|
||||
`description` varchar(500) DEFAULT NULL ,
|
||||
`rule` LONGVARCHAR DEFAULT NULL ,
|
||||
`action` LONGVARCHAR DEFAULT NULL ,
|
||||
`status` INT NOT NULL DEFAULT '1' ,
|
||||
`created_at` TIMESTAMP NOT NULL ,
|
||||
`created_by` varchar(100) NOT NULL ,
|
||||
`updated_at` TIMESTAMP DEFAULT NULL ,
|
||||
`updated_by` varchar(100) DEFAULT NULL ,
|
||||
`ext` LONGVARCHAR DEFAULT NULL ,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_query_rule IS 'tag query rule table';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user