From 7232a74d17635defd5e7e39fb7a8892f12fa3931 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Thu, 06 May 2021 17:50:21 +0800 Subject: [PATCH] screen-manage 优化后台账号增加,更新,删除逻辑 --- screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java | 41 ++++++++++------------------------------- 1 files changed, 10 insertions(+), 31 deletions(-) diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java index 5bfa013..f01c6b1 100644 --- a/screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java +++ b/screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java @@ -175,7 +175,7 @@ AccountDTO accountDTO = new AccountDTO(); //������ ManageAccount manageAccount = accountInsertForm.formConvertEntity(); - List<String> roleIdsStr = accountInsertForm.getRoleIds(); + List<Integer> roleIds = accountInsertForm.getRoleIds(); /*������������������������*/ ManageAccount existAccount = new ManageAccount(); @@ -193,28 +193,19 @@ //������ 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()); @@ -314,7 +305,7 @@ AccountDTO accountDTO = new AccountDTO(); //������ Integer accountId = accountDeleteForm.getAccountId(); - //������������������ + //��������������������������������������������� ManageAccount manageAccount = new ManageAccount(); manageAccount.setIsDelete(Constants.NOT_DELETE); manageAccount.setId(accountId); @@ -338,13 +329,11 @@ //������������������ 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; @@ -383,8 +372,7 @@ if (manageAccountMap.size() > 1) {//������������������������id��������������������������������� manageAccountMapper.updateById(manageAccount); } - //������������������������ - manageAccount = manageAccountMapper.selectById(manageAccount.getId()); + //������������������������������ List<ManageRole> oldRoles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); @@ -394,8 +382,8 @@ * ������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); @@ -406,21 +394,12 @@ 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; } @@ -436,7 +415,7 @@ 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); @@ -452,7 +431,7 @@ 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("���"); -- Gitblit v1.8.0