| | |
| | | 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> |
| | |
| | | @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; |
| | | } |
| | | |
| | | } |