Compare commits
No commits in common. "ac47b3112260cf392e40f8561b017ed53446888f" and "a5680029ffe4f8faa29139e249c80bea60895a0a" have entirely different histories.
ac47b31122
...
a5680029ff
|
@ -20,7 +20,7 @@ public class NewCodeGet {
|
|||
public static final String entity = "Bunny";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Generation("sys_i18n", "sys_i18n_type");
|
||||
Generation("sys_router");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,35 +1,23 @@
|
|||
package cn.bunny.dao.entity.i18n;
|
||||
|
||||
import cn.bunny.dao.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 多语言表
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("sys_i18n")
|
||||
@ApiModel(value = "I18n对象", description = "多语言表")
|
||||
@Schema(name = "I18n对象", title = "多语言表", description = "多语言表")
|
||||
public class I18n extends BaseEntity {
|
||||
|
||||
@ApiModelProperty("多语言key")
|
||||
private Integer keyName;
|
||||
|
||||
@ApiModelProperty("多语言翻译名称")
|
||||
private String translation;
|
||||
|
||||
@ApiModelProperty("多语言类型id")
|
||||
@Schema(name = "typeId", title = "语言类型id")
|
||||
private Long typeId;
|
||||
|
||||
}
|
||||
@Schema(name = "keyName", title = "多语言key")
|
||||
private String keyName;
|
||||
|
||||
@Schema(name = "summary", title = "翻译")
|
||||
private String summary;
|
||||
}
|
|
@ -2,31 +2,24 @@ package cn.bunny.dao.entity.i18n;
|
|||
|
||||
import cn.bunny.dao.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 多语言类型表
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("sys_i18n_type")
|
||||
@ApiModel(value = "I18nType对象", description = "多语言类型表")
|
||||
@TableName("i18n_type")
|
||||
@Schema(name = "I18nType", title = "多语言类型表", description = "多语言类型表")
|
||||
public class I18nType extends BaseEntity {
|
||||
|
||||
@ApiModelProperty("多语言类型(比如zh,en)")
|
||||
private String typeName;
|
||||
@Schema(name = "languageName", title = "语言名称")
|
||||
private String languageName;
|
||||
|
||||
@ApiModelProperty("名称解释(比如中文,英文)")
|
||||
@Schema(name = "summary", title = "语言名")
|
||||
private String summary;
|
||||
|
||||
}
|
||||
@Schema(name = "isDefault", title = "是否作为默认语言")
|
||||
private Byte isDefault;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package cn.bunny.services.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -9,8 +10,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
@Tag(name = "多语言", description = "多语言相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/i18n")
|
||||
public class I18nController {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.bunny.services.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -9,8 +10,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
@Tag(name = "多语言类型", description = "多语言类型相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/i18nType")
|
||||
public class I18nTypeController {
|
||||
|
|
|
@ -2,13 +2,11 @@ package cn.bunny.services.factory;
|
|||
|
||||
import cn.bunny.common.service.utils.JwtHelper;
|
||||
import cn.bunny.common.service.utils.ip.IpUtil;
|
||||
import cn.bunny.common.service.utils.minio.MinioUtil;
|
||||
import cn.bunny.dao.entity.system.AdminUser;
|
||||
import cn.bunny.dao.entity.system.Power;
|
||||
import cn.bunny.dao.entity.system.Role;
|
||||
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
|
||||
import cn.bunny.dao.pojo.constant.RedisUserConstant;
|
||||
import cn.bunny.dao.pojo.constant.UserConstant;
|
||||
import cn.bunny.dao.vo.user.LoginVo;
|
||||
import cn.bunny.services.mapper.PowerMapper;
|
||||
import cn.bunny.services.mapper.RoleMapper;
|
||||
|
@ -17,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
@ -36,18 +33,12 @@ public class UserFactory {
|
|||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@Autowired
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
public LoginVo buildUserVo(AdminUser user, long readMeDay) {
|
||||
// 创建token
|
||||
Long userId = user.getId();
|
||||
String email = user.getEmail();
|
||||
String token = JwtHelper.createToken(userId, email, (int) readMeDay);
|
||||
String avatar = user.getAvatar();
|
||||
|
||||
// 判断用户是否有头像,如果没有头像设置默认头像
|
||||
avatar = StringUtils.hasText(avatar) ? UserConstant.USER_AVATAR : minioUtil.getObjectNameFullPath(avatar);
|
||||
|
||||
// 设置用户IP地址,并更新用户信息
|
||||
AdminUser updateUser = new AdminUser();
|
||||
|
@ -65,19 +56,20 @@ public class UserFactory {
|
|||
List<String> roles = roleMapper.selectListByUserId(userId).stream().map(Role::getRoleCode).toList();
|
||||
List<String> permissions = new ArrayList<>();
|
||||
|
||||
// 判断是否是 admin 如果是admin 赋予所有权限
|
||||
boolean isAdmin = roles.stream().anyMatch(role -> role.equals("admin"));
|
||||
|
||||
if (isAdmin) {
|
||||
permissions.add("*");
|
||||
permissions.add("*::*");
|
||||
permissions.add("*::*::*");
|
||||
} else permissions = powerMapper.selectListByUserId(userId).stream().map(Power::getPowerCode).toList();
|
||||
} else {
|
||||
permissions = powerMapper.selectListByUserId(userId).stream().map(Power::getPowerCode).toList();
|
||||
}
|
||||
|
||||
// 构建返回对象,设置用户需要内容
|
||||
// 构建返回对象
|
||||
LoginVo loginVo = new LoginVo();
|
||||
BeanUtils.copyProperties(user, loginVo);
|
||||
loginVo.setNickname(user.getNickName());
|
||||
loginVo.setAvatar(avatar);
|
||||
loginVo.setToken(token);
|
||||
loginVo.setRefreshToken(token);
|
||||
loginVo.setLastLoginIp(IpUtil.getCurrentUserIpAddress().getRemoteAddr());
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
@Mapper
|
||||
public interface I18nMapper extends BaseMapper<I18n> {
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
@Mapper
|
||||
public interface I18nTypeMapper extends BaseMapper<I18nType> {
|
||||
|
|
|
@ -36,7 +36,8 @@ public class NoTokenAuthenticationFilter extends OncePerRequestFilter {
|
|||
}
|
||||
|
||||
// 判断 token 是否过期
|
||||
if (JwtHelper.isExpired(token)) {
|
||||
boolean expired = JwtHelper.isExpired(token);
|
||||
if (expired) {
|
||||
ResponseUtil.out(response, Result.error(ResultCodeEnum.AUTHENTICATION_EXPIRED));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -9,13 +9,15 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 请求未认证接口
|
||||
*/
|
||||
@Slf4j
|
||||
public class SecurityAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||
@Override
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) {
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
|
||||
String token = response.getHeader("token");
|
||||
String message = authException.getMessage();
|
||||
// 创建结果对象
|
||||
|
|
|
@ -2,6 +2,7 @@ package cn.bunny.services.security.handelr;
|
|||
|
||||
import cn.bunny.dao.pojo.result.Result;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
@ -10,7 +11,7 @@ import java.io.IOException;
|
|||
|
||||
public class SecurityAuthenticationFailureHandler implements org.springframework.security.web.authentication.AuthenticationFailureHandler {
|
||||
@Override
|
||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
|
||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
|
||||
// 错误消息
|
||||
String localizedMessage = exception.getLocalizedMessage();
|
||||
Result<String> result = Result.error(localizedMessage);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.bunny.services.security.service.iml;
|
||||
|
||||
import cn.bunny.common.service.context.BaseContext;
|
||||
import cn.bunny.common.service.utils.JwtHelper;
|
||||
import cn.bunny.dao.entity.system.Power;
|
||||
import cn.bunny.services.mapper.PowerMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -35,6 +36,10 @@ public class CustomAuthorizationManagerServiceImpl implements AuthorizationManag
|
|||
public AuthorizationDecision check(Supplier<Authentication> authentication, RequestAuthorizationContext context) {
|
||||
// 用户的token和用户id、请求Url
|
||||
HttpServletRequest request = context.getRequest();
|
||||
String token = request.getHeader("token");
|
||||
|
||||
// 用户id
|
||||
Long userId = JwtHelper.getUserId(token);
|
||||
|
||||
// 请求地址
|
||||
String requestURI = request.getRequestURI();
|
||||
|
@ -69,6 +74,6 @@ public class CustomAuthorizationManagerServiceImpl implements AuthorizationManag
|
|||
List<Power> powerList = powerMapper.selectListByPowerCodes(powerCodes);
|
||||
|
||||
// 判断是否与请求路径匹配
|
||||
return powerList.stream().anyMatch(power -> requestURI.matches(power.getRequestUrl()));
|
||||
return powerList.stream().anyMatch(power -> power.getRequestUrl().equals(requestURI));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.springframework.util.DigestUtils;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CustomUserDetailsServiceImpl implements cn.bunny.services.security.service.CustomUserDetailsService {
|
||||
public class CustomUserDetailsService implements cn.bunny.services.security.service.CustomUserDetailsService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
@ -60,9 +60,7 @@ public class CustomUserDetailsServiceImpl implements cn.bunny.services.security.
|
|||
Long readMeDay = loginDto.getReadMeDay();
|
||||
|
||||
// 查询用户相关内容
|
||||
LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<AdminUser>()
|
||||
.eq(AdminUser::getEmail, username)
|
||||
.or()
|
||||
LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<AdminUser>().eq(AdminUser::getEmail, username).or()
|
||||
.eq(AdminUser::getUsername, username);
|
||||
AdminUser user = userMapper.selectOne(queryWrapper);
|
||||
|
|
@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
public interface I18nService extends IService<I18n> {
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
public interface I18nTypeService extends IService<I18nType> {
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
@Service
|
||||
public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I18nService {
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
|||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-09-28
|
||||
* @since 2024-09-26
|
||||
*/
|
||||
@Service
|
||||
public class I18nTypeServiceImpl extends ServiceImpl<I18nTypeMapper, I18nType> implements I18nTypeService {
|
||||
|
|
|
@ -11,9 +11,9 @@ import cn.bunny.dao.vo.router.RouterManageVo;
|
|||
import cn.bunny.dao.vo.router.RouterMeta;
|
||||
import cn.bunny.dao.vo.router.UserRouterVo;
|
||||
import cn.bunny.dao.vo.user.LoginVo;
|
||||
import cn.bunny.services.factory.RouterServiceFactory;
|
||||
import cn.bunny.services.mapper.RouterMapper;
|
||||
import cn.bunny.services.service.RouterService;
|
||||
import cn.bunny.services.service.process.RouterServiceProcess;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
@ -39,7 +39,7 @@ import java.util.List;
|
|||
@Transactional
|
||||
public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> implements RouterService {
|
||||
@Autowired
|
||||
private RouterServiceFactory routerServiceFactory;
|
||||
private RouterServiceProcess routerServiceProcess;
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> impleme
|
|||
// 构建树形结构
|
||||
routerVoList.forEach(routerVo -> {
|
||||
if (routerVo.getParentId() == 0) {
|
||||
routerVo.setChildren(routerServiceFactory.handleGetChildrenWIthRouter(routerVo.getId(), routerVoList));
|
||||
routerVo.setChildren(routerServiceProcess.handleGetChildrenWIthRouter(routerVo.getId(), routerVoList));
|
||||
list.add(routerVo);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cn.bunny.services.factory;
|
||||
package cn.bunny.services.service.process;
|
||||
|
||||
import cn.bunny.dao.vo.common.TreeSelectVo;
|
||||
import cn.bunny.dao.vo.router.RouterManageVo;
|
||||
|
@ -10,7 +10,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class RouterServiceFactory {
|
||||
public class RouterServiceProcess {
|
||||
|
||||
/**
|
||||
* * 递归调用设置子路由
|
|
@ -5,19 +5,19 @@
|
|||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.i18n.I18n">
|
||||
<id column="id" property="id"/>
|
||||
<result column="key_name" property="keyName"/>
|
||||
<result column="translation" property="translation"/>
|
||||
<result column="type_id" property="typeId"/>
|
||||
<result column="key_name" property="keyName"/>
|
||||
<result column="summary" property="summary"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, key_name, translation, type_id, create_user, update_user, update_time, create_time, is_deleted
|
||||
id, type_id, key_name, summary, create_user, create_time, update_time, update_user, is_deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -5,18 +5,19 @@
|
|||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.i18n.I18nType">
|
||||
<id column="id" property="id"/>
|
||||
<result column="type_name" property="typeName"/>
|
||||
<result column="language_name" property="languageName"/>
|
||||
<result column="summary" property="summary"/>
|
||||
<result column="is_default" property="isDefault"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, type_name, summary, create_user, update_user, update_time, create_time, is_deleted
|
||||
id, language_name, summary, is_default, create_user, create_time, update_time, update_user, is_deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue