(feature)support adding tag for metric and support super admin configuration (#108)

This commit is contained in:
LXW
2023-09-20 17:00:38 +08:00
committed by GitHub
parent 5a42ff4b78
commit 49ba0e3f41
44 changed files with 693 additions and 256 deletions

View File

@@ -12,6 +12,8 @@ public class UserConstants {
public static final String TOKEN_USER_EMAIL = "token_user_email"; public static final String TOKEN_USER_EMAIL = "token_user_email";
public static final String TOKEN_IS_ADMIN = "token_is_admin";
public static final String TOKEN_ALGORITHM = "HS512"; public static final String TOKEN_ALGORITHM = "HS512";
public static final String TOKEN_CREATE_TIME = "token_create_time"; public static final String TOKEN_CREATE_TIME = "token_create_time";

View File

@@ -18,17 +18,22 @@ public class User {
private String email; private String email;
public static User get(Long id, String name, String displayName, String email) { private Integer isAdmin;
return new User(id, name, displayName, email);
public static User get(Long id, String name, String displayName, String email, Integer isAdmin) {
return new User(id, name, displayName, email, isAdmin);
} }
public static User getFakeUser() { public static User getFakeUser() {
return new User(1L, "admin", "admin", "admin@email"); return new User(1L, "admin", "admin", "admin@email", 1);
} }
public String getDisplayName() { public String getDisplayName() {
return StringUtils.isBlank(displayName) ? name : displayName; return StringUtils.isBlank(displayName) ? name : displayName;
} }
public boolean isSuperAdmin() {
return isAdmin != null && isAdmin == 1;
}
} }

View File

@@ -9,13 +9,14 @@ public class UserWithPassword extends User {
private String password; private String password;
public UserWithPassword(Long id, String name, String displayName, String email, String password) { public UserWithPassword(Long id, String name, String displayName, String email, String password, Integer isAdmin) {
super(id, name, displayName, email); super(id, name, displayName, email, isAdmin);
this.password = password; this.password = password;
} }
public static UserWithPassword get(Long id, String name, String displayName, String email, String password) { public static UserWithPassword get(Long id, String name, String displayName,
return new UserWithPassword(id, name, displayName, email, password); String email, String password, Integer isAdmin) {
return new UserWithPassword(id, name, displayName, email, password, isAdmin);
} }
} }

View File

@@ -71,7 +71,7 @@ public class DefaultUserAdaptor implements UserAdaptor {
} }
if (userDO.getPassword().equals(userReq.getPassword())) { if (userDO.getPassword().equals(userReq.getPassword())) {
UserWithPassword user = UserWithPassword.get(userDO.getId(), userDO.getName(), userDO.getDisplayName(), UserWithPassword user = UserWithPassword.get(userDO.getId(), userDO.getName(), userDO.getDisplayName(),
userDO.getEmail(), userDO.getPassword()); userDO.getEmail(), userDO.getPassword(), userDO.getIsAdmin());
return userTokenUtils.generateToken(user); return userTokenUtils.generateToken(user);
} }
throw new RuntimeException("password not correct, please try again"); throw new RuntimeException("password not correct, please try again");

View File

@@ -1,99 +1,129 @@
package com.tencent.supersonic.auth.authentication.persistence.dataobject; package com.tencent.supersonic.auth.authentication.persistence.dataobject;
public class UserDO { public class UserDO {
/** /**
* *
*/ */
private Long id; private Long id;
/** /**
* *
*/ */
private String name; private String name;
/** /**
* *
*/ */
private String password; private String password;
/** /**
* *
*/ */
private String displayName; private String displayName;
/** /**
* *
*/ */
private String email; private String email;
/** /**
* @return id *
*/
private Integer isAdmin;
/**
*
* @return id
*/ */
public Long getId() { public Long getId() {
return id; return id;
} }
/** /**
* @param id *
* @param id
*/ */
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/** /**
* @return name *
* @return name
*/ */
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* @param name *
* @param name
*/ */
public void setName(String name) { public void setName(String name) {
this.name = name == null ? null : name.trim(); this.name = name == null ? null : name.trim();
} }
/** /**
* @return password *
* @return password
*/ */
public String getPassword() { public String getPassword() {
return password; return password;
} }
/** /**
* @param password *
* @param password
*/ */
public void setPassword(String password) { public void setPassword(String password) {
this.password = password == null ? null : password.trim(); this.password = password == null ? null : password.trim();
} }
/** /**
* @return display_name *
* @return display_name
*/ */
public String getDisplayName() { public String getDisplayName() {
return displayName; return displayName;
} }
/** /**
* @param displayName *
* @param displayName
*/ */
public void setDisplayName(String displayName) { public void setDisplayName(String displayName) {
this.displayName = displayName == null ? null : displayName.trim(); this.displayName = displayName == null ? null : displayName.trim();
} }
/** /**
* @return email *
* @return email
*/ */
public String getEmail() { public String getEmail() {
return email; return email;
} }
/** /**
* @param email *
* @param email
*/ */
public void setEmail(String email) { public void setEmail(String email) {
this.email = email == null ? null : email.trim(); this.email = email == null ? null : email.trim();
} }
/**
*
* @return is_admin
*/
public Integer getIsAdmin() {
return isAdmin;
}
/**
*
* @param isAdmin
*/
public void setIsAdmin(Integer isAdmin) {
this.isAdmin = isAdmin;
}
} }

View File

