From f342a0d88b2a7168f794d0cf545d16a3138acb6d Mon Sep 17 00:00:00 2001 From: wuqiping <wuqiping@qq.com> Date: Wed, 09 Jun 2021 15:55:33 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java | 117 +++++++++++++++------------------------------------------- 1 files changed, 30 insertions(+), 87 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 2076867..dcc9e60 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 @@ -11,10 +11,9 @@ import com.moral.api.entity.ManageRole; import com.moral.api.mapper.ManageAccountMapper; import com.moral.api.mapper.ManageAccountRoleMapper; -import com.moral.api.mapper.ManageMenuMapper; import com.moral.api.mapper.ManageRoleMapper; import com.moral.api.pojo.dto.account.*; -import com.moral.api.pojo.dto.login.AccountInfoDTO; +import com.moral.api.pojo.redisBean.AccountInfoDTO; import com.moral.api.pojo.dto.login.LoginDTO; import com.moral.api.pojo.form.account.AccountDeleteForm; import com.moral.api.pojo.form.account.AccountInsertForm; @@ -40,6 +39,7 @@ import javax.servlet.http.HttpServletRequest; import java.util.*; +import java.util.function.Predicate; /** * <p> @@ -89,21 +89,10 @@ //������������������ QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); wrapper.eq("account", account); - List<ManageAccount> manageAccounts = manageAccountMapper.selectList(wrapper); - if (ObjectUtils.isEmpty(manageAccounts)) { - loginDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); - loginDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); - return loginDTO; - } - //������������������������ - ManageAccount manageAccount = null; - for (ManageAccount value : manageAccounts) { - if (Constants.NOT_DELETE.equals(value.getIsDelete())) - manageAccount = value; - } - + wrapper.eq("is_delete",Constants.NOT_DELETE); + ManageAccount manageAccount = manageAccountMapper.selectOne(wrapper); if (ObjectUtils.isEmpty(manageAccount)) { - loginDTO.setCode(ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode()); + loginDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); loginDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return loginDTO; } @@ -118,7 +107,7 @@ List<ManageRole> roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); //������������ - List<ManageMenu> menus = null; + List<ManageMenu> menus = new ArrayList<>(); if (!ObjectUtils.isEmpty(roles)) { menus = manageMenuService.getParentChildrenMenusByRoles(roles); } @@ -135,7 +124,6 @@ //������������������ loginDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); loginDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - loginDTO.setAccountInfoDTO(accountInfoDTO); loginDTO.setToken(token); //������������������ @@ -267,9 +255,27 @@ //������������ Page resultPage = manageAccountMapper.selectPage(queryPage, wrapper); - - //��������������������������� List<ManageAccount> accounts = resultPage.getRecords(); + //������������������������������admin������admin��������������������� + AccountInfoDTO accountInfoDTO = (AccountInfoDTO) TokenUtils.getUserInfo(); + List<ManageRole> ownRoles = accountInfoDTO.getRoles(); + boolean ownAdminRole = false; + for (ManageRole ownRole : ownRoles) { + String roleName = ownRole.getName(); + if ("admin".equals(roleName)) + ownAdminRole = true; + } + if (!ownAdminRole) { + accounts.removeIf(new Predicate<ManageAccount>() { + @Override + public boolean test(ManageAccount manageAccount) { + if (manageAccount.getAccount().equals("admin")) + return true; + return false; + } + }); + } + //��������������������������� List<AccountDTO> accountDTOS = new ArrayList<>(); for (ManageAccount manageAccount : accounts) { AccountDTO accountDTO = new AccountDTO(); @@ -354,7 +360,6 @@ AccountDTO accountDTO = new AccountDTO(); //������ ManageAccount manageAccount = accountUpdateForm.formConvertEntity(); - List<Integer> roleIds = accountUpdateForm.getRoleIds(); //������������������������������������������ QueryWrapper<ManageAccount> oldAccountWrapper = new QueryWrapper<>(); @@ -370,40 +375,15 @@ } //������ManageAccount��� - Map manageAccountMap = JSONObject.parseObject(JSON.toJSONString(manageAccount), Map.class);//���������Map��������������������������� - if (manageAccountMap.size() > 1) {//������������������������id��������������������������������� - manageAccountMapper.updateById(manageAccount); - } + manageAccountMapper.updateById(manageAccount); - //������������������������������ - List<ManageRole> oldRoles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); - - //���������������������������������ManageAccountRole��� - /* - * ������roleIds���null������������������������������������������ - * ������roleIds��������������������������������������������������� - * ������roleIds��������������������������������������������� - * */ - if (roleIds != null) { - //������������������ - UpdateWrapper<ManageAccountRole> deleteWrapper = new UpdateWrapper<>(); - deleteWrapper.eq("account_id", manageAccount.getId()).set("is_delete", Constants.DELETE); - manageAccountRoleMapper.update(null, deleteWrapper); - /*������������������*/ - for (Integer roleId : roleIds) { - ManageAccountRole manageAccountRole = new ManageAccountRole(); - manageAccountRole.setAccountId(manageAccount.getId()); - manageAccountRole.setRoleId(roleId); - manageAccountRoleMapper.insert(manageAccountRole); - } - } + //������������������ + insertUpdateLog(accountUpdateForm, oldManageAccount); //������token TokenUtils.destoryToken(manageAccount.getId()); //������������������ accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - //������������������ - insertUpdateLog(accountUpdateForm, oldManageAccount, oldRoles); return accountDTO; } @@ -414,7 +394,7 @@ * @Author: ��������� * @Date: 2021/4/8 */ - private void insertUpdateLog(AccountUpdateForm updateForm, ManageAccount oldAccount, List<ManageRole> oldRoles) { + private void insertUpdateLog(AccountUpdateForm updateForm, ManageAccount oldAccount) { //������������������ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); StringBuilder content = new StringBuilder(); @@ -430,43 +410,6 @@ if ("password".equals(key)) {//������������������������������������������ if (!ObjectUtils.isEmpty(updateForm.getPassword())) {//��������������������������������� content.append("���������������;"); - } - } else if ("roleIds".equals(key)) {//������������������������Id��������������������� - List<Integer> newRoleIds = updateForm.getRoleIds(); - - if (newRoleIds != null && 0 == newRoleIds.size()) {//��������������������������������������������������������������� - content.append("������������������������������;"); - } - if ((newRoleIds != null) && (newRoleIds.size() != 0)) {//���������������������������������������������null��������������������������� - StringBuilder oldRolesName = new StringBuilder("���"); - StringBuilder newRolesName = new StringBuilder("���"); - - List<ManageRole> newRoles = null; - if (!ObjectUtils.isEmpty(updateForm.getRoleIds())) { - newRoles = manageRoleMapper.selectBatchIds(updateForm.getRoleIds()); - } - - if (!ObjectUtils.isEmpty(oldRoles)) { - oldRolesName.deleteCharAt(oldRolesName.length() - 1);//������ "���" - oldRolesName.append("["); - for (ManageRole role : oldRoles) { - oldRolesName.append(role.getName() + ","); - } - oldRolesName.deleteCharAt(oldRolesName.length() - 1);//������������������������ - oldRolesName.append("]"); - } - - if (!ObjectUtils.isEmpty(newRoles)) { - newRolesName.deleteCharAt(newRolesName.length() - 1);//������ "���" - newRolesName.append("["); - for (ManageRole role : newRoles) { - newRolesName.append(role.getName() + ","); - } - newRolesName.deleteCharAt(newRolesName.length() - 1);//������������������������ - newRolesName.append("]"); - } - //������������content - content.append(value + ":" + oldRolesName + "->" + newRolesName + ";"); } } else {//������������������ if (newParameters.get(key) != null) { -- Gitblit v1.8.0