feat:前端增加国际化切换

This commit is contained in:
fit2cloud-chenyw
2021-05-18 15:46:14 +08:00
parent 6d54dcece4
commit 31e5cca439
14 changed files with 150 additions and 29 deletions

View File

@@ -23,4 +23,6 @@ public class SysUserEntity implements Serializable {
private String email;
private String phone;
private String language;
}

View File

@@ -35,5 +35,7 @@ public class SysUser implements Serializable {
private Long updateTime;
private String language;
private static final long serialVersionUID = 1L;
}

View File

@@ -1083,6 +1083,76 @@ public class SysUserExample {
addCriterion("update_time not between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andLanguageIsNull() {
addCriterion("`language` is null");
return (Criteria) this;
}
public Criteria andLanguageIsNotNull() {
addCriterion("`language` is not null");
return (Criteria) this;
}
public Criteria andLanguageEqualTo(String value) {
addCriterion("`language` =", value, "language");
return (Criteria) this;
}
public Criteria andLanguageNotEqualTo(String value) {
addCriterion("`language` <>", value, "language");
return (Criteria) this;
}
public Criteria andLanguageGreaterThan(String value) {
addCriterion("`language` >", value, "language");
return (Criteria) this;
}
public Criteria andLanguageGreaterThanOrEqualTo(String value) {
addCriterion("`language` >=", value, "language");
return (Criteria) this;
}
public Criteria andLanguageLessThan(String value) {
addCriterion("`language` <", value, "language");
return (Criteria) this;
}
public Criteria andLanguageLessThanOrEqualTo(String value) {
addCriterion("`language` <=", value, "language");
return (Criteria) this;
}
public Criteria andLanguageLike(String value) {
addCriterion("`language` like", value, "language");
return (Criteria) this;
}
public Criteria andLanguageNotLike(String value) {
addCriterion("`language` not like", value, "language");
return (Criteria) this;
}
public Criteria andLanguageIn(List<String> values) {
addCriterion("`language` in", values, "language");
return (Criteria) this;
}
public Criteria andLanguageNotIn(List<String> values) {
addCriterion("`language` not in", values, "language");
return (Criteria) this;
}
public Criteria andLanguageBetween(String value1, String value2) {
addCriterion("`language` between", value1, value2, "language");
return (Criteria) this;
}
public Criteria andLanguageNotBetween(String value1, String value2) {
addCriterion("`language` not between", value1, value2, "language");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@@ -17,6 +17,7 @@
<result column="pwd_reset_time" jdbcType="BIGINT" property="pwdResetTime" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="language" jdbcType="VARCHAR" property="language" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@@ -78,7 +79,7 @@
</sql>
<sql id="Base_Column_List">
user_id, dept_id, username, nick_name, gender, phone, email, `password`, is_admin,
enabled, create_by, update_by, pwd_reset_time, create_time, update_time
enabled, create_by, update_by, pwd_reset_time, create_time, update_time, `language`
</sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.SysUserExample" resultMap="BaseResultMap">
select
@@ -115,14 +116,14 @@
nick_name, gender, phone,
email, `password`, is_admin,
enabled, create_by, update_by,
pwd_reset_time, create_time, update_time
)
pwd_reset_time, create_time, update_time,
`language`)
values (#{userId,jdbcType=BIGINT}, #{deptId,jdbcType=BIGINT}, #{username,jdbcType=VARCHAR},
#{nickName,jdbcType=VARCHAR}, #{gender,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{isAdmin,jdbcType=BIT},
#{enabled,jdbcType=BIGINT}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR},
#{pwdResetTime,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}
)
#{pwdResetTime,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{language,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.SysUser">
insert into sys_user
@@ -172,6 +173,9 @@
<if test="updateTime != null">
update_time,
</if>
<if test="language != null">
`language`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">
@@ -219,6 +223,9 @@
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="language != null">
#{language,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.dataease.base.domain.SysUserExample" resultType="java.lang.Long">
@@ -275,6 +282,9 @@
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.language != null">
`language` = #{record.language,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@@ -296,7 +306,8 @@
update_by = #{record.updateBy,jdbcType=VARCHAR},
pwd_reset_time = #{record.pwdResetTime,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}
update_time = #{record.updateTime,jdbcType=BIGINT},
`language` = #{record.language,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@@ -346,6 +357,9 @@
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="language != null">
`language` = #{language,jdbcType=VARCHAR},
</if>
</set>
where user_id = #{userId,jdbcType=BIGINT}
</update>
@@ -364,7 +378,8 @@
update_by = #{updateBy,jdbcType=VARCHAR},
pwd_reset_time = #{pwdResetTime,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}
update_time = #{updateTime,jdbcType=BIGINT},
`language` = #{language,jdbcType=VARCHAR}
where user_id = #{userId,jdbcType=BIGINT}
</update>
</mapper>

View File

@@ -6,7 +6,6 @@ import io.dataease.auth.api.dto.CurrentRoleDto;
import io.dataease.auth.entity.SysUserEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface AuthMapper {

View File

@@ -20,11 +20,11 @@
<select id="findUser" resultMap="baseMap">
select user_id, username,nick_name, dept_id, password, enabled,email, phone from sys_user where user_id = #{userId}
select user_id, username,nick_name, dept_id, password, enabled,email, phone, language from sys_user where user_id = #{userId}
</select>
<select id="findUserByName" resultMap="baseMap">
select user_id, username,nick_name, dept_id, password, enabled,email, phone from sys_user where username = #{username}
select user_id, username,nick_name, dept_id, password, enabled,email, phone, language from sys_user where username = #{username}
</select>
<select id="roleCodes" resultType="String">

View File

@@ -19,6 +19,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;
@RestController
@Api(tags = "系统:用户管理")
@@ -89,4 +90,15 @@ public class SysUserController {
public void updatePersonInfo(@RequestBody SysUserCreateRequest request){
sysUserService.updatePersonInfo(request);
}
@ApiOperation("设置语言")
@PostMapping("/setLanguage/{language}")
public void setLanguage(@PathVariable String language) {
CurrentUserDto user = AuthUtils.getUser();
Optional.ofNullable(language).ifPresent(currentLanguage -> {
if (!currentLanguage.equals(user.getLanguage())) {
sysUserService.setLanguage(user.getUserId(), currentLanguage);
}
});
}
}

View File

@@ -201,4 +201,12 @@ public class SysUserService {
return userIds.stream().map(sysUserMapper::selectByPrimaryKey).collect(Collectors.toList());
}
@CacheEvict(value = AuthConstants.USER_CACHE_NAME, key = "'user' + #userId")
public void setLanguage(Long userId,String language) {
SysUser sysUser = new SysUser();
sysUser.setUserId(userId);
sysUser.setLanguage(language);
sysUserMapper.updateByPrimaryKeySelective(sysUser);
}
}