From 10c218463b376967e07a9c28de565ef741a0a308 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Wed, 17 Mar 2021 17:26:24 +0800 Subject: [PATCH] Common模块: 修改用户不存在常量名 修改ResultMessage中使用的常量 manage模块: 账号的增删改查进行修改 --- screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java | 291 ++++++++++++++++++++++++++++++++------------------------- 1 files changed, 164 insertions(+), 127 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 41b198b..d5f40cb 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 @@ -14,12 +14,14 @@ 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.pojo.form.*; import com.moral.api.service.ManageAccountService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +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.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -43,13 +45,13 @@ @Value("${AES.KEY}") private String AESKey; - @Resource + @Autowired ManageAccountMapper manageAccountMapper; - @Resource + @Autowired ManageRoleMapper manageRoleMapper; - @Resource + @Autowired ManageMenuMapper manageMenuMapper; - @Resource + @Autowired ManageAccountRoleMapper manageAccountRoleMapper; public final static String specialCharRegEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~���@#���%������&*������������+|{}������������������������������������]|\n|\r|\t"; @@ -61,55 +63,53 @@ /** * @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 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); //������������������ QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); wrapper.eq("account", account); List<ManageAccount> manageAccounts = manageAccountMapper.selectList(wrapper); if (ObjectUtils.isEmpty(manageAccounts)) { - loginDTO.setCode(LoginDTO.NOT_EXIST); + loginDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); + loginDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return loginDTO; } //������������������������ ManageAccount manageAccount = null; for (ManageAccount value : manageAccounts) { - if("0".equals(value.getIsDelete())) + if ("0".equals(value.getIsDelete())) manageAccount = value; } if (ObjectUtils.isEmpty(manageAccount)) { - loginDTO.setCode(LoginDTO.IS_DELETE); + loginDTO.setCode(ResponseCodeEnum.ACCOUNT_IS_DELETE.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_INVALID.getCode()); + loginDTO.setMsg(ResponseCodeEnum.PASSWORD_INVALID.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 = null; + if (!ObjectUtils.isEmpty(roles)) { + menus = manageMenuMapper.getParentChildrenMenusByRoles(roles); } //������������������ @@ -122,7 +122,8 @@ String token = TokenUtils.getToken(String.valueOf(manageAccount.getId()), accountInfoDTO); //������������������ - loginDTO.setCode(LoginDTO.SUCCESS); + loginDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + loginDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); loginDTO.setAccountInfoDTO(accountInfoDTO); loginDTO.setToken(token); @@ -132,14 +133,14 @@ /** * @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(); + public boolean logout(LogoutForm logoutForm) { + String accountId = logoutForm.getAccountId(); + String token = logoutForm.getToken(); TokenUtils.destoryToken(accountId, token); return true; } @@ -153,47 +154,52 @@ */ @Override @Transactional - public AccountInsertDTO insertAccount(AccountInsertRequest accountInsertRequest) { + public AccountInsertDTO insertAccount(AccountInsertForm accountInsertForm) { AccountInsertDTO accountInsertDTO = new AccountInsertDTO(); //������ - String AESAccount = accountInsertRequest.getAccount(); - String AESPassword = accountInsertRequest.getPassword(); - String account = AESUtils.decrypt(AESAccount, AESKey); + String account = accountInsertForm.getAccount(); + String AESPassword = accountInsertForm.getPassword(); 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(); + 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(AccountInsertDTO.ACCOUNT_EXIST_SPECIAL_CHAR); + accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST_SPECIAL_CHAR.getCode()); + accountInsertDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST_SPECIAL_CHAR.getMsg()); return accountInsertDTO; } /*������������������������������������*/ if (isSpecialChar(password)) { - accountInsertDTO.setCode(AccountInsertDTO.PASSWORD_EXIST_SPECIAL_CHAR); + 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(AccountInsertDTO.ACCOUNT_LENGTH_INVALID); + 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(AccountInsertDTO.PASSWORD_LENGTH_INVALID); + 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(AccountInsertDTO.MOBILE_INVALID); + accountInsertDTO.setCode(ResponseCodeEnum.MOBILE_INVALID.getCode()); + accountInsertDTO.setMsg(ResponseCodeEnum.MOBILE_INVALID.getMsg()); return accountInsertDTO; } /*������������������������������*/ if (!isValidEmail(email)) { - accountInsertDTO.setCode(AccountInsertDTO.EMAIL_INVALID); + accountInsertDTO.setCode(ResponseCodeEnum.EMAIL_INVALID.getCode()); + accountInsertDTO.setMsg(ResponseCodeEnum.EMAIL_INVALID.getMsg()); return accountInsertDTO; } /*������������������������*/ @@ -204,13 +210,10 @@ wrapper.setEntity(exitAccount); List<ManageAccount> exitAccounts = manageAccountMapper.selectList(wrapper); if (!ObjectUtils.isEmpty(exitAccounts)) { - accountInsertDTO.setCode(AccountInsertDTO.ACCOUNT_EXIST); + accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode()); + accountInsertDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); return accountInsertDTO; } - - //String to Integer - List<Integer> roleIds = new ArrayList<>(); - roleIdsStr.forEach(str -> roleIds.add(Integer.parseInt(str))); //������account ManageAccount manageAccount = new ManageAccount(); @@ -222,20 +225,29 @@ 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); - } - ); + /*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); + } //������������������ - List<ManageRole> roles = manageRoleMapper.selectBatchIds(roleIds); accountInsertDTO.setAccount(manageAccount); accountInsertDTO.setRoles(roles); - accountInsertDTO.setCode(AccountInsertDTO.SUCCESS); + accountInsertDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountInsertDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); return accountInsertDTO; } @@ -247,46 +259,63 @@ * @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); - else - queryParams.put("is_delete","0"); - //���������null��������� - queryParams.values().removeIf(value -> ObjectUtils.isEmpty(value)); + 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(); + //������������ Page<ManageAccount> page = new Page<>(pageCount, size); QueryWrapper<ManageAccount> wrapper = new QueryWrapper(); - wrapper.allEq(queryParams); + 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(isDelete)) + wrapper.eq("is_delete", isDelete); + else + wrapper.eq("is_delete", "0"); + 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); + 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); @@ -294,28 +323,30 @@ 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: [accountUpdateRequest] + * @return: com.moral.api.pojo.dto.account.AccountUpdateDTO + * @Author: ��������� + * @Date: 2021/3/16 + */ @Override @Transactional - public AccountUpdateDTO updateAccount(AccountUpdateRequest accountUpdateRequest) { + public AccountUpdateDTO updateAccount(AccountUpdateForm accountUpdateForm) { 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(); + 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<>(); @@ -324,18 +355,21 @@ exitManageAccount.setIsDelete("0"); exitWrapper.setEntity(exitManageAccount); List<ManageAccount> manageAccounts = manageAccountMapper.selectList(exitWrapper); - if(ObjectUtils.isEmpty(manageAccounts)){ - accountUpdateDTO.setCode(AccountUpdateDTO.ACCOUNT_NOT_EXIST); + 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(AccountUpdateDTO.MOBILE_INVALID); + accountUpdateDTO.setCode(ResponseCodeEnum.MOBILE_INVALID.getCode()); + accountUpdateDTO.setMsg(ResponseCodeEnum.MOBILE_INVALID.getMsg()); return accountUpdateDTO; } /*������������������������������*/ if (!isValidEmail(email)) { - accountUpdateDTO.setCode(AccountUpdateDTO.EMAIL_INVALID); + accountUpdateDTO.setCode(ResponseCodeEnum.EMAIL_INVALID.getCode()); + accountUpdateDTO.setMsg(ResponseCodeEnum.EMAIL_INVALID.getMsg()); return accountUpdateDTO; } //������ManageAccount��� @@ -345,12 +379,12 @@ manageAccount.setWechat(wechat); manageAccount.setUserName(userName); QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); - wrapper.eq("id",accountId); - manageAccountMapper.update(manageAccount,wrapper); + wrapper.eq("id", accountId); + manageAccountMapper.update(manageAccount, wrapper); //������ManageAccountRole��� /*������������������������������*/ QueryWrapper<ManageAccountRole> deleteWrapper = new QueryWrapper<>(); - deleteWrapper.eq("account_id",accountId); + deleteWrapper.eq("account_id", accountId); manageAccountRoleMapper.delete(deleteWrapper); /*������������������*/ for (Integer roleId : roleIds) { @@ -362,7 +396,8 @@ //������������������������ List<ManageRole> manageRoles = manageRoleMapper.selectBatchIds(roleIds); //������������������ - accountUpdateDTO.setCode(AccountUpdateDTO.SUCCESS); + accountUpdateDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountUpdateDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); accountUpdateDTO.setRoles(manageRoles); accountUpdateDTO.setAccount(manageAccountMapper.selectById(accountId)); return accountUpdateDTO; @@ -370,18 +405,18 @@ /** - * @Description: ������������������ - * @Param: [accountDeleteRequest] - * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO - * @Author: ��������� - * @Date: 2021/3/16 - */ + * @Description: ������������������ + * @Param: [accountDeleteRequest] + * @return: com.moral.api.pojo.dto.account.AccountDeleteDTO + * @Author: ��������� + * @Date: 2021/3/16 + */ @Override @Transactional - public AccountDeleteDTO deleteAccount(AccountDeleteRequest accountDeleteRequest) { + public AccountDeleteDTO deleteAccount(AccountDeleteForm accountDeleteForm) { AccountDeleteDTO accountDeleteDTO = new AccountDeleteDTO(); //������ - Integer accountId = accountDeleteRequest.getAccountId(); + Integer accountId = accountDeleteForm.getAccountId(); //������������������ ManageAccount manageAccount = new ManageAccount(); manageAccount.setIsDelete("0"); @@ -389,21 +424,23 @@ QueryWrapper<ManageAccount> queryWrapper = new QueryWrapper<>(); queryWrapper.setEntity(manageAccount); ManageAccount existManageAccount = manageAccount.selectOne(queryWrapper); - if(ObjectUtils.isEmpty(existManageAccount)){ - accountDeleteDTO.setCode(AccountDeleteDTO.ACCOUNT_NOT_EXIST); + if (ObjectUtils.isEmpty(existManageAccount)) { + accountDeleteDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); + accountDeleteDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); return accountDeleteDTO; } //������������������ existManageAccount.setIsDelete("1"); UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>(); - deleteAccountWrapper.set("is_delete","1").eq("id",manageAccount.getId()); - manageAccountMapper.update(null,deleteAccountWrapper); + 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); + deleteManageAccountRoleWrapper.set("is_delete", "1").eq("account_id", manageAccount.getId()); + manageAccountRoleMapper.update(null, deleteManageAccountRoleWrapper); //������������������ - accountDeleteDTO.setCode(AccountDeleteDTO.SUCCESS); + accountDeleteDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountDeleteDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); accountDeleteDTO.setAccount(existManageAccount); return accountDeleteDTO; } -- Gitblit v1.8.0