magic-boot/data/magic-api/api/系统管理/用户管理/保存.ms

76 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2021-10-24 20:09:53 +08:00
{
"properties" : { },
"id" : "877918736c764253a85d0780cbd5f763",
"script" : null,
"groupId" : "4f0230049d7e4f39b1e0897cc0f46f9a",
"name" : "保存",
"createTime" : null,
"updateTime" : 1646493559668,
2021-10-24 20:09:53 +08:00
"lock" : "0",
"createBy" : null,
"updateBy" : null,
2021-10-24 20:09:53 +08:00
"path" : "/save",
"method" : "POST",
2021-10-24 20:09:53 +08:00
"parameters" : [ ],
"options" : [ {
"name" : "permission",
"value" : "user:save",
"description" : "允许拥有该权限的访问",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ],
2022-02-06 12:34:56 +08:00
"requestBody" : "{\n\n}",
2021-10-24 20:09:53 +08:00
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
},
"responseBodyDefinition" : null
2021-10-24 20:09:53 +08:00
}
================================
2022-02-01 18:26:42 +08:00
import cn.dev33.satoken.secure.SaSecureUtil;
import org.ssssssss.magicapi.modules.db.cache.SqlCache
2021-10-24 20:09:53 +08:00
2022-02-05 17:20:12 +08:00
var usernameCount = db.selectInt("select count(1) from sys_user where is_del = 0 and username = #{username} ?{id, and id != #{id}}")
if(usernameCount > 0){
exit 0,'登录名称已存在'
}
2022-01-04 14:56:52 +08:00
password = password ? SaSecureUtil.sha256(password) : ''
2021-10-24 20:09:53 +08:00
var user = {
id,
name,
username,
2022-01-04 14:56:52 +08:00
password: password,
2021-10-24 20:09:53 +08:00
phone,
2022-01-13 23:29:56 +08:00
isLogin,
officeId
2021-10-24 20:09:53 +08:00
}
if(id){
2022-01-04 14:56:52 +08:00
SqlCache.delete(`permissions:${id}`)
2021-10-24 20:09:53 +08:00
db.update("""
delete from sys_user_role where user_id = #{id}
""")
}
id = db.table("sys_user").primary("id").saveOrUpdate(user)
for(roleId in roles.split(',')){
2022-01-04 14:56:52 +08:00
db.table("sys_user_role").column('user_id', id).column("role_id", roleId).insert()
2021-10-24 20:09:53 +08:00
}