<?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.fastbee.rechargecard.mapper.NgUrbanMuRightsMapper">

    <resultMap type="NgUrbanMuRights" id="NgUrbanMuRightsResult">
        <result property="muRightsId"    column="mu_rights_id"    />
        <result property="year"    column="year"    />
        <result property="water"    column="water"    />
        <result property="administrative"    column="administrative"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectNgUrbanMuRightsVo">
        select mu_rights_id, year, water, administrative, remark, create_time, update_time, create_by, update_by from ng_urban_mu_rights
    </sql>

    <select id="selectNgUrbanMuRightsList" parameterType="NgUrbanMuRights" resultMap="NgUrbanMuRightsResult">
        <include refid="selectNgUrbanMuRightsVo"/>
        <where>
            <if test="year != null "> and year = #{year}</if>
            <if test="water != null "> and water = #{water}</if>
            <if test="administrative != null  and administrative != ''"> and administrative = #{administrative}</if>
        </where>
    </select>

    <select id="selectNgUrbanMuRightsByMuRightsId" parameterType="Long" resultMap="NgUrbanMuRightsResult">
        <include refid="selectNgUrbanMuRightsVo"/>
        where mu_rights_id = #{muRightsId}
    </select>

    <insert id="insertNgUrbanMuRights" parameterType="NgUrbanMuRights" useGeneratedKeys="true" keyProperty="muRightsId">
        insert into ng_urban_mu_rights
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="year != null">year,</if>
            <if test="water != null">water,</if>
            <if test="administrative != null">administrative,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="year != null">#{year},</if>
            <if test="water != null">#{water},</if>
            <if test="administrative != null">#{administrative},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateNgUrbanMuRights" parameterType="NgUrbanMuRights">
        update ng_urban_mu_rights
        <trim prefix="SET" suffixOverrides=",">
            <if test="year != null">year = #{year},</if>
            <if test="water != null">water = #{water},</if>
            <if test="administrative != null">administrative = #{administrative},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where mu_rights_id = #{muRightsId}
    </update>

    <delete id="deleteNgUrbanMuRightsByMuRightsId" parameterType="Long">
        delete from ng_urban_mu_rights where mu_rights_id = #{muRightsId}
    </delete>

    <delete id="deleteNgUrbanMuRightsByMuRightsIds" parameterType="String">
        delete from ng_urban_mu_rights where mu_rights_id in
        <foreach item="muRightsId" collection="array" open="(" separator="," close=")">
            #{muRightsId}
        </foreach>
    </delete>
</mapper>