package com.winsun.mapper;

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

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

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;

@Mapper
@Component
public interface PartnerMapper extends BaseMapper<Partner> {

    @Update("<script>update sys_user set " +
            "<if test=\"phone != null and phone != ''\">phone = #{phone} ,</if>" +
            "name = #{name} ," +
            "<if test=\"account != null and account != ''\">account = #{account},</if> " +
            "sex = #{sex}, password = #{password}, roleid= #{roleId}, substName = #{subName}  where id=#{id}</script>")
    int updateSysUser(@Param("phone") String phone, @Param("name") String name, @Param("account") String account, @Param("sex") String sex,
                      @Param("password") String password, @Param("roleId") String roleId, @Param("id") String id, @Param("subName") String subName);

    @Update("<script>update hhr_user set ysm = #{ysm} ,grade = #{grade} ,<if test=\"idCard != null and idCard != ''\">" +
            "            id_card = #{idCard},</if> " +
            "position = #{position} ,parent_id = #{parentId} ,parent_ids = #{parentIds}  where id=#{id}</script>")
    int updateHhUser(@Param("ysm") String ysm, @Param("grade") String grade, @Param("idCard") String idCard, @Param("position") String position, @Param("parentId") String parentId, @Param("parentIds") String parentIds, @Param("id") String id);

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

    @Select("select *  from `sys_user` where account = #{account} order by createtime desc")
    List<Map<String, Object>> selectSysUser(String account);

    @Insert(" replace into hhr_user_school(user_id,school_id) VALUES(#{userId},#{schoolId})")
    int saveSchoolRef(@Param("userId") String userId, @Param("schoolId") String schoolId);

    @Select(" select id,name from  sys_role ")
    List<Map<String, Object>> roleList();
}
