<?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.fs.doctor.mapper.DynamicSurveyDataMapper">

    <insert id="insertData" useGeneratedKeys="true" keyProperty="data.id">
        INSERT INTO ${tableName}
        <foreach collection="data.keys" item="key" open="(" separator="," close=")">
            ${key}
        </foreach>
        VALUES
        <foreach collection="data.values" item="value" open="(" separator="," close=")">
            #{value}
        </foreach>
    </insert>

    <select id="selectById" resultType="java.util.Map">
        SELECT * FROM ${tableName} WHERE id = #{id}
    </select>

    <update id="updateById">
        UPDATE ${tableName}
        <set>
            <foreach collection="data.entrySet()" item="entry" index="key" separator=",">
                ${key} = #{entry.value}
            </foreach>
        </set>
        WHERE id = #{id}
    </update>

</mapper>