| | |
| | | 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.*; |
| | | 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.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; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | /** |
| | | * @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 |
| | | */ |
| | |
| | | /** |
| | | * @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 |
| | | */ |
| | |
| | | List<String> roleIdsStr = accountInsertForm.getRoleIds(); |
| | | |
| | | /*判断账号是否存在*/ |
| | | ManageAccount exitAccount = new ManageAccount(); |
| | | exitAccount.setAccount(account); |
| | | exitAccount.setIsDelete(Constants.NOT_DELETE); |
| | | ManageAccount existAccount = new ManageAccount(); |
| | | existAccount.setAccount(account); |
| | | existAccount.setIsDelete(Constants.NOT_DELETE); |
| | | QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); |
| | | wrapper.setEntity(exitAccount); |
| | | wrapper.setEntity(existAccount); |
| | | List<ManageAccount> exitAccounts = manageAccountMapper.selectList(wrapper); |
| | | if (!ObjectUtils.isEmpty(exitAccounts)) { |
| | | accountInsertDTO.setCode(ResponseCodeEnum.ACCOUNT_EXIST.getCode()); |
| | |
| | | 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(accountId)) { |
| | | wrapper.eq("id", accountId); |
| | | } |
| | | |
| | | if(!ObjectUtils.isEmpty(userName)){ |
| | | wrapper.like("user_name",userName); |
| | | if (!ObjectUtils.isEmpty(userName)) { |
| | | wrapper.like("user_name", userName); |
| | | } |
| | | |
| | | if(!ObjectUtils.isEmpty(account)){ |
| | | wrapper.like("account",account); |
| | | if (!ObjectUtils.isEmpty(account)) { |
| | | wrapper.like("account", account); |
| | | } |
| | | |
| | | if(!ObjectUtils.isEmpty(email)){ |
| | | wrapper.like("email",email); |
| | | if (!ObjectUtils.isEmpty(email)) { |
| | | wrapper.like("email", email); |
| | | } |
| | | |
| | | if(!ObjectUtils.isEmpty(mobile)){ |
| | | wrapper.like("mobile",mobile); |
| | | if (!ObjectUtils.isEmpty(mobile)) { |
| | | wrapper.like("mobile", mobile); |
| | | } |
| | | |
| | | if(!ObjectUtils.isEmpty(wechat)){ |
| | | wrapper.like("wechat",wechat); |
| | | 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)) |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id", accountId); |
| | | manageAccountMapper.update(manageAccount, wrapper); |
| | | //更新ManageAccountRole表 |
| | | //如果角色有变动,则更新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); |
| | | 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); |
| | | } |
| | | //获取用户所有角色 |
| | | List<ManageRole> manageRoles = manageRoleMapper.selectBatchIds(roleIds); |
| | | //封装返回结果 |
| | | accountUpdateDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); |
| | | accountUpdateDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); |
| | | accountUpdateDTO.setRoles(manageRoles); |
| | | accountUpdateDTO.setAccount(manageAccountMapper.selectById(accountId)); |
| | | return accountUpdateDTO; |
| | | } |
| | |
| | | manageAccount.setId(accountId); |
| | | QueryWrapper<ManageAccount> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.setEntity(manageAccount); |
| | | ManageAccount existManageAccount = manageAccount.selectOne(queryWrapper); |
| | | ManageAccount existManageAccount = manageAccountMapper.selectOne(queryWrapper); |
| | | if (ObjectUtils.isEmpty(existManageAccount)) { |
| | | accountDeleteDTO.setCode(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); |
| | | accountDeleteDTO.setMsg(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | |
| | | accountDeleteDTO.setAccount(existManageAccount); |
| | | return accountDeleteDTO; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |