*/
@RequestMapping(params = "saveUser")
@ResponseBody
public AjaxJson saveUser(HttpServletRequest req, TSUser user) {
AjaxJson j = new AjaxJson();
// 得到用户的角色
String roleid = oConvertUtils.getString(req.getParameter("roleid"));
String password = oConvertUtils.getString(req.getParameter("password"));
if (StringUtil.isNotEmpty(user.getId())) {
TSUser users = systemService.getEntity(TSUser.class, user.getId());
users.setEmail(user.getEmail());
users.setOfficePhone(user.getOfficePhone());
users.setMobilePhone(user.getMobilePhone());
users.setTSDepart(user.getTSDepart());
users.setRealName(user.getRealName());
users.setStatus(Globals.User_Normal);
users.setActivitiSync(user.getActivitiSync());
systemService.updateEntitie(users);
List<TSRoleUser> ru = systemService.findByProperty(TSRoleUser.class, "TSUser.id", user.getId());
systemService.deleteAllEntitie(ru);
message = "用户: " + users.getUserName() + "更新成功";
if (StringUtil.isNotEmpty(roleid)) {
saveRoleUser(users, roleid);
}
systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
} else {
TSUser users = systemService.findUniqueByProperty(TSUser.class, "userName",user.getUserName());
if (users != null) {
message = "用户: " + users.getUserName() + "已经存在";
} else {
user.setPassword(PasswordUtil.encrypt(user.getUserName(), password, PasswordUtil.getStaticSalt()));
if (user.getTSDepart().equals("")) {
user.setTSDepart(null);
}
user.setStatus(Globals.User_Normal);
systemService.save(user);
message = "用户: " + user.getUserName() + "添加成功";
if (StringUtil.isNotEmpty(roleid)) {
saveRoleUser(user, roleid);
}
systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
}
}
j.setMsg(message);
return j;
}