<?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.dgtly.system.mapper.CommunityMapper">
    
    <resultMap type="Community" id="CommunityResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="qrCode"    column="qr_code"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCommunityVo">
        select id, name, qr_code, create_by, create_time, update_by, update_time, remark from community
    </sql>

    <select id="selectCommunityList" parameterType="Community" resultMap="CommunityResult">
        <include refid="selectCommunityVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="qrCode != null  and qrCode != ''"> and qr_code = #{qrCode}</if>
        </where>
    </select>
    
    <select id="selectCommunityById" parameterType="Long" resultMap="CommunityResult">
        <include refid="selectCommunityVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCommunity" parameterType="Community">
        insert into community
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="name != null  and name != ''">name,</if>
            <if test="qrCode != null  and qrCode != ''">qr_code,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="name != null  and name != ''">#{name},</if>
            <if test="qrCode != null  and qrCode != ''">#{qrCode},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCommunity" parameterType="Community">
        update community
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null  and name != ''">name = #{name},</if>
            <if test="qrCode != null  and qrCode != ''">qr_code = #{qrCode},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCommunityById" parameterType="Long">
        delete from community where id = #{id}
    </delete>

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