From a5b27c528bb73886ccc6b97ea1262b9d7f403cca Mon Sep 17 00:00:00 2001 From: lizijie <lzjiiie@163.com> Date: Wed, 12 May 2021 17:50:11 +0800 Subject: [PATCH] 站点文件提交 --- screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java | 297 ++++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 200 insertions(+), 97 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..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 @@ -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; @@ -24,14 +26,19 @@ 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.LogUtils; import com.moral.constant.Constants; import com.moral.constant.ResponseCodeEnum; 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.*; /** @@ -43,6 +50,7 @@ * @since 2021-03-09 */ @Service +@ConfigurationProperties(prefix = "log-aspect") public class ManageAccountServiceImpl extends ServiceImpl<ManageAccountMapper, ManageAccount> implements ManageAccountService { @@ -54,15 +62,22 @@ ManageMenuService manageMenuService; @Autowired ManageAccountRoleMapper manageAccountRoleMapper; + @Autowired + LogUtils logUtils; + Map<String, String> manageAccountFormMap; + + public void setManageAccountFormMap(Map<String, String> manageAccountFormMap) { + this.manageAccountFormMap = manageAccountFormMap; + } /** - * @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(); @@ -123,6 +138,12 @@ 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 +175,7 @@ AccountDTO accountDTO = new AccountDTO(); //������ ManageAccount manageAccount = accountInsertForm.formConvertEntity(); - List<String> roleIdsStr = accountInsertForm.getRoleIds(); + List<Integer> roleIds = accountInsertForm.getRoleIds(); /*������������������������*/ ManageAccount existAccount = new ManageAccount(); @@ -172,30 +193,29 @@ //������ 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()); + + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������").append(manageAccount.getUserName() + ";") + .append("account���" + manageAccount.getAccount() + ";"); + logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); + return accountDTO; } @@ -211,7 +231,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 +241,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 +266,19 @@ 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); - } + 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); @@ -274,70 +293,6 @@ } /** - * @Description: ������������������ - * @Param: [accountUpdateRequest] - * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO - * @Author: ��������� - * @Date: 2021/3/16 - */ - @Override - @Transactional - public AccountDTO updateAccount(AccountUpdateForm accountUpdateForm) { - 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)) { - accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); - accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); - return accountDTO; - } - - //������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); - //������������������ - accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); - accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - accountDTO.setAccount(manageAccountMapper.selectById(manageAccount.getId())); - return accountDTO; - } - - - /** * @Description: ������������������ * @Param: [accountDeleteRequest] * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO @@ -350,7 +305,7 @@ AccountDTO accountDTO = new AccountDTO(); //������ Integer accountId = accountDeleteForm.getAccountId(); - //������������������ + //��������������������������������������������� ManageAccount manageAccount = new ManageAccount(); manageAccount.setIsDelete(Constants.NOT_DELETE); manageAccount.setId(accountId); @@ -374,9 +329,157 @@ //������������������ 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() + ";"); + logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); + return accountDTO; } + /** + * @Description: ������������������ + * @Param: [accountUpdateRequest] + * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO + * @Author: ��������� + * @Date: 2021/3/16 + */ + @Override + @Transactional + public AccountDTO updateAccount(AccountUpdateForm accountUpdateForm) { + AccountDTO accountDTO = new AccountDTO(); + //������ + ManageAccount manageAccount = accountUpdateForm.formConvertEntity(); + List<Integer> roleIds = accountUpdateForm.getRoleIds(); + + //������������������������������������������ + 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; + } + + //������ManageAccount��� + Map manageAccountMap = JSONObject.parseObject(JSON.toJSONString(manageAccount), Map.class);//���������Map��������������������������� + if (manageAccountMap.size() > 1) {//������������������������id��������������������������������� + 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); + } + } + //������������������ + accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); + //������������������ + insertUpdateLog(accountUpdateForm, oldManageAccount, oldRoles); + return accountDTO; + } + + /** + * @Description: ��������������������������� + * @Param: [form, newAccount, oldAccount] + * @return: void + * @Author: ��������� + * @Date: 2021/4/8 + */ + private void insertUpdateLog(AccountUpdateForm updateForm, ManageAccount oldAccount, List<ManageRole> oldRoles) { + //������������������ + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + StringBuilder content = new StringBuilder(); + content.append("������������������").append(oldAccount.getUserName() + ";") + .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); + //������������������������Map��������������������������� + Set<String> keys = manageAccountFormMap.keySet(); + for (String key : keys) { + String value = manageAccountFormMap.get(key);//��������������������� + 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) { + String newValue = "���"; + String oldValue = "���"; + if (newParameters.get(key) != null && !newParameters.get(key).equals(" ")) { + newValue = String.valueOf(newParameters.get(key)); + } + if (oldParameters.get(key) != null && !oldParameters.get(key).equals(" ")) { + oldValue = String.valueOf(oldParameters.get(key)); + } + content.append(value + ":" + oldValue + "->" + newValue + ";"); + } + } + } + logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); + } + } -- Gitblit v1.8.0