kaiyu
2021-03-25 3b72f1f4dd46191857583a166d5b67722c6b118e
screen-manage/src/main/java/com/moral/api/service/impl/ManageAccountServiceImpl.java
@@ -14,7 +14,12 @@
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;
@@ -23,15 +28,11 @@
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>
@@ -162,11 +163,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());
@@ -230,6 +231,8 @@
        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);
@@ -256,6 +259,15 @@
        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))
@@ -301,13 +313,13 @@
        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);
@@ -319,8 +331,13 @@
            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);
@@ -328,8 +345,9 @@
        QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("id", accountId);
        manageAccountMapper.update(manageAccount, wrapper);
        //更新ManageAccountRole表
        //如果角色有变动,则更新ManageAccountRole表
        /*删除该用户的所有角色*/
        if (!ObjectUtils.isEmpty(roleIds)) {
        QueryWrapper<ManageAccountRole> deleteWrapper = new QueryWrapper<>();
        deleteWrapper.eq("account_id", accountId);
        manageAccountRoleMapper.delete(deleteWrapper);
@@ -342,10 +360,11 @@
        }
        //获取用户所有角色
        List<ManageRole> manageRoles = manageRoleMapper.selectBatchIds(roleIds);
            accountUpdateDTO.setRoles(manageRoles);
        }
        //封装返回结果
        accountUpdateDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
        accountUpdateDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        accountUpdateDTO.setRoles(manageRoles);
        accountUpdateDTO.setAccount(manageAccountMapper.selectById(accountId));
        return accountUpdateDTO;
    }
@@ -370,7 +389,7 @@
        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());
@@ -391,8 +410,6 @@
        accountDeleteDTO.setAccount(existManageAccount);
        return accountDeleteDTO;
    }
}