@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class UserDOExample { public class UserDOExample {
/** /**
* s2_user * s2_user
*/ */
@@ -31,6 +30,7 @@ public class UserDOExample {
protected Integer limitEnd; protected Integer limitEnd;
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public UserDOExample() { public UserDOExample() {
@@ -38,13 +38,7 @@ public class UserDOExample {
} }
/** /**
* @mbg.generated *
*/
public String getOrderByClause() {
return orderByClause;
}
/**
* @mbg.generated * @mbg.generated
*/ */
public void setOrderByClause(String orderByClause) { public void setOrderByClause(String orderByClause) {
@@ -52,13 +46,15 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public boolean isDistinct() { public String getOrderByClause() {
return distinct; return orderByClause;
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void setDistinct(boolean distinct) { public void setDistinct(boolean distinct) {
@@ -66,6 +62,15 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated
*/
public boolean isDistinct() {
return distinct;
}
/**
*
* @mbg.generated * @mbg.generated
*/ */
public List<Criteria> getOredCriteria() { public List<Criteria> getOredCriteria() {
@@ -73,6 +78,7 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void or(Criteria criteria) { public void or(Criteria criteria) {
@@ -80,6 +86,7 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public Criteria or() { public Criteria or() {
@@ -89,6 +96,7 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public Criteria createCriteria() { public Criteria createCriteria() {
@@ -100,6 +108,7 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
protected Criteria createCriteriaInternal() { protected Criteria createCriteriaInternal() {
@@ -108,6 +117,7 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void clear() { public void clear() {
@@ -117,6 +127,15 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart=limitStart;
}
/**
*
* @mbg.generated * @mbg.generated
*/ */
public Integer getLimitStart() { public Integer getLimitStart() {
@@ -124,31 +143,25 @@ public class UserDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void setLimitStart(Integer limitStart) { public void setLimitEnd(Integer limitEnd) {
this.limitStart = limitStart; this.limitEnd=limitEnd;
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public Integer getLimitEnd() { public Integer getLimitEnd() {
return limitEnd; return limitEnd;
} }
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/** /**
* s2_user null * s2_user null
*/ */
protected abstract static class GeneratedCriteria { protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria; protected List<Criterion> criteria;
protected GeneratedCriteria() { protected GeneratedCriteria() {
@@ -528,6 +541,66 @@ public class UserDOExample {
addCriterion("email not between", value1, value2, "email"); addCriterion("email not between", value1, value2, "email");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andIsAdminIsNull() {
addCriterion("is_admin is null");
return (Criteria) this;
}
public Criteria andIsAdminIsNotNull() {
addCriterion("is_admin is not null");
return (Criteria) this;
}
public Criteria andIsAdminEqualTo(Integer value) {
addCriterion("is_admin =", value, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminNotEqualTo(Integer value) {
addCriterion("is_admin <>", value, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminGreaterThan(Integer value) {
addCriterion("is_admin >", value, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminGreaterThanOrEqualTo(Integer value) {
addCriterion("is_admin >=", value, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminLessThan(Integer value) {
addCriterion("is_admin <", value, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminLessThanOrEqualTo(Integer value) {
addCriterion("is_admin <=", value, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminIn(List<Integer> values) {
addCriterion("is_admin in", values, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminNotIn(List<Integer> values) {
addCriterion("is_admin not in", values, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminBetween(Integer value1, Integer value2) {
addCriterion("is_admin between", value1, value2, "isAdmin");
return (Criteria) this;
}
public Criteria andIsAdminNotBetween(Integer value1, Integer value2) {
addCriterion("is_admin not between", value1, value2, "isAdmin");
return (Criteria) this;
}
} }
/** /**
@@ -544,7 +617,6 @@ public class UserDOExample {
* s2_user null * s2_user null
*/ */
public static class Criterion { public static class Criterion {
private String condition; private String condition;
private Object value; private Object value;
@@ -561,6 +633,38 @@ public class UserDOExample {
private String typeHandler; private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) { protected Criterion(String condition) {
super(); super();
this.condition = condition; this.condition = condition;
@@ -596,37 +700,5 @@ public class UserDOExample {
protected Criterion(String condition, Object value, Object secondValue) { protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null); this(condition, value, secondValue, null);
} }
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
} }
} }

View File

@@ -2,6 +2,7 @@ package com.tencent.supersonic.auth.authentication.utils;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_ALGORITHM; import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_ALGORITHM;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_CREATE_TIME; import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_CREATE_TIME;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_IS_ADMIN;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_PREFIX; import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_PREFIX;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_TIME_OUT; import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_TIME_OUT;
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_DISPLAY_NAME; import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_DISPLAY_NAME;
@@ -42,6 +43,7 @@ public class UserTokenUtils {
claims.put(TOKEN_USER_PASSWORD, StringUtils.isEmpty(user.getPassword()) ? "" : user.getPassword()); claims.put(TOKEN_USER_PASSWORD, StringUtils.isEmpty(user.getPassword()) ? "" : user.getPassword());
claims.put(TOKEN_USER_DISPLAY_NAME, user.getDisplayName()); claims.put(TOKEN_USER_DISPLAY_NAME, user.getDisplayName());
claims.put(TOKEN_CREATE_TIME, System.currentTimeMillis()); claims.put(TOKEN_CREATE_TIME, System.currentTimeMillis());
claims.put(TOKEN_IS_ADMIN, user.getIsAdmin());
return generate(claims); return generate(claims);
} }
@@ -52,6 +54,7 @@ public class UserTokenUtils {
claims.put(TOKEN_USER_PASSWORD, "admin"); claims.put(TOKEN_USER_PASSWORD, "admin");
claims.put(TOKEN_USER_DISPLAY_NAME, "admin"); claims.put(TOKEN_USER_DISPLAY_NAME, "admin");
claims.put(TOKEN_CREATE_TIME, System.currentTimeMillis()); claims.put(TOKEN_CREATE_TIME, System.currentTimeMillis());
claims.put(TOKEN_IS_ADMIN, 1);
return generate(claims); return generate(claims);
} }
@@ -63,7 +66,9 @@ public class UserTokenUtils {
String userName = String.valueOf(claims.get(TOKEN_USER_NAME)); String userName = String.valueOf(claims.get(TOKEN_USER_NAME));
String email = String.valueOf(claims.get(TOKEN_USER_EMAIL)); String email = String.valueOf(claims.get(TOKEN_USER_EMAIL));
String displayName = String.valueOf(claims.get(TOKEN_USER_DISPLAY_NAME)); String displayName = String.valueOf(claims.get(TOKEN_USER_DISPLAY_NAME));
return User.get(userId, userName, displayName, email); Integer isAdmin = claims.get(TOKEN_IS_ADMIN) == null
? 0 : Integer.parseInt(claims.get(TOKEN_IS_ADMIN).toString());
return User.get(userId, userName, displayName, email, isAdmin);
} }
public UserWithPassword getUserWithPassword(HttpServletRequest request) { public UserWithPassword getUserWithPassword(HttpServletRequest request) {
@@ -79,7 +84,9 @@ public class UserTokenUtils {
String email = String.valueOf(claims.get(TOKEN_USER_EMAIL)); String email = String.valueOf(claims.get(TOKEN_USER_EMAIL));
String displayName = String.valueOf(claims.get(TOKEN_USER_DISPLAY_NAME)); String displayName = String.valueOf(claims.get(TOKEN_USER_DISPLAY_NAME));
String password = String.valueOf(claims.get(TOKEN_USER_PASSWORD)); String password = String.valueOf(claims.get(TOKEN_USER_PASSWORD));
return UserWithPassword.get(userId, userName, displayName, email, password); Integer isAdmin = claims.get(TOKEN_IS_ADMIN) == null
? 0 : Integer.parseInt(claims.get(TOKEN_IS_ADMIN).toString());
return UserWithPassword.get(userId, userName, displayName, email, password, isAdmin);
} }
private Claims getClaims(String token) { private Claims getClaims(String token) {

View File

@@ -2,11 +2,12 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tencent.supersonic.auth.authentication.persistence.mapper.UserDOMapper"> <mapper namespace="com.tencent.supersonic.auth.authentication.persistence.mapper.UserDOMapper">
<resultMap id="BaseResultMap" type="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO"> <resultMap id="BaseResultMap" type="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
<id column="id" jdbcType="BIGINT" property="id" /> <result column="id" jdbcType="BIGINT" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="password" jdbcType="VARCHAR" property="password" /> <result column="password" jdbcType="VARCHAR" property="password" />
<result column="display_name" jdbcType="VARCHAR" property="displayName" /> <result column="display_name" jdbcType="VARCHAR" property="displayName" />
<result column="email" jdbcType="VARCHAR" property="email" /> <result column="email" jdbcType="VARCHAR" property="email" />
<result column="is_admin" jdbcType="INTEGER" property="isAdmin" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@@ -38,7 +39,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, name, password, display_name, email id, name, password, display_name, email, is_admin
</sql> </sql>
<select id="selectByExample" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample" resultMap="BaseResultMap">
select select
@@ -57,21 +58,13 @@
limit #{limitStart} , #{limitEnd} limit #{limitStart} , #{limitEnd}
</if> </if>
</select> </select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from s2_user
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from s2_user
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO"> <insert id="insert" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
insert into s2_user (id, name, password, insert into s2_user (id, name, password,
display_name, email) display_name, email, is_admin
)
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{displayName,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}) #{displayName,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{isAdmin,jdbcType=INTEGER}
)
</insert> </insert>
<insert id="insertSelective" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO"> <insert id="insertSelective" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
insert into s2_user insert into s2_user
@@ -91,6 +84,9 @@
<if test="email != null"> <if test="email != null">
email, email,
</if> </if>
<if test="isAdmin != null">
is_admin,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@@ -108,6 +104,9 @@
<if test="email != null"> <if test="email != null">
#{email,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR},
</if> </if>
<if test="isAdmin != null">
#{isAdmin,jdbcType=INTEGER},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDOExample" resultType="java.lang.Long">
@@ -116,30 +115,4 @@
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
</select> </select>
<update id="updateByPrimaryKeySelective" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
update s2_user
<set>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
</if>
<if test="displayName != null">
display_name = #{displayName,jdbcType=VARCHAR},
</if>
<if test="email != null">
email = #{email,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.tencent.supersonic.auth.authentication.persistence.dataobject.UserDO">
update s2_user
set name = #{name,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR},
display_name = #{displayName,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper> </mapper>

View File

@@ -49,7 +49,7 @@ public interface SemanticLayer {
PageInfo<DimensionResp> getDimensionPage(PageDimensionReq pageDimensionCmd); PageInfo<DimensionResp> getDimensionPage(PageDimensionReq pageDimensionCmd);
PageInfo<MetricResp> getMetricPage(PageMetricReq pageMetricCmd); PageInfo<MetricResp> getMetricPage(PageMetricReq pageMetricCmd, User user);
List<DomainResp> getDomainList(User user); List<DomainResp> getDomainList(User user);

View File

@@ -110,17 +110,18 @@ public class ChatConfigController {
} }
@PostMapping("/dimension/page") @PostMapping("/dimension/page")
public PageInfo<DimensionResp> getDimension(@RequestBody PageDimensionReq pageDimensionCmd, public PageInfo<DimensionResp> getDimension(@RequestBody PageDimensionReq pageDimensionReq,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
return semanticLayer.getDimensionPage(pageDimensionCmd); return semanticLayer.getDimensionPage(pageDimensionReq);
} }
@PostMapping("/metric/page") @PostMapping("/metric/page")
public PageInfo<MetricResp> getMetric(@RequestBody PageMetricReq pageMetrricCmd, public PageInfo<MetricResp> getMetric(@RequestBody PageMetricReq pageMetricReq,
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
return semanticLayer.getMetricPage(pageMetrricCmd); User user = UserHolder.findUser(request, response);
return semanticLayer.getMetricPage(pageMetricReq, user);
} }

View File

@@ -111,9 +111,9 @@ public class LocalSemanticLayer extends BaseSemanticLayer {
} }
@Override @Override
public PageInfo<MetricResp> getMetricPage(PageMetricReq pageMetricReq) { public PageInfo<MetricResp> getMetricPage(PageMetricReq pageMetricReq, User user) {
metricService = ContextUtils.getBean(MetricService.class); metricService = ContextUtils.getBean(MetricService.class);
return metricService.queryMetric(pageMetricReq); return metricService.queryMetric(pageMetricReq, user);
} }
} }

View File

@@ -258,7 +258,7 @@ public class RemoteSemanticLayer extends BaseSemanticLayer {
} }
@Override @Override
public PageInfo<MetricResp> getMetricPage(PageMetricReq pageMetricCmd) { public PageInfo<MetricResp> getMetricPage(PageMetricReq pageMetricCmd, User user) {
String body = JsonUtil.toString(pageMetricCmd); String body = JsonUtil.toString(pageMetricCmd);
DefaultSemanticConfig defaultSemanticConfig = ContextUtils.getBean(DefaultSemanticConfig.class); DefaultSemanticConfig defaultSemanticConfig = ContextUtils.getBean(DefaultSemanticConfig.class);
log.info("url:{}", defaultSemanticConfig.getSemanticUrl() + defaultSemanticConfig.getFetchMetricPagePath()); log.info("url:{}", defaultSemanticConfig.getSemanticUrl() + defaultSemanticConfig.getFetchMetricPagePath());

View File

@@ -1,4 +1,4 @@
insert into s2_user (id, `name`, password, display_name, email) values (1, 'admin','admin','admin','admin@xx.com'); insert into s2_user (id, `name`, password, display_name, email, is_admin) values (1, 'admin','admin','admin','admin@xx.com', 1);
insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (4, 'lucy','123456','lucy','lucy@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (4, 'lucy','123456','lucy','lucy@xx.com');

View File

@@ -87,6 +87,7 @@ create table s2_user
display_name varchar(100) null, display_name varchar(100) null,
password varchar(100) null, password varchar(100) null,
email varchar(100) null, email varchar(100) null,
is_admin INT null,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
COMMENT ON TABLE s2_user IS 'user information table'; COMMENT ON TABLE s2_user IS 'user information table';

View File

@@ -36,7 +36,7 @@ insert into s2_auth_groups (group_id, config)
values (2, '{"domainId":"1","name":"tom_sales_permission","groupId":2,"authRules":[{"metrics":["stay_hours"],"dimensions":["page"]}],"dimensionFilters":["department in (''sales'')"],"dimensionFilterDescription":"开通 tom sales部门权限", "authorizedUsers":["tom"],"authorizedDepartmentIds":[]}'); values (2, '{"domainId":"1","name":"tom_sales_permission","groupId":2,"authRules":[{"metrics":["stay_hours"],"dimensions":["page"]}],"dimensionFilters":["department in (''sales'')"],"dimensionFilterDescription":"开通 tom sales部门权限", "authorizedUsers":["tom"],"authorizedDepartmentIds":[]}');
insert into s2_user (id, `name`, password, display_name, email) values (1, 'admin','admin','admin','admin@xx.com'); insert into s2_user (id, `name`, password, display_name, email, is_admin) values (1, 'admin','admin','admin','admin@xx.com', 1);
insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (4, 'lucy','123456','lucy','lucy@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (4, 'lucy','123456','lucy','lucy@xx.com');

View File

@@ -80,6 +80,7 @@ create table s2_user
display_name varchar(100) null, display_name varchar(100) null,
password varchar(100) null, password varchar(100) null,
email varchar(100) null, email varchar(100) null,
is_admin INT null,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
COMMENT ON TABLE s2_user IS 'user information table'; COMMENT ON TABLE s2_user IS 'user information table';
@@ -108,6 +109,7 @@ CREATE TABLE IF NOT EXISTS `s2_metric` (
`data_format_type` varchar(50) DEFAULT NULL , `data_format_type` varchar(50) DEFAULT NULL ,
`data_format` varchar(500) DEFAULT NULL, `data_format` varchar(500) DEFAULT NULL,
`alias` varchar(500) DEFAULT NULL, `alias` varchar(500) DEFAULT NULL,
`tags` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
COMMENT ON TABLE s2_metric IS 'metric information table'; COMMENT ON TABLE s2_metric IS 'metric information table';

View File

@@ -1,8 +1,8 @@
-- sample user -- sample user
insert into s2_user (id, `name`, password, display_name, email) values (1, 'admin','admin','admin','admin@xx.com'); insert into s2_user (id, `name`, password, display_name, email, is_admin) values (1, 'admin','admin','admin','admin@xx.com', 1);
insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (4, 'lucy','123456','lucy','lucy@xx.com'); insert into s2_user (id, `name`, password, display_name, email, is_admin) values (4, 'lucy','123456','lucy','lucy@xx.com', 1);
insert into s2_user (id, `name`, password, display_name, email) values (5, 'alice','123456','alice','alice@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (5, 'alice','123456','alice','alice@xx.com');
-- sample models -- sample models

View File

@@ -87,6 +87,7 @@ create table s2_user
display_name varchar(100) null, display_name varchar(100) null,
password varchar(100) null, password varchar(100) null,
email varchar(100) null, email varchar(100) null,
is_admin INT null,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
COMMENT ON TABLE s2_user IS 'user information table'; COMMENT ON TABLE s2_user IS 'user information table';
@@ -190,6 +191,7 @@ CREATE TABLE IF NOT EXISTS `s2_metric` (
`data_format_type` varchar(50) DEFAULT NULL , `data_format_type` varchar(50) DEFAULT NULL ,
`data_format` varchar(500) DEFAULT NULL, `data_format` varchar(500) DEFAULT NULL,
`alias` varchar(500) DEFAULT NULL, `alias` varchar(500) DEFAULT NULL,
`tags` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
COMMENT ON TABLE s2_metric IS 'metric information table'; COMMENT ON TABLE s2_metric IS 'metric information table';

View File

@@ -254,6 +254,7 @@ CREATE TABLE `s2_metric` (
`data_format_type` varchar(50) DEFAULT NULL COMMENT '数值类型', `data_format_type` varchar(50) DEFAULT NULL COMMENT '数值类型',
`data_format` varchar(500) DEFAULT NULL COMMENT '数值类型参数', `data_format` varchar(500) DEFAULT NULL COMMENT '数值类型参数',
`alias` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `alias` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`tags` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='指标表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='指标表';
@@ -368,7 +369,8 @@ create table s2_user
display_name varchar(100) null, display_name varchar(100) null,
password varchar(100) null, password varchar(100) null,
email varchar(100) null, email varchar(100) null,
is_admin int(11) null,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
insert into s2_user (id, `name`, password, display_name, email) values (1, 'admin','admin','admin','admin@xx.com'); insert into s2_user (id, `name`, password, display_name, email, is_admin) values (1, 'admin','admin','admin','admin@xx.com', 1);

View File

@@ -48,5 +48,10 @@ alter table s2_database drop column domain_id;
alter table s2_chat add column agent_id int after chat_id; alter table s2_chat add column agent_id int after chat_id;
--20230907 --20230907
ALTER TABLE s2_model add alias varchar(200) default null after domain_id;
ALTER TABLE s2_model add alias varchar(200) default null after domain_id; --20230919
alter table s2_metric add tags varchar(500) null;
--20230920
alter table s2_user add is_admin int null;

View File

@@ -23,7 +23,7 @@ import static java.time.LocalDate.now;
public class DataUtils { public class DataUtils {
private static final User user_test = new User(1L, "admin", "admin", "admin@email"); private static final User user_test = User.getFakeUser();
public static User getUser() { public static User getUser() {
return user_test; return user_test;

View File

@@ -1,5 +1,5 @@
-- sample user -- sample user
insert into s2_user (id, `name`, password, display_name, email) values (1, 'admin','admin','admin','admin@xx.com'); insert into s2_user (id, `name`, password, display_name, email, is_admin) values (1, 'admin','admin','admin','admin@xx.com', 1);
insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (2, 'jack','123456','jack','jack@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (3, 'tom','123456','tom','tom@xx.com');
insert into s2_user (id, `name`, password, display_name, email) values (4, 'lucy','123456','lucy','lucy@xx.com'); insert into s2_user (id, `name`, password, display_name, email) values (4, 'lucy','123456','lucy','lucy@xx.com');

View File

@@ -102,6 +102,7 @@ create table s2_user
display_name varchar(100) null, display_name varchar(100) null,
password varchar(100) null, password varchar(100) null,
email varchar(100) null, email varchar(100) null,
is_admin INT null,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
COMMENT ON TABLE s2_user IS 'user information table'; COMMENT ON TABLE s2_user IS 'user information table';
@@ -205,6 +206,7 @@ CREATE TABLE IF NOT EXISTS `s2_metric` (
`data_format_type` varchar(50) DEFAULT NULL , `data_format_type` varchar(50) DEFAULT NULL ,
`data_format` varchar(500) DEFAULT NULL, `data_format` varchar(500) DEFAULT NULL,
`alias` varchar(500) DEFAULT NULL, `alias` varchar(500) DEFAULT NULL,
`tags` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
); );
COMMENT ON TABLE s2_metric IS 'metric information table'; COMMENT ON TABLE s2_metric IS 'metric information table';

View File

@@ -4,6 +4,7 @@ package com.tencent.supersonic.semantic.api.model.request;
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem; import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
import com.tencent.supersonic.common.pojo.DataFormat; import com.tencent.supersonic.common.pojo.DataFormat;
import lombok.Data; import lombok.Data;
import java.util.List;
@Data @Data
@@ -17,4 +18,6 @@ public class MetricBaseReq extends SchemaItem {
private DataFormat dataFormat; private DataFormat dataFormat;
private List<String> tags;
} }

View File

@@ -9,6 +9,4 @@ public class PageMetricReq extends PageSchemaItemReq {
private String type; private String type;
private String key;
} }

View File

@@ -16,4 +16,5 @@ public class PageSchemaItemReq extends PageBaseReq {
private List<Long> modelIds = Lists.newArrayList(); private List<Long> modelIds = Lists.newArrayList();
private Integer sensitiveLevel; private Integer sensitiveLevel;
private Integer status; private Integer status;
private String key;
} }

View File

@@ -1,11 +1,15 @@
package com.tencent.supersonic.semantic.api.model.response; package com.tencent.supersonic.semantic.api.model.response;
import com.google.common.collect.Lists;
import com.tencent.supersonic.common.pojo.DataFormat; import com.tencent.supersonic.common.pojo.DataFormat;
import com.tencent.supersonic.semantic.api.model.pojo.MetricTypeParams; import com.tencent.supersonic.semantic.api.model.pojo.MetricTypeParams;
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem; import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.List;
@Data @Data
@@ -14,6 +18,8 @@ public class MetricResp extends SchemaItem {
private Long modelId; private Long modelId;
private Long domainId;
private String modelName; private String modelName;
//ATOMIC DERIVED //ATOMIC DERIVED
@@ -27,5 +33,15 @@ public class MetricResp extends SchemaItem {
private String alias; private String alias;
private List<String> tags;
private boolean hasAdminRes = false;
public void setTag(String tag) {
if (StringUtils.isBlank(tag)) {
tags = Lists.newArrayList();
} else {
tags = Arrays.asList(tag.split(","));
}
}
} }

View File

@@ -72,7 +72,8 @@ public class DatabaseServiceImpl implements DatabaseService {
private void fillPermission(List<DatabaseResp> databaseResps, User user) { private void fillPermission(List<DatabaseResp> databaseResps, User user) {
databaseResps.forEach(databaseResp -> { databaseResps.forEach(databaseResp -> {
if (databaseResp.getAdmins().contains(user.getName()) if (databaseResp.getAdmins().contains(user.getName())
|| user.getName().equalsIgnoreCase(databaseResp.getCreatedBy())) { || user.getName().equalsIgnoreCase(databaseResp.getCreatedBy())
|| user.isSuperAdmin()) {
databaseResp.setHasPermission(true); databaseResp.setHasPermission(true);
databaseResp.setHasEditPermission(true); databaseResp.setHasEditPermission(true);
databaseResp.setHasUsePermission(true); databaseResp.setHasUsePermission(true);
@@ -111,7 +112,8 @@ public class DatabaseServiceImpl implements DatabaseService {
List<String> viewers = databaseResp.getViewers(); List<String> viewers = databaseResp.getViewers();
if (!admins.contains(user.getName()) if (!admins.contains(user.getName())
&& !viewers.contains(user.getName()) && !viewers.contains(user.getName())
&& !databaseResp.getCreatedBy().equalsIgnoreCase(user.getName())) { && !databaseResp.getCreatedBy().equalsIgnoreCase(user.getName())
&& !user.isSuperAdmin()) {
String message = String.format("您暂无当前数据库%s权限, 请联系数据库管理员%s开通", String message = String.format("您暂无当前数据库%s权限, 请联系数据库管理员%s开通",
databaseResp.getName(), databaseResp.getName(),
String.join(",", admins)); String.join(",", admins));

View File

@@ -96,12 +96,12 @@ public class DomainServiceImpl implements DomainService {
@Override @Override
public List<DomainResp> getDomainListWithAdminAuth(User user) { public List<DomainResp> getDomainListWithAdminAuth(User user) {
Set<DomainResp> domainWithAuthAll = getDomainAuthSet(user.getName(), AuthType.ADMIN); Set<DomainResp> domainWithAuthAll = getDomainAuthSet(user, AuthType.ADMIN);
if (!CollectionUtils.isEmpty(domainWithAuthAll)) { if (!CollectionUtils.isEmpty(domainWithAuthAll)) {
List<Long> domainIds = domainWithAuthAll.stream().map(DomainResp::getId).collect(Collectors.toList()); List<Long> domainIds = domainWithAuthAll.stream().map(DomainResp::getId).collect(Collectors.toList());
domainWithAuthAll.addAll(getParentDomain(domainIds)); domainWithAuthAll.addAll(getParentDomain(domainIds));
} }
List<ModelResp> modelResps = modelService.getModelAuthList(user.getName(), AuthType.ADMIN); List<ModelResp> modelResps = modelService.getModelAuthList(user, AuthType.ADMIN);
if (!CollectionUtils.isEmpty(modelResps)) { if (!CollectionUtils.isEmpty(modelResps)) {
List<Long> domainIds = modelResps.stream().map(ModelResp::getDomainId).collect(Collectors.toList()); List<Long> domainIds = modelResps.stream().map(ModelResp::getDomainId).collect(Collectors.toList());
domainWithAuthAll.addAll(getParentDomain(domainIds)); domainWithAuthAll.addAll(getParentDomain(domainIds));
@@ -111,18 +111,18 @@ public class DomainServiceImpl implements DomainService {
} }
@Override @Override
public Set<DomainResp> getDomainAuthSet(String userName, AuthType authTypeEnum) { public Set<DomainResp> getDomainAuthSet(User user, AuthType authTypeEnum) {
List<DomainResp> domainResps = getDomainList(); List<DomainResp> domainResps = getDomainList();
Set<String> orgIds = userService.getUserAllOrgId(userName); Set<String> orgIds = userService.getUserAllOrgId(user.getName());
List<DomainResp> domainWithAuth = Lists.newArrayList(); List<DomainResp> domainWithAuth = Lists.newArrayList();
if (authTypeEnum.equals(AuthType.ADMIN)) { if (authTypeEnum.equals(AuthType.ADMIN)) {
domainWithAuth = domainResps.stream() domainWithAuth = domainResps.stream()
.filter(domainResp -> checkAdminPermission(orgIds, userName, domainResp)) .filter(domainResp -> checkAdminPermission(orgIds, user, domainResp))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
if (authTypeEnum.equals(AuthType.VISIBLE)) { if (authTypeEnum.equals(AuthType.VISIBLE)) {
domainWithAuth = domainResps.stream() domainWithAuth = domainResps.stream()
.filter(domainResp -> checkViewerPermission(orgIds, userName, domainResp)) .filter(domainResp -> checkViewerPermission(orgIds, user, domainResp))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
List<Long> domainIds = domainWithAuth.stream().map(DomainResp::getId) List<Long> domainIds = domainWithAuth.stream().map(DomainResp::getId)
@@ -240,11 +240,13 @@ public class DomainServiceImpl implements DomainService {
} }
private boolean checkAdminPermission(Set<String> orgIds, String userName, DomainResp domainResp) { private boolean checkAdminPermission(Set<String> orgIds, User user, DomainResp domainResp) {
List<String> admins = domainResp.getAdmins(); List<String> admins = domainResp.getAdmins();
List<String> adminOrgs = domainResp.getAdminOrgs(); List<String> adminOrgs = domainResp.getAdminOrgs();
if (admins.contains(userName) || domainResp.getCreatedBy().equals(userName)) { if (user.isSuperAdmin()) {
return true;
}
if (admins.contains(user.getName()) || domainResp.getCreatedBy().equals(user.getName())) {
return true; return true;
} }
if (CollectionUtils.isEmpty(adminOrgs)) { if (CollectionUtils.isEmpty(adminOrgs)) {
@@ -258,12 +260,17 @@ public class DomainServiceImpl implements DomainService {
return false; return false;
} }
private boolean checkViewerPermission(Set<String> orgIds, String userName, DomainResp domainDesc) { private boolean checkViewerPermission(Set<String> orgIds, User user, DomainResp domainDesc) {
List<String> admins = domainDesc.getAdmins(); List<String> admins = domainDesc.getAdmins();
List<String> viewers = domainDesc.getViewers(); List<String> viewers = domainDesc.getViewers();
List<String> adminOrgs = domainDesc.getAdminOrgs(); List<String> adminOrgs = domainDesc.getAdminOrgs();
List<String> viewOrgs = domainDesc.getViewOrgs(); List<String> viewOrgs = domainDesc.getViewOrgs();
if (admins.contains(userName) || viewers.contains(userName) || domainDesc.getCreatedBy().equals(userName)) { if (user.isSuperAdmin()) {
return true;
}
if (admins.contains(user.getName())
|| viewers.contains(user.getName())
|| domainDesc.getCreatedBy().equals(user.getName())) {
return true; return true;
} }
if (CollectionUtils.isEmpty(adminOrgs) && CollectionUtils.isEmpty(viewOrgs)) { if (CollectionUtils.isEmpty(adminOrgs) && CollectionUtils.isEmpty(viewOrgs)) {

View File

@@ -9,6 +9,7 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.common.pojo.DataAddEvent; import com.tencent.supersonic.common.pojo.DataAddEvent;
import com.tencent.supersonic.common.pojo.DataDeleteEvent; import com.tencent.supersonic.common.pojo.DataDeleteEvent;
import com.tencent.supersonic.common.pojo.DataUpdateEvent; import com.tencent.supersonic.common.pojo.DataUpdateEvent;
import com.tencent.supersonic.common.pojo.enums.AuthType;
import com.tencent.supersonic.common.pojo.enums.DictWordType; import com.tencent.supersonic.common.pojo.enums.DictWordType;
import com.tencent.supersonic.common.util.ChatGptHelper; import com.tencent.supersonic.common.util.ChatGptHelper;
import com.tencent.supersonic.semantic.api.model.pojo.Measure; import com.tencent.supersonic.semantic.api.model.pojo.Measure;
@@ -28,6 +29,7 @@ import com.tencent.supersonic.semantic.model.domain.utils.MetricConverter;
import com.tencent.supersonic.semantic.model.domain.MetricService; import com.tencent.supersonic.semantic.model.domain.MetricService;
import com.tencent.supersonic.semantic.model.domain.pojo.Metric; import com.tencent.supersonic.semantic.model.domain.pojo.Metric;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -123,7 +125,7 @@ public class MetricServiceImpl implements MetricService {
} }
@Override @Override
public PageInfo<MetricResp> queryMetric(PageMetricReq pageMetricReq) { public PageInfo<MetricResp> queryMetric(PageMetricReq pageMetricReq, User user) {
MetricFilter metricFilter = new MetricFilter(); MetricFilter metricFilter = new MetricFilter();
BeanUtils.copyProperties(pageMetricReq, metricFilter); BeanUtils.copyProperties(pageMetricReq, metricFilter);
Set<DomainResp> domainResps = domainService.getDomainChildren(pageMetricReq.getDomainIds()); Set<DomainResp> domainResps = domainService.getDomainChildren(pageMetricReq.getDomainIds());
@@ -137,7 +139,9 @@ public class MetricServiceImpl implements MetricService {
.doSelectPageInfo(() -> queryMetric(metricFilter)); .doSelectPageInfo(() -> queryMetric(metricFilter));
PageInfo<MetricResp> pageInfo = new PageInfo<>(); PageInfo<MetricResp> pageInfo = new PageInfo<>();
BeanUtils.copyProperties(metricDOPageInfo, pageInfo); BeanUtils.copyProperties(metricDOPageInfo, pageInfo);
pageInfo.setList(convertList(metricDOPageInfo.getList())); List<MetricResp> metricResps = convertList(metricDOPageInfo.getList());
fillAdminRes(metricResps, user);
pageInfo.setList(metricResps);
return pageInfo; return pageInfo;
} }
@@ -145,6 +149,21 @@ public class MetricServiceImpl implements MetricService {
return metricRepository.getMetric(metricFilter); return metricRepository.getMetric(metricFilter);
} }
private void fillAdminRes(List<MetricResp> metricResps, User user) {
List<ModelResp> modelResps = modelService.getModelListWithAuth(user, null, AuthType.ADMIN);
if (CollectionUtils.isEmpty(modelResps)) {
return;
}
Set<Long> modelIdSet = modelResps.stream().map(ModelResp::getId).collect(Collectors.toSet());
for (MetricResp metricResp : metricResps) {
if (modelIdSet.contains(metricResp.getModelId())) {
metricResp.setHasAdminRes(true);
}
}
}
@Override @Override
public MetricResp getMetric(Long modelId, String bizName) { public MetricResp getMetric(Long modelId, String bizName) {
List<MetricResp> metricDescs = getMetricByModelId(modelId); List<MetricResp> metricDescs = getMetricByModelId(modelId);
@@ -250,6 +269,16 @@ public class MetricServiceImpl implements MetricService {
}); });
} }
@Override
public Set<String> getMetricTags() {
List<MetricResp> metricResps = getMetrics();
if (CollectionUtils.isEmpty(metricResps)) {
return new HashSet<>();
}
return metricResps.stream().flatMap(metricResp ->
metricResp.getTags().stream()).collect(Collectors.toSet());
}
private void saveMetricBatch(List<Metric> metrics, User user) { private void saveMetricBatch(List<Metric> metrics, User user) {
if (CollectionUtils.isEmpty(metrics)) { if (CollectionUtils.isEmpty(metrics)) {
@@ -293,7 +322,7 @@ public class MetricServiceImpl implements MetricService {
Map<Long, ModelResp> modelMap = modelService.getModelMap(); Map<Long, ModelResp> modelMap = modelService.getModelMap();
if (!CollectionUtils.isEmpty(metricDOS)) { if (!CollectionUtils.isEmpty(metricDOS)) {
metricDescs = metricDOS.stream() metricDescs = metricDOS.stream()
.map(metricDO -> MetricConverter.convert2MetricDesc(metricDO, modelMap)) .map(metricDO -> MetricConverter.convert2MetricResp(metricDO, modelMap))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
return metricDescs; return metricDescs;

View File

@@ -96,10 +96,10 @@ public class ModelServiceImpl implements ModelService {
} }
@Override @Override
public List<ModelResp> getModelListWithAuth(String userName, Long domainId, AuthType authType) { public List<ModelResp> getModelListWithAuth(User user, Long domainId, AuthType authType) {
List<ModelResp> modelResps = getModelAuthList(userName, authType); List<ModelResp> modelResps = getModelAuthList(user, authType);
Set<ModelResp> modelRespSet = new HashSet<>(modelResps); Set<ModelResp> modelRespSet = new HashSet<>(modelResps);
List<ModelResp> modelRespsAuthInheritDomain = getModelRespAuthInheritDomain(userName, authType); List<ModelResp> modelRespsAuthInheritDomain = getModelRespAuthInheritDomain(user, authType);
modelRespSet.addAll(modelRespsAuthInheritDomain); modelRespSet.addAll(modelRespsAuthInheritDomain);
if (domainId != null && domainId > 0) { if (domainId != null && domainId > 0) {
modelRespSet = modelRespSet.stream().filter(modelResp -> modelRespSet = modelRespSet.stream().filter(modelResp ->
@@ -108,8 +108,8 @@ public class ModelServiceImpl implements ModelService {
return fillMetricInfo(new ArrayList<>(modelRespSet)); return fillMetricInfo(new ArrayList<>(modelRespSet));
} }
public List<ModelResp> getModelRespAuthInheritDomain(String userName, AuthType authType) { public List<ModelResp> getModelRespAuthInheritDomain(User user, AuthType authType) {
Set<DomainResp> domainResps = domainService.getDomainAuthSet(userName, authType); Set<DomainResp> domainResps = domainService.getDomainAuthSet(user, authType);
if (CollectionUtils.isEmpty(domainResps)) { if (CollectionUtils.isEmpty(domainResps)) {
return Lists.newArrayList(); return Lists.newArrayList();
} }
@@ -120,18 +120,18 @@ public class ModelServiceImpl implements ModelService {
} }
@Override @Override
public List<ModelResp> getModelAuthList(String userName, AuthType authTypeEnum) { public List<ModelResp> getModelAuthList(User user, AuthType authTypeEnum) {
List<ModelResp> modelResps = getModelList(); List<ModelResp> modelResps = getModelList();
Set<String> orgIds = userService.getUserAllOrgId(userName); Set<String> orgIds = userService.getUserAllOrgId(user.getName());
List<ModelResp> modelWithAuth = Lists.newArrayList(); List<ModelResp> modelWithAuth = Lists.newArrayList();
if (authTypeEnum.equals(AuthType.ADMIN)) { if (authTypeEnum.equals(AuthType.ADMIN)) {
modelWithAuth = modelResps.stream() modelWithAuth = modelResps.stream()
.filter(modelResp -> checkAdminPermission(orgIds, userName, modelResp)) .filter(modelResp -> checkAdminPermission(orgIds, user, modelResp))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
if (authTypeEnum.equals(AuthType.VISIBLE)) { if (authTypeEnum.equals(AuthType.VISIBLE)) {
modelWithAuth = modelResps.stream() modelWithAuth = modelResps.stream()
.filter(domainResp -> checkViewerPermission(orgIds, userName, domainResp)) .filter(domainResp -> checkViewerPermission(orgIds, user, domainResp))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
return modelWithAuth; return modelWithAuth;
@@ -324,9 +324,13 @@ public class ModelServiceImpl implements ModelService {
return new ArrayList<>(getModelMap().keySet()); return new ArrayList<>(getModelMap().keySet());
} }
public static boolean checkAdminPermission(Set<String> orgIds, String userName, ModelResp modelResp) { public static boolean checkAdminPermission(Set<String> orgIds, User user, ModelResp modelResp) {
List<String> admins = modelResp.getAdmins(); List<String> admins = modelResp.getAdmins();
List<String> adminOrgs = modelResp.getAdminOrgs(); List<String> adminOrgs = modelResp.getAdminOrgs();
if (user.isSuperAdmin()) {
return true;
}
String userName = user.getName();
if (admins.contains(userName) || modelResp.getCreatedBy().equals(userName)) { if (admins.contains(userName) || modelResp.getCreatedBy().equals(userName)) {
return true; return true;
} }
@@ -341,14 +345,18 @@ public class ModelServiceImpl implements ModelService {
return false; return false;
} }
public static boolean checkViewerPermission(Set<String> orgIds, String userName, ModelResp modelResp) { public static boolean checkViewerPermission(Set<String> orgIds, User user, ModelResp modelResp) {
List<String> admins = modelResp.getAdmins(); List<String> admins = modelResp.getAdmins();
List<String> viewers = modelResp.getViewers(); List<String> viewers = modelResp.getViewers();
List<String> adminOrgs = modelResp.getAdminOrgs(); List<String> adminOrgs = modelResp.getAdminOrgs();
List<String> viewOrgs = modelResp.getViewOrgs(); List<String> viewOrgs = modelResp.getViewOrgs();
if (user.isSuperAdmin()) {
return true;
}
if (modelResp.openToAll()) { if (modelResp.openToAll()) {
return true; return true;
} }
String userName = user.getName();
if (admins.contains(userName) || viewers.contains(userName) || modelResp.getCreatedBy().equals(userName)) { if (admins.contains(userName) || viewers.contains(userName) || modelResp.getCreatedBy().equals(userName)) {
return true; return true;
} }

View File

@@ -30,7 +30,7 @@ public interface DomainService {
List<DomainResp> getDomainListWithAdminAuth(User user); List<DomainResp> getDomainListWithAdminAuth(User user);
Set<DomainResp> getDomainAuthSet(String userName, AuthType authTypeEnum); Set<DomainResp> getDomainAuthSet(User user, AuthType authTypeEnum);
Set<DomainResp> getDomainChildren(List<Long> domainId); Set<DomainResp> getDomainChildren(List<Long> domainId);

View File

@@ -7,6 +7,7 @@ import com.tencent.supersonic.semantic.api.model.request.PageMetricReq;
import com.tencent.supersonic.semantic.api.model.response.MetricResp; import com.tencent.supersonic.semantic.api.model.response.MetricResp;
import java.util.List; import java.util.List;
import java.util.Set;
public interface MetricService { public interface MetricService {
@@ -22,7 +23,7 @@ public interface MetricService {
void createMetricBatch(List<MetricReq> metricReqs, User user) throws Exception; void createMetricBatch(List<MetricReq> metricReqs, User user) throws Exception;
PageInfo<MetricResp> queryMetric(PageMetricReq pageMetrricReq); PageInfo<MetricResp> queryMetric(PageMetricReq pageMetricReq, User user);
MetricResp getMetric(Long modelId, String bizName); MetricResp getMetric(Long modelId, String bizName);
@@ -35,4 +36,6 @@ public interface MetricService {
void deleteMetric(Long id) throws Exception; void deleteMetric(Long id) throws Exception;
List<String> mockAlias(MetricReq metricReq, String mockType, User user); List<String> mockAlias(MetricReq metricReq, String mockType, User user);
Set<String> getMetricTags();
} }

View File

@@ -13,9 +13,9 @@ import java.util.Map;
public interface ModelService { public interface ModelService {
List<ModelResp> getModelListWithAuth(String userName, Long domainId, AuthType authType); List<ModelResp> getModelListWithAuth(User user, Long domainId, AuthType authType);
List<ModelResp> getModelAuthList(String userName, AuthType authTypeEnum); List<ModelResp> getModelAuthList(User user, AuthType authTypeEnum);
List<ModelResp> getModelByDomainIds(List<Long> domainIds); List<ModelResp> getModelByDomainIds(List<Long> domainIds);

View File

@@ -3,116 +3,247 @@ package com.tencent.supersonic.semantic.model.domain.dataobject;
import java.util.Date; import java.util.Date;
public class MetricDO { public class MetricDO {
/**
*
*/
private Long id; private Long id;
/**
* 主体域ID
*/
private Long modelId; private Long modelId;
/**
* 指标名称
*/
private String name; private String name;
/**
* 字段名称
*/
private String bizName; private String bizName;
/**
* 描述
*/
private String description; private String description;
/**
* 指标状态,0正常,1下架,2删除
*/
private Integer status; private Integer status;
/**
* 敏感级别
*/
private Integer sensitiveLevel; private Integer sensitiveLevel;
/**
* 指标类型 proxy,expr
*/
private String type; private String type;
/**
* 创建时间
*/
private Date createdAt; private Date createdAt;
/**
* 创建人
*/
private String createdBy; private String createdBy;
/**
* 更新时间
*/
private Date updatedAt; private Date updatedAt;
/**
* 更新人
*/
private String updatedBy; private String updatedBy;
/**
* 数值类型
*/
private String dataFormatType; private String dataFormatType;
/**
* 数值类型参数
*/
private String dataFormat; private String dataFormat;
/**
*
*/
private String alias; private String alias;
/**
*
*/
private String tags;
/**
* 类型参数
*/
private String typeParams; private String typeParams;
/**
*
* @return id
*/
public Long getId() { public Long getId() {
return id; return id;
} }
/**
*
* @param id
*/
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
/**
* 主体域ID
* @return model_id 主体域ID
*/
public Long getModelId() { public Long getModelId() {
return modelId; return modelId;
} }
/**
* 主体域ID
* @param modelId 主体域ID
*/
public void setModelId(Long modelId) { public void setModelId(Long modelId) {
this.modelId = modelId; this.modelId = modelId;
} }
/**
* 指标名称
* @return name 指标名称
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
* 指标名称
* @param name 指标名称
*/
public void setName(String name) { public void setName(String name) {
this.name = name == null ? null : name.trim(); this.name = name == null ? null : name.trim();
} }
/**
* 字段名称
* @return biz_name 字段名称
*/
public String getBizName() { public String getBizName() {
return bizName; return bizName;
} }
/**
* 字段名称
* @param bizName 字段名称
*/
public void setBizName(String bizName) { public void setBizName(String bizName) {
this.bizName = bizName == null ? null : bizName.trim(); this.bizName = bizName == null ? null : bizName.trim();
} }
/**
* 描述
* @return description 描述
*/
public String getDescription() { public String getDescription() {
return description; return description;
} }
/**
* 描述
* @param description 描述
*/
public void setDescription(String description) { public void setDescription(String description) {
this.description = description == null ? null : description.trim(); this.description = description == null ? null : description.trim();
} }
/**
* 指标状态,0正常,1下架,2删除
* @return status 指标状态,0正常,1下架,2删除
*/
public Integer getStatus() { public Integer getStatus() {
return status; return status;
} }
/**
* 指标状态,0正常,1下架,2删除
* @param status 指标状态,0正常,1下架,2删除
*/
public void setStatus(Integer status) { public void setStatus(Integer status) {
this.status = status; this.status = status;
} }
/**
* 敏感级别
* @return sensitive_level 敏感级别
*/
public Integer getSensitiveLevel() { public Integer getSensitiveLevel() {
return sensitiveLevel; return sensitiveLevel;
} }
/**
* 敏感级别
* @param sensitiveLevel 敏感级别
*/
public void setSensitiveLevel(Integer sensitiveLevel) { public void setSensitiveLevel(Integer sensitiveLevel) {
this.sensitiveLevel = sensitiveLevel; this.sensitiveLevel = sensitiveLevel;
} }
/**
* 指标类型 proxy,expr
* @return type 指标类型 proxy,expr
*/
public String getType() { public String getType() {
return type; return type;
} }
/**
* 指标类型 proxy,expr
* @param type 指标类型 proxy,expr
*/
public void setType(String type) { public void setType(String type) {
this.type = type == null ? null : type.trim(); this.type = type == null ? null : type.trim();
} }
/**
* 创建时间
* @return created_at 创建时间
*/
public Date getCreatedAt() { public Date getCreatedAt() {
return createdAt; return createdAt;
} }
/**
* 创建时间
* @param createdAt 创建时间
*/
public void setCreatedAt(Date createdAt) { public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt; this.createdAt = createdAt;
} }
/**
* 创建人
* @return created_by 创建人
*/
public String getCreatedBy() { public String getCreatedBy() {
return createdBy; return createdBy;
} }
/**
* 创建人
* @param createdBy 创建人
*/
public void setCreatedBy(String createdBy) { public void setCreatedBy(String createdBy) {
this.createdBy = createdBy == null ? null : createdBy.trim(); this.createdBy = createdBy == null ? null : createdBy.trim();
} }
@@ -182,21 +313,37 @@ public class MetricDO {
} }
/** /**
* *
* @return alias * @return alias
*/ */
public String getAlias() { public String getAlias() {
return alias; return alias;
} }
/** /**
* *
* @param alias * @param alias
*/ */
public void setAlias(String alias) { public void setAlias(String alias) {
this.alias = alias == null ? null : alias.trim(); this.alias = alias == null ? null : alias.trim();
} }
/**
*
* @return tags
*/
public String getTags() {
return tags;
}
/**
*
* @param tags
*/
public void setTags(String tags) {
this.tags = tags == null ? null : tags.trim();
}
/** /**
* 类型参数 * 类型参数
* @return type_params 类型参数 * @return type_params 类型参数
@@ -212,4 +359,4 @@ public class MetricDO {
public void setTypeParams(String typeParams) { public void setTypeParams(String typeParams) {
this.typeParams = typeParams == null ? null : typeParams.trim(); this.typeParams = typeParams == null ? null : typeParams.trim();
} }
} }

View File

@@ -31,6 +31,7 @@ public class MetricDOExample {
protected Integer limitEnd; protected Integer limitEnd;
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public MetricDOExample() { public MetricDOExample() {
@@ -38,6 +39,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void setOrderByClause(String orderByClause) { public void setOrderByClause(String orderByClause) {
@@ -45,6 +47,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public String getOrderByClause() { public String getOrderByClause() {
@@ -52,6 +55,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void setDistinct(boolean distinct) { public void setDistinct(boolean distinct) {
@@ -59,6 +63,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public boolean isDistinct() { public boolean isDistinct() {
@@ -66,6 +71,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public List<Criteria> getOredCriteria() { public List<Criteria> getOredCriteria() {
@@ -73,6 +79,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void or(Criteria criteria) { public void or(Criteria criteria) {
@@ -80,6 +87,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public Criteria or() { public Criteria or() {
@@ -89,6 +97,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public Criteria createCriteria() { public Criteria createCriteria() {
@@ -100,6 +109,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
protected Criteria createCriteriaInternal() { protected Criteria createCriteriaInternal() {
@@ -108,6 +118,7 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void clear() { public void clear() {
@@ -117,13 +128,15 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void setLimitStart(Integer limitStart) { public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart; this.limitStart=limitStart;
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public Integer getLimitStart() { public Integer getLimitStart() {
@@ -131,13 +144,15 @@ public class MetricDOExample {
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public void setLimitEnd(Integer limitEnd) { public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd; this.limitEnd=limitEnd;
} }
/** /**
*
* @mbg.generated * @mbg.generated
*/ */
public Integer getLimitEnd() { public Integer getLimitEnd() {
@@ -1177,6 +1192,76 @@ public class MetricDOExample {
addCriterion("alias not between", value1, value2, "alias"); addCriterion("alias not between", value1, value2, "alias");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagsIsNull() {
addCriterion("tags is null");
return (Criteria) this;
}
public Criteria andTagsIsNotNull() {
addCriterion("tags is not null");
return (Criteria) this;
}
public Criteria andTagsEqualTo(String value) {
addCriterion("tags =", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotEqualTo(String value) {
addCriterion("tags <>", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThan(String value) {
addCriterion("tags >", value, "tags");
return (Criteria) this;
}
public Criteria andTagsGreaterThanOrEqualTo(String value) {
addCriterion("tags >=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThan(String value) {
addCriterion("tags <", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLessThanOrEqualTo(String value) {
addCriterion("tags <=", value, "tags");
return (Criteria) this;
}
public Criteria andTagsLike(String value) {
addCriterion("tags like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsNotLike(String value) {
addCriterion("tags not like", value, "tags");
return (Criteria) this;
}
public Criteria andTagsIn(List<String> values) {
addCriterion("tags in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsNotIn(List<String> values) {
addCriterion("tags not in", values, "tags");
return (Criteria) this;
}
public Criteria andTagsBetween(String value1, String value2) {
addCriterion("tags between", value1, value2, "tags");
return (Criteria) this;
}
public Criteria andTagsNotBetween(String value1, String value2) {
addCriterion("tags not between", value1, value2, "tags");
return (Criteria) this;
}
} }
/** /**
@@ -1209,6 +1294,38 @@ public class MetricDOExample {
private String typeHandler; private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) { protected Criterion(String condition) {
super(); super();
this.condition = condition; this.condition = condition;
@@ -1244,37 +1361,5 @@ public class MetricDOExample {
protected Criterion(String condition, Object value, Object secondValue) { protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null); this(condition, value, secondValue, null);
} }
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
} }
} }

View File

@@ -1,10 +1,12 @@
package com.tencent.supersonic.semantic.model.domain.pojo; package com.tencent.supersonic.semantic.model.domain.pojo;
import com.tencent.supersonic.common.pojo.DataFormat; import com.tencent.supersonic.common.pojo.DataFormat;
import com.tencent.supersonic.semantic.api.model.pojo.MetricTypeParams; import com.tencent.supersonic.semantic.api.model.pojo.MetricTypeParams;
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem; import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import java.util.List;
@Data @Data
public class Metric extends SchemaItem { public class Metric extends SchemaItem {
@@ -23,4 +25,13 @@ public class Metric extends SchemaItem {
private String alias; private String alias;
private List<String> tags;
public String getTag() {
if (CollectionUtils.isEmpty(tags)) {
return "";
}
return StringUtils.join(tags, ",");
}
} }

View File

@@ -37,6 +37,7 @@ public class MetricConverter {
if (metric.getDataFormat() != null) { if (metric.getDataFormat() != null) {
metricDO.setDataFormat(JSONObject.toJSONString(metric.getDataFormat())); metricDO.setDataFormat(JSONObject.toJSONString(metric.getDataFormat()));
} }
metricDO.setTags(metric.getTag());
return metricDO; return metricDO;
} }
@@ -51,27 +52,23 @@ public class MetricConverter {
BeanUtils.copyProperties(metric, metricDO); BeanUtils.copyProperties(metric, metricDO);
metricDO.setTypeParams(JSONObject.toJSONString(metric.getTypeParams())); metricDO.setTypeParams(JSONObject.toJSONString(metric.getTypeParams()));
metricDO.setDataFormat(JSONObject.toJSONString(metric.getDataFormat())); metricDO.setDataFormat(JSONObject.toJSONString(metric.getDataFormat()));
metricDO.setTags(metric.getTag());
return metricDO; return metricDO;
} }
public static MetricResp convert2MetricDesc(MetricDO metricDO, Map<Long, ModelResp> modelMap) { public static MetricResp convert2MetricResp(MetricDO metricDO, Map<Long, ModelResp> modelMap) {
MetricResp metricDesc = new MetricResp(); MetricResp metricResp = new MetricResp();
BeanUtils.copyProperties(metricDO, metricDesc); BeanUtils.copyProperties(metricDO, metricResp);
metricDesc.setTypeParams(JSONObject.parseObject(metricDO.getTypeParams(), MetricTypeParams.class)); metricResp.setTypeParams(JSONObject.parseObject(metricDO.getTypeParams(), MetricTypeParams.class));
metricDesc.setDataFormat(JSONObject.parseObject(metricDO.getDataFormat(), DataFormat.class)); metricResp.setDataFormat(JSONObject.parseObject(metricDO.getDataFormat(), DataFormat.class));
ModelResp modelResp = modelMap.get(metricDO.getModelId()); ModelResp modelResp = modelMap.get(metricDO.getModelId());
if (modelResp != null) { if (modelResp != null) {
metricDesc.setModelName(modelResp.getName()); metricResp.setModelName(modelResp.getName());
metricResp.setDomainId(modelResp.getDomainId());
} }
return metricDesc; metricResp.setTag(metricDO.getTags());
} return metricResp;
public static Metric convert2Metric(MetricDO metricDO) {
Metric metric = new Metric();
BeanUtils.copyProperties(metricDO, metric);
metric.setTypeParams(JSONObject.parseObject(metricDO.getTypeParams(), MetricTypeParams.class));
return metric;
} }

View File

@@ -9,6 +9,7 @@ import com.tencent.supersonic.semantic.api.model.request.PageMetricReq;
import com.tencent.supersonic.semantic.api.model.response.MetricResp; import com.tencent.supersonic.semantic.api.model.response.MetricResp;
import com.tencent.supersonic.semantic.model.domain.MetricService; import com.tencent.supersonic.semantic.model.domain.MetricService;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@@ -68,8 +69,11 @@ public class MetricController {
@PostMapping("/queryMetric") @PostMapping("/queryMetric")
public PageInfo<MetricResp> queryMetric(@RequestBody PageMetricReq pageMetrricReq) { public PageInfo<MetricResp> queryMetric(@RequestBody PageMetricReq pageMetricReq,
return metricService.queryMetric(pageMetrricReq); HttpServletRequest request,
HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
return metricService.queryMetric(pageMetricReq, user);
} }
@GetMapping("getMetric/{modelId}/{bizName}") @GetMapping("getMetric/{modelId}/{bizName}")
@@ -90,4 +94,9 @@ public class MetricController {
} }
@GetMapping("/getMetricTags")
public Set<String> getMetricTags() {
return metricService.getMetricTags();
}
} }

View File

@@ -60,7 +60,7 @@ public class ModelController {
HttpServletRequest request, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
User user = UserHolder.findUser(request, response); User user = UserHolder.findUser(request, response);
return modelService.getModelListWithAuth(user.getName(), domainId, AuthType.ADMIN); return modelService.getModelListWithAuth(user, domainId, AuthType.ADMIN);
} }

View File

@@ -17,6 +17,7 @@
<result column="data_format_type" jdbcType="VARCHAR" property="dataFormatType" /> <result column="data_format_type" jdbcType="VARCHAR" property="dataFormatType" />
<result column="data_format" jdbcType="VARCHAR" property="dataFormat" /> <result column="data_format" jdbcType="VARCHAR" property="dataFormat" />
<result column="alias" jdbcType="VARCHAR" property="alias" /> <result column="alias" jdbcType="VARCHAR" property="alias" />
<result column="tags" jdbcType="VARCHAR" property="tags" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO">
<result column="type_params" jdbcType="LONGVARCHAR" property="typeParams" /> <result column="type_params" jdbcType="LONGVARCHAR" property="typeParams" />
@@ -52,7 +53,7 @@
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, model_id, name, biz_name, description, status, sensitive_level, type, created_at, id, model_id, name, biz_name, description, status, sensitive_level, type, created_at,
created_by, updated_at, updated_by, data_format_type, data_format, alias created_by, updated_at, updated_by, data_format_type, data_format, alias, tags
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
type_params type_params
@@ -108,13 +109,13 @@
sensitive_level, type, created_at, sensitive_level, type, created_at,
created_by, updated_at, updated_by, created_by, updated_at, updated_by,
data_format_type, data_format, alias, data_format_type, data_format, alias,
type_params) tags, type_params)
values (#{id,jdbcType=BIGINT}, #{modelId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, values (#{id,jdbcType=BIGINT}, #{modelId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{bizName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{bizName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
#{sensitiveLevel,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{sensitiveLevel,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP},
#{createdBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR}, #{createdBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR},
#{dataFormatType,jdbcType=VARCHAR}, #{dataFormat,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR}, #{dataFormatType,jdbcType=VARCHAR}, #{dataFormat,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR},
#{typeParams,jdbcType=LONGVARCHAR}) #{tags,jdbcType=VARCHAR}, #{typeParams,jdbcType=LONGVARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO"> <insert id="insertSelective" parameterType="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO">
insert into s2_metric insert into s2_metric
@@ -164,6 +165,9 @@
<if test="alias != null"> <if test="alias != null">
alias, alias,
</if> </if>
<if test="tags != null">
tags,
</if>
<if test="typeParams != null"> <if test="typeParams != null">
type_params, type_params,
</if> </if>
@@ -214,6 +218,9 @@
<if test="alias != null"> <if test="alias != null">
#{alias,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR},
</if> </if>
<if test="tags != null">
#{tags,jdbcType=VARCHAR},
</if>
<if test="typeParams != null"> <if test="typeParams != null">
#{typeParams,jdbcType=LONGVARCHAR}, #{typeParams,jdbcType=LONGVARCHAR},
</if> </if>
@@ -270,6 +277,9 @@
<if test="alias != null"> <if test="alias != null">
alias = #{alias,jdbcType=VARCHAR}, alias = #{alias,jdbcType=VARCHAR},
</if> </if>
<if test="tags != null">
tags = #{tags,jdbcType=VARCHAR},
</if>
<if test="typeParams != null"> <if test="typeParams != null">
type_params = #{typeParams,jdbcType=LONGVARCHAR}, type_params = #{typeParams,jdbcType=LONGVARCHAR},
</if> </if>
@@ -292,6 +302,7 @@
data_format_type = #{dataFormatType,jdbcType=VARCHAR}, data_format_type = #{dataFormatType,jdbcType=VARCHAR},
data_format = #{dataFormat,jdbcType=VARCHAR}, data_format = #{dataFormat,jdbcType=VARCHAR},
alias = #{alias,jdbcType=VARCHAR}, alias = #{alias,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR},
type_params = #{typeParams,jdbcType=LONGVARCHAR} type_params = #{typeParams,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
@@ -310,7 +321,8 @@
updated_by = #{updatedBy,jdbcType=VARCHAR}, updated_by = #{updatedBy,jdbcType=VARCHAR},
data_format_type = #{dataFormatType,jdbcType=VARCHAR}, data_format_type = #{dataFormatType,jdbcType=VARCHAR},
data_format = #{dataFormat,jdbcType=VARCHAR}, data_format = #{dataFormat,jdbcType=VARCHAR},
alias = #{alias,jdbcType=VARCHAR} alias = #{alias,jdbcType=VARCHAR},
tags = #{tags,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
</mapper> </mapper>

View File

@@ -2,22 +2,26 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tencent.supersonic.semantic.model.infrastructure.mapper.MetricDOCustomMapper"> <mapper namespace="com.tencent.supersonic.semantic.model.infrastructure.mapper.MetricDOCustomMapper">
<resultMap id="BaseResultMap" <resultMap id="BaseResultMap" type="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO">
type="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO"> <id column="id" jdbcType="BIGINT" property="id" />
<id column="id" jdbcType="BIGINT" property="id"/> <result column="model_id" jdbcType="BIGINT" property="modelId" />
<result column="model_id" jdbcType="BIGINT" property="modelId"/> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="name" jdbcType="VARCHAR" property="name"/> <result column="biz_name" jdbcType="VARCHAR" property="bizName" />
<result column="biz_name" jdbcType="VARCHAR" property="bizName"/> <result column="description" jdbcType="VARCHAR" property="description" />
<result column="description" jdbcType="VARCHAR" property="description"/> <result column="status" jdbcType="INTEGER" property="status" />
<result column="type" jdbcType="VARCHAR" property="type"/> <result column="sensitive_level" jdbcType="INTEGER" property="sensitiveLevel" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/> <result column="type" jdbcType="VARCHAR" property="type" />
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/> <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/> <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/> <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
<result column="data_format_type" jdbcType="VARCHAR" property="dataFormatType" />
<result column="data_format" jdbcType="VARCHAR" property="dataFormat" />
<result column="alias" jdbcType="VARCHAR" property="alias" />
<result column="tags" jdbcType="VARCHAR" property="tags" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO">
type="com.tencent.supersonic.semantic.model.domain.dataobject.MetricDO"> <result column="type_params" jdbcType="LONGVARCHAR" property="typeParams" />
<result column="type_params" jdbcType="LONGVARCHAR" property="typeParams"/>
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@@ -51,12 +55,11 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id id, model_id, name, biz_name, description, status, sensitive_level, type, created_at,
, model_id, name, biz_name, description, type, created_at, created_by, updated_at, created_by, updated_at, updated_by, data_format_type, data_format, alias, tags
updated_by
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
typeParams type_params
</sql> </sql>
<insert id="batchInsert" parameterType="java.util.List"> <insert id="batchInsert" parameterType="java.util.List">
@@ -108,7 +111,8 @@
and ( id like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or and ( id like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
biz_name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or biz_name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
description like CONCAT('%',#{key , jdbcType=VARCHAR},'%') ) description like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
tags like CONCAT('%',#{key , jdbcType=VARCHAR},'%') )
</if> </if>
<if test="id != null"> <if test="id != null">
and id like CONCAT('%',#{id , jdbcType=VARCHAR},'%') and id like CONCAT('%',#{id , jdbcType=VARCHAR},'%')

View File

@@ -119,7 +119,7 @@ public class SchemaServiceImpl implements SchemaService {
@Override @Override
public PageInfo<MetricResp> queryMetric(PageMetricReq pageMetricCmd, User user) { public PageInfo<MetricResp> queryMetric(PageMetricReq pageMetricCmd, User user) {
return metricService.queryMetric(pageMetricCmd); return metricService.queryMetric(pageMetricCmd, user);
} }
@Override @Override
@@ -129,7 +129,7 @@ public class SchemaServiceImpl implements SchemaService {
@Override @Override
public List<ModelResp> getModelList(User user, AuthType authTypeEnum, Long domainId) { public List<ModelResp> getModelList(User user, AuthType authTypeEnum, Long domainId) {
return modelService.getModelListWithAuth(user.getName(), domainId, authTypeEnum); return modelService.getModelListWithAuth(user, domainId, authTypeEnum);
} }
} }

View File

@@ -140,7 +140,7 @@ public class DataPermissionAOP {
private boolean doModelAdmin(User user, QueryStructReq queryStructReq) { private boolean doModelAdmin(User user, QueryStructReq queryStructReq) {
Long modelId = queryStructReq.getModelId(); Long modelId = queryStructReq.getModelId();
List<ModelResp> modelListAdmin = modelService.getModelListWithAuth(user.getName(), null, AuthType.ADMIN); List<ModelResp> modelListAdmin = modelService.getModelListWithAuth(user, null, AuthType.ADMIN);
if (CollectionUtils.isEmpty(modelListAdmin)) { if (CollectionUtils.isEmpty(modelListAdmin)) {
return false; return false;
} else { } else {
@@ -153,7 +153,7 @@ public class DataPermissionAOP {
private void doModelVisible(User user, QueryStructReq queryStructReq) { private void doModelVisible(User user, QueryStructReq queryStructReq) {
Boolean visible = true; Boolean visible = true;
Long modelId = queryStructReq.getModelId(); Long modelId = queryStructReq.getModelId();
List<ModelResp> modelListVisible = modelService.getModelListWithAuth(user.getName(), null, AuthType.VISIBLE); List<ModelResp> modelListVisible = modelService.getModelListWithAuth(user, null, AuthType.VISIBLE);
if (CollectionUtils.isEmpty(modelListVisible)) { if (CollectionUtils.isEmpty(modelListVisible)) {
visible = false; visible = false;
} else { } else {