From 8fa47457bcda1c05b7df2c04a1d4c31eec51272c Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Wed, 17 Mar 2021 09:06:00 +0800
Subject: [PATCH] common模块:     添加验证码工具类

---
 screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java |  305 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 240 insertions(+), 65 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 389c024..41b198b 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,6 +1,8 @@
 package com.moral.api.service.impl;
 
 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.ManageAccount;
 import com.moral.api.entity.ManageAccountRole;
 import com.moral.api.entity.ManageMenu;
@@ -9,12 +11,10 @@
 import com.moral.api.mapper.ManageAccountRoleMapper;
 import com.moral.api.mapper.ManageMenuMapper;
 import com.moral.api.mapper.ManageRoleMapper;
-import com.moral.api.pojo.dto.AccountDTO;
-import com.moral.api.pojo.dto.AccountInfoDTO;
-import com.moral.api.pojo.dto.LoginDTO;
-import com.moral.api.pojo.request.AccountAddRequest;
-import com.moral.api.pojo.request.LoginRequest;
-import com.moral.api.pojo.request.LogoutRequest;
+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.request.*;
 import com.moral.api.service.ManageAccountService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.moral.util.AESUtils;
@@ -52,15 +52,16 @@
     @Resource
     ManageAccountRoleMapper manageAccountRoleMapper;
 
-    public final static String specialCharRegEx =  "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~���@#���%������&*������������+|{}������������������������������������]|\n|\r|\t";
+    public final static String specialCharRegEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~���@#���%������&*������������+|{}������������������������������������]|\n|\r|\t";
 
     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+)*$";
+
     /**
      * @Description: ������
      * @Param: [parameters]
-     * @return: java.util.Map<java.lang.String   ,   java.lang.Object>
+     * @return: java.util.Map<java.lang.String               ,               java.lang.Object>
      * @Author: ���������
      * @Date: 2021/3/11
      */
@@ -76,13 +77,19 @@
         //������������������
         QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>();
         wrapper.eq("account", account);
