<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.EventCategoryDao">

    <select id="selectEventCategoryList" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategory" resultType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategory">
        SELECT
        a.id,
        a.value,
        a.label,
        a.parent_id,
        ifnull(a.is_easy,0) as is_easy,
        a.sort
        FROM
        sys_dict a
        WHERE
        a.del_flag = '0'
        AND a.type = 'event_category'
        <!--<if test="id != null and id != ''">
            AND a.parent_id = #{id}
        </if>
        <if test="id == null or id == ''">
            AND a.parent_id = '0'
        </if>-->
        <if test="label!=null and label!=''">
            and a.label LIKE CONCAT('%', #{label}, '%')
        </if>
        ORDER BY a.sort
    </select>

    <insert id="insertEventCategory" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategory">
      insert into sys_dict
      (
        id,
        value,
        type,
        dict_type,
        <if test="label != null and label != ''">label,</if>
        <if test="sort != null and sort != ''">sort,</if>
        <if test="parent_id != null and parent_id != ''">parent_id,</if>
        create_by,
        create_date
      )
      values
      (
        uuid(),
        uuid(),
        'event_category',
        1,
        <if test="label != null and label != ''">#{label},</if>
        <if test="sort != null and sort != ''">#{sort},</if>
        <if test="parent_id != null and parent_id != ''">#{parent_id},</if>
        #{_user.id},
        now()
      )
    </insert>

    <update id="updateEventCategory" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategory">
      update sys_dict
      <set>
        <if test="label != null and label != ''">label = #{label},</if>
        <if test="sort != null and sort != ''">sort = #{sort},</if>
        <if test="del_flag != null and del_flag != ''">del_flag = #{del_flag},</if>
        <if test="is_easy != null and is_easy != ''">is_easy = #{is_easy},</if>
      </set>
      where id = #{id}
    </update>

    <select id="selectEventCategoryOtherList" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategoryOther"
            resultType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategoryOther">
        select
        a.id,
        a.event_id,
        a.event_category_other_name,
        a.event_category_mini_other_name,
        b.name as create_by,
        DATE_FORMAT(a.create_time,'%Y-%m-%d %T') create_time
        from jl_event_category_other a
        join sys_user b on a.create_by=b.id
        where a.del_flag='0'
        <if test="event_category_other_name!=null and event_category_other_name!=''">
            and a.event_category_other_name LIKE CONCAT('%', #{event_category_other_name}, '%')
        </if>
        <if test="event_category_mini_other_name!=null and event_category_mini_other_name!=''">
            and a.event_category_mini_other_name LIKE CONCAT('%', #{event_category_mini_other_name}, '%')
        </if>
        order by a.sort asc
    </select>

    <update id="updateEventCategoryOther" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategoryOther">
        update jl_event_category_other
        set update_by=#{_user.id},
        update_time=now()
        <if test="del_flag!=null and del_flag!=''">
            ,del_flag=#{del_flag}
        </if>
        <if test="sort!=null and sort!=''">
            ,sort=#{sort}
        </if>
        where id=#{id}
    </update>

    <select id="selectEventCategory"  parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategory" resultType="com.scpyun.platform.jilinsscgsdp.bean.entity.EventCategory">
        SELECT
        a.id,
        a.value,
        a.label,
        a.parent_id,
        ifnull(a.is_easy,0) as is_easy,
        a.sort
        FROM
        sys_dict a
        WHERE
        a.del_flag = '0'
        AND a.type = 'event_category'
        AND a.value=#{value}
    </select>

</mapper>
