package com.lideeyunji.service.system.mapper;

import com.lideeyunji.tool.framework.mybatis.core.mapper.BaseMapperX;
import com.lideeyunji.tool.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.lideeyunji.service.system.entity.UserDeptDO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface UserDeptMapper extends BaseMapperX<UserDeptDO> {

    default List<UserDeptDO> selectListByUserId(Long userId) {
        return selectList(UserDeptDO::getUserId, userId);
    }

    default void deleteByUserIdAndDeptId(Long userId, Long deptId) {
        delete(new LambdaQueryWrapperX<UserDeptDO>()
                .eq(UserDeptDO::getUserId, userId)
                .eq(UserDeptDO::getDeptId, deptId));
    }

    default void deleteByUserId(Long userId) {
        delete(Wrappers.lambdaUpdate(UserDeptDO.class).eq(UserDeptDO::getUserId, userId));
    }
}
