<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.miaxis.user.mapper.UserInfoMapper">

    <resultMap type="UserInfo" id="UserInfoResult">
        <result property="id"    column="id"    />
        <result property="inscode"    column="inscode"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="cardtype"    column="cardtype"    />
        <result property="idcard"    column="idcard"    />
        <result property="birthday"    column="birthday"    />
        <result property="phone"    column="phone"    />
        <result property="password"    column="password"    />
        <result property="wechar"    column="wechar"    />
        <result property="openid"    column="openid"    />
        <result property="busitype"    column="busitype"    />
        <result property="perdritype"    column="perdritype"    />
        <result property="traintype"    column="traintype"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="coachnum"    column="coachnum"    />
        <result property="status"    column="status"    />
        <result property="photo"    column="photo"    />
        <result property="schoolClassTypeId"    column="school_class_type_id"    />
    </resultMap>

    <sql id="selectUserInfoVo">
        select id, name, sex, cardtype, idcard, birthday, phone, password,  wechar, openid, busitype, perdritype, traintype, create_time, update_time, coachnum, status,photo,school_class_type_id from user_info
    </sql>


    <select id="selectUserInfoById" parameterType="Long" resultMap="UserInfoResult">
        <include refid="selectUserInfoVo"/>
        where id = #{id}
    </select>

    <select id="selectUserInfoByMobile"  resultMap="UserInfoResult">
        <include refid="selectUserInfoVo"/>
        where phone = #{phone}
    </select>

    <delete id="deleteUserInfoById" parameterType="Long">
        delete from user_info where id = #{id}
    </delete>

    <delete id="deleteUserInfoByIds" parameterType="String">
        delete from user_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getMyRegistrationInformation" resultType="UserVo">
        SELECT
        u.name,
        u.phone,
        DATE_FORMAT(u.create_time,'%Y-%m-%d %H:%i:%s') AS createDate,
        s.name as schoolName,
        sct.class_name as className,
        sct.total_price as price
        FROM
        user_info u
        LEFT JOIN sys_dept s ON s.inscode = u.inscode
        LEFT JOIN school_class_type sct ON sct.id = u.school_class_type_id
        where u.id = #{userId}
    </select>

</mapper>