-        ManageAccount manageAccount = manageAccountMapper.selectOne(wrapper);
-        if (ObjectUtils.isEmpty(manageAccount)) {
+        List<ManageAccount> manageAccounts = manageAccountMapper.selectList(wrapper);
+        if (ObjectUtils.isEmpty(manageAccounts)) {
             loginDTO.setCode(LoginDTO.NOT_EXIST);
             return loginDTO;
         }
         //������������������������
-        if (manageAccount.getIsDelete().equals("1")) {
+        ManageAccount manageAccount = null;
+        for (ManageAccount value : manageAccounts) {
+            if("0".equals(value.getIsDelete()))
+                manageAccount = value;
+        }
+
+        if (ObjectUtils.isEmpty(manageAccount)) {
             loginDTO.setCode(LoginDTO.IS_DELETE);
             return loginDTO;
         }
@@ -125,85 +132,85 @@
     /**
      * @Description: ������
      * @Param: [parameters]
-     * @return: java.util.Map<java.lang.String   ,   java.lang.Object>
+     * @return: java.util.Map<java.lang.String               ,               java.lang.Object>
      * @Author: ���������
      * @Date: 2021/3/11
      */
     @Override
     public boolean logout(LogoutRequest logoutRequest) {
         String accountId = logoutRequest.getAccountId();
-        String token  = logoutRequest.getToken();
-        TokenUtils.destoryToken(accountId,token);
+        String token = logoutRequest.getToken();
+        TokenUtils.destoryToken(accountId, token);
         return true;
     }
 
     /**
-    * @Description: ������������������
-            * @Param: [accountAddRequest]
-            * @return: com.moral.api.pojo.dto.AccountDTO
-            * @Author: ���������
-            * @Date: 2021/3/13
-            */
+     * @Description: ������������������
+     * @Param: [accountAddRequest]
+     * @return: com.moral.api.pojo.dto.AccountDTO
+     * @Author: ���������
+     * @Date: 2021/3/13
+     */
     @Override
     @Transactional
-    public AccountDTO addAccount(AccountAddRequest accountAddRequest) {
-        AccountDTO accountDTO = new AccountDTO();
+    public AccountInsertDTO insertAccount(AccountInsertRequest accountInsertRequest) {
+        AccountInsertDTO accountInsertDTO = new AccountInsertDTO();
         //������
-        String AESAccount = accountAddRequest.getAccount();
-        String AESPassword = accountAddRequest.getPassword();
-        String account = AESUtils.decrypt(AESAccount,AESKey);
-        String password = MD5Utils.saltMD5(AESUtils.decrypt(AESPassword,AESKey));
-        String userName = accountAddRequest.getUserName();
-        String email = accountAddRequest.getEmail();
-        String mobile = accountAddRequest.getMobile();
-        String wechat = accountAddRequest.getWechat();
-        String isDelete = accountAddRequest.getIsDelete();
-        List<String> roleIdsStr = accountAddRequest.getRoleIds();
+        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)){
-            accountDTO.setCode(AccountDTO.ACCOUNT_EXIST_SPECIAL_CHAR);
-            return accountDTO;
+        if (isSpecialChar(account)) {
+            accountInsertDTO.setCode(AccountInsertDTO.ACCOUNT_EXIST_SPECIAL_CHAR);
+            return accountInsertDTO;
         }
         /*������������������������������������*/
-        if(isSpecialChar(password)){
-            accountDTO.setCode(AccountDTO.PASSWORD_EXIST_SPECIAL_CHAR);
-            return accountDTO;
+        if (isSpecialChar(password)) {
+            accountInsertDTO.setCode(AccountInsertDTO.PASSWORD_EXIST_SPECIAL_CHAR);
+            return accountInsertDTO;
         }
         /*���������������������������������*/
-        if(account.length()>=20){
-            accountDTO.setCode(AccountDTO.ACCOUNT_LENGTH_INVALID);
-            return accountDTO;
+        if (account.length() >= 20||account.length()<=6) {
+            accountInsertDTO.setCode(AccountInsertDTO.ACCOUNT_LENGTH_INVALID);
+            return accountInsertDTO;
         }
         /*������������������������������*/
-        if(AESUtils.decrypt(AESPassword,AESKey).length()>=20){
-            accountDTO.setCode(AccountDTO.PASSWORD_LENGTH_INVALID);
-            return accountDTO;
+        if (AESUtils.decrypt(AESPassword, AESKey).length() >= 20||AESUtils.decrypt(AESPassword, AESKey).length() <= 6) {
+            accountInsertDTO.setCode(AccountInsertDTO.PASSWORD_LENGTH_INVALID);
+            return accountInsertDTO;
         }
         /*���������������������������������*/
-        if(!isValidMobile(mobile)){
-            accountDTO.setCode(AccountDTO.MOBILE_INVALID);
-            return accountDTO;
+        if (!isValidMobile(mobile)) {
+            accountInsertDTO.setCode(AccountInsertDTO.MOBILE_INVALID);
+            return accountInsertDTO;
         }
         /*������������������������������*/
-        if(!isValidEmail(email)){
-            accountDTO.setCode(AccountDTO.EMAIL_INVALID);
-            return accountDTO;
+        if (!isValidEmail(email)) {
+            accountInsertDTO.setCode(AccountInsertDTO.EMAIL_INVALID);
+            return accountInsertDTO;
         }
-        /*���������������������������*/
+        /*������������������������*/
         ManageAccount exitAccount = new ManageAccount();
         exitAccount.setAccount(account);
+        exitAccount.setIsDelete("0");
         QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>();
         wrapper.setEntity(exitAccount);
         List<ManageAccount> exitAccounts = manageAccountMapper.selectList(wrapper);
-        if(!ObjectUtils.isEmpty(exitAccounts)){
-            accountDTO.setCode(AccountDTO.ACCOUNT_EXIST);
-            return accountDTO;
+        if (!ObjectUtils.isEmpty(exitAccounts)) {
+            accountInsertDTO.setCode(AccountInsertDTO.ACCOUNT_EXIST);
+            return accountInsertDTO;
         }
 
         //String to Integer
         List<Integer> roleIds = new ArrayList<>();
-        roleIdsStr.forEach(str->roleIds.add(Integer.parseInt(str)));
+        roleIdsStr.forEach(str -> roleIds.add(Integer.parseInt(str)));
 
         //������account
         ManageAccount manageAccount = new ManageAccount();
@@ -213,12 +220,11 @@
         manageAccount.setEmail(email);
         manageAccount.setMobile(mobile);
         manageAccount.setWechat(wechat);
-        manageAccount.setIsDelete(isDelete);
         manageAccountMapper.insert(manageAccount);
         //������account_role
         Integer accountId = manageAccount.getId();
         roleIdsStr.forEach(
-                value->{
+                value -> {
                     ManageAccountRole manageAccountRole = new ManageAccountRole();
                     manageAccountRole.setAccountId(accountId);
                     manageAccountRole.setRoleId(Integer.parseInt(value));
@@ -227,30 +233,199 @@
         );
         //������������������
         List<ManageRole> roles = manageRoleMapper.selectBatchIds(roleIds);
-        accountDTO.setAccount(manageAccount);
-        accountDTO.setRoles(roles);
-        accountDTO.setCode(AccountDTO.SUCCESS);
-        return accountDTO;
+        accountInsertDTO.setAccount(manageAccount);
+        accountInsertDTO.setRoles(roles);
+        accountInsertDTO.setCode(AccountInsertDTO.SUCCESS);
+        return accountInsertDTO;
     }
 
-    private static boolean isSpecialChar(String str){
+    /**
+     * @Description: ������������������
+     * @Param: [accountQueryRequest]
+     * @return: com.moral.api.pojo.dto.AccountDTO
+     * @Author: ���������
+     * @Date: 2021/3/15
+     */
+    @Override
+    public AccountQueryDTO queryAccount(AccountQueryRequest accountQueryRequest) {
+        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);
+        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);
+        //���������������������������
+        List<ManageAccount> accounts = resultPage.getRecords();
+        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);
+        accountQueryDTO.setCurrent(resultPage.getCurrent());
+        accountQueryDTO.setPages(resultPage.getPages());
+        accountQueryDTO.setSize(resultPage.getSize());
+        accountQueryDTO.setTotal(resultPage.getTotal());
+
+        return accountQueryDTO;
+    }
+
+    /**
+    * @Description: ������������������
+            * @Param: [accountUpdateRequest]
+            * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO
+            * @Author: ���������
+            * @Date: 2021/3/16
+            */
+    @Override
+    @Transactional
+    public AccountUpdateDTO updateAccount(AccountUpdateRequest accountUpdateRequest) {
+        AccountUpdateDTO accountUpdateDTO = new AccountUpdateDTO();
+        //������
+        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���
+        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.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;
+        }
+        //������������������
+        existManageAccount.setIsDelete("1");
+        UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>();
+        deleteAccountWrapper.set("is_delete","1").eq("id",manageAccount.getId());
+        manageAccountMapper.update(null,deleteAccountWrapper);
+        //������������������������������
+        UpdateWrapper<ManageAccountRole> deleteManageAccountRoleWrapper = new UpdateWrapper<>();
+        deleteManageAccountRoleWrapper.set("is_delete","1").eq("account_id",manageAccount.getId());
+        manageAccountRoleMapper.update(null,deleteManageAccountRoleWrapper);
+        //������������������
+        accountDeleteDTO.setCode(AccountDeleteDTO.SUCCESS);
+        accountDeleteDTO.setAccount(existManageAccount);
+        return accountDeleteDTO;
+    }
+
+
+    private static boolean isSpecialChar(String str) {
         Pattern pattern = Pattern.compile(specialCharRegEx);
         Matcher matcher = pattern.matcher(str);
         return matcher.find();
     }
 
-    private static boolean isValidMobile(String str){
+    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){
+    private static boolean isValidEmail(String str) {
         Pattern pattern = Pattern.compile(emailRegEx);
         Matcher matcher = pattern.matcher(str);
         return matcher.find();
     }
-
 
 
 }

--
Gitblit v1.8.0