1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.moral.api.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.moral.api.entity.ManageAccountRole;
import com.moral.api.mapper.ManageAccountRoleMapper;
import com.moral.api.pojo.dto.accountRole.AccountRoleDTO;
import com.moral.api.pojo.form.accountRole.AccountRoleUpdateForm;
import com.moral.api.service.ManageAccountRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
 
/**
 * <p>
 * 后台账户角色关系表 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-03-09
 */
@Service
public class ManageAccountRoleServiceImpl extends ServiceImpl<ManageAccountRoleMapper, ManageAccountRole> implements ManageAccountRoleService {
 
    @Autowired
    ManageAccountRoleMapper manageAccountRoleMapper;
 
    @Override
    @Transactional
    public AccountRoleDTO updateAccountRole(AccountRoleUpdateForm form) {
        //创建返回对象
        AccountRoleDTO dto = new AccountRoleDTO();
        //取参
        Integer accountId = form.getAccountId();
        Integer roleId = form.getRoleId();
        //先删除原有角色再进行分配
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.set("is_delete", Constants.DELETE);
        updateWrapper.eq("account_id", accountId);
        manageAccountRoleMapper.update(null, updateWrapper);
        if(!ObjectUtils.isEmpty(roleId)){
            ManageAccountRole role = new ManageAccountRole();
            role.setAccountId(accountId);
            role.setRoleId(roleId);
            manageAccountRoleMapper.insert(role);
        }
        //封装返回参数
        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        return dto;
    }
 
}