<?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="dvalueMapper">

    <select id="selectDValue" parameterType="pd" resultType="pd">
        select * from s_gxhpz_dvalue where 1=1
        <if test="d_value_code != null and d_value_code != ''">
            and d_value_code = #{d_value_code}
        </if>

        <if test="dValueName != null and dValueName != ''">
            and dValueName = #{dValueName}
        </if>

        <if test="createdBy != null and createdBy != ''">
            and createdBy = #{createdBy}
        </if>
        <if test="createdTime != null">
            and createdTime = #{createdTime}
        </if>
        <if test="updatedBy != null and updatedBy != ''">
            and updatedBy = #{updatedBy}
        </if>
        <if test="updatedTime != null">
            and updatedTime = #{updatedTime}
        </if>
        <if test="status != null and status != ''">
            and status = #{status}
        </if>
        <if test="remarks != null and remarks != ''">
            and remarks = #{remarks}
        </if>
        <if test="id != null and id != ''">
            and id = #{id}
        </if>
    </select>
    <select id="selectOneById" parameterType="pd" resultType="pd">
        select * from s_gxhpz_dvalue   where 1=1 and id=#{id}
    </select>
    <select id="checkValueByCode" parameterType="pd" resultType="pd">
        select * from s_gxhpz_dvalue   where d_value_code=#{d_value_code}
    </select>
    <select id="selectOne" parameterType="pd" resultType="pd">
        select *
        from s_gxhpz_dvalue  v

        where 1=1
        <if test="query != null and query != ''">
            AND (v.dValueName LIKE CONCAT('%', #{query}, '%')
            OR v.d_value_code = #{query})
        </if>
        and v.status = 1
        LIMIT 1
    </select>
    <update id="updateDValue" parameterType="pd">
        update s_gxhpz_dvalue
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="d_value_code != null and d_value_code != ''">
                d_value_code = #{d_value_code},
            </if>

            <if test="dValueName != null and dValueName != ''">
                dValueName = #{dValueName},
            </if>

            <if test="createdBy != null and createdBy != ''">
                createdBy = #{createdBy},
            </if>
            <if test="createdTime != null">
                createdTime = #{createdTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updatedBy = #{updatedBy},
            </if>
            <if test="updatedTime != null">
                updatedTime = #{updatedTime},
            </if>
            <if test="status != null and status != ''">
                status = #{status},
            </if>
            <if test="remarks != null and remarks != ''">
                remarks = #{remarks},
            </if>
        </trim>
        <if test="id != null">
            where id = #{id}
        </if>
    </update>
    <update id="updateDValueByd_value_code" parameterType="pd">
        update s_gxhpz_dvalue
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">

            <if test="dValueName != null and dValueName != ''">
                dValueName = #{dValueName},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updatedBy = #{updatedBy},
            </if>
            <if test="updatedTime != null">
                updatedTime = #{updatedTime},
            </if>
            <if test="status != null and status != ''">
                status = #{status},
            </if>
        </trim>
        <if test="d_value_code != null and d_value_code != ''">
            where d_value_code = #{d_value_code}
        </if>
    </update>
    <delete id="deleteDvalueByIds" parameterType="java.util.List">
        <if test="list != null and list.size() > 0">
            delete from s_gxhpz_dvalue
            where id in
            <foreach item="id" index="index" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </delete>


    <insert id="insertDValue" parameterType="pd">
        insert into s_gxhpz_dvalue
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="d_value_code != null and d_value_code != ''">
                d_value_code,
            </if>

            <if test="dValueName != null and dValueName != ''">
                dValueName,
            </if>
            <if test="createdBy != null and createdBy != ''">
                createdBy,
            </if>
            <if test="createdTime != null">
                createdTime,
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updatedBy,
            </if>
            <if test="updatedTime != null">
                updatedTime,
            </if>
            <if test="status != null and status !=''">
                status,
            </if>
            <if test="remarks != null and remarks != ''">
                remarks,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="d_value_code != null and d_value_code != ''">
                #{d_value_code},
            </if>

            <if test="dValueName != null and dValueName != ''">
                #{dValueName},
            </if>
            <if test="createdBy != null and createdBy != ''">
                #{createdBy},
            </if>
            <if test="createdTime != null">
                #{createdTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                #{updatedBy},
            </if>
            <if test="updatedTime != null">
                #{updatedTime},
            </if>
            <if test="status != null and status !=''">
                #{status},
            </if>
            <if test="remarks != null and remarks != ''">
                #{remarks},
            </if>
        </trim>
    </insert>

    <update id="changeStatus" parameterType="pd">
        update s_gxhpz_dvalue set  status = #{status}, updatedBy = #{updatedBy},updatedTime = #{updatedTime} where   id = #{id}
    </update>
</mapper>
