From 3b72f1f4dd46191857583a166d5b67722c6b118e Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Thu, 25 Mar 2021 17:19:50 +0800
Subject: [PATCH] manage模块     添加组织增删改功能 查待完成

---
 screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java |  395 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 395 insertions(+), 0 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 6dba8fb..08da75a 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,10 +1,38 @@
 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;
+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.dto.login.LoginDTO;
+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.constant.Constants;
+import com.moral.constant.ResponseCodeEnum;
+import com.moral.util.AESUtils;
+import com.moral.util.MD5Utils;
+import com.moral.util.TokenUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+
+import java.util.*;
 
 /**
  * <p>
@@ -17,4 +45,371 @@
 @Service
 public class ManageAccountServiceImpl extends ServiceImpl<ManageAccountMapper, ManageAccount> implements ManageAccountService {
 
+
+    @Autowired
+    ManageAccountMapper manageAccountMapper;
+    @Autowired
+    ManageRoleMapper manageRoleMapper;
+    @Autowired
+    ManageMenuMapper manageMenuMapper;
+    @Autowired
+    ManageAccountRoleMapper manageAccountRoleMapper;
+
+
+    /**
+     * @Description: ������
+     * @Param: [parameters]
+     * @return: java.util.Map<java.lang.String                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               java.lang.Object>
+     * @Author: ���������
+     * @Date: 2021/3/11
+     */
+    @Override
+    public LoginDTO login(LoginForm loginForm) {
+        LoginDTO loginDTO = new LoginDTO();
+        //������
+        String account = loginForm.getAccount();
+        String AESPassword = loginForm.getPassword();
+        //������
+        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(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode());
+            loginDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
+            return loginDTO;
+        }
+        //������������������������
+        ManageAccount manageAccount = null;
+        for (ManageAccount value : manageAccounts) {
+            if (Constants.NOT_DELETE.equals(value.getIsDelete()))
+                manageAccount = value;
+        }
+
+        if (ObjectUtils.isEmpty(manageAccount)) {
+            loginDTO.setCode(ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode());
+            loginDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
+            return loginDTO;
+        }
+        //������������
+        if (!MD5Utils.saltMD5Verify(password, manageAccount.getPassword())) {
+            loginDTO.setCode(ResponseCodeEnum.PASSWORD_ERROR.getCode());
+            loginDTO.setMsg(ResponseCodeEnum.PASSWORD_ERROR.getMsg());
+            return loginDTO;
+        }
+
+        //������������
+        List<ManageRole> roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId());
+
+        //������������
+        List<ManageMenu> menus = null;
+        if (!ObjectUtils.isEmpty(roles)) {
+            menus = manageMenuMapper.getParentChildrenMenusByRoles(roles);
+        }
+
+        //������������������
+        AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
+        accountInfoDTO.setAccount(manageAccount);
+        accountInfoDTO.setMenus(menus);
+        accountInfoDTO.setRoles(roles);
+
+        //������token ������������������
+        String token = TokenUtils.getToken(String.valueOf(manageAccount.getId()), accountInfoDTO);
+
+        //������������������
+        loginDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        loginDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+        loginDTO.setAccountInfoDTO(accountInfoDTO);
+        loginDTO.setToken(token);
+
+        return loginDTO;
+    }
+
+    /**
+     * @Description: ������
+     * @Param: [parameters]
+     * @return: java.util.Map<java.lang.String                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               java.lang.Object>
+     * @Author: ���������
+     * @Date: 2021/3/11
+     */
+    @Override
+    public boolean logout(LogoutForm logoutForm) {
+        String accountId = logoutForm.getAccountId();
+        String token = logoutForm.getToken();
+        TokenUtils.destoryToken(accountId, token);
+        return true;
+    }
+
+    /**
+     * @Description: ������������������
+     * @Param: [accountAddRequest]
+     * @return: com.moral.api.pojo.dto.AccountDTO
+     * @Author: ���������
+     * @Date: 2021/3/13
+     */
+    @Override
+    @Transactional
+    public AccountInsertDTO insertAccount(AccountInsertForm accountInsertForm) {
+        AccountInsertDTO accountInsertDTO = new AccountInsertDTO();
+        //������
+        String account = accountInsertForm.getAccount();
+        String AESPassword = accountInsertForm.getPassword();
+        String password = MD5Utils.saltMD5(AESUtils.decrypt(AESPassword));
+        String userName = accountInsertForm.getUserName();
+        String email = accountInsertForm.getEmail();
+        String mobile = accountInsertForm.getMobile();
+        String wechat = accountInsertForm.getWechat();
+        List<String> roleIdsStr = accountInsertForm.getRoleIds();
+
+        /*������������������������*/
+        ManageAccount existAccount = new ManageAccount();
+        existAccount.setAccount(account);
+        existAccount.setIsDelete(Constants.NOT_DELETE);
+        QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>();
+        wrapper.setEntity(existAccount);
+        List<ManageAccount> exitAccounts = manageAccountMapper.selectList(wrapper);
+        if (!ObjectUtils.isEmpty(exitAccounts)) {
+            accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode());
+            accountInsertDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST.getMsg());
+            return accountInsertDTO;
+        }
+
+        //������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)));
+
+            Integer accountId = manageAccount.getId();
+            roleIdsStr.forEach(
+                    value -> {
+                        ManageAccountRole manageAccountRole = new ManageAccountRole();
+                        manageAccountRole.setAccountId(accountId);
+                        manageAccountRole.setRoleId(Integer.parseInt(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;
+    }
+
+    /**
+     * @Description: ������������������
+     * @Param: [accountQueryRequest]
+     * @return: com.moral.api.pojo.dto.AccountDTO
+     * @Author: ���������
+     * @Date: 2021/3/15
+     */
+    @Override
+    public AccountQueryDTO queryAccount(AccountQueryForm accountQueryForm) {
+        AccountQueryDTO accountQueryDTO = new AccountQueryDTO();
+        //������
+        Integer pageCount = 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();
+
+        //������������
+        Page<ManageAccount> page = new Page<>(pageCount, size);
+        QueryWrapper<ManageAccount> wrapper = new QueryWrapper();
+        if (!ObjectUtils.isEmpty(accountId)) {
+            wrapper.eq("id", accountId);
+        }
+
+        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(order)) {
+            if (!ObjectUtils.isEmpty(orderType)) {
+                if (orderType.equals(Constants.ORDER_ASC))
+                    wrapper.orderByAsc(order);
+                else
+                    wrapper.orderByDesc(order);
+            }
+        }
+
+        if (!ObjectUtils.isEmpty(isDelete))
+            wrapper.eq("is_delete", isDelete);
+        else
+            wrapper.eq("is_delete", Constants.NOT_DELETE);
+
+        Page resultPage = manageAccountMapper.selectPage(page, 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);
+            }
+        }
+        //������������������
+        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
+     */
+    @Override
+    @Transactional
+    public AccountUpdateDTO updateAccount(AccountUpdateForm accountUpdateForm) {
+        AccountUpdateDTO accountUpdateDTO = new AccountUpdateDTO();
+        //������
+        Integer accountId = accountUpdateForm.getAccountId();
+        String password = accountUpdateForm.getPassword();
+        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(Constants.NOT_DELETE);
+        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;
+        }
+        //������password
+        if(!ObjectUtils.isEmpty(password)){
+            password = MD5Utils.saltMD5(AESUtils.decrypt(password));
+        }
+        //������ManageAccount���
+        ManageAccount manageAccount = new ManageAccount();
+        manageAccount.setPassword(password);
+        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���
+        /*������������������������������*/
+        if (!ObjectUtils.isEmpty(roleIds)) {
+            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.setRoles(manageRoles);
+        }
+        //������������������
+        accountUpdateDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        accountUpdateDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+        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(AccountDeleteForm accountDeleteForm) {
+        AccountDeleteDTO accountDeleteDTO = new AccountDeleteDTO();
+        //������
+        Integer accountId = accountDeleteForm.getAccountId();
+        //������������������
+        ManageAccount manageAccount = new ManageAccount();
+        manageAccount.setIsDelete(Constants.NOT_DELETE);
+        manageAccount.setId(accountId);
+        QueryWrapper<ManageAccount> queryWrapper = new QueryWrapper<>();
+        queryWrapper.setEntity(manageAccount);
+        ManageAccount existManageAccount = manageAccountMapper.selectOne(queryWrapper);
+        if (ObjectUtils.isEmpty(existManageAccount)) {
+            accountDeleteDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode());
+            accountDeleteDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg());
+            return accountDeleteDTO;
+        }
+        //������������������
+        existManageAccount.setIsDelete(Constants.DELETE);
+        UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>();
+        deleteAccountWrapper.set("is_delete", Constants.DELETE).eq("id", manageAccount.getId());
+        manageAccountMapper.update(null, deleteAccountWrapper);
+        //������������������������������
+        UpdateWrapper<ManageAccountRole> deleteManageAccountRoleWrapper = new UpdateWrapper<>();
+        deleteManageAccountRoleWrapper.set("is_delete", Constants.DELETE).eq("account_id", manageAccount.getId());
+        manageAccountRoleMapper.update(null, deleteManageAccountRoleWrapper);
+        //������������������
+        accountDeleteDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        accountDeleteDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+        accountDeleteDTO.setAccount(existManageAccount);
+        return accountDeleteDTO;
+    }
+
+
 }

--
Gitblit v1.8.0