package io.hmit.modules.serviceOrder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.modules.serviceOrder.dao.RoleUserDao;
import io.hmit.modules.serviceOrder.dto.RoleUserDTO;
import io.hmit.modules.serviceOrder.entity.RoleUserEntity;
import io.hmit.modules.serviceOrder.service.RoleUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 角色用户关系
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2021-01-26
 */
@Service
public class RoleUserServiceImpl extends CrudServiceImpl<RoleUserDao, RoleUserEntity, RoleUserDTO> implements RoleUserService {

    @Override
    public QueryWrapper<RoleUserEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String userId = params.get("userId") != null?params.get("userId").toString():"";

        QueryWrapper<RoleUserEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.eq(StringUtils.isNotBlank(userId), "user_id", userId);

        return wrapper;
    }


    @Override
    public void addRelation(Long roleId, Long userId) {
        RoleUserEntity roleUserEntity = new RoleUserEntity();
        roleUserEntity.setRoleId(roleId);
        roleUserEntity.setUserId(userId);
        insert(roleUserEntity);
    }
}
