<?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.zkqy.system.mapper.CommonMapper">


    <resultMap id="retMap" type="com.zkqy.system.entity.CommonEntity" autoMapping="true">
        <collection property="resultMap" ofType="map" autoMapping="true"
                    javaType="map"></collection>
    </resultMap>

    <select id="selectList" resultMap="retMap">
        select * from ${tableName}
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key}=#{value}
                </foreach>
            </if>
        </where>
    </select>

    <select id="queryTableList" resultMap="retMap">
        ${Sql}
    </select>

    <insert id="batchInsert">
        insert into ${tableName}
        <foreach collection="fieldNames" item="fieldName" open="(" close=")" separator=",">
            ${fieldName}
        </foreach>
        values
        <foreach collection="fieldValues" item="map" separator=",">
            <foreach collection="map" item="value" index="key" separator="," open="(" close=")">
                #{value}
            </foreach>
        </foreach>
    </insert>

    <delete id="batchDelete">
        update ${tableName} set del_flag = '2'
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key} in
                    <foreach collection="value" item="v" open="(" close=")" separator=",">
                        #{v}
                    </foreach>
                </foreach>
            </if>
        </where>
    </delete>

    <update id="edit">
        update ${tableName} set
        <foreach collection="fields" item="field" index="key" separator=",">
            ${key}=#{field}
        </foreach>
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key}=#{value}
                </foreach>
            </if>
        </where>
    </update>

    <select id="selectDropDownList" resultType="map">
        select ${fieldKey} as fieldKey,${fieldName} as fieldName from ${tableName}
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key}=#{value}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectDropDownListByDict" resultType="map">
        select dict_value as fieldKey,dict_label as fieldName from sys_dict_data where dict_type = #{dictType} and status = '0'
    </select>

    <select id="getInfoById" resultMap="retMap">
        select * from ${tableName}
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key} = #{value}
                </foreach>
            </if>
        </where>
    </select>

    <select id="executeSql" resultType="map">
        ${sql}
    </select>

    <select id="queryDropDownBoxData" resultType="map">
        select * from {DBNAME}.${tableName}
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key} in
                    <foreach collection="value" item="v" open="(" close=")" separator=",">
                        #{v}
                    </foreach>
                </foreach>
            </if>
        </where>
    </select>

</mapper>
