Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
97111a9c
Commit
97111a9c
authored
Jun 27, 2019
by
季圣华
Browse files
增加多租户的功能
parent
a6223e57
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
docs/jsh_erp(后续更新参考这个更新).sql
View file @
97111a9c
...
...
@@ -1655,4 +1655,26 @@ where Type = 'RoleFunctions' and KeyId = '10';
-- ----------------------------
drop
table
jsh_asset
;
drop
table
jsh_assetcategory
;
drop
table
jsh_assetname
;
\ No newline at end of file
drop
table
jsh_assetname
;
-- ----------------------------
-- 时间:2019年6月27日
-- 增加租户表
-- ----------------------------
DROP
TABLE
IF
EXISTS
`jsh_tenant`
;
CREATE
TABLE
`jsh_tenant`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'主键'
,
`tenant_id`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'用户id'
,
`login_name`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'登录名'
,
`user_num_limit`
int
(
11
)
DEFAULT
NULL
COMMENT
'用户数量限制'
,
`bills_num_limit`
int
(
11
)
DEFAULT
NULL
COMMENT
'单据数量限制'
,
`create_time`
datetime
DEFAULT
NULL
COMMENT
'创建时间'
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
81
DEFAULT
CHARSET
=
utf8
COMMENT
=
'租户'
;
-- ----------------------------
-- 时间:2019年6月27日
-- 给租户表增加数据
-- ----------------------------
INSERT
INTO
`jsh_tenant`
VALUES
(
'13'
,
'63'
,
'jsh'
,
'20'
,
'2000'
,
null
);
docs/jsh_erp(第一次建库请使用这个).sql
View file @
97111a9c
...
...
@@ -1882,6 +1882,29 @@ CREATE TABLE `tbl_sequence` (
-- ----------------------------
INSERT
INTO
`tbl_sequence`
VALUES
(
'depot_number_seq'
,
'1'
,
'999999999999999999'
,
'304'
,
'1'
,
'单据编号sequence'
);
-- ----------------------------
-- Table structure for jsh_tenant
-- ----------------------------
DROP
TABLE
IF
EXISTS
`jsh_tenant`
;
CREATE
TABLE
`jsh_tenant`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'主键'
,
`tenant_id`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'用户id'
,
`login_name`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'登录名'
,
`user_num_limit`
int
(
11
)
DEFAULT
NULL
COMMENT
'用户数量限制'
,
`bills_num_limit`
int
(
11
)
DEFAULT
NULL
COMMENT
'单据数量限制'
,
`create_time`
datetime
DEFAULT
NULL
COMMENT
'创建时间'
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
81
DEFAULT
CHARSET
=
utf8
COMMENT
=
'租户'
;
-- ----------------------------
-- Records of jsh_tenant
-- ----------------------------
INSERT
INTO
`jsh_tenant`
VALUES
(
'13'
,
'63'
,
'jsh'
,
'20'
,
'2000'
,
null
);
INSERT
INTO
`jsh_tenant`
VALUES
(
'14'
,
'92'
,
'abc123'
,
'2'
,
'200'
,
null
);
INSERT
INTO
`jsh_tenant`
VALUES
(
'15'
,
'94'
,
'jzh'
,
'2'
,
'200'
,
null
);
INSERT
INTO
`jsh_tenant`
VALUES
(
'16'
,
'95'
,
'qiankun'
,
'2'
,
'200'
,
null
);
INSERT
INTO
`jsh_tenant`
VALUES
(
'17'
,
'96'
,
'czq'
,
'2'
,
'200'
,
null
);
-- ----------------------------
-- Function structure for `_nextval`
-- ----------------------------
...
...
src/main/java/com/jsh/erp/config/TenantConfig.java
View file @
97111a9c
...
...
@@ -59,7 +59,8 @@ public class TenantConfig {
// 这里可以判断是否过滤表
if
(
"databasechangelog"
.
equals
(
tableName
)
||
"databasechangeloglock"
.
equals
(
tableName
)
||
"jsh_materialproperty"
.
equals
(
tableName
)
||
"tbl_sequence"
.
equals
(
tableName
)
||
"dual"
.
equals
(
tableName
)
||
"jsh_userbusiness"
.
equals
(
tableName
)
||
"jsh_app"
.
equals
(
tableName
)
||
"jsh_functions"
.
equals
(
tableName
))
{
||
"jsh_userbusiness"
.
equals
(
tableName
)
||
"jsh_app"
.
equals
(
tableName
)
||
"jsh_functions"
.
equals
(
tableName
)
||
"jsh_tenant"
.
equals
(
tableName
))
{
return
true
;
}
else
{
return
false
;
...
...
src/main/java/com/jsh/erp/controller/UserController.java
View file @
97111a9c
...
...
@@ -7,10 +7,12 @@ import com.github.pagehelper.PageHelper;
import
com.github.pagehelper.PageInfo
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.Tenant
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.entities.UserEx
;
import
com.jsh.erp.datasource.vo.TreeNodeEx
;
import
com.jsh.erp.exception.BusinessParamCheckingException
;
import
com.jsh.erp.service.tenant.TenantService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.*
;
import
org.slf4j.Logger
;
...
...
@@ -52,6 +54,9 @@ public class UserController {
@Resource
private
UserService
userService
;
@Resource
private
TenantService
tenantService
;
private
static
String
message
=
"成功"
;
private
static
final
String
HTTP
=
"http://"
;
private
static
final
String
CODE_OK
=
"200"
;
...
...
@@ -107,19 +112,15 @@ public class UserController {
msgTip
=
"user can login"
;
request
.
getSession
().
setAttribute
(
"user"
,
user
);
if
((
"open"
).
equals
(
mybatisPlusStatus
))
{
String
url
=
HTTP
+
manageIp
+
":"
+
managePort
+
"/tenant/getTenant?tenantId="
+
user
.
getTenantId
();
JSONObject
obj
=
HttpClient
.
httpGet
(
url
);
if
(
obj
!=
null
&&
obj
.
getString
(
"code"
).
equals
(
CODE_OK
))
{
JSONObject
dataObj
=
obj
.
getJSONObject
(
"data"
);
if
(
dataObj
!=
null
)
{
String
tenantId
=
dataObj
.
getString
(
"tenantId"
);
String
userNumLimit
=
dataObj
.
getString
(
"userNumLimit"
);
String
billsNumLimit
=
dataObj
.
getString
(
"billsNumLimit"
);
if
(
tenantId
!=
null
)
{
request
.
getSession
().
setAttribute
(
"tenantId"
,
tenantId
);
//租户tenantId
request
.
getSession
().
setAttribute
(
"userNumLimit"
,
userNumLimit
);
//用户限制数
request
.
getSession
().
setAttribute
(
"billsNumLimit"
,
billsNumLimit
);
//单据限制数
}
Tenant
tenant
=
tenantService
.
getTenantByTenantId
(
user
.
getTenantId
());
if
(
tenant
!=
null
)
{
Long
tenantId
=
tenant
.
getTenantId
();
Integer
userNumLimit
=
tenant
.
getUserNumLimit
();
Integer
billsNumLimit
=
tenant
.
getBillsNumLimit
();
if
(
tenantId
!=
null
)
{
request
.
getSession
().
setAttribute
(
"tenantId"
,
tenantId
);
//租户tenantId
request
.
getSession
().
setAttribute
(
"userNumLimit"
,
userNumLimit
);
//用户限制数
request
.
getSession
().
setAttribute
(
"billsNumLimit"
,
billsNumLimit
);
//单据限制数
}
}
}
...
...
@@ -351,33 +352,7 @@ public class UserController {
ue
.
setLoginame
(
loginame
);
ue
.
setPassword
(
password
);
userService
.
checkUserNameAndLoginName
(
ue
);
//检查用户名和登录名
ue
=
userService
.
registerUser
(
ue
,
manageRoleId
);
/**
* create by: qiankunpingtai
* create time: 2019/4/9 17:17
* website:https://qiankunpingtai.cn
* description:
* 这里涉及到多个项目,需要用分布式事务去处理
* 为了不使问题复杂化,暂时另外开启一个线程去处理其它项目的数据操作
*/
final
UserEx
ueFinal
=
ue
;
final
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
1
);
executorService
.
execute
(()
->
{
try
{
//调第三方接口创建租户管理信息
String
url
=
HTTP
+
manageIp
+
":"
+
managePort
+
"/tenant/add"
;
JSONObject
tenantObj
=
new
JSONObject
();
tenantObj
.
put
(
"tenantId"
,
ueFinal
.
getId
());
tenantObj
.
put
(
"loginName"
,
ueFinal
.
getLoginame
());
String
param
=
URLEncoder
.
encode
(
tenantObj
.
toString
());
HttpClient
.
httpPost
(
url
+
"?info="
+
param
,
param
);
logger
.
info
(
"===============创建租户信息完成==============="
);
}
catch
(
Exception
e
){
//记录一下第三方接口创建租户管理信息创建失败
logger
.
debug
(
"调用第三方接口创建租户管理信息失败:tenantId:[{}],loginName:[{}]"
,
ueFinal
.
getId
(),
ueFinal
.
getLoginame
());
}
});
ue
=
userService
.
registerUser
(
ue
,
manageRoleId
,
request
);
return
result
;
}
/**
...
...
src/main/java/com/jsh/erp/datasource/entities/Tenant.java
0 → 100644
View file @
97111a9c
package
com.jsh.erp.datasource.entities
;
import
java.util.Date
;
public
class
Tenant
{
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.id
*
* @mbggenerated
*/
private
Long
id
;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.tenant_id
*
* @mbggenerated
*/
private
Long
tenantId
;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.login_name
*
* @mbggenerated
*/
private
String
loginName
;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.user_num_limit
*
* @mbggenerated
*/
private
Integer
userNumLimit
;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.bills_num_limit
*
* @mbggenerated
*/
private
Integer
billsNumLimit
;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column jsh_tenant.create_time
*
* @mbggenerated
*/
private
Date
createTime
;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.id
*
* @return the value of jsh_tenant.id
*
* @mbggenerated
*/
public
Long
getId
()
{
return
id
;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.id
*
* @param id the value for jsh_tenant.id
*
* @mbggenerated
*/
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.tenant_id
*
* @return the value of jsh_tenant.tenant_id
*
* @mbggenerated
*/
public
Long
getTenantId
()
{
return
tenantId
;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.tenant_id
*
* @param tenantId the value for jsh_tenant.tenant_id
*
* @mbggenerated
*/
public
void
setTenantId
(
Long
tenantId
)
{
this
.
tenantId
=
tenantId
;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.login_name
*
* @return the value of jsh_tenant.login_name
*
* @mbggenerated
*/
public
String
getLoginName
()
{
return
loginName
;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.login_name
*
* @param loginName the value for jsh_tenant.login_name
*
* @mbggenerated
*/
public
void
setLoginName
(
String
loginName
)
{
this
.
loginName
=
loginName
==
null
?
null
:
loginName
.
trim
();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.user_num_limit
*
* @return the value of jsh_tenant.user_num_limit
*
* @mbggenerated
*/
public
Integer
getUserNumLimit
()
{
return
userNumLimit
;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.user_num_limit
*
* @param userNumLimit the value for jsh_tenant.user_num_limit
*
* @mbggenerated
*/
public
void
setUserNumLimit
(
Integer
userNumLimit
)
{
this
.
userNumLimit
=
userNumLimit
;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.bills_num_limit
*
* @return the value of jsh_tenant.bills_num_limit
*
* @mbggenerated
*/
public
Integer
getBillsNumLimit
()
{
return
billsNumLimit
;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.bills_num_limit
*
* @param billsNumLimit the value for jsh_tenant.bills_num_limit
*
* @mbggenerated
*/
public
void
setBillsNumLimit
(
Integer
billsNumLimit
)
{
this
.
billsNumLimit
=
billsNumLimit
;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column jsh_tenant.create_time
*
* @return the value of jsh_tenant.create_time
*
* @mbggenerated
*/
public
Date
getCreateTime
()
{
return
createTime
;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column jsh_tenant.create_time
*
* @param createTime the value for jsh_tenant.create_time
*
* @mbggenerated
*/
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
}
\ No newline at end of file
src/main/java/com/jsh/erp/datasource/entities/TenantExample.java
0 → 100644
View file @
97111a9c
This diff is collapsed.
Click to expand it.
src/main/java/com/jsh/erp/datasource/mappers/TenantMapper.java
0 → 100644
View file @
97111a9c
package
com.jsh.erp.datasource.mappers
;
import
com.jsh.erp.datasource.entities.Tenant
;
import
com.jsh.erp.datasource.entities.TenantExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
public
interface
TenantMapper
{
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
countByExample
(
TenantExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
deleteByExample
(
TenantExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
deleteByPrimaryKey
(
Long
id
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
insert
(
Tenant
record
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
insertSelective
(
Tenant
record
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
List
<
Tenant
>
selectByExample
(
TenantExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
Tenant
selectByPrimaryKey
(
Long
id
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
updateByExampleSelective
(
@Param
(
"record"
)
Tenant
record
,
@Param
(
"example"
)
TenantExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
updateByExample
(
@Param
(
"record"
)
Tenant
record
,
@Param
(
"example"
)
TenantExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
updateByPrimaryKeySelective
(
Tenant
record
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table jsh_tenant
*
* @mbggenerated
*/
int
updateByPrimaryKey
(
Tenant
record
);
}
\ No newline at end of file
src/main/java/com/jsh/erp/datasource/mappers/TenantMapperEx.java
0 → 100644
View file @
97111a9c
package
com.jsh.erp.datasource.mappers
;
import
com.jsh.erp.datasource.entities.Tenant
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
TenantMapperEx
{
List
<
Tenant
>
selectByConditionTenant
(
@Param
(
"loginName"
)
String
loginName
,
@Param
(
"offset"
)
Integer
offset
,
@Param
(
"rows"
)
Integer
rows
);
Long
countsByTenant
(
@Param
(
"loginName"
)
String
loginName
);
}
\ No newline at end of file
src/main/java/com/jsh/erp/service/ResourceInfo.java
View file @
97111a9c
...
...
@@ -24,6 +24,10 @@ import java.lang.annotation.*;
* depotItem-90
* accountHead-95
* accountItem-100
* serialNumber-105
* organization-110
* orgaUserRel-115
* tenant-120
*/
@Target
({
ElementType
.
TYPE
,
ElementType
.
ANNOTATION_TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
...
...
src/main/java/com/jsh/erp/service/tenant/TenantComponent.java
0 → 100644
View file @
97111a9c
package
com.jsh.erp.service.tenant
;
import
com.jsh.erp.service.ICommonQuery
;
import
com.jsh.erp.service.user.UserResource
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.Constants
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
@Service
(
value
=
"tenant_component"
)
@UserResource
public
class
TenantComponent
implements
ICommonQuery
{
@Resource
private
TenantService
tenantService
;
@Override
public
Object
selectOne
(
Long
id
)
throws
Exception
{
return
tenantService
.
getTenant
(
id
);
}
@Override
public
List
<?>
select
(
Map
<
String
,
String
>
map
)
throws
Exception
{
return
getTenantList
(
map
);
}
private
List
<?>
getTenantList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
loginName
=
StringUtil
.
getInfo
(
search
,
"loginName"
);
return
tenantService
.
select
(
loginName
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
loginName
=
StringUtil
.
getInfo
(
search
,
"loginName"
);
return
tenantService
.
countTenant
(
loginName
);
}
@Override
public
int
insert
(
String
beanJson
,
HttpServletRequest
request
)
throws
Exception
{
return
tenantService
.
insertTenant
(
beanJson
,
request
);
}
@Override
public
int
update
(
String
beanJson
,
Long
id
)
throws
Exception
{
return
tenantService
.
updateTenant
(
beanJson
,
id
);
}
@Override
public
int
delete
(
Long
id
)
throws
Exception
{
return
tenantService
.
deleteTenant
(
id
);
}
@Override
public
int
batchDelete
(
String
ids
)
throws
Exception
{
return
tenantService
.
batchDeleteTenant
(
ids
);
}
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
tenantService
.
checkIsNameExist
(
id
,
name
);
}
}
src/main/java/com/jsh/erp/service/tenant/TenantResource.java
0 → 100644
View file @
97111a9c
package
com.jsh.erp.service.tenant
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2019-6-27 22:56:56
*/
@ResourceInfo
(
value
=
"tenant"
,
type
=
120
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
TenantResource
{
}
src/main/java/com/jsh/erp/service/tenant/TenantService.java
0 → 100644
View file @
97111a9c
package
com.jsh.erp.service.tenant
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.*
;
import
com.jsh.erp.datasource.mappers.TenantMapper
;
import
com.jsh.erp.datasource.mappers.TenantMapperEx
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.*
;
@Service
public
class
TenantService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
TenantService
.
class
);
@Resource
private
TenantMapper
tenantMapper
;
@Resource
private
TenantMapperEx
tenantMapperEx
;
public
Tenant
getTenant
(
long
id
)
throws
Exception
{
Tenant
result
=
null
;
try
{
result
=
tenantMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
);
}
return
result
;
}
public
List
<
Tenant
>
getTenant
()
throws
Exception
{
TenantExample
example
=
new
TenantExample
();
List
<
Tenant
>
list
=
null
;
try
{
list
=
tenantMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
);
}
return
list
;
}
public
List
<
Tenant
>
select
(
String
loginName
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
Tenant
>
list
=
null
;
try
{
list
=
tenantMapperEx
.
selectByConditionTenant
(
loginName
,
offset
,
rows
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
);
}
return
list
;
}
public
Long
countTenant
(
String
loginName
)
throws
Exception
{
Long
result
=
null
;
try
{
result
=
tenantMapperEx
.
countsByTenant
(
loginName
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertTenant
(
String
beanJson
,
HttpServletRequest
request
)
throws
Exception
{
Tenant
tenant
=
JSONObject
.
parseObject
(
beanJson
,
Tenant
.
class
);
int
result
=
0
;
try
{
tenant
.
setUserNumLimit
(
2
);
//默认用户限制数量
tenant
.
setBillsNumLimit
(
200
);
//默认单据限制数量
tenant
.
setCreateTime
(
new
Date
());
result
=
tenantMapper
.
insertSelective
(
tenant
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateTenant
(
String
beanJson
,
Long
id
)
throws
Exception
{
Tenant
tenant
=
JSONObject
.
parseObject
(
beanJson
,
Tenant
.
class
);
int
result
=
0
;
try
{
tenant
.
setId
(
id
);
result
=
tenantMapper
.
updateByPrimaryKeySelective
(
tenant
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteTenant
(
Long
id
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
tenantMapper
.
deleteByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteTenant
(
String
ids
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
TenantExample
example
=
new
TenantExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
int
result
=
0
;
try
{
result
=
tenantMapper
.
deleteByExample
(
example
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_WRITE_FAIL_CODE
,
ExceptionConstants
.
DATA_WRITE_FAIL_MSG
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
TenantExample
example
=
new
TenantExample
();
example
.
createCriteria
().
andIdEqualTo
(
id
);
List
<
Tenant
>
list
=
null
;
try
{
list
=
tenantMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
logger
.
error
(
"异常码[{}],异常提示[{}],异常[{}]"
,
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
,
e
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DATA_READ_FAIL_CODE
,
ExceptionConstants
.
DATA_READ_FAIL_MSG
);
}
return
list
==
null
?
0
:
list
.
size
();
}
public
Tenant
getTenantByTenantId
(
long
tenantId
)
{
Tenant
tenant
=
new
Tenant
();
TenantExample
example
=
new
TenantExample
();
example
.
createCriteria
().
andTenantIdEqualTo
(
tenantId
);
List
<
Tenant
>
list
=
tenantMapper
.
selectByExample
(
example
);
if
(
list
.
size
()>
0
)
{
tenant
=
list
.
get
(
0
);
}
return
tenant
;
}
}
src/main/java/com/jsh/erp/service/user/UserService.java
View file @
97111a9c
...
...
@@ -15,6 +15,7 @@ import com.jsh.erp.datasource.vo.TreeNodeEx;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.orgaUserRel.OrgaUserRelService
;
import
com.jsh.erp.service.tenant.TenantService
;
import
com.jsh.erp.service.userBusiness.UserBusinessService
;
import
com.jsh.erp.utils.ExceptionCodeConstants
;
import
com.jsh.erp.utils.JshException
;
...
...
@@ -49,7 +50,8 @@ public class UserService {
private
LogService
logService
;
@Resource
private
UserService
userService
;
@Resource
private
TenantService
tenantService
;
@Resource
private
UserBusinessService
userBusinessService
;
...
...
@@ -416,7 +418,7 @@ public class UserService {
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
UserEx
registerUser
(
UserEx
ue
,
Integer
manageRoleId
)
throws
Exception
{
public
UserEx
registerUser
(
UserEx
ue
,
Integer
manageRoleId
,
HttpServletRequest
request
)
throws
Exception
{
/**
* create by: qiankunpingtai
* create time: 2019/4/9 18:00
...
...
@@ -456,6 +458,13 @@ public class UserService {
ubArr
.
add
(
manageRoleId
);
ubObj
.
put
(
"value"
,
ubArr
.
toString
());
userBusinessService
.
insertUserBusiness
(
ubObj
.
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
//创建租户信息
JSONObject
tenantObj
=
new
JSONObject
();
tenantObj
.
put
(
"tenantId"
,
ue
.
getId
());
tenantObj
.
put
(
"loginName"
,
ue
.
getLoginame
());
String
param
=
tenantObj
.
toJSONString
();
tenantService
.
insertTenant
(
param
,
request
);
logger
.
info
(
"===============创建租户信息完成==============="
);
if
(
result
>
0
)
{
return
ue
;
}
...
...
src/main/resources/mapper_xml/TenantMapper.xml
0 → 100644
View file @
97111a9c
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"com.jsh.erp.datasource.mappers.TenantMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.jsh.erp.datasource.entities.Tenant"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id
column=
"id"
property=
"id"
jdbcType=
"BIGINT"
/>
<result
column=
"tenant_id"
property=
"tenantId"
jdbcType=
"BIGINT"
/>
<result
column=
"login_name"
property=
"loginName"
jdbcType=
"VARCHAR"
/>
<result
column=
"user_num_limit"
property=
"userNumLimit"
jdbcType=
"INTEGER"
/>
<result
column=
"bills_num_limit"
property=
"billsNumLimit"
jdbcType=
"INTEGER"
/>
<result
column=
"create_time"
property=
"createTime"
jdbcType=
"TIMESTAMP"
/>
</resultMap>
<sql
id=
"Example_Where_Clause"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where
>
<foreach
collection=
"oredCriteria"
item=
"criteria"
separator=
"or"
>
<if
test=
"criteria.valid"
>
<trim
prefix=
"("
suffix=
")"
prefixOverrides=
"and"
>
<foreach
collection=
"criteria.criteria"
item=
"criterion"
>
<choose
>
<when
test=
"criterion.noValue"
>
and ${criterion.condition}
</when>
<when
test=
"criterion.singleValue"
>
and ${criterion.condition} #{criterion.value}
</when>
<when
test=
"criterion.betweenValue"
>
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when
test=
"criterion.listValue"
>
and ${criterion.condition}
<foreach
collection=
"criterion.value"
item=
"listItem"
open=
"("
close=
")"
separator=
","
>
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql
id=
"Update_By_Example_Where_Clause"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where
>
<foreach
collection=
"example.oredCriteria"
item=
"criteria"
separator=
"or"
>
<if
test=
"criteria.valid"
>
<trim
prefix=
"("
suffix=
")"
prefixOverrides=
"and"
>
<foreach
collection=
"criteria.criteria"
item=
"criterion"
>
<choose
>
<when
test=
"criterion.noValue"
>
and ${criterion.condition}
</when>
<when
test=
"criterion.singleValue"
>
and ${criterion.condition} #{criterion.value}
</when>
<when
test=
"criterion.betweenValue"
>
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when
test=
"criterion.listValue"
>
and ${criterion.condition}
<foreach
collection=
"criterion.value"
item=
"listItem"
open=
"("
close=
")"
separator=
","
>
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql
id=
"Base_Column_List"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, tenant_id, login_name, user_num_limit, bills_num_limit, create_time
</sql>
<select
id=
"selectByExample"
resultMap=
"BaseResultMap"
parameterType=
"com.jsh.erp.datasource.entities.TenantExample"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if
test=
"distinct"
>
distinct
</if>
<include
refid=
"Base_Column_List"
/>
from jsh_tenant
<if
test=
"_parameter != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
<if
test=
"orderByClause != null"
>
order by ${orderByClause}
</if>
</select>
<select
id=
"selectByPrimaryKey"
resultMap=
"BaseResultMap"
parameterType=
"java.lang.Long"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include
refid=
"Base_Column_List"
/>
from jsh_tenant
where id = #{id,jdbcType=BIGINT}
</select>
<delete
id=
"deleteByPrimaryKey"
parameterType=
"java.lang.Long"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from jsh_tenant
where id = #{id,jdbcType=BIGINT}
</delete>
<delete
id=
"deleteByExample"
parameterType=
"com.jsh.erp.datasource.entities.TenantExample"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from jsh_tenant
<if
test=
"_parameter != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</delete>
<insert
id=
"insert"
parameterType=
"com.jsh.erp.datasource.entities.Tenant"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into jsh_tenant (id, tenant_id, login_name,
user_num_limit, bills_num_limit, create_time
)
values (#{id,jdbcType=BIGINT}, #{tenantId,jdbcType=BIGINT}, #{loginName,jdbcType=VARCHAR},
#{userNumLimit,jdbcType=INTEGER}, #{billsNumLimit,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}
)
</insert>
<insert
id=
"insertSelective"
parameterType=
"com.jsh.erp.datasource.entities.Tenant"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into jsh_tenant
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"tenantId != null"
>
tenant_id,
</if>
<if
test=
"loginName != null"
>
login_name,
</if>
<if
test=
"userNumLimit != null"
>
user_num_limit,
</if>
<if
test=
"billsNumLimit != null"
>
bills_num_limit,
</if>
<if
test=
"createTime != null"
>
create_time,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=BIGINT},
</if>
<if
test=
"tenantId != null"
>
#{tenantId,jdbcType=BIGINT},
</if>
<if
test=
"loginName != null"
>
#{loginName,jdbcType=VARCHAR},
</if>
<if
test=
"userNumLimit != null"
>
#{userNumLimit,jdbcType=INTEGER},
</if>
<if
test=
"billsNumLimit != null"
>
#{billsNumLimit,jdbcType=INTEGER},
</if>
<if
test=
"createTime != null"
>
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select
id=
"countByExample"
parameterType=
"com.jsh.erp.datasource.entities.TenantExample"
resultType=
"java.lang.Integer"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from jsh_tenant
<if
test=
"_parameter != null"
>
<include
refid=
"Example_Where_Clause"
/>
</if>
</select>
<update
id=
"updateByExampleSelective"
parameterType=
"map"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update jsh_tenant
<set
>
<if
test=
"record.id != null"
>
id = #{record.id,jdbcType=BIGINT},
</if>
<if
test=
"record.tenantId != null"
>
tenant_id = #{record.tenantId,jdbcType=BIGINT},
</if>
<if
test=
"record.loginName != null"
>
login_name = #{record.loginName,jdbcType=VARCHAR},
</if>
<if
test=
"record.userNumLimit != null"
>
user_num_limit = #{record.userNumLimit,jdbcType=INTEGER},
</if>
<if
test=
"record.billsNumLimit != null"
>
bills_num_limit = #{record.billsNumLimit,jdbcType=INTEGER},
</if>
<if
test=
"record.createTime != null"
>
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
</set>
<if
test=
"_parameter != null"
>
<include
refid=
"Update_By_Example_Where_Clause"
/>
</if>
</update>
<update
id=
"updateByExample"
parameterType=
"map"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update jsh_tenant
set id = #{record.id,jdbcType=BIGINT},
tenant_id = #{record.tenantId,jdbcType=BIGINT},
login_name = #{record.loginName,jdbcType=VARCHAR},
user_num_limit = #{record.userNumLimit,jdbcType=INTEGER},
bills_num_limit = #{record.billsNumLimit,jdbcType=INTEGER},
create_time = #{record.createTime,jdbcType=TIMESTAMP}
<if
test=
"_parameter != null"
>
<include
refid=
"Update_By_Example_Where_Clause"
/>
</if>
</update>
<update
id=
"updateByPrimaryKeySelective"
parameterType=
"com.jsh.erp.datasource.entities.Tenant"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update jsh_tenant
<set
>
<if
test=
"tenantId != null"
>
tenant_id = #{tenantId,jdbcType=BIGINT},
</if>
<if
test=
"loginName != null"
>
login_name = #{loginName,jdbcType=VARCHAR},
</if>
<if
test=
"userNumLimit != null"
>
user_num_limit = #{userNumLimit,jdbcType=INTEGER},
</if>
<if
test=
"billsNumLimit != null"
>
bills_num_limit = #{billsNumLimit,jdbcType=INTEGER},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update
id=
"updateByPrimaryKey"
parameterType=
"com.jsh.erp.datasource.entities.Tenant"
>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update jsh_tenant
set tenant_id = #{tenantId,jdbcType=BIGINT},
login_name = #{loginName,jdbcType=VARCHAR},
user_num_limit = #{userNumLimit,jdbcType=INTEGER},
bills_num_limit = #{billsNumLimit,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
src/main/resources/mapper_xml/TenantMapperEx.xml
0 → 100644
View file @
97111a9c
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.jsh.erp.datasource.mappers.TenantMapperEx"
>
<select
id=
"selectByConditionTenant"
parameterType=
"com.jsh.erp.datasource.entities.TenantExample"
resultMap=
"com.jsh.erp.datasource.mappers.TenantMapper.BaseResultMap"
>
select *
FROM jsh_tenant
where 1=1
<if
test=
"loginName != null"
>
and loginame like '%${loginName}%'
</if>
<if
test=
"offset != null and rows != null"
>
limit #{offset},#{rows}
</if>
</select>
<select
id=
"countsByTenant"
resultType=
"java.lang.Long"
>
SELECT
COUNT(id)
FROM jsh_tenant
WHERE 1=1
<if
test=
"loginName != null"
>
and loginame like '%${loginName}%'
</if>
</select>
</mapper>
\ No newline at end of file
src/test/resources/generatorConfig.xml
View file @
97111a9c
...
...
@@ -63,6 +63,7 @@
<table tableName="jsh_userbusiness" domainObjectName="UserBusiness"></table>
<table tableName="jsh_serial_number" domainObjectName="SerialNumber"></table>
<table tableName="jsh_organization" domainObjectName="Organization"></table>
<table tableName="jsh_orga_user_rel" domainObjectName="OrgaUserRel"></table> -->
<table tableName="jsh_orga_user_rel" domainObjectName="OrgaUserRel"></table>
<table tableName="jsh_tenant" domainObjectName="Tenant"></table> -->
</context>
</generatorConfiguration>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment