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
1ea88a2e
Commit
1ea88a2e
authored
Aug 02, 2020
by
季圣华
Browse files
优化系统配置模块
parent
ed32ab54
Changes
9
Hide whitespace changes
Inline
Side-by-side
erp_web/js/common/common.js
View file @
1ea88a2e
...
...
@@ -422,35 +422,6 @@
return
res
;
}
/**
* 检查当前用户是否是演示用户
*/
function
checkIsTestUser
()
{
var
result
=
false
;
var
demonstrateOpen
=
false
;
$
.
ajax
({
type
:
"
get
"
,
url
:
"
/user/getDemonstrateOpen
"
,
dataType
:
"
json
"
,
async
:
false
,
//设置为同步
success
:
function
(
res
)
{
if
(
res
&&
res
.
code
===
200
)
{
demonstrateOpen
=
res
.
data
.
demonstrateOpen
;
}
}
});
if
(
demonstrateOpen
)
{
var
loginName
=
sessionStorage
.
getItem
(
"
loginName
"
);
if
(
loginName
==
"
jsh
"
)
{
$
.
messager
.
alert
(
'
提示
'
,
'
演示用户禁止操作!
'
,
'
warning
'
);
result
=
true
;
}
else
{
result
=
false
;
}
}
return
result
;
}
/**
* 判断一个值是否数字
* @param value
...
...
erp_web/pages/manage/systemConfig.html
View file @
1ea88a2e
...
...
@@ -246,21 +246,66 @@
//删除系统配置信息
function
deleteSystemConfig
(
systemConfigId
)
{
if
(
checkIsTestUser
())
{
$
.
messager
.
confirm
(
'
删除确认
'
,
'
确定要删除此系统配置信息吗?
'
,
function
(
r
)
{
if
(
r
)
{
$
.
ajax
({
type
:
"
post
"
,
url
:
"
/systemConfig/batchDeleteSystemConfigByIds
"
,
dataType
:
"
json
"
,
data
:
({
ids
:
systemConfigId
}),
success
:
function
(
res
)
{
if
(
res
&&
res
.
code
==
200
)
{
$
(
"
#searchBtn
"
).
click
();
}
else
if
(
res
.
code
==
-
1
)
{
$
.
messager
.
alert
(
'
提示
'
,
'
演示用户禁止操作!
'
,
'
warning
'
);
}
else
{
$
.
messager
.
alert
(
'
删除提示
'
,
'
删除系统配置信息失败,请稍后再试!
'
,
'
error
'
);
}
},
//此处添加错误处理
error
:
function
()
{
$
.
messager
.
alert
(
'
删除提示
'
,
'
删除系统配置信息异常,请稍后再试!
'
,
'
error
'
);
return
;
}
});
}
});
}
//批量删除系统配置
function
batDeleteSystemConfig
()
{
var
row
=
$
(
'
#tableData
'
).
datagrid
(
'
getChecked
'
);
if
(
row
.
length
==
0
)
{
$
.
messager
.
alert
(
'
删除提示
'
,
'
没有记录被选中!
'
,
'
warning
'
);
return
;
}
else
{
$
.
messager
.
confirm
(
'
删除确认
'
,
'
确定要删除此系统配置信息吗?
'
,
function
(
r
)
{
}
if
(
row
.
length
>
0
)
{
$
.
messager
.
confirm
(
'
删除确认
'
,
'
确定要删除选中的
'
+
row
.
length
+
'
条系统配置信息吗?
'
,
function
(
r
)
{
if
(
r
)
{
var
ids
=
""
;
for
(
var
i
=
0
;
i
<
row
.
length
;
i
++
)
{
if
(
i
==
row
.
length
-
1
)
{
ids
+=
row
[
i
].
id
;
break
;
}
ids
+=
row
[
i
].
id
+
"
,
"
;
}
$
.
ajax
({
type
:
"
post
"
,
url
:
"
/systemConfig/batchDeleteSystemConfigByIds
"
,
dataType
:
"
json
"
,
async
:
false
,
data
:
({
ids
:
systemConfigId
ids
:
ids
}),
success
:
function
(
res
)
{
if
(
res
&&
res
.
code
==
200
)
{
if
(
res
&&
res
.
code
==
=
200
)
{
$
(
"
#searchBtn
"
).
click
();
$
(
"
:checkbox
"
).
attr
(
"
checked
"
,
false
);
}
else
if
(
res
.
code
===
-
1
)
{
$
.
messager
.
alert
(
'
提示
'
,
'
演示用户禁止操作!
'
,
'
warning
'
);
}
else
{
$
.
messager
.
alert
(
'
删除提示
'
,
'
删除系统配置信息失败,请稍后再试!
'
,
'
error
'
);
}
...
...
@@ -276,55 +321,6 @@
}
}
//批量删除系统配置
function
batDeleteSystemConfig
()
{
if
(
checkIsTestUser
())
{
return
;
}
else
{
var
row
=
$
(
'
#tableData
'
).
datagrid
(
'
getChecked
'
);
if
(
row
.
length
==
0
)
{
$
.
messager
.
alert
(
'
删除提示
'
,
'
没有记录被选中!
'
,
'
warning
'
);
return
;
}
if
(
row
.
length
>
0
)
{
$
.
messager
.
confirm
(
'
删除确认
'
,
'
确定要删除选中的
'
+
row
.
length
+
'
条系统配置信息吗?
'
,
function
(
r
)
{
if
(
r
)
{
var
ids
=
""
;
for
(
var
i
=
0
;
i
<
row
.
length
;
i
++
)
{
if
(
i
==
row
.
length
-
1
)
{
ids
+=
row
[
i
].
id
;
break
;
}
ids
+=
row
[
i
].
id
+
"
,
"
;
}
$
.
ajax
({
type
:
"
post
"
,
url
:
"
/systemConfig/batchDeleteSystemConfigByIds
"
,
dataType
:
"
json
"
,
async
:
false
,
data
:
({
ids
:
ids
}),
success
:
function
(
res
)
{
if
(
res
&&
res
.
code
===
200
)
{
$
(
"
#searchBtn
"
).
click
();
$
(
"
:checkbox
"
).
attr
(
"
checked
"
,
false
);
}
else
{
$
.
messager
.
alert
(
'
删除提示
'
,
'
删除系统配置信息失败,请稍后再试!
'
,
'
error
'
);
}
},
//此处添加错误处理
error
:
function
()
{
$
.
messager
.
alert
(
'
删除提示
'
,
'
删除系统配置信息异常,请稍后再试!
'
,
'
error
'
);
return
;
}
});
}
});
}
}
}
//增加系统配置
var
url
;
var
systemConfigId
=
0
;
...
...
@@ -353,9 +349,6 @@
//保存系统配置信息
$
(
"
#saveSystemConfig
"
).
off
(
"
click
"
).
on
(
"
click
"
,
function
()
{
if
(
checkIsTestUser
())
{
return
;
}
if
(
checkCompanyName
())
{
return
;
}
...
...
@@ -377,11 +370,15 @@
info
:
JSON
.
stringify
(
infoObj
)
},
success
:
function
(
res
)
{
if
(
res
&&
res
.
code
===
200
)
{
$
(
'
#systemConfigDlg
'
).
dialog
(
'
close
'
);
//加载完以后重新初始化
var
opts
=
$
(
"
#tableData
"
).
datagrid
(
'
options
'
);
showSystemConfigDetails
(
opts
.
pageNumber
,
opts
.
pageSize
);
if
(
res
)
{
if
(
res
.
code
===
200
)
{
$
(
'
#systemConfigDlg
'
).
dialog
(
'
close
'
);
//加载完以后重新初始化
var
opts
=
$
(
"
#tableData
"
).
datagrid
(
'
options
'
);
showSystemConfigDetails
(
opts
.
pageNumber
,
opts
.
pageSize
);
}
else
if
(
res
.
code
===
-
1
)
{
$
.
messager
.
alert
(
'
提示
'
,
'
演示用户禁止操作!
'
,
'
warning
'
);
}
}
},
//此处添加错误处理
...
...
src/main/java/com/jsh/erp/constants/ExceptionConstants.java
View file @
1ea88a2e
...
...
@@ -385,6 +385,10 @@ public class ExceptionConstants {
public
static
final
int
ORGA_USER_REL_EDIT_FAILED_CODE
=
11500002
;
public
static
final
String
ORGA_USER_REL_EDIT_FAILED_MSG
=
"修改机构用户关联关系失败"
;
//演示用户禁止操作
public
static
final
int
SYSTEM_CONFIG_TEST_USER_CODE
=
-
1
;
public
static
final
String
SYSTEM_CONFIG_TEST_USER_MSG
=
"演示用户禁止操作"
;
/**
* 标准正常返回/操作成功返回
...
...
src/main/java/com/jsh/erp/controller/ResourceController.java
View file @
1ea88a2e
...
...
@@ -82,6 +82,8 @@ public class ResourceController {
int
insert
=
configResourceManager
.
insert
(
apiName
,
beanJson
,
request
);
if
(
insert
>
0
)
{
return
returnJson
(
objectMap
,
ErpInfo
.
OK
.
name
,
ErpInfo
.
OK
.
code
);
}
else
if
(
insert
==
-
1
)
{
return
returnJson
(
objectMap
,
ErpInfo
.
TEST_USER
.
name
,
ErpInfo
.
TEST_USER
.
code
);
}
else
{
return
returnJson
(
objectMap
,
ErpInfo
.
ERROR
.
name
,
ErpInfo
.
ERROR
.
code
);
}
...
...
@@ -95,6 +97,8 @@ public class ResourceController {
int
update
=
configResourceManager
.
update
(
apiName
,
beanJson
,
id
,
request
);
if
(
update
>
0
)
{
return
returnJson
(
objectMap
,
ErpInfo
.
OK
.
name
,
ErpInfo
.
OK
.
code
);
}
else
if
(
update
==
-
1
)
{
return
returnJson
(
objectMap
,
ErpInfo
.
TEST_USER
.
name
,
ErpInfo
.
TEST_USER
.
code
);
}
else
{
return
returnJson
(
objectMap
,
ErpInfo
.
ERROR
.
name
,
ErpInfo
.
ERROR
.
code
);
}
...
...
src/main/java/com/jsh/erp/controller/SystemConfigController.java
View file @
1ea88a2e
...
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.service.systemConfig.SystemConfigService
;
import
com.jsh.erp.service.user.UserService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -21,21 +22,30 @@ import javax.annotation.Resource;
@RequestMapping
(
value
=
"/systemConfig"
)
public
class
SystemConfigController
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SystemConfigController
.
class
);
@Resource
private
SystemConfigService
systemConfigService
;
@Resource
private
UserService
userService
;
/**
* 批量删除系统配置信息
*/
@RequestMapping
(
value
=
"/batchDeleteSystemConfigByIds"
)
public
Object
batchDeleteSystemConfigByIds
(
@RequestParam
(
"ids"
)
String
ids
)
throws
Exception
{
JSONObject
result
=
ExceptionConstants
.
standardSuccess
();
int
i
=
systemConfigService
.
batchDeleteSystemConfigByIds
(
ids
);
if
(
i
<
1
){
logger
.
error
(
"异常码[{}],异常提示[{}],参数,ids[{}]"
,
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_CODE
,
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_MSG
,
ids
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_CODE
,
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_MSG
);
int
i
=
0
;
if
(
userService
.
checkIsTestUser
())
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
SYSTEM_CONFIG_TEST_USER_CODE
,
ExceptionConstants
.
SYSTEM_CONFIG_TEST_USER_MSG
);
}
else
{
i
=
systemConfigService
.
batchDeleteSystemConfigByIds
(
ids
);
if
(
i
<
1
){
logger
.
error
(
"异常码[{}],异常提示[{}],参数,ids[{}]"
,
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_CODE
,
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_MSG
,
ids
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_CODE
,
ExceptionConstants
.
SYSTEM_CONFIG_DELETE_FAILED_MSG
);
}
}
return
result
;
}
...
...
src/main/java/com/jsh/erp/controller/UserController.java
View file @
1ea88a2e
...
...
@@ -43,9 +43,6 @@ public class UserController {
@Value
(
"${manage.roleId}"
)
private
Integer
manageRoleId
;
@Value
(
"${demonstrate.open}"
)
private
boolean
demonstrateOpen
;
@Resource
private
UserService
userService
;
...
...
@@ -59,27 +56,6 @@ public class UserController {
private
static
final
String
HTTP
=
"http://"
;
private
static
final
String
CODE_OK
=
"200"
;
/**
* 是否开启演示状态,默认关闭
* @param request
* @return
*/
@GetMapping
(
value
=
"/getDemonstrateOpen"
)
public
BaseResponseInfo
getDemonstrateOpen
(
HttpServletRequest
request
)
{
BaseResponseInfo
res
=
new
BaseResponseInfo
();
try
{
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
data
.
put
(
"demonstrateOpen"
,
demonstrateOpen
);
res
.
code
=
200
;
res
.
data
=
data
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
res
.
code
=
500
;
res
.
data
=
"获取失败"
;
}
return
res
;
}
@PostMapping
(
value
=
"/login"
)
public
BaseResponseInfo
login
(
@RequestParam
(
value
=
"loginName"
,
required
=
false
)
String
loginName
,
@RequestParam
(
value
=
"password"
,
required
=
false
)
String
password
,
...
...
src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java
View file @
1ea88a2e
...
...
@@ -86,9 +86,13 @@ public class SystemConfigService {
SystemConfig
systemConfig
=
JSONObject
.
parseObject
(
beanJson
,
SystemConfig
.
class
);
int
result
=
0
;
try
{
result
=
systemConfigMapper
.
insertSelective
(
systemConfig
);
logService
.
insertLog
(
"系统配置"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
systemConfig
.
getCompanyName
()).
toString
(),
request
);
if
(
userService
.
checkIsTestUser
())
{
result
=-
1
;
}
else
{
result
=
systemConfigMapper
.
insertSelective
(
systemConfig
);
logService
.
insertLog
(
"系统配置"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
systemConfig
.
getCompanyName
()).
toString
(),
request
);
}
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
...
...
@@ -101,9 +105,13 @@ public class SystemConfigService {
systemConfig
.
setId
(
id
);
int
result
=
0
;
try
{
result
=
systemConfigMapper
.
updateByPrimaryKeySelective
(
systemConfig
);
logService
.
insertLog
(
"系统配置"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
systemConfig
.
getCompanyName
()).
toString
(),
request
);
if
(
userService
.
checkIsTestUser
())
{
result
=-
1
;
}
else
{
result
=
systemConfigMapper
.
updateByPrimaryKeySelective
(
systemConfig
);
logService
.
insertLog
(
"系统配置"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
systemConfig
.
getCompanyName
()).
toString
(),
request
);
}
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
...
...
src/main/java/com/jsh/erp/service/user/UserService.java
View file @
1ea88a2e
...
...
@@ -23,6 +23,7 @@ import com.jsh.erp.utils.StringUtil;
import
com.jsh.erp.utils.Tools
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
...
...
@@ -39,6 +40,12 @@ import java.util.Objects;
@Service
public
class
UserService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
UserService
.
class
);
private
static
final
String
TEST_USER
=
"jsh"
;
@Value
(
"${demonstrate.open}"
)
private
boolean
demonstrateOpen
;
@Resource
private
UserMapper
userMapper
;
...
...
@@ -55,7 +62,6 @@ public class UserService {
@Resource
private
UserBusinessService
userBusinessService
;
public
User
getUser
(
long
id
)
throws
Exception
{
User
result
=
null
;
try
{
...
...
@@ -314,6 +320,25 @@ public class UserService {
return
(
User
)
request
.
getSession
().
getAttribute
(
"user"
);
}
/**
* 检查当前用户是否是演示用户
* @return
*/
public
Boolean
checkIsTestUser
()
throws
Exception
{
Boolean
result
=
false
;
try
{
if
(
demonstrateOpen
)
{
User
user
=
getCurrentUser
();
if
(
TEST_USER
.
equals
(
user
.
getLoginName
()))
{
result
=
true
;
}
}
}
catch
(
Exception
e
)
{
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
/**
* 根据用户名查询id
* @param loginName
...
...
src/main/java/com/jsh/erp/utils/ErpInfo.java
View file @
1ea88a2e
...
...
@@ -13,7 +13,8 @@ public enum ErpInfo {
WARING_MSG
(
201
,
"提醒信息"
),
REDIRECT
(
301
,
"session失效,重定向"
),
FORWARD_REDIRECT
(
302
,
"转发请求session失效"
),
FORWARD_FAILED
(
303
,
"转发请求失败!"
);
FORWARD_FAILED
(
303
,
"转发请求失败!"
),
TEST_USER
(-
1
,
"演示用户禁止操作"
);
public
final
int
code
;
public
final
String
name
;
...
...
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