<?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.xinelu.manage.mapper.crowdinfo.CrowdInfoMapper">

    <resultMap type="CrowdInfo" id="CrowdInfoResult">
            <result property="id" column="id"/>
            <result property="crowdName" column="crowd_name"/>
            <result property="minSuitableAge" column="min_suitable_age"/>
            <result property="maxSuitableAge" column="max_suitable_age"/>
            <result property="suitableGender" column="suitable_gender"/>
            <result property="crowdType" column="crowd_type"/>
            <result property="specialType" column="special_type"/>
            <result property="whetherDisable" column="whether_disable"/>
            <result property="remark" column="remark"/>
            <result property="sort" column="sort"/>
            <result property="delFlag" column="del_flag"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectCrowdInfoVo">
        select id, crowd_name, min_suitable_age, max_suitable_age, suitable_gender, crowd_type, special_type, whether_disable, remark, sort, del_flag, create_by, create_time, update_by, update_time from crowd_info
    </sql>

    <select id="selectCrowdInfoList" parameterType="CrowdInfo" resultMap="CrowdInfoResult">
        <include refid="selectCrowdInfoVo"/>
        <where>
            del_flag = 0
            <if test="crowdName != null  and crowdName != ''">
                and crowd_name like concat('%', #{crowdName}, '%')
            </if>
            <if test="minSuitableAge != null ">
                and min_suitable_age = #{minSuitableAge}
            </if>
            <if test="maxSuitableAge != null ">
                and max_suitable_age = #{maxSuitableAge}
            </if>
            <if test="suitableGender != null  and suitableGender != ''">
                and suitable_gender = #{suitableGender}
            </if>
            <if test="crowdType != null  and crowdType != ''">
                and crowd_type = #{crowdType}
            </if>
            <if test="specialType != null  and specialType != ''">
                and special_type = #{specialType}
            </if>
            <if test="whetherDisable != null ">
                and whether_disable = #{whetherDisable}
            </if>
        </where>
        order by sort
    </select>

    <select id="selectCrowdInfoById" parameterType="Long"
            resultMap="CrowdInfoResult">
            <include refid="selectCrowdInfoVo"/>
            where id = #{id}
    </select>

    <insert id="insertCrowdInfo" parameterType="CrowdInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into crowd_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="crowdName != null">crowd_name,
        </if>
        <if test="minSuitableAge != null">min_suitable_age,
        </if>
        <if test="maxSuitableAge != null">max_suitable_age,
        </if>
        <if test="suitableGender != null">suitable_gender,
        </if>
        <if test="crowdType != null">crowd_type,
        </if>
        <if test="specialType != null">special_type,
        </if>
        <if test="whetherDisable != null">whether_disable,
        </if>
        <if test="remark != null">remark,
        </if>
        <if test="sort != null">sort,
        </if>
        <if test="delFlag != null">del_flag,
        </if>
        <if test="createBy != null">create_by,
        </if>
        <if test="createTime != null">create_time,
        </if>
        <if test="updateBy != null">update_by,
        </if>
        <if test="updateTime != null">update_time,
        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="crowdName != null">#{crowdName},
            </if>
            <if test="minSuitableAge != null">#{minSuitableAge},
            </if>
            <if test="maxSuitableAge != null">#{maxSuitableAge},
            </if>
            <if test="suitableGender != null">#{suitableGender},
            </if>
            <if test="crowdType != null">#{crowdType},
            </if>
            <if test="specialType != null">#{specialType},
            </if>
            <if test="whetherDisable != null">#{whetherDisable},
            </if>
            <if test="remark != null">#{remark},
            </if>
            <if test="sort != null">#{sort},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateCrowdInfo" parameterType="CrowdInfo">
        update crowd_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="crowdName != null">crowd_name =
                #{crowdName},
            </if>
            <if test="minSuitableAge != null">min_suitable_age =
                #{minSuitableAge},
            </if>
            <if test="maxSuitableAge != null">max_suitable_age =
                #{maxSuitableAge},
            </if>
            <if test="suitableGender != null">suitable_gender =
                #{suitableGender},
            </if>
            <if test="crowdType != null">crowd_type =
                #{crowdType},
            </if>
            <if test="specialType != null">special_type =
                #{specialType},
            </if>
            <if test="whetherDisable != null">whether_disable =
                #{whetherDisable},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
            <if test="sort != null">sort =
                #{sort},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCrowdInfoById" parameterType="Long">
        delete from crowd_info where id = #{id}
    </delete>

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