| | |
| | | AccountDTO accountDTO = new AccountDTO(); |
| | | //取参 |
| | | ManageAccount manageAccount = accountInsertForm.formConvertEntity(); |
| | | List<String> roleIdsStr = accountInsertForm.getRoleIds(); |
| | | List<Integer> roleIds = accountInsertForm.getRoleIds(); |
| | | |
| | | /*判断账号是否存在*/ |
| | | ManageAccount existAccount = new ManageAccount(); |
| | |
| | | //插入 |
| | | manageAccountMapper.insert(manageAccount); |
| | | |
| | | //封装account_role |
| | | /*String to Integer*/ |
| | | List<ManageRole> roles = null; |
| | | //如果新建账号没有分配角色则不进行操作 |
| | | if (!ObjectUtils.isEmpty(roleIdsStr)) { |
| | | List<Integer> roleIds = new ArrayList<>(); |
| | | roleIdsStr.forEach(str -> roleIds.add(Integer.parseInt(str))); |
| | | |
| | | if (!ObjectUtils.isEmpty(roleIds)) { |
| | | Integer accountId = manageAccount.getId(); |
| | | roleIdsStr.forEach( |
| | | roleIds.forEach( |
| | | value -> { |
| | | ManageAccountRole manageAccountRole = new ManageAccountRole(); |
| | | manageAccountRole.setAccountId(accountId); |
| | | manageAccountRole.setRoleId(Integer.parseInt(value)); |
| | | manageAccountRole.setRoleId(value); |
| | | manageAccountRoleMapper.insert(manageAccountRole); |
| | | } |
| | | ); |
| | | roles = manageRoleMapper.selectBatchIds(roleIds); |
| | | } |
| | | //封装返回结果 |
| | | accountDTO.setAccount(manageAccount); |
| | | accountDTO.setRoles(roles); |
| | | accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | | |
| | |
| | | AccountDTO accountDTO = new AccountDTO(); |
| | | //取参 |
| | | Integer accountId = accountDeleteForm.getAccountId(); |
| | | //查询是否存在 |
| | | //查询要删除的账号,用于插入日志 |
| | | ManageAccount manageAccount = new ManageAccount(); |
| | | manageAccount.setIsDelete(Constants.NOT_DELETE); |
| | | manageAccount.setId(accountId); |
| | |
| | | //封装返回结果 |
| | | accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | | accountDTO.setAccount(existManageAccount); |
| | | |
| | | //操作插入日志 |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("删除了用户:").append(existManageAccount.getUserName() + ";") |
| | | .append("账号:" + existManageAccount.getAccount() + ";"); |
| | | .append("账号:" + existManageAccount.getAccount() + ";"); |
| | | logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); |
| | | |
| | | return accountDTO; |
| | |
| | | if (manageAccountMap.size() > 1) {//判断如果没有除了id以外的任何属性则不更新 |
| | | manageAccountMapper.updateById(manageAccount); |
| | | } |
| | | //获取更新后的对象 |
| | | manageAccount = manageAccountMapper.selectById(manageAccount.getId()); |
| | | |
| | | //获取账号更新前的角色 |
| | | List<ManageRole> oldRoles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); |
| | | |
| | |
| | | * 如果roleIds为空,则是该账号所有的角色都被移除 |
| | | * 如果roleIds有元素,则是该账号的角色有更新 |
| | | * */ |
| | | List<ManageRole> roles = null; |
| | | if (roleIds != null) { |
| | | //删除原有角色 |
| | | UpdateWrapper<ManageAccountRole> deleteWrapper = new UpdateWrapper<>(); |
| | | deleteWrapper.eq("account_id", manageAccount.getId()).set("is_delete", Constants.DELETE); |
| | | manageAccountRoleMapper.update(null, deleteWrapper); |
| | |
| | | manageAccountRole.setRoleId(roleId); |
| | | manageAccountRoleMapper.insert(manageAccountRole); |
| | | } |
| | | //获取用户所有角色 |
| | | if (roleIds.size() != 0) |
| | | roles = manageRoleMapper.selectBatchIds(roleIds); |
| | | } else { |
| | | roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); |
| | | } |
| | | accountDTO.setRoles(roles); |
| | | //封装返回结果 |
| | | accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | | accountDTO.setAccount(manageAccount); |
| | | |
| | | //操作插入日志 |
| | | insertUpdateLog(accountUpdateForm, oldManageAccount, oldRoles); |
| | | |
| | | return accountDTO; |
| | | } |
| | | |
| | |
| | | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
| | | StringBuilder content = new StringBuilder(); |
| | | content.append("修改了用户:").append(oldAccount.getUserName() + ";") |
| | | .append("账号:" + oldAccount.getAccount() + ";"); |
| | | .append("账号:" + oldAccount.getAccount() + ";"); |
| | | //对象转为Map,获取对象更新前后的属性 |
| | | Map<String, Object> newParameters = JSONObject.parseObject(JSON.toJSONString(updateForm), Map.class); |
| | | Map<String, Object> oldParameters = JSONObject.parseObject(JSON.toJSONString(oldAccount), Map.class); |
| | |
| | | List<Integer> newRoleIds = updateForm.getRoleIds(); |
| | | |
| | | if (newRoleIds != null && 0 == newRoleIds.size()) {//如果新的角色集合为空,则是删除了所有的角色 |
| | | content.append("删除了所有角色;"); |
| | | content.append("角色:删除了所有角色;"); |
| | | } |
| | | if ((newRoleIds != null) && (newRoleIds.size() != 0)) {//如果新的角色集合不为空,且不为null,则角色进行了更新 |
| | | StringBuilder oldRolesName = new StringBuilder("空"); |