<?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.yanzhu.jh.work.mapper.WorkJournalismMapper">
    
    <resultMap type="WorkJournalism" id="WorkJournalismResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="mainImage"    column="main_image"    />
        <result property="intro"    column="intro"    />
        <result property="content"    column="content"    />
        <result property="type"    column="type"    />
        <result property="source"    column="source"    />
        <result property="openUrl"    column="open_url"    />
        <result property="readNum"    column="read_num"    />
        <result property="statusFlag"    column="status_flag"    />
        <result property="topFlag"    column="top_flag"    />
        <result property="files"    column="files"    />
        <result property="sortNum"    column="sort_num"    />
        <result property="isDel"    column="is_del"    />
        <result property="createUser"    column="create_user"    />
        <result property="createDate"    column="create_date"    />
        <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="selectWorkJournalismVo">
        select id, title, main_image, intro, content, type, source, open_url, read_num, status_flag, top_flag, files, sort_num, is_del, create_user, create_date, create_by, create_time, update_by, update_time, remark from work_journalism
    </sql>

    <select id="selectWorkJournalismList" parameterType="WorkJournalism" resultMap="WorkJournalismResult">
        select id, title, main_image, intro, type, source, open_url, read_num, status_flag, top_flag, files, sort_num, is_del, create_user, create_date, create_by, create_time, update_by, update_time, remark from work_journalism
        <where>
            and is_del=0
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="statusFlag != null  and statusFlag != ''"> and status_flag = #{statusFlag}</if>
            <if test="topFlag != null  and topFlag != ''"> and top_flag = #{topFlag}</if>
            <if test="sortNum != null "> and sort_num = #{sortNum}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_date between #{params.beginCreateTime} and #{params.endCreateTime}</if>
            <if test='activeName == "dfb"'> and status_flag in (1,3)</if>
            <if test='activeName == "yfb"'> and status_flag=2</if>
        </where>
        order by top_flag desc, sort_num asc, create_date desc
    </select>

    <select id="selectBgscreenWorkJournalismList" resultMap="WorkJournalismResult">
        select id, title, main_image, intro, type, source, open_url, read_num, status_flag, top_flag, files, sort_num, is_del, create_user, create_date, create_by, create_time, update_by, update_time, remark from work_journalism
            where is_del=0
            and status_flag=2
        order by top_flag desc, sort_num asc, create_date desc
        limit 0,4
    </select>

    <select id="findWorkJournalismGroupStatus" parameterType="WorkJournalism" resultType="map">
        select status_flag as statusFlag, count(id) as total from work_journalism
        <where>
            and is_del=0
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_date between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
        group by status_flag
    </select>
    
    <select id="selectWorkJournalismById" parameterType="Long" resultMap="WorkJournalismResult">
        <include refid="selectWorkJournalismVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWorkJournalism" parameterType="WorkJournalism" useGeneratedKeys="true" keyProperty="id">
        insert into work_journalism
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="mainImage != null">main_image,</if>
            <if test="intro != null">intro,</if>
            <if test="content != null">content,</if>
            <if test="type != null">type,</if>
            <if test="source != null">source,</if>
            <if test="openUrl != null">open_url,</if>
            <if test="readNum != null">read_num,</if>
            <if test="statusFlag != null">status_flag,</if>
            <if test="topFlag != null">top_flag,</if>
            <if test="files != null">files,</if>
            <if test="sortNum != null">sort_num,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createUser != null">create_user,</if>
            <if test="createDate != null">create_date,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="mainImage != null">#{mainImage},</if>
            <if test="intro != null">#{intro},</if>
            <if test="content != null">#{content},</if>
            <if test="type != null">#{type},</if>
            <if test="source != null">#{source},</if>
            <if test="openUrl != null">#{openUrl},</if>
            <if test="readNum != null">#{readNum},</if>
            <if test="statusFlag != null">#{statusFlag},</if>
            <if test="topFlag != null">#{topFlag},</if>
            <if test="files != null">#{files},</if>
            <if test="sortNum != null">#{sortNum},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createDate != null">#{createDate},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWorkJournalism" parameterType="WorkJournalism">
        update work_journalism
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="mainImage != null">main_image = #{mainImage},</if>
            <if test="intro != null">intro = #{intro},</if>
            <if test="content != null">content = #{content},</if>
            <if test="type != null">type = #{type},</if>
            <if test="source != null">source = #{source},</if>
            <if test="openUrl != null">open_url = #{openUrl},</if>
            <if test="readNum != null">read_num = #{readNum},</if>
            <if test="statusFlag != null">status_flag = #{statusFlag},</if>
            <if test="topFlag != null">top_flag = #{topFlag},</if>
            <if test="files != null">files = #{files},</if>
            <if test="sortNum != null">sort_num = #{sortNum},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createUser != null">create_user = #{createUser},</if>
            <if test="createDate != null">create_date = #{createDate},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWorkJournalismById" parameterType="Long">
        delete from work_journalism where id = #{id}
    </delete>

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