package com.winsun.mapper;

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

import com.winsun.bean.Schools;
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>> getSupervisorRef();
    
    @Select("select * from `hhr_supervisor_school` where user_id = #userId ")
    List<Map<String,Object>> getSupervisorByUserId(@Param("userId") String userId);
    
    @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);

    @Delete("delete from hhr_supervisor_school where user_id = #{userId}")
    int deleteSupervisorSchoolByUserId(@Param("userId") String userId);

    @Select("SELECT s.* FROM hhr_user u" +
            " LEFT JOIN hhr_user_school us ON u.`id`=us.`user_id`" +
            " LEFT JOIN hhr_school s ON s.`id`=us.`school_id`" +
            " WHERE u.id=#{id}")
    Map<String, Object> querySchoolById(@Param("id") String id);


    Map<String, Object> querySchoolMap(@Param("subName") String subName,@Param("schoolName") String schoolName);

    int insertSchoolMap(Map<String,Object> map);

    int updateSchoolMap(Map<String,Object> map);

    int insertNetworkInfo(Map<String,Object> map);

    List<Schools> selectHhrSchool();
}
