@@ -1,5 +1,7 @@
package com.gxwebsoft.common.system.controller ;
import cn.hutool.core.date.DateField ;
import cn.hutool.core.date.DateTime ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.util.StrUtil ;
import com.alibaba.fastjson.JSONObject ;
@@ -101,7 +103,7 @@ public class MainController extends BaseController {
Integer tenantId = param . getTenantId ( ) ;
// 判断租户是否销毁
final Tenant tenant = tenantService . getById ( tenantId ) ;
if ( tenant = = null ) {
if ( tenant = = null ) {
throw new BusinessException ( " 租户不存在 " ) ;
}
// 登录账号|手机号码|邮箱登录
@@ -138,7 +140,7 @@ public class MainController extends BaseController {
String access_token = JwtUtil . buildToken ( new JwtSubject ( username , tenantId ) ,
tokenExpireTime , configProperties . getTokenKey ( ) ) ;
// 同步redis
redisUtil . set ( " access_token: " + user . getUserId ( ) , access_token , tokenExpireTime , TimeUnit . SECONDS ) ;
redisUtil . set ( " access_token: " + user . getUserId ( ) , access_token , tokenExpireTime , TimeUnit . SECONDS ) ;
return success ( " 登录成功 " , new LoginResult ( access_token , user ) ) ;
}
@@ -155,11 +157,11 @@ public class MainController extends BaseController {
@GetMapping ( " /auth/tenant " )
public ApiResult < ? > tenant ( ) {
Integer tenantId = getTenantId ( ) ;
if ( tenantId = = null ) {
if ( tenantId = = null ) {
throw new BusinessException ( " 缺少参数tenantId " ) ;
}
Tenant tenant = tenantService . getByIdRel ( tenantId ) ;
if ( tenant = = null ) {
if ( tenant = = null ) {
throw new BusinessException ( " 该租户不存在 " ) ;
}
// 企业信息
@@ -184,10 +186,12 @@ public class MainController extends BaseController {
menu . setMenuType ( 0 ) ;
list . add ( menu ) ;
tenant . setMenu ( list ) ;
// 服务器时间
tenant . setDate ( serverTime ( ) ) ;
// 授权信息
HashMap < String , Object > config = new HashMap < > ( ) ;
config . put ( " LICENSE_CODE " , " dk9mcwJyetRWQlxWRiojIzJCLi8mcQ5Wa4ojI0NWZqJWd6ICZpJCL0kjNwl1NnhENahnIvl2cyVmdiwiIiATMuEjI6IibQf0NW== " ) ;
config . put ( " MAP_KEY " , " 8191620da39a742c6f18f010c084c772 " ) ;
config . put ( " LICENSE_CODE " , " dk9mcwJyetRWQlxWRiojIzJCLi8mcQ5Wa4ojI0NWZqJWd6ICZpJCL0kjNwl1NnhENahnIvl2cyVmdiwiIiATMuEjI6IibQf0NW== " ) ;
config . put ( " MAP_KEY " , " 8191620da39a742c6f18f010c084c772 " ) ;
tenant . setConfig ( config ) ;
return success ( tenant ) ;
}
@@ -449,7 +453,7 @@ public class MainController extends BaseController {
String email = user . getEmail ( ) ; // 邮箱
// 短信验证
if ( ! StrUtil . equals ( code , cacheClient . get ( phone , String . class ) ) & & ! StrUtil . equals ( code , " 170083 " ) ) {
if ( ! StrUtil . equals ( code , cacheClient . get ( phone , String . class ) ) & & ! StrUtil . equals ( code , " 170083 " ) ) {
throw new BusinessException ( " 验证码不正确 " ) ;
}
@@ -968,8 +972,36 @@ public class MainController extends BaseController {
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 " ) ;
// 发送邮件通知
emailRecordService . sendEmail ( title , content . concat ( adminUrl ) , email ) ;
return success ( " 注册成功 " , tenant . getTenantId ( ) ) ;
emailRecordService . sendEmail ( title , content . concat ( adminUrl ) , email ) ;
return success ( " 注册成功 " , tenant . getTenantId ( ) ) ;
}
/**
* 获取服务器时间
* @return String
*/
@ApiOperation ( " 获取服务器时间 " )
@GetMapping ( " /serverTime " )
public ApiResult < ? > serverTime ( ) {
HashMap < String , Object > map = new HashMap < > ( ) ;
// 今天日期
DateTime date = DateUtil . date ( ) ;
String today = DateUtil . today ( ) ;
// 明天日期
final DateTime dateTime = DateUtil . tomorrow ( ) ;
String tomorrow = DateUtil . format ( dateTime , " yyyy-MM-dd " ) ;
// 今天星期几
final int week = DateUtil . thisDayOfWeek ( ) ; ;
final DateTime nextWeek = DateUtil . nextWeek ( ) ;
map . put ( " now " , DateUtil . now ( ) ) ;
map . put ( " today " , today ) ;
map . put ( " tomorrow " , tomorrow ) ;
map . put ( " week " , week ) ;
map . put ( " minDate " , DateUtil . offset ( date , DateField . DAY_OF_WEEK , - 7 ) ) ;
map . put ( " maxDate " , DateUtil . offset ( date , DateField . DAY_OF_WEEK , 7 ) ) ;
map . put ( " nextWeek " , nextWeek ) ;
return success ( map ) ;
}
// 缓存租户信息
@@ -978,6 +1010,6 @@ public class MainController extends BaseController {
if ( StrUtil . isEmpty ( tenant . getTenantCode ( ) ) ) {
tenant . setTenantCode ( CommonUtil . randomUUID16 ( ) ) ;
}
redisUtil . set ( key , tenant ) ;
redisUtil . set ( key , tenant ) ;
}
}