init
This commit is contained in:
@@ -35,7 +35,8 @@ public class I18nConfig implements LocaleResolver {
|
|||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public Locale resolveLocale(HttpServletRequest request) {
|
public Locale resolveLocale(HttpServletRequest request) {
|
||||||
// 默认语言设置为中文
|
return Locale.CHINA;
|
||||||
|
/*// 默认语言设置为中文
|
||||||
String defaultLocal = homeSettingService.getHomeSetting().getDefaultLocal();
|
String defaultLocal = homeSettingService.getHomeSetting().getDefaultLocal();
|
||||||
Locale locale = null;
|
Locale locale = null;
|
||||||
// 从请求的头部获取Accept-Language标头,该标头指定了客户端期望的语言
|
// 从请求的头部获取Accept-Language标头,该标头指定了客户端期望的语言
|
||||||
@@ -61,7 +62,7 @@ public class I18nConfig implements LocaleResolver {
|
|||||||
locale = Locale.CHINA;
|
locale = Locale.CHINA;
|
||||||
}
|
}
|
||||||
// 返回解析得到的Locale对象作为解析后的语言设置
|
// 返回解析得到的Locale对象作为解析后的语言设置
|
||||||
return locale;
|
return locale;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public class ExecutorConstant {
|
|||||||
COMMON_EXECUTOR = TtlExecutors.getTtlExecutor(commonExecutor);
|
COMMON_EXECUTOR = TtlExecutors.getTtlExecutor(commonExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static ThreadFactory init(String nameFormat){
|
private static ThreadFactory init(String nameFormat){
|
||||||
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,24 @@ public class OssClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UploadResult uploadFile(byte[] data, String tenantPrefix, String suffix, String contentType) {
|
||||||
|
return upload(data, getPath(properties.getPrefix(),tenantPrefix, suffix), contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPath(String prefix,String tenantPrefix, String suffix) {
|
||||||
|
// 生成uuid
|
||||||
|
String uuid = IdUtil.fastSimpleUUID();
|
||||||
|
// 文件路径
|
||||||
|
String path = DateUtils.datePath() + "/" + uuid;
|
||||||
|
if(StringUtils.isNotBlank(tenantPrefix)){
|
||||||
|
path = tenantPrefix + "/" + path;
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(prefix)) {
|
||||||
|
path = prefix + "/" + path;
|
||||||
|
}
|
||||||
|
return path + suffix;
|
||||||
|
}
|
||||||
|
|
||||||
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) {
|
||||||
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
return upload(data, getPath(properties.getPrefix(), suffix), contentType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,11 +110,12 @@ public class TenantHelper {
|
|||||||
* @param handle 处理执行方法
|
* @param handle 处理执行方法
|
||||||
*/
|
*/
|
||||||
public static void dynamic(String tenantId, Runnable handle) {
|
public static void dynamic(String tenantId, Runnable handle) {
|
||||||
|
String oldTenant = getTenantId();
|
||||||
setTenantId(tenantId);
|
setTenantId(tenantId);
|
||||||
try {
|
try {
|
||||||
handle.run();
|
handle.run();
|
||||||
} finally {
|
} finally {
|
||||||
clearTenant();
|
setTenantId(oldTenant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,11 +125,12 @@ public class TenantHelper {
|
|||||||
* @param handle 处理执行方法
|
* @param handle 处理执行方法
|
||||||
*/
|
*/
|
||||||
public static <T> T dynamic(String tenantId, Supplier<T> handle) {
|
public static <T> T dynamic(String tenantId, Supplier<T> handle) {
|
||||||
|
String oldTenant = getTenantId();
|
||||||
setTenantId(tenantId);
|
setTenantId(tenantId);
|
||||||
try {
|
try {
|
||||||
return handle.get();
|
return handle.get();
|
||||||
} finally {
|
} finally {
|
||||||
clearTenant();
|
setTenantId(oldTenant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class SysOssController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("system:oss:upload")
|
// @SaCheckPermission("system:oss:upload")
|
||||||
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
@Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
|
||||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
|
public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.ruoyi.system.domain;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.ruoyi.component.mybatis.core.domain.BaseEntity;
|
import com.ruoyi.component.mybatis.core.domain.BaseEntity;
|
||||||
|
import com.ruoyi.component.tenant.core.TenantEntity;
|
||||||
|
import com.ruoyi.component.tenant.helper.TenantHelper;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@@ -14,7 +16,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName("sys_oss")
|
@TableName("sys_oss")
|
||||||
public class SysOss extends BaseEntity {
|
public class SysOss extends TenantEntity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象存储主键
|
* 对象存储主键
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.dev33.satoken.secure.BCrypt;
|
|||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.ruoyi.component.core.constant.CacheConstants;
|
import com.ruoyi.component.core.constant.CacheConstants;
|
||||||
import com.ruoyi.component.core.constant.Constants;
|
import com.ruoyi.component.core.constant.Constants;
|
||||||
@@ -79,12 +80,12 @@ public class SysLoginService {
|
|||||||
}
|
}
|
||||||
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
// 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可
|
||||||
SysUser user = TenantHelper.ignore(() -> loadUserByUsername(username));
|
SysUser user = TenantHelper.ignore(() -> loadUserByUsername(username));
|
||||||
|
TenantHelper.setTenantId(user.getTenantId());
|
||||||
checkLogin(LoginType.PASSWORD, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
checkLogin(LoginType.PASSWORD, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
||||||
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
// 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
||||||
LoginUser loginUser = buildLoginUser(user);
|
LoginUser loginUser = buildLoginUser(user);
|
||||||
// 生成token
|
// 生成token
|
||||||
LoginHelper.loginByDevice(loginUser, DeviceType.PC);
|
LoginHelper.loginByDevice(loginUser, DeviceType.PC);
|
||||||
TenantHelper.setTenantId(loginUser.getTenantId());
|
|
||||||
recordLogininfor(username,loginUser.getUserType(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
recordLogininfor(username,loginUser.getUserType(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||||
recordLoginInfo(user.getUserId(), username);
|
recordLoginInfo(user.getUserId(), username);
|
||||||
return StpUtil.getTokenValue();
|
return StpUtil.getTokenValue();
|
||||||
|
|||||||
@@ -19,11 +19,15 @@ import com.ruoyi.component.oss.core.OssClient;
|
|||||||
import com.ruoyi.component.oss.entity.UploadResult;
|
import com.ruoyi.component.oss.entity.UploadResult;
|
||||||
import com.ruoyi.component.oss.enumd.AccessPolicyType;
|
import com.ruoyi.component.oss.enumd.AccessPolicyType;
|
||||||
import com.ruoyi.component.oss.factory.OssFactory;
|
import com.ruoyi.component.oss.factory.OssFactory;
|
||||||
|
import com.ruoyi.component.satoken.utils.LoginHelper;
|
||||||
|
import com.ruoyi.component.tenant.helper.TenantHelper;
|
||||||
import com.ruoyi.system.domain.SysOss;
|
import com.ruoyi.system.domain.SysOss;
|
||||||
import com.ruoyi.system.domain.bo.SysOssBo;
|
import com.ruoyi.system.domain.bo.SysOssBo;
|
||||||
import com.ruoyi.system.domain.vo.SysOssVo;
|
import com.ruoyi.system.domain.vo.SysOssVo;
|
||||||
|
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||||
import com.ruoyi.system.mapper.SysOssMapper;
|
import com.ruoyi.system.mapper.SysOssMapper;
|
||||||
import com.ruoyi.system.service.ISysOssService;
|
import com.ruoyi.system.service.ISysOssService;
|
||||||
|
import com.ruoyi.system.service.ISysTenantService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@@ -50,6 +54,7 @@ import java.util.stream.Collectors;
|
|||||||
public class SysOssServiceImpl implements ISysOssService, OssService {
|
public class SysOssServiceImpl implements ISysOssService, OssService {
|
||||||
|
|
||||||
private final SysOssMapper baseMapper;
|
private final SysOssMapper baseMapper;
|
||||||
|
private final ISysTenantService tenantService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) {
|
public TableDataInfo<SysOssVo> queryPageList(SysOssBo bo, PageQuery pageQuery) {
|
||||||
@@ -133,12 +138,16 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysOssVo upload(MultipartFile file) {
|
public SysOssVo upload(MultipartFile file) {
|
||||||
|
SysTenantVo tenant = tenantService.queryByTenantId(TenantHelper.getTenantId());
|
||||||
|
if(tenant == null){
|
||||||
|
throw new ServiceException("平台错误");
|
||||||
|
}
|
||||||
String originalfileName = file.getOriginalFilename();
|
String originalfileName = file.getOriginalFilename();
|
||||||
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
|
||||||
OssClient storage = OssFactory.instance();
|
OssClient storage = OssFactory.instance();
|
||||||
UploadResult uploadResult;
|
UploadResult uploadResult;
|
||||||
try {
|
try {
|
||||||
uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
|
uploadResult = storage.uploadFile(file.getBytes(), tenant.getPrefix(), suffix, file.getContentType());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ServiceException(e.getMessage());
|
throw new ServiceException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
|||||||
roleDept.setRoleId(roleId);
|
roleDept.setRoleId(roleId);
|
||||||
roleDept.setDeptId(deptId);
|
roleDept.setDeptId(deptId);
|
||||||
roleDeptMapper.insert(roleDept);
|
roleDeptMapper.insert(roleDept);
|
||||||
String adminUsername = bo.getPrefix()+"_admin";
|
String adminUsername = bo.getPrefix()+"-admin";
|
||||||
// 检测用户是否存在
|
// 检测用户是否存在
|
||||||
SysUser sysUser = userMapper.selectUserByUserName(adminUsername);
|
SysUser sysUser = userMapper.selectUserByUserName(adminUsername);
|
||||||
if(sysUser != null){
|
if(sysUser != null){
|
||||||
|
|||||||
Reference in New Issue
Block a user