@ResponseBody @RequestMapping("addEntity") @SystemLog(module = "系统管理", methods = "用户管理-新增用户") // 凡需要处理业务逻辑的,都需要记录操作日志 @Transactional(readOnly = false) // 需要事务操作必须加入此注解 public String addEntity(String txtGroupsSelect) { try { UserFormMap userFormMap = getFormMap(UserFormMap.class); userFormMap.put("txtGroupsSelect", txtGroupsSelect); PasswordHelper passwordHelper = new PasswordHelper(); userFormMap.set("password", "123456789"); passwordHelper.encryptPassword(userFormMap); userMapper.addEntity(userFormMap); // 新增后返回新增信息 if (!Common.isEmpty(txtGroupsSelect)) { String[] txt = txtGroupsSelect.split(","); UserRoleFormMap userRoleFormMap = new UserRoleFormMap(); for (String roleId : txt) { userRoleFormMap.put("userId", userFormMap.get("id")); userRoleFormMap.put("roleId", roleId); userMapper.addEntity(userRoleFormMap); } } } catch (Exception e) { logger.error("添加账号异常", e); throw new SystemException("添加账号异常"); } return Constant.SUCCESS; }
@RequestMapping("editUI") public String editUI(Model model) throws Exception { String id = getParam("id"); if (Common.isNotEmpty(id)) { model.addAttribute("user", userMapper.findByFirst("id", id, UserFormMap.class)); } return Common.BACKGROUND_PATH + "/system/user/edit"; }
@ResponseBody @RequestMapping("editEntity") @Transactional(readOnly = false) @SystemLog(module = "系统管理", methods = "用户管理-修改用户") public String editEntity(String txtGroupsSelect) throws Exception { UserFormMap userFormMap = getFormMap(UserFormMap.class); userFormMap.put("txtGroupsSelect", txtGroupsSelect); userMapper.deleteByAttribute("userId", userFormMap.getStr("id"), UserRoleFormMap.class); userMapper.editEntity(userFormMap); if (!Common.isEmpty(txtGroupsSelect)) { String[] txt = txtGroupsSelect.split(","); for (String roleId : txt) { UserRoleFormMap userRoleFormMap = new UserRoleFormMap(); userRoleFormMap.put("userId", userFormMap.get("id")); userRoleFormMap.put("roleId", roleId); userMapper.addEntity(userRoleFormMap); } } return Constant.SUCCESS; }