From ffb2063003d3e735f3f8848207078b75c3f05bfa Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Fri, 21 May 2021 16:24:40 +0800
Subject: [PATCH] screen-manage 修改删除用户BUG
---
screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java | 513 +++++++++++++++++++++++++++++---------------------------
1 files changed, 267 insertions(+), 246 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 d5f40cb..2076867 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;
@@ -14,23 +16,30 @@
import com.moral.api.pojo.dto.account.*;
import com.moral.api.pojo.dto.login.AccountInfoDTO;
import com.moral.api.pojo.dto.login.LoginDTO;
-import com.moral.api.pojo.form.*;
+import com.moral.api.pojo.form.account.AccountDeleteForm;
+import com.moral.api.pojo.form.account.AccountInsertForm;
+import com.moral.api.pojo.form.account.AccountQueryForm;
+import com.moral.api.pojo.form.account.AccountUpdateForm;
+import com.moral.api.pojo.form.login.LoginForm;
+import com.moral.api.pojo.form.login.LogoutForm;
import com.moral.api.service.ManageAccountService;
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.AESUtils;
-import com.moral.util.MD5Utils;
-import com.moral.util.TokenUtils;
+import com.moral.util.*;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
+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.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* <p>
@@ -41,31 +50,33 @@
* @since 2021-03-09
*/
@Service
+@ConfigurationProperties(prefix = "log-aspect")
public class ManageAccountServiceImpl extends ServiceImpl<ManageAccountMapper, ManageAccount> implements ManageAccountService {
- @Value("${AES.KEY}")
- private String AESKey;
+
@Autowired
ManageAccountMapper manageAccountMapper;
@Autowired
ManageRoleMapper manageRoleMapper;
@Autowired
- ManageMenuMapper manageMenuMapper;
+ ManageMenuService manageMenuService;
@Autowired
ManageAccountRoleMapper manageAccountRoleMapper;
+ @Autowired
+ LogUtils logUtils;
- public final static String specialCharRegEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~���@#���%������&*������������+|{}������������������������������������]|\n|\r|\t";
+ Map<String, String> manageAccountFormMap;
- public final static String mobileRegEx = "^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\\d{8}$";
-
- public final static String emailRegEx = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
+ public void setManageAccountFormMap(Map<String, String> manageAccountFormMap) {
+ this.manageAccountFormMap = manageAccountFormMap;
+ }
/**
- * @Description: ������
- * @Param: [parameters]
- * @return: java.util.Map<java.lang.String , java.lang.Object>
+ * @Description: ������������
+ * @Param: [loginForm]
+ * @return: com.moral.api.pojo.dto.login.LoginDTO
* @Author: ���������
- * @Date: 2021/3/11
+ * @Date: 2021/3/30
*/
@Override
public LoginDTO login(LoginForm loginForm) {
@@ -74,7 +85,7 @@
String account = loginForm.getAccount();
String AESPassword = loginForm.getPassword();
//������
- String password = AESUtils.decrypt(AESPassword, AESKey);
+ String password = AESUtils.decrypt(AESPassword);
//������������������
QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>();
wrapper.eq("account", account);
@@ -87,7 +98,7 @@
//������������������������
ManageAccount manageAccount = null;
for (ManageAccount value : manageAccounts) {
- if ("0".equals(value.getIsDelete()))
+ if (Constants.NOT_DELETE.equals(value.getIsDelete()))
manageAccount = value;
}
@@ -98,8 +109,8 @@
}
//������������
if (!MD5Utils.saltMD5Verify(password, manageAccount.getPassword())) {
- loginDTO.setCode(ResponseCodeEnum.PASSWORD_INVALID.getCode());
- loginDTO.setMsg(ResponseCodeEnum.PASSWORD_INVALID.getMsg());
+ loginDTO.setCode(ResponseCodeEnum.PASSWORD_ERROR.getCode());
+ loginDTO.setMsg(ResponseCodeEnum.PASSWORD_ERROR.getMsg());
return loginDTO;
}
@@ -109,7 +120,7 @@
//������������
List<ManageMenu> menus = null;
if (!ObjectUtils.isEmpty(roles)) {
- menus = manageMenuMapper.getParentChildrenMenusByRoles(roles);
+ menus = manageMenuService.getParentChildrenMenusByRoles(roles);
}
//������������������
@@ -127,13 +138,19 @@
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;
}
/**
* @Description: ������
* @Param: [parameters]
- * @return: java.util.Map<java.lang.String , java.lang.Object>
+ * @return:
* @Author: ���������
* @Date: 2021/3/11
*/
@@ -154,101 +171,52 @@
*/
@Override
@Transactional
- public AccountInsertDTO insertAccount(AccountInsertForm accountInsertForm) {
- AccountInsertDTO accountInsertDTO = new AccountInsertDTO();
+ public AccountDTO insertAccount(AccountInsertForm accountInsertForm) {
+ AccountDTO accountDTO = new AccountDTO();
//������
- String account = accountInsertForm.getAccount();
- String AESPassword = accountInsertForm.getPassword();
- String password = MD5Utils.saltMD5(AESUtils.decrypt(AESPassword, AESKey));
- String userName = accountInsertForm.getUserName();
- String email = accountInsertForm.getEmail();
- String mobile = accountInsertForm.getMobile();
- String wechat = accountInsertForm.getWechat();
- List<String> roleIdsStr = accountInsertForm.getRoleIds();
- //������������������������������������
- /*���������������������������������������*/
- if (isSpecialChar(account)) {
- accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST_SPECIAL_CHAR.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST_SPECIAL_CHAR.getMsg());
- return accountInsertDTO;
- }
- /*������������������������������������*/
- if (isSpecialChar(password)) {
- accountInsertDTO.setCode(ResponseCodeEnum.PASSWORD_EXIST_SPECIAL_CHAR.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.PASSWORD_EXIST_SPECIAL_CHAR.getMsg());
- return accountInsertDTO;
- }
- /*���������������������������������*/
- if (account.length() >= 20 || account.length() <= 6) {
- accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_LENGTH_INVALID.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.ACCOUNT_LENGTH_INVALID.getMsg());
- return accountInsertDTO;
- }
- /*������������������������������*/
- if (AESUtils.decrypt(AESPassword, AESKey).length() >= 20 || AESUtils.decrypt(AESPassword, AESKey).length() <= 6) {
- accountInsertDTO.setCode(ResponseCodeEnum.PASSWORD_LENGTH_INVALID.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.PASSWORD_LENGTH_INVALID.getMsg());
- return accountInsertDTO;
- }
- /*���������������������������������*/
- if (!isValidMobile(mobile)) {
- accountInsertDTO.setCode(ResponseCodeEnum.MOBILE_INVALID.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.MOBILE_INVALID.getMsg());
- return accountInsertDTO;
- }
- /*������������������������������*/
- if (!isValidEmail(email)) {
- accountInsertDTO.setCode(ResponseCodeEnum.EMAIL_INVALID.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.EMAIL_INVALID.getMsg());
- return accountInsertDTO;
- }
+ ManageAccount manageAccount = accountInsertForm.formConvertEntity();
+ List<Integer> roleIds = accountInsertForm.getRoleIds();
+
/*������������������������*/
- ManageAccount exitAccount = new ManageAccount();
- exitAccount.setAccount(account);
- exitAccount.setIsDelete("0");
+ ManageAccount existAccount = new ManageAccount();
+ existAccount.setAccount(manageAccount.getAccount());
+ existAccount.setIsDelete(Constants.NOT_DELETE);
QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>();
- wrapper.setEntity(exitAccount);
- List<ManageAccount> exitAccounts = manageAccountMapper.selectList(wrapper);
- if (!ObjectUtils.isEmpty(exitAccounts)) {
- accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST.getMsg());
- return accountInsertDTO;
+ wrapper.setEntity(existAccount);
+ ManageAccount exitAccountResult = manageAccountMapper.selectOne(wrapper);
+ if (!ObjectUtils.isEmpty(exitAccountResult)) {
+ accountDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode());
+ accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST.getMsg());
+ return accountDTO;
}
- //������account
- ManageAccount manageAccount = new ManageAccount();
- manageAccount.setAccount(account);
- manageAccount.setPassword(password);
- manageAccount.setUserName(userName);
- manageAccount.setEmail(email);
- manageAccount.setMobile(mobile);
- manageAccount.setWechat(wechat);
+ //������
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);
}
//������������������
- accountInsertDTO.setAccount(manageAccount);
- accountInsertDTO.setRoles(roles);
- accountInsertDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
- accountInsertDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
- return accountInsertDTO;
+ 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;
}
/**
@@ -261,62 +229,57 @@
@Override
public AccountQueryDTO queryAccount(AccountQueryForm accountQueryForm) {
AccountQueryDTO accountQueryDTO = new AccountQueryDTO();
+
//������
- Integer pageCount = accountQueryForm.getPage();
+ Integer page = accountQueryForm.getPage();
Integer size = accountQueryForm.getSize();
- Integer accountId = accountQueryForm.getAccountId();
- String account = accountQueryForm.getAccount();
String userName = accountQueryForm.getUserName();
String email = accountQueryForm.getEmail();
String mobile = accountQueryForm.getMobile();
String wechat = accountQueryForm.getWechat();
String isDelete = accountQueryForm.getIsDelete();
+ String order = accountQueryForm.getOrder();
+ String orderType = accountQueryForm.getOrderType();
+ Date createStartTime = accountQueryForm.getCreateStartTime();
+ Date createEndTime = accountQueryForm.getCreateEndTime();
- //������������
- Page<ManageAccount> page = new Page<>(pageCount, size);
- QueryWrapper<ManageAccount> wrapper = new QueryWrapper();
- if(!ObjectUtils.isEmpty(accountId)){
- wrapper.eq("id",accountId);
+ //������������������
+ Page<ManageAccount> queryPage = new Page<>(page, size);
+ NullFilterWrapper<ManageAccount> wrapper = new NullFilterWrapper<>();
+
+ wrapper.like("user_name", userName);
+ wrapper.like("email", email);
+ wrapper.like("mobile", mobile);
+ wrapper.like("wechat", wechat);
+ wrapper.between("create_time", createStartTime, createEndTime);
+
+ if (!ObjectUtils.isEmpty(order) && !ObjectUtils.isEmpty(orderType)) { //������������������������
+ if (orderType.equals(Constants.ORDER_ASC))
+ wrapper.orderByAsc(ConvertUtils.toLine(order));
+ else
+ wrapper.orderByDesc(ConvertUtils.toLine(order));
}
- if(!ObjectUtils.isEmpty(userName)){
- wrapper.like("user_name",userName);
- }
-
- if(!ObjectUtils.isEmpty(account)){
- wrapper.like("account",account);
- }
-
- if(!ObjectUtils.isEmpty(email)){
- wrapper.like("email",email);
- }
-
- if(!ObjectUtils.isEmpty(mobile)){
- wrapper.like("mobile",mobile);
- }
-
- if(!ObjectUtils.isEmpty(wechat)){
- wrapper.like("wechat",wechat);
- }
-
- if (!ObjectUtils.isEmpty(isDelete))
+ if (!ObjectUtils.isEmpty(isDelete))//������������������������
wrapper.eq("is_delete", isDelete);
else
- wrapper.eq("is_delete", "0");
+ 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);
accountQueryDTO.setCurrent(resultPage.getCurrent());
@@ -330,81 +293,6 @@
}
/**
- * @Description: ������������������
- * @Param: [accountUpdateRequest]
- * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO
- * @Author: ���������
- * @Date: 2021/3/16
- */
- @Override
- @Transactional
- public AccountUpdateDTO updateAccount(AccountUpdateForm accountUpdateForm) {
- AccountUpdateDTO accountUpdateDTO = new AccountUpdateDTO();
- //������
- Integer accountId = accountUpdateForm.getAccountId();
- String email = accountUpdateForm.getEmail();
- String mobile = accountUpdateForm.getMobile();
- String wechat = accountUpdateForm.getWechat();
- String userName = accountUpdateForm.getUserName();
- List<Integer> roleIds = accountUpdateForm.getRoleIds();
- //������������������������������
- /*������������������������������������*/
- QueryWrapper<ManageAccount> exitWrapper = new QueryWrapper<>();
- ManageAccount exitManageAccount = new ManageAccount();
- exitManageAccount.setId(accountId);
- exitManageAccount.setIsDelete("0");
- exitWrapper.setEntity(exitManageAccount);
- List<ManageAccount> manageAccounts = manageAccountMapper.selectList(exitWrapper);
- if (ObjectUtils.isEmpty(manageAccounts)) {
- accountUpdateDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode());
- accountUpdateDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
- return accountUpdateDTO;
- }
- /*���������������������������������*/
- if (!isValidMobile(mobile)) {
- accountUpdateDTO.setCode(ResponseCodeEnum.MOBILE_INVALID.getCode());
- accountUpdateDTO.setMsg(ResponseCodeEnum.MOBILE_INVALID.getMsg());
- return accountUpdateDTO;
- }
- /*������������������������������*/
- if (!isValidEmail(email)) {
- accountUpdateDTO.setCode(ResponseCodeEnum.EMAIL_INVALID.getCode());
- accountUpdateDTO.setMsg(ResponseCodeEnum.EMAIL_INVALID.getMsg());
- return accountUpdateDTO;
- }
- //������ManageAccount���
- ManageAccount manageAccount = new ManageAccount();
- manageAccount.setEmail(email);
- manageAccount.setMobile(mobile);
- manageAccount.setWechat(wechat);
- manageAccount.setUserName(userName);
- QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>();
- wrapper.eq("id", accountId);
- manageAccountMapper.update(manageAccount, wrapper);
- //������ManageAccountRole���
- /*������������������������������*/
- QueryWrapper<ManageAccountRole> deleteWrapper = new QueryWrapper<>();
- deleteWrapper.eq("account_id", accountId);
- manageAccountRoleMapper.delete(deleteWrapper);
- /*������������������*/
- for (Integer roleId : roleIds) {
- ManageAccountRole manageAccountRole = new ManageAccountRole();
- manageAccountRole.setAccountId(accountId);
- manageAccountRole.setRoleId(roleId);
- manageAccountRoleMapper.insert(manageAccountRole);
- }
- //������������������������
- List<ManageRole> manageRoles = manageRoleMapper.selectBatchIds(roleIds);
- //������������������
- accountUpdateDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
- accountUpdateDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
- accountUpdateDTO.setRoles(manageRoles);
- accountUpdateDTO.setAccount(manageAccountMapper.selectById(accountId));
- return accountUpdateDTO;
- }
-
-
- /**
* @Description: ������������������
* @Param: [accountDeleteRequest]
* @return: com.moral.api.pojo.dto.account.AccountDeleteDTO
@@ -413,55 +301,188 @@
*/
@Override
@Transactional
- public AccountDeleteDTO deleteAccount(AccountDeleteForm accountDeleteForm) {
- AccountDeleteDTO accountDeleteDTO = new AccountDeleteDTO();
+ public AccountDTO deleteAccount(AccountDeleteForm accountDeleteForm) {
+ AccountDTO accountDTO = new AccountDTO();
//������
Integer accountId = accountDeleteForm.getAccountId();
- //������������������
+ //���������������������������������������������
ManageAccount manageAccount = new ManageAccount();
- manageAccount.setIsDelete("0");
+ manageAccount.setIsDelete(Constants.NOT_DELETE);
manageAccount.setId(accountId);
QueryWrapper<ManageAccount> queryWrapper = new QueryWrapper<>();
queryWrapper.setEntity(manageAccount);
- ManageAccount existManageAccount = manageAccount.selectOne(queryWrapper);
+ ManageAccount existManageAccount = manageAccountMapper.selectOne(queryWrapper);
if (ObjectUtils.isEmpty(existManageAccount)) {
- accountDeleteDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode());
- accountDeleteDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
- return accountDeleteDTO;
+ accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode());
+ accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
+ return accountDTO;
}
//������������������
- existManageAccount.setIsDelete("1");
UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>();
- deleteAccountWrapper.set("is_delete", "1").eq("id", manageAccount.getId());
+ deleteAccountWrapper.eq("id", accountId);
+ deleteAccountWrapper.set("is_delete", Constants.DELETE);
manageAccountMapper.update(null, deleteAccountWrapper);
//������������������������������
UpdateWrapper<ManageAccountRole> deleteManageAccountRoleWrapper = new UpdateWrapper<>();
- deleteManageAccountRoleWrapper.set("is_delete", "1").eq("account_id", manageAccount.getId());
+ deleteManageAccountRoleWrapper.set("is_delete", Constants.DELETE).eq("account_id", manageAccount.getId());
manageAccountRoleMapper.update(null, deleteManageAccountRoleWrapper);
+ //������token
+ TokenUtils.destoryToken(accountId);
//������������������
- accountDeleteDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
- accountDeleteDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
- accountDeleteDTO.setAccount(existManageAccount);
- return accountDeleteDTO;
+ accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ //������������������
+ 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();
- private static boolean isSpecialChar(String str) {
- Pattern pattern = Pattern.compile(specialCharRegEx);
- Matcher matcher = pattern.matcher(str);
- return matcher.find();
+ //������������������������������������������
+ 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);
+ }
+ }
+ //������token
+ TokenUtils.destoryToken(manageAccount.getId());
+ //������������������
+ accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ //������������������
+ insertUpdateLog(accountUpdateForm, oldManageAccount, oldRoles);
+ return accountDTO;
}
- private static boolean isValidMobile(String str) {
- Pattern pattern = Pattern.compile(mobileRegEx);
- Matcher matcher = pattern.matcher(str);
- return matcher.find();
- }
+ /**
+ * @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();
- private static boolean isValidEmail(String str) {
- Pattern pattern = Pattern.compile(emailRegEx);
- Matcher matcher = pattern.matcher(str);
- return matcher.find();
+ 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