table use changed

This commit is contained in:
Captain.B 2020-02-25 11:48:39 +08:00
parent 2afa1bca4c
commit bfa3ef70cf
6 changed files with 219 additions and 138 deletions

View File

@ -17,10 +17,12 @@ public class User implements Serializable {
private Long updateTime; private Long updateTime;
private String lastSourceId;
private String language; private String language;
private String lastWorkspaceId;
private String lastOrganizationId;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public String getId() { public String getId() {
@ -79,14 +81,6 @@ public class User implements Serializable {
this.updateTime = updateTime; this.updateTime = updateTime;
} }
public String getLastSourceId() {
return lastSourceId;
}
public void setLastSourceId(String lastSourceId) {
this.lastSourceId = lastSourceId == null ? null : lastSourceId.trim();
}
public String getLanguage() { public String getLanguage() {
return language; return language;
} }
@ -94,4 +88,20 @@ public class User implements Serializable {
public void setLanguage(String language) { public void setLanguage(String language) {
this.language = language == null ? null : language.trim(); this.language = language == null ? null : language.trim();
} }
public String getLastWorkspaceId() {
return lastWorkspaceId;
}
public void setLastWorkspaceId(String lastWorkspaceId) {
this.lastWorkspaceId = lastWorkspaceId == null ? null : lastWorkspaceId.trim();
}
public String getLastOrganizationId() {
return lastOrganizationId;
}
public void setLastOrganizationId(String lastOrganizationId) {
this.lastOrganizationId = lastOrganizationId == null ? null : lastOrganizationId.trim();
}
} }

View File

@ -574,76 +574,6 @@ public class UserExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andLastSourceIdIsNull() {
addCriterion("last_source_id is null");
return (Criteria) this;
}
public Criteria andLastSourceIdIsNotNull() {
addCriterion("last_source_id is not null");
return (Criteria) this;
}
public Criteria andLastSourceIdEqualTo(String value) {
addCriterion("last_source_id =", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotEqualTo(String value) {
addCriterion("last_source_id <>", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdGreaterThan(String value) {
addCriterion("last_source_id >", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdGreaterThanOrEqualTo(String value) {
addCriterion("last_source_id >=", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdLessThan(String value) {
addCriterion("last_source_id <", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdLessThanOrEqualTo(String value) {
addCriterion("last_source_id <=", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdLike(String value) {
addCriterion("last_source_id like", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotLike(String value) {
addCriterion("last_source_id not like", value, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdIn(List<String> values) {
addCriterion("last_source_id in", values, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotIn(List<String> values) {
addCriterion("last_source_id not in", values, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdBetween(String value1, String value2) {
addCriterion("last_source_id between", value1, value2, "lastSourceId");
return (Criteria) this;
}
public Criteria andLastSourceIdNotBetween(String value1, String value2) {
addCriterion("last_source_id not between", value1, value2, "lastSourceId");
return (Criteria) this;
}
public Criteria andLanguageIsNull() { public Criteria andLanguageIsNull() {
addCriterion("language is null"); addCriterion("language is null");
return (Criteria) this; return (Criteria) this;
@ -713,6 +643,146 @@ public class UserExample {
addCriterion("language not between", value1, value2, "language"); addCriterion("language not between", value1, value2, "language");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andLastWorkspaceIdIsNull() {
addCriterion("last_workspace_id is null");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdIsNotNull() {
addCriterion("last_workspace_id is not null");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdEqualTo(String value) {
addCriterion("last_workspace_id =", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdNotEqualTo(String value) {
addCriterion("last_workspace_id <>", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdGreaterThan(String value) {
addCriterion("last_workspace_id >", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdGreaterThanOrEqualTo(String value) {
addCriterion("last_workspace_id >=", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdLessThan(String value) {
addCriterion("last_workspace_id <", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdLessThanOrEqualTo(String value) {
addCriterion("last_workspace_id <=", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdLike(String value) {
addCriterion("last_workspace_id like", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdNotLike(String value) {
addCriterion("last_workspace_id not like", value, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdIn(List<String> values) {
addCriterion("last_workspace_id in", values, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdNotIn(List<String> values) {
addCriterion("last_workspace_id not in", values, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdBetween(String value1, String value2) {
addCriterion("last_workspace_id between", value1, value2, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastWorkspaceIdNotBetween(String value1, String value2) {
addCriterion("last_workspace_id not between", value1, value2, "lastWorkspaceId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdIsNull() {
addCriterion("last_organization_id is null");
return (Criteria) this;
}
public Criteria andLastOrganizationIdIsNotNull() {
addCriterion("last_organization_id is not null");
return (Criteria) this;
}
public Criteria andLastOrganizationIdEqualTo(String value) {
addCriterion("last_organization_id =", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdNotEqualTo(String value) {
addCriterion("last_organization_id <>", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdGreaterThan(String value) {
addCriterion("last_organization_id >", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdGreaterThanOrEqualTo(String value) {
addCriterion("last_organization_id >=", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdLessThan(String value) {
addCriterion("last_organization_id <", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdLessThanOrEqualTo(String value) {
addCriterion("last_organization_id <=", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdLike(String value) {
addCriterion("last_organization_id like", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdNotLike(String value) {
addCriterion("last_organization_id not like", value, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdIn(List<String> values) {
addCriterion("last_organization_id in", values, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdNotIn(List<String> values) {
addCriterion("last_organization_id not in", values, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdBetween(String value1, String value2) {
addCriterion("last_organization_id between", value1, value2, "lastOrganizationId");
return (Criteria) this;
}
public Criteria andLastOrganizationIdNotBetween(String value1, String value2) {
addCriterion("last_organization_id not between", value1, value2, "lastOrganizationId");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {

View File

@ -9,8 +9,9 @@
<result column="status" jdbcType="VARCHAR" property="status" /> <result column="status" jdbcType="VARCHAR" property="status" />
<result column="create_time" jdbcType="BIGINT" property="createTime" /> <result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" /> <result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="last_source_id" jdbcType="VARCHAR" property="lastSourceId" />
<result column="language" jdbcType="VARCHAR" property="language" /> <result column="language" jdbcType="VARCHAR" property="language" />
<result column="last_workspace_id" jdbcType="VARCHAR" property="lastWorkspaceId" />
<result column="last_organization_id" jdbcType="VARCHAR" property="lastOrganizationId" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -71,7 +72,8 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, name, email, phone, status, create_time, update_time, last_source_id, language id, name, email, phone, status, create_time, update_time, language, last_workspace_id,
last_organization_id
</sql> </sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.UserExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.base.domain.UserExample" resultMap="BaseResultMap">
select select
@ -106,12 +108,12 @@
<insert id="insert" parameterType="io.metersphere.base.domain.User"> <insert id="insert" parameterType="io.metersphere.base.domain.User">
insert into user (id, name, email, insert into user (id, name, email,
phone, status, create_time, phone, status, create_time,
update_time, last_source_id, language update_time, language, last_workspace_id,
) last_organization_id)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{phone,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{lastSourceId,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR} #{updateTime,jdbcType=BIGINT}, #{language,jdbcType=VARCHAR}, #{lastWorkspaceId,jdbcType=VARCHAR},
) #{lastOrganizationId,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.User"> <insert id="insertSelective" parameterType="io.metersphere.base.domain.User">
insert into user insert into user
@ -137,12 +139,15 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time, update_time,
</if> </if>
<if test="lastSourceId != null">
last_source_id,
</if>
<if test="language != null"> <if test="language != null">
language, language,
</if> </if>
<if test="lastWorkspaceId != null">
last_workspace_id,
</if>
<if test="lastOrganizationId != null">
last_organization_id,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -166,12 +171,15 @@
<if test="updateTime != null"> <if test="updateTime != null">
#{updateTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
</if> </if>
<if test="lastSourceId != null">
#{lastSourceId,jdbcType=VARCHAR},
</if>
<if test="language != null"> <if test="language != null">
#{language,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR},
</if> </if>
<if test="lastWorkspaceId != null">
#{lastWorkspaceId,jdbcType=VARCHAR},
</if>
<if test="lastOrganizationId != null">
#{lastOrganizationId,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.UserExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="io.metersphere.base.domain.UserExample" resultType="java.lang.Long">
@ -204,12 +212,15 @@
<if test="record.updateTime != null"> <if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
</if> </if>
<if test="record.lastSourceId != null">
last_source_id = #{record.lastSourceId,jdbcType=VARCHAR},
</if>
<if test="record.language != null"> <if test="record.language != null">
language = #{record.language,jdbcType=VARCHAR}, language = #{record.language,jdbcType=VARCHAR},
</if> </if>
<if test="record.lastWorkspaceId != null">
last_workspace_id = #{record.lastWorkspaceId,jdbcType=VARCHAR},
</if>
<if test="record.lastOrganizationId != null">
last_organization_id = #{record.lastOrganizationId,jdbcType=VARCHAR},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
@ -224,8 +235,9 @@
status = #{record.status,jdbcType=VARCHAR}, status = #{record.status,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
last_source_id = #{record.lastSourceId,jdbcType=VARCHAR}, language = #{record.language,jdbcType=VARCHAR},
language = #{record.language,jdbcType=VARCHAR} last_workspace_id = #{record.lastWorkspaceId,jdbcType=VARCHAR},
last_organization_id = #{record.lastOrganizationId,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -251,12 +263,15 @@
<if test="updateTime != null"> <if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
</if> </if>
<if test="lastSourceId != null">
last_source_id = #{lastSourceId,jdbcType=VARCHAR},
</if>
<if test="language != null"> <if test="language != null">
language = #{language,jdbcType=VARCHAR}, language = #{language,jdbcType=VARCHAR},
</if> </if>
<if test="lastWorkspaceId != null">
last_workspace_id = #{lastWorkspaceId,jdbcType=VARCHAR},
</if>
<if test="lastOrganizationId != null">
last_organization_id = #{lastOrganizationId,jdbcType=VARCHAR},
</if>
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
@ -268,8 +283,9 @@
status = #{status,jdbcType=VARCHAR}, status = #{status,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
last_source_id = #{lastSourceId,jdbcType=VARCHAR}, language = #{language,jdbcType=VARCHAR},
language = #{language,jdbcType=VARCHAR} last_workspace_id = #{lastWorkspaceId,jdbcType=VARCHAR},
last_organization_id = #{lastOrganizationId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
</mapper> </mapper>

View File

@ -21,20 +21,14 @@ public class UserDTO {
private Long updateTime; private Long updateTime;
private String lastSourceId; private String workspaceId;
private String organizationId;
private List<Role> roles = new ArrayList<>(); private List<Role> roles = new ArrayList<>();
private List<UserRole> userRoles = new ArrayList<>(); private List<UserRole> userRoles = new ArrayList<>();
public String getLastSourceId() {
return lastSourceId;
}
public void setLastSourceId(String lastSourceId) {
this.lastSourceId = lastSourceId;
}
public List<Role> getRoles() { public List<Role> getRoles() {
return roles; return roles;
} }
@ -108,4 +102,20 @@ public class UserDTO {
public void setUserRoles(List<UserRole> userRoles) { public void setUserRoles(List<UserRole> userRoles) {
this.userRoles = userRoles; this.userRoles = userRoles;
} }
public String getWorkspaceId() {
return workspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
}
public String getOrganizationId() {
return organizationId;
}
public void setOrganizationId(String organizationId) {
this.organizationId = organizationId;
}
} }

View File

@ -223,7 +223,8 @@ public class UserService {
public void switchUserRole(UserDTO user, String sourceId) { public void switchUserRole(UserDTO user, String sourceId) {
User newUser = new User(); User newUser = new User();
user.setLastSourceId(sourceId); // todo 切换处理
// user.setLastSourceId(sourceId);
BeanUtils.copyProperties(user, newUser); BeanUtils.copyProperties(user, newUser);
// 切换工作空间或组织之后更新 session 里的 user // 切换工作空间或组织之后更新 session 里的 user
SessionUtils.putUser(SessionUser.fromUser(user)); SessionUtils.putUser(SessionUser.fromUser(user));

View File

@ -1,43 +1,17 @@
package io.metersphere.user; package io.metersphere.user;
import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import java.io.Serializable; import java.io.Serializable;
import static io.metersphere.commons.constants.RoleConstants.*;
public class SessionUser extends UserDTO implements Serializable { public class SessionUser extends UserDTO implements Serializable {
private static final long serialVersionUID = -7149638440406959033L; private static final long serialVersionUID = -7149638440406959033L;
private String workspaceId;
private String organizationId;
public String getWorkspaceId() {
return workspaceId;
}
public String getOrganizationId() {
return organizationId;
}
public static SessionUser fromUser(UserDTO user) { public static SessionUser fromUser(UserDTO user) {
SessionUser sessionUser = new SessionUser(); SessionUser sessionUser = new SessionUser();
BeanUtils.copyProperties(user, sessionUser); BeanUtils.copyProperties(user, sessionUser);
String lastSourceId = sessionUser.getLastSourceId();
user.getUserRoles().forEach(ur -> {
if (StringUtils.equals(ur.getSourceId(), lastSourceId)) {
if (StringUtils.equals(ur.getRoleId(), ORG_ADMIN)) {
sessionUser.organizationId = lastSourceId;
return;
}
if (StringUtils.equalsAny(ur.getRoleId(), TEST_MANAGER, TEST_USER, TEST_VIEWER)) {
sessionUser.workspaceId = lastSourceId;
}
}
});
return sessionUser; return sessionUser;
} }