<?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.goldenwater.gx.mapper.GxExchangeQualityMapper">

    <resultMap type="com.goldenwater.gx.domain.GxExchangeQuality" id="GxExchangeQualityResult">
        <id     property="id"            column="id"             />
        <result property="bizCode"       column="biz_code"       />
        <result property="stcd"          column="stcd"           />
        <result property="analysisDate"  column="analysis_date"  />
        <result property="type"          column="type"           />
        <result property="value"         column="value"          />
        <result property="cnt"           column="cnt"            />
        <result property="description"   column="description"    />
        <result property="starttime"     column="starttime"      />
        <result property="endtime"       column="endtime"        />
        <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="delFlag"       column="del_flag"       />
        <result property="stnm"          column="stnm"           />
    </resultMap>

    <select id="selectGxExchangeQualityList" parameterType="com.goldenwater.gx.domain.GxExchangeQuality" resultMap="GxExchangeQualityResult">
        select q.id, q.biz_code, q.stcd, q.analysis_date, q.type, q.value, q.cnt,
               q.description, q.starttime, q.endtime, q.create_by, q.create_time,
               q.update_by, q.update_time, q.del_flag,
               s.stnm
        from gx_exchange_quality q
        left join gx_exchange_station s on q.stcd = s.stcd and s.del_flag = '0'
        where q.del_flag = '0'
        <if test="bizCode != null and bizCode != ''">
            AND q.biz_code = #{bizCode}
        </if>
        <if test="stcd != null and stcd != ''">
            AND q.stcd = #{stcd}
        </if>
        <if test="type != null and type != ''">
            AND q.type = #{type}
        </if>
        <if test="params.beginTime != null and params.beginTime != ''">
            AND q.analysis_date &gt;= TO_DATE(#{params.beginTime}, 'YYYY-MM-DD')
        </if>
        <if test="params.endTime != null and params.endTime != ''">
            AND q.analysis_date &lt;= TO_DATE(#{params.endTime}, 'YYYY-MM-DD')
        </if>
        order by q.analysis_date desc
    </select>

    <select id="selectGxExchangeQualityById" parameterType="Long" resultMap="GxExchangeQualityResult">
        select q.id, q.biz_code, q.stcd, q.analysis_date, q.type, q.value, q.cnt,
               q.description, q.starttime, q.endtime, q.create_by, q.create_time,
               q.update_by, q.update_time, q.del_flag, s.stnm
        from gx_exchange_quality q
        left join gx_exchange_station s on q.stcd = s.stcd and s.del_flag = '0'
        where q.id = #{id} and q.del_flag = '0'
    </select>

    <insert id="insertGxExchangeQuality" parameterType="com.goldenwater.gx.domain.GxExchangeQuality" useGeneratedKeys="true" keyProperty="id">
        insert into gx_exchange_quality
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bizCode != null and bizCode != ''">biz_code,</if>
            <if test="stcd != null and stcd != ''">stcd,</if>
            <if test="analysisDate != null">analysis_date,</if>
            <if test="type != null">type,</if>
            <if test="value != null">value,</if>
            <if test="cnt != null">cnt,</if>
            <if test="description != null">description,</if>
            <if test="starttime != null">starttime,</if>
            <if test="endtime != null">endtime,</if>
            <if test="createBy != null">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bizCode != null and bizCode != ''">#{bizCode},</if>
            <if test="stcd != null and stcd != ''">#{stcd},</if>
            <if test="analysisDate != null">#{analysisDate},</if>
            <if test="type != null">#{type},</if>
            <if test="value != null">#{value},</if>
            <if test="cnt != null">#{cnt},</if>
            <if test="description != null">#{description},</if>
            <if test="starttime != null">#{starttime},</if>
            <if test="endtime != null">#{endtime},</if>
            <if test="createBy != null">#{createBy},</if>
            SYSDATE
        </trim>
    </insert>

    <update id="updateGxExchangeQuality" parameterType="com.goldenwater.gx.domain.GxExchangeQuality">
        update gx_exchange_quality
        <set>
            <if test="value != null">value = #{value},</if>
            <if test="cnt != null">cnt = #{cnt},</if>
            <if test="description != null">description = #{description},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = SYSDATE
        </set>
        where id = #{id}
    </update>

    <update id="deleteGxExchangeQualityById" parameterType="Long">
        update gx_exchange_quality set del_flag = '1' where id = #{id}
    </update>

    <update id="deleteGxExchangeQualityByIds" parameterType="Long">
        update gx_exchange_quality set del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
