<?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.bonus.canteen.user.mapper.UserFaceMapper">
    <resultMap type="com.bonus.canteen.user.domain.UserFace" id="UserFaceResult">
        <result property="faceId"    column="face_id"    />
        <result property="userId"    column="user_id"    />
        <result property="photoUrl"    column="photo_url"    />
        <result property="features"    column="features"    />
        <result property="photoType"    column="photo_type"    />
        <result property="faceVer"    column="face_ver"    />
        <result property="featuresBuildStatus"    column="features_build_status"    />
        <result property="featuresBuildTime"    column="features_build_time"    />
        <result property="faceState"    column="face_state"    />
        <result property="errorMsg"    column="error_msg"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectUserFaceVo">
        select face_id, user_id, photo_url, features, photo_type, face_ver, features_build_status, features_build_time, face_state, error_msg, del_flag, create_by, create_time, update_by, update_time, remark from sys_user_face
    </sql>

    <select id="selectUserFaceList" parameterType="com.bonus.canteen.user.domain.UserFace" resultMap="UserFaceResult">
        <include refid="selectUserFaceVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="photoUrl != null  and photoUrl != ''"> and photo_url = #{photoUrl}</if>
            <if test="features != null  and features != ''"> and features = #{features}</if>
            <if test="photoType != null "> and photo_type = #{photoType}</if>
            <if test="faceVer != null "> and face_ver = #{faceVer}</if>
            <if test="featuresBuildStatus != null "> and features_build_status = #{featuresBuildStatus}</if>
            <if test="featuresBuildTime != null "> and features_build_time = #{featuresBuildTime}</if>
            <if test="faceState != null "> and face_state = #{faceState}</if>
            <if test="errorMsg != null  and errorMsg != ''"> and error_msg = #{errorMsg}</if>
        </where>
    </select>
    
    <select id="selectUserFaceByFaceId" parameterType="Long" resultMap="UserFaceResult">
        <include refid="selectUserFaceVo"/>
        where face_id = #{faceId}
    </select>
        
    <insert id="insertUserFace" parameterType="com.bonus.canteen.user.domain.UserFace" useGeneratedKeys="true" keyProperty="faceId">
        insert into sys_user_face
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="photoUrl != null and photoUrl != ''">photo_url,</if>
            <if test="features != null">features,</if>
            <if test="photoType != null">photo_type,</if>
            <if test="faceVer != null">face_ver,</if>
            <if test="featuresBuildStatus != null">features_build_status,</if>
            <if test="featuresBuildTime != null">features_build_time,</if>
            <if test="faceState != null">face_state,</if>
            <if test="errorMsg != null">error_msg,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="photoUrl != null and photoUrl != ''">#{photoUrl},</if>
            <if test="features != null">#{features},</if>
            <if test="photoType != null">#{photoType},</if>
            <if test="faceVer != null">#{faceVer},</if>
            <if test="featuresBuildStatus != null">#{featuresBuildStatus},</if>
            <if test="featuresBuildTime != null">#{featuresBuildTime},</if>
            <if test="faceState != null">#{faceState},</if>
            <if test="errorMsg != null">#{errorMsg},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateUserFace" parameterType="com.bonus.canteen.user.domain.UserFace">
        update sys_user_face
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="photoUrl != null and photoUrl != ''">photo_url = #{photoUrl},</if>
            <if test="features != null">features = #{features},</if>
            <if test="photoType != null">photo_type = #{photoType},</if>
            <if test="faceVer != null">face_ver = #{faceVer},</if>
            <if test="featuresBuildStatus != null">features_build_status = #{featuresBuildStatus},</if>
            <if test="featuresBuildTime != null">features_build_time = #{featuresBuildTime},</if>
            <if test="faceState != null">face_state = #{faceState},</if>
            <if test="errorMsg != null">error_msg = #{errorMsg},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where face_id = #{faceId}
    </update>

    <delete id="deleteUserFaceByFaceId" parameterType="Long">
        delete from sys_user_face where face_id = #{faceId}
    </delete>

    <delete id="deleteUserFaceByFaceIds" parameterType="String">
        delete from sys_user_face where face_id in 
        <foreach item="faceId" collection="array" open="(" separator="," close=")">
            #{faceId}
        </foreach>
    </delete>
</mapper>