V3.4.3删除用户bug
当添加用户登录系统后,就会产生外键关键删除报错情况,查看了下,是用户主键关联了日志表(t_s_log)造成的。手动删除相关用户的日志,即可顺利删除用户。/**
* 用户信息录入和更新
*
* @param user
* @param req
* @return
*/
@RequestMapping(params = "del")
@ResponseBody
public AjaxJson del(TSUser user, HttpServletRequest req) {
AjaxJson j = new AjaxJson();
if ("admin".equals(user.getUserName())) {
message = "超级管理员不可删除";
j.setMsg(message);
return j;
}
user = systemService.getEntity(TSUser.class, user.getId());
List<TSRoleUser> roleUser = systemService.findByProperty(TSRoleUser.class,
"TSUser.id",
user.getId());
List<TSLog> logUser = systemService.findByProperty(TSLog.class, "TSUser.id", user.getId());
if (!user.getStatus().equals(Globals.User_ADMIN)) {
if (roleUser.size() > 0) {
// 删除用户时先删除用户和角色关系表
delRoleUser(user);
userService.delete(user);
message = "用户:" + user.getUserName() + "删除成功";
systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
} else if (logUser.size() > 0) {
// 删除用户时先删除用户日志
delLogUser(user);
userService.delete(user);
message = "用户:" + user.getUserName() + "删除成功";
systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
} else {
userService.delete(user);
message = "用户:" + user.getUserName() + "删除成功";
}
} else {
message = "超级管理员不可删除";
}
j.setMsg(message);
return j;
}
// 同步删除用户角色关联表
public void delRoleUser(TSUser user) {
List<TSRoleUser> roleUserList = systemService.findByProperty(TSRoleUser.class,
"TSUser.id",
user.getId());
if (roleUserList.size() >= 1) {
for (TSRoleUser tRoleUser : roleUserList) {
systemService.delete(tRoleUser);
}
}
}
// 同步删除用户关联日志
public void delLogUser(TSUser user) {
List<TSLog> logUserLisst = systemService.findByProperty(TSLog.class,
"TSUser.id",
user.getId());
if (logUserLisst.size() >= 1) {
for (TSLog tSLog : logUserLisst) {
systemService.delete(tSLog);
}
}
} 我修复了这个bug,代码贴在上方了,请更新UserController.java这个文件,Good luck:D 楼主英明 不对,操作日志不能删除。要保留
页:
[1]