|
|
|
@ -256,6 +256,41 @@ public class SysUserController { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/adddep", method = RequestMethod.POST) |
|
|
|
|
public Result<SysUser> adddep(@RequestBody JSONObject jsonObject) { |
|
|
|
|
Result<SysUser> result = new Result<SysUser>(); |
|
|
|
|
String selectedRoles = jsonObject.getString("selectedroles"); |
|
|
|
|
String selectedDeparts = jsonObject.getString("selecteddeparts"); |
|
|
|
|
try { |
|
|
|
|
boolean rs=sysUserService.isDepCode(selectedDeparts); |
|
|
|
|
if(!rs) |
|
|
|
|
{ |
|
|
|
|
result.error500("不能添加非院系用户"); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class); |
|
|
|
|
user.setCreateTime(new Date());//设置创建时间
|
|
|
|
|
String salt = oConvertUtils.randomGen(8); |
|
|
|
|
user.setSalt(salt); |
|
|
|
|
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt); |
|
|
|
|
user.setPassword(passwordEncode); |
|
|
|
|
user.setStatus(1); |
|
|
|
|
user.setDelFlag(CommonConstant.DEL_FLAG_0); |
|
|
|
|
//用户表字段org_code不能在这里设置他的值
|
|
|
|
|
user.setOrgCode(null); |
|
|
|
|
// 保存用户走一个service 保证事务
|
|
|
|
|
//获取租户ids
|
|
|
|
|
String relTenantIds = jsonObject.getString("relTenantIds"); |
|
|
|
|
sysUserService.saveUser(user, selectedRoles, selectedDeparts, relTenantIds); |
|
|
|
|
baseCommonService.addLog("添加用户,username: " +user.getUsername() ,CommonConstant.LOG_TYPE_2, 2); |
|
|
|
|
result.success("添加成功!"); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
result.error500("操作失败"); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//@RequiresPermissions("system:user:edit")
|
|
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
|
|
|
|
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) { |
|
|
|
@ -291,6 +326,47 @@ public class SysUserController { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//@RequiresPermissions("system:user:edit")
|
|
|
|
|
@RequestMapping(value = "/editdep", method = {RequestMethod.PUT,RequestMethod.POST}) |
|
|
|
|
public Result<SysUser> editdep(@RequestBody JSONObject jsonObject) { |
|
|
|
|
Result<SysUser> result = new Result<SysUser>(); |
|
|
|
|
try { |
|
|
|
|
SysUser sysUser = sysUserService.getById(jsonObject.getString("id")); |
|
|
|
|
baseCommonService.addLog("编辑用户,username: " +sysUser.getUsername() ,CommonConstant.LOG_TYPE_2, 2); |
|
|
|
|
if(sysUser==null) { |
|
|
|
|
result.error500("未找到对应实体"); |
|
|
|
|
}else { |
|
|
|
|
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class); |
|
|
|
|
user.setUpdateTime(new Date()); |
|
|
|
|
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
|
|
|
|
|
user.setPassword(sysUser.getPassword()); |
|
|
|
|
String roles = jsonObject.getString("selectedroles"); |
|
|
|
|
String departs = jsonObject.getString("selecteddeparts"); |
|
|
|
|
boolean rs=sysUserService.isDepCode(departs); |
|
|
|
|
if(!rs) |
|
|
|
|
{ |
|
|
|
|
result.error500("不能添加非院系用户"); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
if(oConvertUtils.isEmpty(departs)){ |
|
|
|
|
//vue3.0前端只传递了departIds
|
|
|
|
|
departs=user.getDepartIds(); |
|
|
|
|
} |
|
|
|
|
//用户表字段org_code不能在这里设置他的值
|
|
|
|
|
user.setOrgCode(null); |
|
|
|
|
// 修改用户走一个service 保证事务
|
|
|
|
|
//获取租户ids
|
|
|
|
|
String relTenantIds = jsonObject.getString("relTenantIds"); |
|
|
|
|
sysUserService.editUser(user, roles, departs, relTenantIds); |
|
|
|
|
result.success("修改成功!"); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
result.error500("操作失败"); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除用户 |
|
|
|
|
*/ |
|
|
|
|