<?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.zehong.system.mapper.TPublicSentimentMapper">
    
    <resultMap type="com.zehong.system.domain.TPublicSentiment" id="TPublicSentimentResult">
        <result property="sentimentId"    column="sentiment_id"    />
        <result property="shengId"    column="sheng_id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="sentimentFile"    column="sentiment_file"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="status"    column="status"    />
        <result property="disposeTitle"    column="dispose_title"    />
        <result property="disposeContent"    column="dispose_content"    />
        <result property="disposeFile"    column="dispose_file"    />
        <result property="person"    column="person"    />
        <result property="phone"    column="phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="region"    column="region"    />
        <result property="startTime"    column="start_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTPublicSentimentVo">
        select sentiment_id, sheng_id, title, content, sentiment_file, enterprise_id, status,
        (SELECT enterprise_name FROM t_enterprise_info e WHERE e.enterprise_id = f.enterprise_id) as enterpriseName,
        dispose_title, dispose_content, dispose_file, person, phone, create_time, is_del, region, start_time,update_time from t_public_sentiment f
    </sql>

    <select id="selectTPublicSentimentList" parameterType="TPublicSentiment" resultMap="TPublicSentimentResult">
        <include refid="selectTPublicSentimentVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="enterpriseId != null  and enterpriseId != ''"> and enterprise_id = #{enterpriseId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="region != null  and region != ''"> and region = #{region}</if>
            <if test="startTime != null  and startTime != ''"> AND date_format(start_time,'%y') &gt;= date_format(#{startTime},'%y')</if>
        </where>
    </select>
    
    <select id="selectTPublicSentimentById" parameterType="Long" resultMap="TPublicSentimentResult">
        <include refid="selectTPublicSentimentVo"/>
        where sentiment_id = #{sentimentId}
    </select>
        
    <insert id="insertTPublicSentiment" parameterType="TPublicSentiment" useGeneratedKeys="true" keyProperty="sentimentId">
        insert into t_public_sentiment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shengId != null">sheng_id,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="sentimentFile != null">sentiment_file,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
            <if test="status != null">status,</if>
            <if test="disposeTitle != null and disposeTitle != ''">dispose_title,</if>
            <if test="disposeContent != null and disposeContent != ''">dispose_content,</if>
            <if test="disposeFile != null">dispose_file,</if>
            <if test="person != null">person,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="region != null">region,</if>
            <if test="startTime != null">start_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shengId != null">#{shengId},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="sentimentFile != null">#{sentimentFile},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
            <if test="status != null">#{status},</if>
            <if test="disposeTitle != null and disposeTitle != ''">#{disposeTitle},</if>
            <if test="disposeContent != null and disposeContent != ''">#{disposeContent},</if>
            <if test="disposeFile != null">#{disposeFile},</if>
            <if test="person != null">#{person},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="region != null">#{region},</if>
            <if test="startTime != null">#{startTime},</if>
         </trim>
    </insert>

    <update id="updateTPublicSentiment" parameterType="TPublicSentiment">
        update t_public_sentiment
        <trim prefix="SET" suffixOverrides=",">
            <if test="shengId != null">sheng_id = #{shengId},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="sentimentFile != null">sentiment_file = #{sentimentFile},</if>
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="disposeTitle != null and disposeTitle != ''">dispose_title = #{disposeTitle},</if>
            <if test="disposeContent != null and disposeContent != ''">dispose_content = #{disposeContent},</if>
            <if test="disposeFile != null">dispose_file = #{disposeFile},</if>
            <if test="person != null">person = #{person},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="region != null">region = #{region},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where sentiment_id = #{sentimentId}
    </update>

    <delete id="deleteTPublicSentimentById" parameterType="Long">
        delete from t_public_sentiment where sentiment_id = #{sentimentId}
    </delete>

    <delete id="deleteTPublicSentimentByIds" parameterType="String">
        delete from t_public_sentiment where sentiment_id in 
        <foreach item="sentimentId" collection="array" open="(" separator="," close=")">
            #{sentimentId}
        </foreach>
    </delete>

    <select id="queryAllByNotDeleteAndCreateTime" resultType="com.zehong.system.domain.dto.TComplainDealDTO">
        select sentiment_id as complainDealId,status as complainStatus ,start_time as createTime, update_time as updateTime,MONTH(start_time) as createTimeYear ,region as township from t_public_sentiment
        where is_del = '0'
        <if test="startOfMonth != null and  endOfMonth != null">
            and start_time  <![CDATA[>=]]> #{startOfMonth} and start_time  <![CDATA[<=]]> #{endOfMonth}
        </if>
        <if test="township != null and township != '' and township != 0 ">
            and region = #{township}
        </if>
        order by create_time asc
    </select>
</mapper>