<?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.scm.contract.dao.management.TagDataDao">

    <sql id="columns">
        a
        .
        `tag_type_id`
        AS "tagTypeId",
		a.`status` AS "status",
		a.`data_type` AS "dataType",
		a.`number` AS "number"
    </sql>

    <sql id="joins">
    </sql>

    <insert id="saveOrUpdateBash">
        INSERT INTO `tag_data`
        (`tag_type_id`,`status`,`data_type`,`number`) values
        <foreach item="data" index="index" collection="tagDataList" separator=",">
            (
            #{data.tagTypeId},
            #{data.status},
            #{data.dataType},
            #{data.number}
            )
        </foreach>
        ON DUPLICATE KEY UPDATE
        `tag_type_id`=values(`tag_type_id`),`status`=values(`status`),`data_type`=values(`data_type`),`number`=values(`number`)
    </insert>

    <select id="list" resultType="com.scm.contract.model.management.TagData">
        SELECT
        <include refid="columns"/>
        FROM tag_data a
        <include refid="joins"/>
    </select>

    <select id="getListBy" resultType="com.scm.contract.model.management.TagData">
        <foreach item="data" index="index" collection="tagDataList" separator=" UNION ALL ">
            SELECT
            <include refid="columns"/>
            FROM tag_data a
            <where>
                <if test="data.tagTypeId != null and data.tagTypeId != ''">
                    AND a.`tag_type_id` = #{data.tagTypeId}
                </if>
                <if test="data.status != null and data.status != ''">
                    AND a.`status` = #{data.status}
                </if>
                <if test="data.dataType != null and data.dataType != ''">
                    AND a.`data_type` = #{data.dataType}
                </if>
            </where>
        </foreach>
    </select>

</mapper>
