改造核心框架
This commit is contained in:
@@ -5,12 +5,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.gxwebsoft.common.core.Constants;
|
import com.gxwebsoft.common.core.Constants;
|
||||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||||
|
import com.gxwebsoft.common.system.entity.Company;
|
||||||
import com.gxwebsoft.common.system.entity.User;
|
import com.gxwebsoft.common.system.entity.User;
|
||||||
|
import com.gxwebsoft.common.system.mapper.CompanyMapper;
|
||||||
|
import com.gxwebsoft.common.system.service.CompanyService;
|
||||||
import com.gxwebsoft.common.system.service.UserService;
|
import com.gxwebsoft.common.system.service.UserService;
|
||||||
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.InitBinder;
|
import org.springframework.web.bind.annotation.InitBinder;
|
||||||
|
|
||||||
@@ -31,6 +35,8 @@ public class BaseController {
|
|||||||
private StringRedisTemplate stringRedisTemplate;
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
@Resource
|
@Resource
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
@Resource
|
||||||
|
private CompanyService companyService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前登录的user
|
* 获取当前登录的user
|
||||||
@@ -74,12 +80,31 @@ public class BaseController {
|
|||||||
return loginUser.getTenantId();
|
return loginUser.getTenantId();
|
||||||
}
|
}
|
||||||
// 从请求头拿tenantId
|
// 从请求头拿tenantId
|
||||||
if(StrUtil.isNotBlank(request.getHeader("tenantId"))){
|
if (StrUtil.isNotBlank(request.getHeader("tenantId"))) {
|
||||||
return Integer.valueOf(request.getHeader("tenantId"));
|
return Integer.valueOf(request.getHeader("tenantId"));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前登录的企业信息
|
||||||
|
*
|
||||||
|
* @return Company
|
||||||
|
*/
|
||||||
|
public Company getCompany() {
|
||||||
|
List<Company> list = companyService.list(new LambdaQueryWrapper<Company>().eq(Company::getAuthoritative, 1));
|
||||||
|
if (!CollectionUtils.isEmpty(list)) {
|
||||||
|
final Company company = list.get(0);
|
||||||
|
return company;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCompanyId() {
|
||||||
|
Company company = getCompany();
|
||||||
|
return company.getCompanyId();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回成功
|
* 返回成功
|
||||||
*
|
*
|
||||||
@@ -189,7 +214,7 @@ public class BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 自定义函数
|
// 自定义函数
|
||||||
public String getAuthorization(){
|
public String getAuthorization() {
|
||||||
return request.getHeader("Authorization");
|
return request.getHeader("Authorization");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,11 +224,12 @@ public class BaseController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据账号|手机号码|邮箱查找用户ID
|
* 根据账号|手机号码|邮箱查找用户ID
|
||||||
|
*
|
||||||
* @return userId
|
* @return userId
|
||||||
*/
|
*/
|
||||||
public Integer getUserIdByUsername(String username, Integer tenantId){
|
public Integer getUserIdByUsername(String username, Integer tenantId) {
|
||||||
// 按账号搜素
|
// 按账号搜素
|
||||||
User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username).eq(User::getTenantId,tenantId));
|
User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username).eq(User::getTenantId, tenantId));
|
||||||
if (user != null && user.getUserId() > 0) {
|
if (user != null && user.getUserId() > 0) {
|
||||||
return user.getUserId();
|
return user.getUserId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -926,20 +926,9 @@ public class MainController extends BaseController {
|
|||||||
String title = "恭喜!您的账号已注册成功";
|
String title = "恭喜!您的账号已注册成功";
|
||||||
String content = "租户ID:".concat(tenant.getTenantId().toString()).concat("\r\n名称:" + tenantName).concat("\r\n账号:" + phone).concat("\r\n密码:" + password);
|
String content = "租户ID:".concat(tenant.getTenantId().toString()).concat("\r\n名称:" + tenantName).concat("\r\n账号:" + phone).concat("\r\n密码:" + password);
|
||||||
String adminUrl = "\r\n后台管理:".concat("https://admin.gxwebsoft.com");
|
String adminUrl = "\r\n后台管理:".concat("https://admin.gxwebsoft.com");
|
||||||
sendEmail(title,content.concat(adminUrl),email);
|
|
||||||
return success("注册成功",tenant.getTenantId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void sendEmail(String title, String content, String receiver) {
|
|
||||||
// 发送邮件通知
|
// 发送邮件通知
|
||||||
EmailRecord emailRecord = new EmailRecord();
|
emailRecordService.sendEmail(title,content.concat(adminUrl),email);
|
||||||
emailRecord.setTitle(title);
|
return success("注册成功",tenant.getTenantId());
|
||||||
emailRecord.setContent(content);
|
|
||||||
emailRecord.setReceiver(receiver);
|
|
||||||
emailRecord.setCreateUserId(42);
|
|
||||||
emailRecordService.sendTextEmail(title,content,receiver.split(","));
|
|
||||||
emailRecordService.save(emailRecord);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 缓存租户信息
|
// 缓存租户信息
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.gxwebsoft.common.system.controller;
|
package com.gxwebsoft.common.system.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||||
import com.gxwebsoft.common.core.web.*;
|
import com.gxwebsoft.common.core.web.*;
|
||||||
|
import com.gxwebsoft.common.system.entity.Company;
|
||||||
import com.gxwebsoft.common.system.entity.Menu;
|
import com.gxwebsoft.common.system.entity.Menu;
|
||||||
import com.gxwebsoft.common.system.entity.Plug;
|
|
||||||
import com.gxwebsoft.common.system.param.MenuParam;
|
import com.gxwebsoft.common.system.param.MenuParam;
|
||||||
|
import com.gxwebsoft.common.system.service.CompanyService;
|
||||||
import com.gxwebsoft.common.system.service.MenuService;
|
import com.gxwebsoft.common.system.service.MenuService;
|
||||||
import com.gxwebsoft.common.system.service.PlugService;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -29,7 +28,7 @@ public class MenuController extends BaseController {
|
|||||||
@Resource
|
@Resource
|
||||||
private MenuService menuService;
|
private MenuService menuService;
|
||||||
@Resource
|
@Resource
|
||||||
private PlugService plugService;
|
private CompanyService companyService;
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:menu:list')")
|
@PreAuthorize("hasAuthority('sys:menu:list')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@@ -134,7 +133,12 @@ public class MenuController extends BaseController {
|
|||||||
@PostMapping("/clone")
|
@PostMapping("/clone")
|
||||||
public ApiResult<?> onClone(@RequestBody MenuParam param){
|
public ApiResult<?> onClone(@RequestBody MenuParam param){
|
||||||
if(menuService.cloneMenu(param)){
|
if(menuService.cloneMenu(param)){
|
||||||
return success("克隆成功,请刷新");
|
Integer companyId = getCompanyId();
|
||||||
|
Company company = new Company();
|
||||||
|
company.setCompanyId(companyId);
|
||||||
|
company.setPlanId(param.getTenantId());
|
||||||
|
companyService.updateById(company);
|
||||||
|
return success("克隆成功");
|
||||||
}
|
}
|
||||||
return fail("克隆失败");
|
return fail("克隆失败");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,6 +133,9 @@ public class Company implements Serializable {
|
|||||||
@ApiModelProperty(value = "排序")
|
@ApiModelProperty(value = "排序")
|
||||||
private Integer sortNumber;
|
private Integer sortNumber;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "当前使用的租户模板")
|
||||||
|
private Integer planId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "用户ID")
|
@ApiModelProperty(value = "用户ID")
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
|
||||||
@@ -170,4 +173,8 @@ public class Company implements Serializable {
|
|||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String nickname;
|
private String nickname;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否已安装")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Boolean installed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,9 +123,11 @@ public class User implements UserDetails {
|
|||||||
private Integer organizationId;
|
private Integer organizationId;
|
||||||
|
|
||||||
@ApiModelProperty("客户ID")
|
@ApiModelProperty("客户ID")
|
||||||
|
@TableField(exist = false)
|
||||||
private Integer customerId;
|
private Integer customerId;
|
||||||
|
|
||||||
@ApiModelProperty("企业ID")
|
@ApiModelProperty("企业ID")
|
||||||
|
@TableField(exist = false)
|
||||||
private Integer companyId;
|
private Integer companyId;
|
||||||
|
|
||||||
@ApiModelProperty("注册来源客户端")
|
@ApiModelProperty("注册来源客户端")
|
||||||
@@ -191,6 +193,7 @@ public class User implements UserDetails {
|
|||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
@ApiModelProperty("公司名称")
|
@ApiModelProperty("公司名称")
|
||||||
|
@TableField(exist = false)
|
||||||
private String companyName;
|
private String companyName;
|
||||||
|
|
||||||
@ApiModelProperty("是否已实名认证")
|
@ApiModelProperty("是否已实名认证")
|
||||||
|
|||||||
@@ -65,4 +65,8 @@ public class MenuParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer tenantId;
|
private Integer tenantId;
|
||||||
|
|
||||||
|
@ApiModelProperty("企业ID")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private Integer companyId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,4 +47,5 @@ public interface EmailRecordService extends IService<EmailRecord> {
|
|||||||
void sendHtmlEmail(String title, String path, Map<String, Object> map, String[] toEmails)
|
void sendHtmlEmail(String title, String path, Map<String, Object> map, String[] toEmails)
|
||||||
throws MessagingException, IOException;
|
throws MessagingException, IOException;
|
||||||
|
|
||||||
|
void sendEmail(String title, String content, String receiver);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -69,4 +70,17 @@ public class EmailRecordServiceImpl extends ServiceImpl<EmailRecordMapper, Email
|
|||||||
sendFullTextEmail(title, html, toEmails); // 发送邮件
|
sendFullTextEmail(title, html, toEmails); // 发送邮件
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
@Override
|
||||||
|
public void sendEmail(String title, String content, String receiver) {
|
||||||
|
// 发送邮件通知
|
||||||
|
EmailRecord emailRecord = new EmailRecord();
|
||||||
|
emailRecord.setTitle(title);
|
||||||
|
emailRecord.setContent(content);
|
||||||
|
emailRecord.setReceiver(receiver);
|
||||||
|
emailRecord.setCreateUserId(42);
|
||||||
|
sendTextEmail(title,content,receiver.split(","));
|
||||||
|
save(emailRecord);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.gxwebsoft.common.system.entity.User;
|
|||||||
import com.gxwebsoft.common.system.entity.UserRole;
|
import com.gxwebsoft.common.system.entity.UserRole;
|
||||||
import com.gxwebsoft.common.system.mapper.UserMapper;
|
import com.gxwebsoft.common.system.mapper.UserMapper;
|
||||||
import com.gxwebsoft.common.system.param.UserParam;
|
import com.gxwebsoft.common.system.param.UserParam;
|
||||||
|
import com.gxwebsoft.common.system.service.CompanyService;
|
||||||
import com.gxwebsoft.common.system.service.RoleMenuService;
|
import com.gxwebsoft.common.system.service.RoleMenuService;
|
||||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||||
import com.gxwebsoft.common.system.service.UserService;
|
import com.gxwebsoft.common.system.service.UserService;
|
||||||
@@ -46,6 +47,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
@Resource
|
@Resource
|
||||||
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||||
@Resource
|
@Resource
|
||||||
|
private CompanyService companyService;
|
||||||
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,24 +82,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null));
|
user.setAuthorities(roleMenuService.listMenuByUserId(user.getUserId(), null));
|
||||||
// 系统配置信息
|
// 系统配置信息
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
// 1)基本信息
|
// 1)云存储
|
||||||
final String setting = redisUtil.get("setting:setting:" + user.getTenantId());
|
|
||||||
if(setting != null){
|
|
||||||
final JSONObject site = JSONObject.parseObject(setting);
|
|
||||||
map.put("siteName",site.getString("siteName"));
|
|
||||||
map.put("remarks",site.getString("remarks"));
|
|
||||||
map.put("keyword",site.getString("keyword"));
|
|
||||||
map.put("icp",site.getString("icp"));
|
|
||||||
map.put("copyright",site.getString("copyright"));
|
|
||||||
map.put("company",site.getString("company"));
|
|
||||||
map.put("address",site.getString("address"));
|
|
||||||
map.put("phone",site.getString("phone"));
|
|
||||||
map.put("email",site.getString("email"));
|
|
||||||
map.put("domain",site.getString("domain"));
|
|
||||||
map.put("support",site.getString("support"));
|
|
||||||
map.put("logo",site.getString("logo"));
|
|
||||||
}
|
|
||||||
// 2)云存储
|
|
||||||
String key = "setting:upload:" + user.getTenantId();
|
String key = "setting:upload:" + user.getTenantId();
|
||||||
final String upload = redisUtil.get(key);
|
final String upload = redisUtil.get(key);
|
||||||
if(upload != null){
|
if(upload != null){
|
||||||
@@ -107,10 +93,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||||||
user.setSystem(map);
|
user.setSystem(map);
|
||||||
}
|
}
|
||||||
// 企业信息
|
// 企业信息
|
||||||
String key2 = "company:authoritative:" + user.getTenantId();
|
final Company company = companyService.getByTenantIdRel(user.getTenantId());
|
||||||
final Company company = redisUtil.get(key2, Company.class);
|
if (company != null) {
|
||||||
|
user.setCompanyId(company.getCompanyId());
|
||||||
user.setCompanyInfo(company);
|
user.setCompanyInfo(company);
|
||||||
user.setSystem(map);
|
}
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ public class SysGenerator {
|
|||||||
// "sys_user_grade"
|
// "sys_user_grade"
|
||||||
// "sys_user_referee"
|
// "sys_user_referee"
|
||||||
// "sys_notice"
|
// "sys_notice"
|
||||||
"sys_plug"
|
// "sys_plug"
|
||||||
|
"sys_plug_record"
|
||||||
};
|
};
|
||||||
// 需要去除的表前缀
|
// 需要去除的表前缀
|
||||||
private static final String[] TABLE_PREFIX = new String[]{
|
private static final String[] TABLE_PREFIX = new String[]{
|
||||||
|
|||||||
Reference in New Issue
Block a user