From f9f8f90ac63d6ce3274410d3721b173f40db6e41 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Fri, 25 Aug 2023 14:12:48 +0800 Subject: [PATCH] chore:过滤海城小时数据 --- screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java | 302 ++++++++++++++++++++++++++++--------------------- 1 files changed, 172 insertions(+), 130 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 9d89da3..f62a6f5 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 @@ -1,5 +1,7 @@ package com.moral.api.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -9,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; @@ -24,15 +25,23 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.api.config.mybatis.wrapper.NullFilterWrapper; import com.moral.api.service.ManageMenuService; +import com.moral.api.util.CompareFieldUtils; +import com.moral.api.util.LogUtils; import com.moral.constant.Constants; import com.moral.constant.ResponseCodeEnum; +import com.moral.pojo.CompareFieldResult; import com.moral.util.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.util.*; +import java.util.function.Predicate; /** * <p> @@ -55,14 +64,13 @@ @Autowired ManageAccountRoleMapper manageAccountRoleMapper; - /** - * @Description: ������������ - * @Param: [loginForm] - * @return: com.moral.api.pojo.dto.login.LoginDTO - * @Author: ��������� - * @Date: 2021/3/30 - */ + * @Description: ������������ + * @Param: [loginForm] + * @return: com.moral.api.pojo.dto.login.LoginDTO + * @Author: ��������� + * @Date: 2021/3/30 + */ @Override public LoginDTO login(LoginForm loginForm) { LoginDTO loginDTO = new LoginDTO(); @@ -74,21 +82,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; } @@ -103,7 +100,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); } @@ -116,12 +113,16 @@ //������token ������������������ String token = TokenUtils.getToken(String.valueOf(manageAccount.getId()), accountInfoDTO); - //������������������ loginDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); loginDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - loginDTO.setAccountInfoDTO(accountInfoDTO); loginDTO.setToken(token); + + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + StringBuilder content = new StringBuilder(); + content.append(manageAccount.getUserName()).append("���������������������;"); + LogUtils.saveLoginForManage(request, content.toString(), manageAccount, manageAccount.getUserName()); return loginDTO; } @@ -154,7 +155,7 @@ AccountDTO accountDTO = new AccountDTO(); //������ ManageAccount manageAccount = accountInsertForm.formConvertEntity(); - List<String> roleIdsStr = accountInsertForm.getRoleIds(); + List<Integer> roleIds = accountInsertForm.getRoleIds(); /*������������������������*/ ManageAccount existAccount = new ManageAccount(); @@ -172,28 +173,21 @@ //������ 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); } + //������������������ + insertLog(manageAccount); //������������������ - accountDTO.setAccount(manageAccount); - accountDTO.setRoles(roles); accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return accountDTO; @@ -211,7 +205,7 @@ AccountQueryDTO accountQueryDTO = new AccountQueryDTO(); //������ - Integer pageCount = accountQueryForm.getPage(); + Integer page = accountQueryForm.getPage(); Integer size = accountQueryForm.getSize(); String userName = accountQueryForm.getUserName(); String email = accountQueryForm.getEmail(); @@ -221,10 +215,10 @@ String order = accountQueryForm.getOrder(); String orderType = accountQueryForm.getOrderType(); Date createStartTime = accountQueryForm.getCreateStartTime(); - Date createEndTime = DateUtils.getDateOfDay(accountQueryForm.getCreateEndTime(), 1); + Date createEndTime = accountQueryForm.getCreateEndTime(); //������������������ - Page<ManageAccount> page = new Page<>(pageCount, size); + Page<ManageAccount> queryPage = new Page<>(page, size); NullFilterWrapper<ManageAccount> wrapper = new NullFilterWrapper<>(); wrapper.like("user_name", userName); @@ -246,20 +240,37 @@ wrapper.eq("is_delete", Constants.NOT_DELETE); //������������ - Page resultPage = manageAccountMapper.selectPage(page, wrapper); - - //��������������������������� + Page resultPage = manageAccountMapper.selectPage(queryPage, wrapper); List<ManageAccount> accounts = resultPage.getRecords(); - List<AccountDTO> accountDTOS = new ArrayList<>(); - if (!ObjectUtils.isEmpty(accounts)) { - for (ManageAccount manageAccount : accounts) { - AccountDTO accountDTO = new AccountDTO(); - List<ManageRole> roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); - accountDTO.setRoles(roles); - accountDTO.setAccount(manageAccount); - accountDTOS.add(accountDTO); - } + //������������������������������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(); + List<ManageRole> roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); + accountDTO.setRoles(roles); + accountDTO.setAccount(manageAccount); + accountDTOS.add(accountDTO); + } + //������������������ accountQueryDTO.setAccountDTOS(accountDTOS); @@ -271,6 +282,57 @@ accountQueryDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return accountQueryDTO; + } + + /** + * @Description: ������������������ + * @Param: [accountDeleteRequest] + * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO + * @Author: ��������� + * @Date: 2021/3/16 + */ + @Override + @Transactional + public AccountDTO deleteAccount(AccountDeleteForm accountDeleteForm) { + AccountDTO accountDTO = new AccountDTO(); + //������ + Integer accountId = accountDeleteForm.getAccountId(); + //��������������������������������������������� + ManageAccount manageAccount = new ManageAccount(); + manageAccount.setIsDelete(Constants.NOT_DELETE); + manageAccount.setId(accountId); + QueryWrapper<ManageAccount> queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(manageAccount); + ManageAccount existManageAccount = manageAccountMapper.selectOne(queryWrapper); + if (ObjectUtils.isEmpty(existManageAccount)) { + accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); + accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); + return accountDTO; + } + //��������������������������� + AccountInfoDTO accountInfo = (AccountInfoDTO) TokenUtils.getUserInfo(); + if(accountInfo.getAccount().getId().equals(accountId)){ + accountDTO.setCode(ResponseCodeEnum.CANNOT_DELETE_ONESELF.getCode()); + accountDTO.setMsg(ResponseCodeEnum.CANNOT_DELETE_ONESELF.getMsg()); + return accountDTO; + } + //������������������ + UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>(); + deleteAccountWrapper.eq("id", accountId); + deleteAccountWrapper.set("is_delete", Constants.DELETE); + manageAccountMapper.update(null, deleteAccountWrapper); + //������������������������������ + UpdateWrapper<ManageAccountRole> deleteManageAccountRoleWrapper = new UpdateWrapper<>(); + deleteManageAccountRoleWrapper.set("is_delete", Constants.DELETE).eq("account_id", manageAccount.getId()); + manageAccountRoleMapper.update(null, deleteManageAccountRoleWrapper); + //������token + TokenUtils.destoryToken(accountId); + //������������������ + accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); + //������������������ + deleteLog(existManageAccount); + return accountDTO; } /** @@ -286,16 +348,15 @@ AccountDTO accountDTO = new AccountDTO(); //������ ManageAccount manageAccount = accountUpdateForm.formConvertEntity(); - List<Integer> roleIds = accountUpdateForm.getRoleIds(); - //������������������������������������ - QueryWrapper<ManageAccount> exitWrapper = new QueryWrapper<>(); - ManageAccount exitManageAccount = new ManageAccount(); - exitManageAccount.setId(manageAccount.getId()); - exitManageAccount.setIsDelete(Constants.NOT_DELETE); - exitWrapper.setEntity(exitManageAccount); - List<ManageAccount> manageAccounts = manageAccountMapper.selectList(exitWrapper); - if (ObjectUtils.isEmpty(manageAccounts)) { + //������������������������������������������ + QueryWrapper<ManageAccount> oldAccountWrapper = new QueryWrapper<>(); + ManageAccount oldManageAccount = new ManageAccount(); + oldManageAccount.setId(manageAccount.getId()); + oldManageAccount.setIsDelete(Constants.NOT_DELETE); + oldAccountWrapper.setEntity(oldManageAccount); + oldManageAccount = manageAccountMapper.selectOne(oldAccountWrapper); + if (ObjectUtils.isEmpty(oldManageAccount)) { accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return accountDTO; @@ -303,80 +364,61 @@ //������ManageAccount��� manageAccountMapper.updateById(manageAccount); - - //���������������������������������ManageAccountRole��� - /* - * ������roleIds���null������������������������������������������ - * ������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); - /*������������������*/ - for (Integer roleId : roleIds) { - ManageAccountRole manageAccountRole = new ManageAccountRole(); - manageAccountRole.setAccountId(manageAccount.getId()); - manageAccountRole.setRoleId(roleId); - manageAccountRoleMapper.insert(manageAccountRole); - } - //������������������������ - if (roleIds.size() != 0) - roles = manageRoleMapper.selectBatchIds(roleIds); - } else { - roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); - } - accountDTO.setRoles(roles); + //������������������ + updateLog(oldManageAccount,manageAccount); + //������token + TokenUtils.destoryToken(manageAccount.getId()); //������������������ accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - accountDTO.setAccount(manageAccountMapper.selectById(manageAccount.getId())); return accountDTO; + } + + /** + * @Description: ������������������������ + * @Param: [oldAccount, newAccount] + * @return: void + * @Author: ��������� + * @Date: 2021/8/25 + */ + private void updateLog(ManageAccount oldAccount,ManageAccount newAccount){ + List<CompareFieldResult> results = CompareFieldUtils.compare(ManageAccount.class, oldAccount, newAccount); + StringBuilder content = new StringBuilder("���������������������"+";"); + content.append("���������"+oldAccount.getAccount()+";"); + //������������������ + if(!ObjectUtils.isEmpty(newAccount.getPassword())) + content.append("���������������"); + String resultContent = CompareFieldUtils.resultsConvertContent(results,content.toString()); + LogUtils.saveOperationForManage(resultContent, Constants.UPDATE_OPERATE_TYPE); + } + + /** + * @Description: ������������������������ + * @Param: [account] + * @return: void + * @Author: ��������� + * @Date: 2021/8/25 + */ + private void insertLog(ManageAccount manageAccount){ + StringBuilder content = new StringBuilder(); + content.append("������������������������").append(manageAccount.getUserName() + ";") + .append("account���" + manageAccount.getAccount() + ";"); + LogUtils.saveOperationForManage(content.toString(), Constants.INSERT_OPERATE_TYPE); } /** - * @Description: ������������������ - * @Param: [accountDeleteRequest] - * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO - * @Author: ��������� - * @Date: 2021/3/16 - */ - @Override - @Transactional - public AccountDTO deleteAccount(AccountDeleteForm accountDeleteForm) { - AccountDTO accountDTO = new AccountDTO(); - //������ - Integer accountId = accountDeleteForm.getAccountId(); - //������������������ - ManageAccount manageAccount = new ManageAccount(); - manageAccount.setIsDelete(Constants.NOT_DELETE); - manageAccount.setId(accountId); - QueryWrapper<ManageAccount> queryWrapper = new QueryWrapper<>(); - queryWrapper.setEntity(manageAccount); - ManageAccount existManageAccount = manageAccountMapper.selectOne(queryWrapper); - if (ObjectUtils.isEmpty(existManageAccount)) { - accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); - accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); - return accountDTO; - } - //������������������ - UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>(); - deleteAccountWrapper.eq("id", accountId); - deleteAccountWrapper.set("is_delete", Constants.DELETE); - manageAccountMapper.update(null, deleteAccountWrapper); - //������������������������������ - UpdateWrapper<ManageAccountRole> deleteManageAccountRoleWrapper = new UpdateWrapper<>(); - deleteManageAccountRoleWrapper.set("is_delete", Constants.DELETE).eq("account_id", manageAccount.getId()); - manageAccountRoleMapper.update(null, deleteManageAccountRoleWrapper); - //������������������ - accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); - accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - accountDTO.setAccount(existManageAccount); - return accountDTO; + * @Description: ������������������������ + * @Param: [manageAccount] + * @return: void + * @Author: ��������� + * @Date: 2021/8/25 + */ + private void deleteLog(ManageAccount manageAccount){ + StringBuilder content = new StringBuilder(); + content.append("������������������").append(manageAccount.getUserName() + ";") + .append("������:" + manageAccount.getAccount() + ";"); + LogUtils.saveOperationForManage( content.toString(), Constants.DELETE_OPERATE_TYPE); } - - } + -- Gitblit v1.8.0