package com.winsun.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.winsun.bean.School;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component
public interface SchoolMapper extends BaseMapper<School> {

    @Select("select * from hhr_school  where id  in( select school_id from hhr_user_school where  user_id= #{userId} )")
    List<Map<String,Object>> getuserToSchool(@Param("userId")String userId);

    @Select("select school_id schoolId from `hhr_user_school` where  user_id = #{partner}")
    String selectSchoolIdByUserId(String partner);

    @Select("SELECT sub_name FROM `hhr_school` GROUP BY  sub_name")
    List<String> selectAdress();

    @Update("update hhr_user_school set school_id = #{schoolId} where user_id = #{userId}")
    Integer updateUserSchool(@Param("userId")String usrId ,@Param("schoolId")String schoolId);

    @Update("insert into hhr_user_school (school_id,user_id) values (#{schoolId},#{userId})")
    Integer insertUserSchool(@Param("userId")String usrId ,@Param("schoolId")String schoolId);
    
    @Select("select * from `hhr_user_school` ")
    List<Map<String,Object>> getSchoolRef();
    
    @Select("select * from `hhr_supervisor_school` ")
    List<Map<String,Object>> getSupervisorSchoolRef();
    
    @Insert(" replace into hhr_supervisor_school(user_id,school) values(#{userId},#{school})  ")
    int addSupervisorSchool(@Param("userId") String userId, @Param("school") String school);
    
    @Delete(" delete from hhr_supervisor_school where id = #{id}  ")
    int deleteSupervisorSchool(@Param("id") String id);
}
