| | |
| | | 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.mapper.ManageAccountRoleMapper; |
| | | import com.moral.api.mapper.ManageMenuMapper; |
| | | import com.moral.api.mapper.ManageRoleMapper; |
| | | import com.moral.api.pojo.dto.account.AccountDTO; |
| | | import com.moral.api.pojo.dto.account.AccountInsertDTO; |
| | | import com.moral.api.pojo.dto.account.AccountQueryDTO; |
| | | import com.moral.api.pojo.dto.account.AccountUpdateDTO; |
| | | 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.*; |
| | |
| | | //查询是否存在 |
| | | 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; |
| | | } |
| | |
| | | String email = accountInsertRequest.getEmail(); |
| | | String mobile = accountInsertRequest.getMobile(); |
| | | String wechat = accountInsertRequest.getWechat(); |
| | | String isDelete = accountInsertRequest.getIsDelete(); |
| | | List<String> roleIdsStr = accountInsertRequest.getRoleIds(); |
| | | //校验参数是否符合业务逻辑 |
| | | /*判断用户名是否包含特殊字符*/ |
| | |
| | | accountInsertDTO.setCode(AccountInsertDTO.EMAIL_INVALID); |
| | | return accountInsertDTO; |
| | | } |
| | | /*判断用户名是否存在*/ |
| | | /*判断账号是否存在*/ |
| | | ManageAccount exitAccount = new ManageAccount(); |
| | | exitAccount.setAccount(account); |
| | | exitAccount.setIsDelete("0"); |
| | |
| | | manageAccount.setEmail(email); |
| | | manageAccount.setMobile(mobile); |
| | | manageAccount.setWechat(wechat); |
| | | manageAccount.setIsDelete(isDelete); |
| | | manageAccountMapper.insert(manageAccount); |
| | | //封装account_role |
| | | Integer accountId = manageAccount.getId(); |
| | |
| | | queryParams.put("email", email); |
| | | queryParams.put("mobile", mobile); |
| | | queryParams.put("wechat", wechat); |
| | | queryParams.put("is_delete", isDelete); |
| | | 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); |
| | |
| | | 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) { |
| | |
| | | String email = accountUpdateRequest.getEmail(); |
| | | String mobile = accountUpdateRequest.getMobile(); |
| | | String wechat = accountUpdateRequest.getWechat(); |
| | | String isDelete = accountUpdateRequest.getIsDelete(); |
| | | String userName = accountUpdateRequest.getUserName(); |
| | | List<Integer> roleIds = accountUpdateRequest.getRoleIds(); |
| | | //校验参数是否符合逻辑 |
| | |
| | | manageAccount.setEmail(email); |
| | | manageAccount.setMobile(mobile); |
| | | manageAccount.setWechat(wechat); |
| | | manageAccount.setIsDelete(isDelete); |
| | | manageAccount.setUserName(userName); |
| | | QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id",accountId); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @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) { |