From f0376f72170c2eb236bec5560b8c5734edd222f1 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Wed, 31 Mar 2021 17:16:40 +0800 Subject: [PATCH] common模块: 增加了convert工具类,驼峰和下划线相互转换 更新了Date工具类,添加根据Date,day获取目标date的方法 更新WebUtils工具类,添加获取请求Ip方法 manage模块: 组织和后台用户增删改查模块全部完成 增加aop用作日志插入 --- screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java | 210 ++++++++++++++++++++++------------------------------ 1 files changed, 88 insertions(+), 122 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 08da75a..c2b8aad 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 @@ -22,11 +22,10 @@ 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.api.config.mybatis.wrapper.NullFilterWrapper; 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 com.moral.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,12 +56,12 @@ /** - * @Description: ������ - * @Param: [parameters] - * @return: java.util.Map<java.lang.String , java.lang.Object> - * @Author: ��������� - * @Date: 2021/3/11 - */ + * @Description: ������������ + * @Param: [loginForm] + * @return: com.moral.api.pojo.dto.login.LoginDTO + * @Author: ��������� + * @Date: 2021/3/30 + */ @Override public LoginDTO login(LoginForm loginForm) { LoginDTO loginDTO = new LoginDTO(); @@ -129,7 +128,7 @@ /** * @Description: ������ * @Param: [parameters] - * @return: java.util.Map<java.lang.String , java.lang.Object> + * @return: * @Author: ��������� * @Date: 2021/3/11 */ @@ -150,40 +149,28 @@ */ @Override @Transactional - public AccountInsertDTO insertAccount(AccountInsertForm accountInsertForm) { - AccountInsertDTO accountInsertDTO = new AccountInsertDTO(); + public AccountDTO insertAccount(AccountInsertForm accountInsertForm) { + AccountDTO accountDTO = new AccountDTO(); //������ - 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(); + ManageAccount manageAccount = accountInsertForm.formConvertEntity(); List<String> roleIdsStr = accountInsertForm.getRoleIds(); /*������������������������*/ ManageAccount existAccount = new ManageAccount(); - existAccount.setAccount(account); + existAccount.setAccount(manageAccount.getAccount()); 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; + ManageAccount exitAccountResult = manageAccountMapper.selectOne(wrapper); + if (!ObjectUtils.isEmpty(exitAccountResult)) { + accountDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode()); + accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); + return accountDTO; } - //������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; @@ -204,11 +191,11 @@ roles = manageRoleMapper.selectBatchIds(roleIds); } //������������������ - accountInsertDTO.setAccount(manageAccount); - accountInsertDTO.setRoles(roles); - accountInsertDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); - accountInsertDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - return accountInsertDTO; + accountDTO.setAccount(manageAccount); + accountDTO.setRoles(roles); + accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); + return accountDTO; } /** @@ -221,11 +208,10 @@ @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(); @@ -233,49 +219,34 @@ String isDelete = accountQueryForm.getIsDelete(); String order = accountQueryForm.getOrder(); String orderType = accountQueryForm.getOrderType(); + Date createStartTime = accountQueryForm.getCreateStartTime(); + Date createEndTime = DateUtils.getDateOfDay(accountQueryForm.getCreateEndTime(), 1); - //������������ + //������������������ Page<ManageAccount> page = new Page<>(pageCount, size); - QueryWrapper<ManageAccount> wrapper = new QueryWrapper(); - if (!ObjectUtils.isEmpty(accountId)) { - wrapper.eq("id", accountId); + 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(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)) + 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<>(); @@ -288,6 +259,7 @@ accountDTOS.add(accountDTO); } } + //������������������ accountQueryDTO.setAccountDTOS(accountDTOS); accountQueryDTO.setCurrent(resultPage.getCurrent()); @@ -309,64 +281,58 @@ */ @Override @Transactional - public AccountUpdateDTO updateAccount(AccountUpdateForm accountUpdateForm) { - AccountUpdateDTO accountUpdateDTO = new AccountUpdateDTO(); + public AccountDTO updateAccount(AccountUpdateForm accountUpdateForm) { + AccountDTO accountDTO = new AccountDTO(); //������ - Integer accountId = accountUpdateForm.getAccountId(); - String password = accountUpdateForm.getPassword(); - String email = accountUpdateForm.getEmail(); - String mobile = accountUpdateForm.getMobile(); - String wechat = accountUpdateForm.getWechat(); - String userName = accountUpdateForm.getUserName(); + ManageAccount manageAccount = accountUpdateForm.formConvertEntity(); List<Integer> roleIds = accountUpdateForm.getRoleIds(); + //������������������������������������ QueryWrapper<ManageAccount> exitWrapper = new QueryWrapper<>(); ManageAccount exitManageAccount = new ManageAccount(); - exitManageAccount.setId(accountId); + exitManageAccount.setId(manageAccount.getId()); 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; + accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); + accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); + return accountDTO; } - //������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); + manageAccountMapper.updateById(manageAccount); + //���������������������������������ManageAccountRole��� - /*������������������������������*/ - if (!ObjectUtils.isEmpty(roleIds)) { - QueryWrapper<ManageAccountRole> deleteWrapper = new QueryWrapper<>(); - deleteWrapper.eq("account_id", accountId); - manageAccountRoleMapper.delete(deleteWrapper); + /* + * ������roleIds���null������������������������������������������ + * ������roleIds��������������������������������������������������� + * ������roleIds��������������������������������������������� + * */ + List<ManageRole> roles = null; + if (roleIds != null) { + UpdateWrapper<ManageAccountRole> deleteWrapper = new UpdateWrapper<>(); + deleteWrapper.eq("account_id", manageAccount.getId()).set("is_delete", Constants.DELETE); + manageAccountRoleMapper.update(null, deleteWrapper); /*������������������*/ for (Integer roleId : roleIds) { ManageAccountRole manageAccountRole = new ManageAccountRole(); - manageAccountRole.setAccountId(accountId); + manageAccountRole.setAccountId(manageAccount.getId()); manageAccountRole.setRoleId(roleId); manageAccountRoleMapper.insert(manageAccountRole); } //������������������������ - List<ManageRole> manageRoles = manageRoleMapper.selectBatchIds(roleIds); - accountUpdateDTO.setRoles(manageRoles); + if (roleIds.size() != 0) + roles = manageRoleMapper.selectBatchIds(roleIds); + } else { + roles = manageRoleMapper.getManageRoleByAccountId(manageAccount.getId()); } + accountDTO.setRoles(roles); //������������������ - accountUpdateDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); - accountUpdateDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); - accountUpdateDTO.setAccount(manageAccountMapper.selectById(accountId)); - return accountUpdateDTO; + accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); + accountDTO.setAccount(manageAccountMapper.selectById(manageAccount.getId())); + return accountDTO; } @@ -379,8 +345,8 @@ */ @Override @Transactional - public AccountDeleteDTO deleteAccount(AccountDeleteForm accountDeleteForm) { - AccountDeleteDTO accountDeleteDTO = new AccountDeleteDTO(); + public AccountDTO deleteAccount(AccountDeleteForm accountDeleteForm) { + AccountDTO accountDTO = new AccountDTO(); //������ Integer accountId = accountDeleteForm.getAccountId(); //������������������ @@ -391,24 +357,24 @@ 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; + accountDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); + accountDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); + return accountDTO; } //������������������ - existManageAccount.setIsDelete(Constants.DELETE); UpdateWrapper<ManageAccount> deleteAccountWrapper = new UpdateWrapper<>(); - deleteAccountWrapper.set("is_delete", Constants.DELETE).eq("id", manageAccount.getId()); + deleteAccountWrapper.eq("id", accountId); + deleteAccountWrapper.set("is_delete", Constants.DELETE); 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; + accountDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); + accountDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); + accountDTO.setAccount(existManageAccount); + return accountDTO; } -- Gitblit v1.8.0