|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.request.*; | 
|---|
|  |  |  | 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.util.AESUtils; | 
|---|
|  |  |  | import com.moral.util.MD5Utils; | 
|---|
|  |  |  | import com.moral.util.TokenUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | 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.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.regex.Matcher; | 
|---|
|  |  |  | import java.util.regex.Pattern; | 
|---|
|  |  |  | import java.util.function.Predicate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | * @since 2021-03-09 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | @ConfigurationProperties(prefix = "log-aspect") | 
|---|
|  |  |  | public class ManageAccountServiceImpl extends ServiceImpl<ManageAccountMapper, ManageAccount> implements ManageAccountService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${AES.KEY}") | 
|---|
|  |  |  | private String AESKey; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ManageAccountMapper manageAccountMapper; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ManageRoleMapper manageRoleMapper; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | ManageMenuMapper manageMenuMapper; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 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(LoginRequest loginRequest) { | 
|---|
|  |  |  | public LoginDTO login(LoginForm loginForm) { | 
|---|
|  |  |  | LoginDTO loginDTO = new LoginDTO(); | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | String AESAccount = loginRequest.getAccount(); | 
|---|
|  |  |  | String AESPassword = loginRequest.getPassword(); | 
|---|
|  |  |  | String account = loginForm.getAccount(); | 
|---|
|  |  |  | String AESPassword = loginForm.getPassword(); | 
|---|
|  |  |  | //解密 | 
|---|
|  |  |  | String account = AESUtils.decrypt(AESAccount, AESKey); | 
|---|
|  |  |  | String password = AESUtils.decrypt(AESPassword, AESKey); | 
|---|
|  |  |  | String password = AESUtils.decrypt(AESPassword); | 
|---|
|  |  |  | //查询是否存在 | 
|---|
|  |  |  | QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("account", account); | 
|---|
|  |  |  | List<ManageAccount> manageAccounts = manageAccountMapper.selectList(wrapper); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(manageAccounts)) { | 
|---|
|  |  |  | loginDTO.setCode(LoginDTO.NOT_EXIST); | 
|---|
|  |  |  | return loginDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //查询是否逻辑删除 | 
|---|
|  |  |  | ManageAccount manageAccount = null; | 
|---|
|  |  |  | for (ManageAccount value : manageAccounts) { | 
|---|
|  |  |  | if("0".equals(value.getIsDelete())) | 
|---|
|  |  |  | manageAccount = value; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | wrapper.eq("is_delete",Constants.NOT_DELETE); | 
|---|
|  |  |  | ManageAccount manageAccount = manageAccountMapper.selectOne(wrapper); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(manageAccount)) { | 
|---|
|  |  |  | loginDTO.setCode(LoginDTO.IS_DELETE); | 
|---|
|  |  |  | loginDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); | 
|---|
|  |  |  | loginDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); | 
|---|
|  |  |  | return loginDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //校验密码 | 
|---|
|  |  |  | if (!MD5Utils.saltMD5Verify(password, manageAccount.getPassword())) { | 
|---|
|  |  |  | loginDTO.setCode(LoginDTO.PASSWORD_ERROR); | 
|---|
|  |  |  | loginDTO.setCode(ResponseCodeEnum.PASSWORD_ERROR.getCode()); | 
|---|
|  |  |  | loginDTO.setMsg(ResponseCodeEnum.PASSWORD_ERROR.getMsg()); | 
|---|
|  |  |  | return loginDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询角色 | 
|---|
|  |  |  | List<ManageRole> roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(roles)) {//判断账号是否存在角色 | 
|---|
|  |  |  | loginDTO.setCode(LoginDTO.ROLE_EMPTY); | 
|---|
|  |  |  | return loginDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询菜单 | 
|---|
|  |  |  | List<ManageMenu> menus = manageMenuMapper.getParentChildrenMenusByRoles(roles); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(menus)) {//判断账号是否存在菜单 | 
|---|
|  |  |  | loginDTO.setCode(LoginDTO.MENU_EMPTY); | 
|---|
|  |  |  | return loginDTO; | 
|---|
|  |  |  | List<ManageMenu> menus = new ArrayList<>(); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(roles)) { | 
|---|
|  |  |  | menus = manageMenuService.getParentChildrenMenusByRoles(roles); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //封装用户信息 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取token 并且存入缓存 | 
|---|
|  |  |  | String token = TokenUtils.getToken(String.valueOf(manageAccount.getId()), accountInfoDTO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //封装返回结果 | 
|---|
|  |  |  | loginDTO.setCode(LoginDTO.SUCCESS); | 
|---|
|  |  |  | loginDTO.setAccountInfoDTO(accountInfoDTO); | 
|---|
|  |  |  | loginDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | loginDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean logout(LogoutRequest logoutRequest) { | 
|---|
|  |  |  | String accountId = logoutRequest.getAccountId(); | 
|---|
|  |  |  | String token = logoutRequest.getToken(); | 
|---|
|  |  |  | public boolean logout(LogoutForm logoutForm) { | 
|---|
|  |  |  | String accountId = logoutForm.getAccountId(); | 
|---|
|  |  |  | String token = logoutForm.getToken(); | 
|---|
|  |  |  | TokenUtils.destoryToken(accountId, token); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public AccountInsertDTO insertAccount(AccountInsertRequest accountInsertRequest) { | 
|---|
|  |  |  | AccountInsertDTO accountInsertDTO = new AccountInsertDTO(); | 
|---|
|  |  |  | public AccountDTO insertAccount(AccountInsertForm accountInsertForm) { | 
|---|
|  |  |  | AccountDTO accountDTO = new AccountDTO(); | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | String AESAccount = accountInsertRequest.getAccount(); | 
|---|
|  |  |  | String AESPassword = accountInsertRequest.getPassword(); | 
|---|
|  |  |  | String account = AESUtils.decrypt(AESAccount, AESKey); | 
|---|
|  |  |  | String password = MD5Utils.saltMD5(AESUtils.decrypt(AESPassword, AESKey)); | 
|---|
|  |  |  | String userName = accountInsertRequest.getUserName(); | 
|---|
|  |  |  | String email = accountInsertRequest.getEmail(); | 
|---|
|  |  |  | String mobile = accountInsertRequest.getMobile(); | 
|---|
|  |  |  | String wechat = accountInsertRequest.getWechat(); | 
|---|
|  |  |  | List<String> roleIdsStr = accountInsertRequest.getRoleIds(); | 
|---|
|  |  |  | //校验参数是否符合业务逻辑 | 
|---|
|  |  |  | /*判断用户名是否包含特殊字符*/ | 
|---|
|  |  |  | if (isSpecialChar(account)) { | 
|---|
|  |  |  | accountInsertDTO.setCode(AccountInsertDTO.ACCOUNT_EXIST_SPECIAL_CHAR); | 
|---|
|  |  |  | return accountInsertDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*判断密码是否包含特殊字符*/ | 
|---|
|  |  |  | if (isSpecialChar(password)) { | 
|---|
|  |  |  | accountInsertDTO.setCode(AccountInsertDTO.PASSWORD_EXIST_SPECIAL_CHAR); | 
|---|
|  |  |  | return accountInsertDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*判断用户名是否超过长度*/ | 
|---|
|  |  |  | if (account.length() >= 20||account.length()<=6) { | 
|---|
|  |  |  | accountInsertDTO.setCode(AccountInsertDTO.ACCOUNT_LENGTH_INVALID); | 
|---|
|  |  |  | return accountInsertDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*判断密码是否超过长度*/ | 
|---|
|  |  |  | if (AESUtils.decrypt(AESPassword, AESKey).length() >= 20||AESUtils.decrypt(AESPassword, AESKey).length() <= 6) { | 
|---|
|  |  |  | accountInsertDTO.setCode(AccountInsertDTO.PASSWORD_LENGTH_INVALID); | 
|---|
|  |  |  | return accountInsertDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*判断手机号是否符合规则*/ | 
|---|
|  |  |  | if (!isValidMobile(mobile)) { | 
|---|
|  |  |  | accountInsertDTO.setCode(AccountInsertDTO.MOBILE_INVALID); | 
|---|
|  |  |  | return accountInsertDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*判断邮箱是否符合规则*/ | 
|---|
|  |  |  | if (!isValidEmail(email)) { | 
|---|
|  |  |  | accountInsertDTO.setCode(AccountInsertDTO.EMAIL_INVALID); | 
|---|
|  |  |  | 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(AccountInsertDTO.ACCOUNT_EXIST); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //String to Integer | 
|---|
|  |  |  | List<Integer> roleIds = new ArrayList<>(); | 
|---|
|  |  |  | roleIdsStr.forEach(str -> roleIds.add(Integer.parseInt(str))); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //封装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 | 
|---|
|  |  |  | Integer accountId = manageAccount.getId(); | 
|---|
|  |  |  | roleIdsStr.forEach( | 
|---|
|  |  |  | value -> { | 
|---|
|  |  |  | ManageAccountRole manageAccountRole = new ManageAccountRole(); | 
|---|
|  |  |  | manageAccountRole.setAccountId(accountId); | 
|---|
|  |  |  | manageAccountRole.setRoleId(Integer.parseInt(value)); | 
|---|
|  |  |  | manageAccountRoleMapper.insert(manageAccountRole); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //如果新建账号没有分配角色则不进行操作 | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(roleIds)) { | 
|---|
|  |  |  | Integer accountId = manageAccount.getId(); | 
|---|
|  |  |  | roleIds.forEach( | 
|---|
|  |  |  | value -> { | 
|---|
|  |  |  | ManageAccountRole manageAccountRole = new ManageAccountRole(); | 
|---|
|  |  |  | manageAccountRole.setAccountId(accountId); | 
|---|
|  |  |  | manageAccountRole.setRoleId(value); | 
|---|
|  |  |  | manageAccountRoleMapper.insert(manageAccountRole); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //封装返回结果 | 
|---|
|  |  |  | List<ManageRole> roles = manageRoleMapper.selectBatchIds(roleIds); | 
|---|
|  |  |  | accountInsertDTO.setAccount(manageAccount); | 
|---|
|  |  |  | accountInsertDTO.setRoles(roles); | 
|---|
|  |  |  | accountInsertDTO.setCode(AccountInsertDTO.SUCCESS); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | * @Date: 2021/3/15 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public AccountQueryDTO queryAccount(AccountQueryRequest accountQueryRequest) { | 
|---|
|  |  |  | public AccountQueryDTO queryAccount(AccountQueryForm accountQueryForm) { | 
|---|
|  |  |  | AccountQueryDTO accountQueryDTO = new AccountQueryDTO(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | Integer pageCount = accountQueryRequest.getPage(); | 
|---|
|  |  |  | Integer size = accountQueryRequest.getSize(); | 
|---|
|  |  |  | Integer accountId = accountQueryRequest.getAccountId(); | 
|---|
|  |  |  | String account = accountQueryRequest.getAccount(); | 
|---|
|  |  |  | String userName = accountQueryRequest.getUserName(); | 
|---|
|  |  |  | String email = accountQueryRequest.getEmail(); | 
|---|
|  |  |  | String mobile = accountQueryRequest.getMobile(); | 
|---|
|  |  |  | String wechat = accountQueryRequest.getWechat(); | 
|---|
|  |  |  | String isDelete = accountQueryRequest.getIsDelete(); | 
|---|
|  |  |  | //封装查询参数 | 
|---|
|  |  |  | Map<String, Object> queryParams = new HashMap<>(); | 
|---|
|  |  |  | queryParams.put("id", accountId); | 
|---|
|  |  |  | queryParams.put("account", account); | 
|---|
|  |  |  | queryParams.put("user_name", userName); | 
|---|
|  |  |  | queryParams.put("email", email); | 
|---|
|  |  |  | queryParams.put("mobile", mobile); | 
|---|
|  |  |  | queryParams.put("wechat", wechat); | 
|---|
|  |  |  | if(!ObjectUtils.isEmpty(isDelete)) | 
|---|
|  |  |  | queryParams.put("is_delete", isDelete); | 
|---|
|  |  |  | Integer page = accountQueryForm.getPage(); | 
|---|
|  |  |  | Integer size = accountQueryForm.getSize(); | 
|---|
|  |  |  | 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> 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(isDelete))//逻辑删除条件构造 | 
|---|
|  |  |  | wrapper.eq("is_delete", isDelete); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | queryParams.put("is_delete","0"); | 
|---|
|  |  |  | //过滤为null的参数 | 
|---|
|  |  |  | queryParams.values().removeIf(value -> ObjectUtils.isEmpty(value)); | 
|---|
|  |  |  | //查询用户 | 
|---|
|  |  |  | Page<ManageAccount> page = new Page<>(pageCount, size); | 
|---|
|  |  |  | QueryWrapper<ManageAccount> wrapper = new QueryWrapper(); | 
|---|
|  |  |  | wrapper.allEq(queryParams); | 
|---|
|  |  |  | Page resultPage = manageAccountMapper.selectPage(page, wrapper); | 
|---|
|  |  |  | //查询用户对应的角色 | 
|---|
|  |  |  | wrapper.eq("is_delete", Constants.NOT_DELETE); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询结果 | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | 
|---|
|  |  |  | accountDTO.setAccount(manageAccount); | 
|---|
|  |  |  | accountDTOS.add(accountDTO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //封装返回结果 | 
|---|
|  |  |  | accountQueryDTO.setAccountDTOS(accountDTOS); | 
|---|
|  |  |  | accountQueryDTO.setCurrent(resultPage.getCurrent()); | 
|---|
|  |  |  | accountQueryDTO.setPages(resultPage.getPages()); | 
|---|
|  |  |  | accountQueryDTO.setSize(resultPage.getSize()); | 
|---|
|  |  |  | accountQueryDTO.setTotal(resultPage.getTotal()); | 
|---|
|  |  |  | accountQueryDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | accountQueryDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return accountQueryDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 更新后台账号 | 
|---|
|  |  |  | * @Param: [accountUpdateRequest] | 
|---|
|  |  |  | * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/3/16 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | * @Description: 删除后台账号 | 
|---|
|  |  |  | * @Param: [accountDeleteRequest] | 
|---|
|  |  |  | * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/3/16 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public AccountUpdateDTO updateAccount(AccountUpdateRequest accountUpdateRequest) { | 
|---|
|  |  |  | AccountUpdateDTO accountUpdateDTO = new AccountUpdateDTO(); | 
|---|
|  |  |  | public AccountDTO deleteAccount(AccountDeleteForm accountDeleteForm) { | 
|---|
|  |  |  | AccountDTO accountDTO = new AccountDTO(); | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | Integer accountId = accountUpdateRequest.getAccountId(); | 
|---|
|  |  |  | String email = accountUpdateRequest.getEmail(); | 
|---|
|  |  |  | String mobile = accountUpdateRequest.getMobile(); | 
|---|
|  |  |  | String wechat = accountUpdateRequest.getWechat(); | 
|---|
|  |  |  | String userName = accountUpdateRequest.getUserName(); | 
|---|
|  |  |  | List<Integer> roleIds = accountUpdateRequest.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(AccountUpdateDTO.ACCOUNT_NOT_EXIST); | 
|---|
|  |  |  | return accountUpdateDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*判断手机号是否符合规则*/ | 
|---|
|  |  |  | if (!isValidMobile(mobile)) { | 
|---|
|  |  |  | accountUpdateDTO.setCode(AccountUpdateDTO.MOBILE_INVALID); | 
|---|
|  |  |  | return accountUpdateDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*判断邮箱是否符合规则*/ | 
|---|
|  |  |  | if (!isValidEmail(email)) { | 
|---|
|  |  |  | accountUpdateDTO.setCode(AccountUpdateDTO.EMAIL_INVALID); | 
|---|
|  |  |  | return accountUpdateDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新ManageAccount表 | 
|---|
|  |  |  | Integer accountId = accountDeleteForm.getAccountId(); | 
|---|
|  |  |  | //查询要删除的账号,用于插入日志 | 
|---|
|  |  |  | 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(AccountUpdateDTO.SUCCESS); | 
|---|
|  |  |  | accountUpdateDTO.setRoles(manageRoles); | 
|---|
|  |  |  | accountUpdateDTO.setAccount(manageAccountMapper.selectById(accountId)); | 
|---|
|  |  |  | return accountUpdateDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 删除后台账号 | 
|---|
|  |  |  | * @Param: [accountDeleteRequest] | 
|---|
|  |  |  | * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/3/16 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public AccountDeleteDTO deleteAccount(AccountDeleteRequest accountDeleteRequest) { | 
|---|
|  |  |  | AccountDeleteDTO accountDeleteDTO = new AccountDeleteDTO(); | 
|---|
|  |  |  | //取参 | 
|---|
|  |  |  | Integer accountId = accountDeleteRequest.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); | 
|---|
|  |  |  | if(ObjectUtils.isEmpty(existManageAccount)){ | 
|---|
|  |  |  | accountDeleteDTO.setCode(AccountDeleteDTO.ACCOUNT_NOT_EXIST); | 
|---|
|  |  |  | return accountDeleteDTO; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //逻辑删除账号 | 
|---|
|  |  |  | existManageAccount.setIsDelete("1"); | 
|---|
|  |  |  | UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>(); | 
|---|
|  |  |  | deleteAccountWrapper.set("is_delete","1").eq("id",manageAccount.getId()); | 
|---|
|  |  |  | manageAccountMapper.update(null,deleteAccountWrapper); | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | manageAccountRoleMapper.update(null,deleteManageAccountRoleWrapper); | 
|---|
|  |  |  | deleteManageAccountRoleWrapper.set("is_delete", Constants.DELETE).eq("account_id", manageAccount.getId()); | 
|---|
|  |  |  | manageAccountRoleMapper.update(null, deleteManageAccountRoleWrapper); | 
|---|
|  |  |  | //销毁token | 
|---|
|  |  |  | TokenUtils.destoryToken(accountId); | 
|---|
|  |  |  | //封装返回结果 | 
|---|
|  |  |  | accountDeleteDTO.setCode(AccountDeleteDTO.SUCCESS); | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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表 | 
|---|
|  |  |  | manageAccountMapper.updateById(manageAccount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | insertUpdateLog(accountUpdateForm, oldManageAccount); | 
|---|
|  |  |  | //销毁token | 
|---|
|  |  |  | TokenUtils.destoryToken(manageAccount.getId()); | 
|---|
|  |  |  | //封装返回结果 | 
|---|
|  |  |  | accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|---|
|  |  |  | accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|---|
|  |  |  | return accountDTO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static boolean isValidMobile(String str) { | 
|---|
|  |  |  | Pattern pattern = Pattern.compile(mobileRegEx); | 
|---|
|  |  |  | Matcher matcher = pattern.matcher(str); | 
|---|
|  |  |  | return matcher.find(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static boolean isValidEmail(String str) { | 
|---|
|  |  |  | Pattern pattern = Pattern.compile(emailRegEx); | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | 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 (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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|