<?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="cn.gov.customs.wxjy.task.dao.SyncDataStatusMapper">

    <resultMap type="SyncDataStatus" id="SyncDataStatusResult">
        <result property="ID" column="ID"/>
        <result property="businessType" column="BUSINESS_TYPE"/>
        <result property="businessId" column="BUSINESS_ID"/>
        <result property="syncTime" column="SYNC_TIME"/>
        <result property="syncVersion" column="SYNC_VERSION"/>
        <result property="isDeleted" column="IS_DELETED"/>
    </resultMap>

    <sql id="baseVo">
        select ID, BUSINESS_TYPE, BUSINESS_ID, SYNC_TIME, SYNC_VERSION, IS_DELETED
        from WXJY_SYNC_DATA_STATUS
    </sql>

    <select id="selectList" parameterType="SyncDataStatusQuery" resultMap="SyncDataStatusResult">
        <include refid="baseVo"/>
        <where>
        <if test="businessType != null  and businessType != ''">
            and BUSINESS_TYPE = #{businessType}
        </if>
        <if test="businessId != null  and businessId != ''">
            and BUSINESS_ID = #{businessId}
        </if>
        <if test="syncTime != null  and syncTime != ''">
            and SYNC_TIME = #{syncTime}
        </if>
        <if test="syncVersion != null  and syncVersion != ''">
            and SYNC_VERSION = #{syncVersion}
        </if>
        <if test="isDeleted != null  and isDeleted != ''">
            and IS_DELETED = #{isDeleted}
        </if>
        </where>
    </select>

    <select id="selectByID" parameterType="String"
        resultMap="SyncDataStatusResult">
        <include refid="baseVo"/>
        where ID = #{ID}
    </select>
    <select id="selectDataIdsByBusinessType" resultType="java.lang.String">
        select BUSINESS_ID from WXJY_SYNC_DATA_STATUS where BUSINESS_TYPE = #{businessType} and IS_DELETED = 0
    </select>
    <select id="selectByBusinessAndDataId" resultType="cn.gov.customs.wxjy.task.pojo.SyncDataStatus">
        <include refid="baseVo"/> where BUSINESS_TYPE = #{businessType} and BUSINESS_ID = #{businessId}
    </select>

    <insert id="insert" parameterType="SyncDataStatus">
        insert into WXJY_SYNC_DATA_STATUS
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ID != null and ID != ''">ID,
            </if>
            <if test="businessType != null and businessType != ''">BUSINESS_TYPE,
            </if>
            <if test="businessId != null and businessId != ''">BUSINESS_ID,
            </if>
            <if test="syncTime != null and syncTime != ''">SYNC_TIME,
            </if>
            <if test="syncVersion != null">SYNC_VERSION,
            </if>
            <if test="isDeleted != null">IS_DELETED,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ID != null and ID != ''">#{ID},
            </if>
            <if test="businessType != null and businessType != ''">#{businessType},
            </if>
            <if test="businessId != null and businessId != ''">#{businessId},
            </if>
            <if test="syncTime != null and syncTime != ''">#{syncTime},
            </if>
            <if test="syncVersion != null">#{syncVersion},
            </if>
            <if test="isDeleted != null">#{isDeleted},
            </if>
        </trim>
    </insert>

    <update id="update" parameterType="SyncDataStatus">
        update WXJY_SYNC_DATA_STATUS
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessType != null and businessType != ''">BUSINESS_TYPE =
                #{businessType},
            </if>
            <if test="businessId != null and businessId != ''">BUSINESS_ID =
                #{businessId},
            </if>
            <if test="syncTime != null and syncTime != ''">SYNC_TIME =
                #{syncTime},
            </if>
            <if test="syncVersion != null">SYNC_VERSION =
                #{syncVersion},
            </if>
            <if test="isDeleted != null">IS_DELETED =
                #{isDeleted},
            </if>
        </trim>
        where ID = #{ID}
    </update>
    <update id="updateSyncTime">
        UPDATE WXJY_SYNC_DATA_STATUS SET sync_time = #{syncTime}, sync_version = sync_version + 1
            WHERE business_type = #{businessType} AND BUSINESS_ID = #{businessId}
    </update>

    <delete id="deleteByID" parameterType="String">
        delete
        from WXJY_SYNC_DATA_STATUS where ID = #{ID}
    </delete>

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

    <delete id="logicDelete" parameterType="String">
        update  WXJY_SYNC_DATA_STATUS set is_del = 1  where ID = #{ID}
    </delete>
</mapper>