<?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.trouble.mapper.SmzSspProblemmodifyDraftMapper">
    
    <resultMap type="SmzSspProblemmodifyDraft" id="SmzSspProblemmodifyDraftResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="projectId"    />
        <result property="infoType"    column="infoType"    />
        <result property="marksPicture"    column="marks_picture"    />
        <result property="marksVideo"    column="marks_video"    />
        <result property="problemArea"    column="problemArea"    />
        <result property="workParts"    column="workParts"    />
        <result property="changeInfo"    column="changeInfo"    />
        <result property="lordSent"    column="lordSent"    />
        <result property="lordSentUser"    column="lordSentUser"    />
        <result property="copySend"    column="copySend"    />
        <result property="copySendUser"    column="copySendUser"    />
        <result property="checkState"    column="checkState"    />
        <result property="nickedArea"    column="nickedArea"    />
        <result property="nickedTime"    column="nickedTime"    />
        <result property="projectType"    column="projectType"    />
        <result property="processName"    column="processName"    />
        <result property="projectName"    column="projectName"    />
        <result property="nickedInfo"    column="nickedInfo"    />
        <result property="checkUser"    column="checkUser"    />
        <result property="checkUserPhone"    column="checkUserPhone"    />
        <result property="smarkUrl"    column="smark_url"    />
        <result property="isDel"    column="isDel"    />
        <result property="createUser"    column="createUser"    />
        <result property="createUserName"    column="createUserName"    />
        <result property="createUserDeptName"    column="createUserDeptName"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
        <result property="dangerType"    column="danger_type"    />
        <result property="recheckSend"    column="recheckSend"    />
        <result property="recheckSendUser"    column="recheckSendUser"    />
        <result property="roleType"    column="roleType"    />
        <result property="problemType"    column="problemType"    />
    </resultMap>

    <sql id="selectSmzSspProblemmodifyDraftVo">
        select d.id, d.projectId, d.infoType, d.marks_picture, d.marks_video, d.problemArea, d.workParts, d.changeInfo, d.lordSent, d.lordSentUser, d.copySend, d.copySendUser, d.checkState, d.nickedArea, d.nickedTime, d.projectType, d.processName, d.projectName, d.nickedInfo, d.checkUser, d.checkUserPhone, d.smark_url, d.isDel, d.createUser, u.nick_name as createUserName, sd.dept_name as createUserDeptName, d.createTime, d.updateUser, d.updateTime, d.danger_type, d.recheckSend, d.recheckSendUser, d.roleType, d.problemType from smz_ssp_problemmodify_draft d
        left join sur_project sp on d.projectId = sp.id
        left join sys_user u on u.phonenumber = d.createUser
        left join sys_dept sd on sd.dept_id = u.dept_id
    </sql>

    <select id="selectSmzSspProblemmodifyDraftList" parameterType="SmzSspProblemmodifyDraft" resultMap="SmzSspProblemmodifyDraftResult">
        <include refid="selectSmzSspProblemmodifyDraftVo"/>
        <where>  
            <if test="projectId != null "> and d.projectId = #{projectId}</if>
            <if test="infoType != null "> and d.infoType = #{infoType}</if>
            <if test="roleType != null "> and d.roleType = #{roleType}</if>
            <if test="lordSent != null  and lordSent != ''"> and (d.lordSent like concat('%', #{lordSent}, '%') or d.lordSentUser like concat('%', #{lordSent}, '%'))</if>
            <!-- 查询条件-项目部门 -->
            <if test="projectDeptId != null "> and sp.deptId = #{projectDeptId}</if>
            <!--部门数据-->
            <if test='nowRole != "1" and nowRole != "2"'>
                <if test="nowUserName != null  and nowUserName != ''"> and d.createUser = #{nowUserName}</if>
                <if test="createUser != null  and createUser != ''"> and d.createUser = #{createUser}</if>
            </if>
        </where>
        order by d.createTime desc
    </select>
    
    <select id="selectSmzSspProblemmodifyDraftById" parameterType="Long" resultMap="SmzSspProblemmodifyDraftResult">
        <include refid="selectSmzSspProblemmodifyDraftVo"/>
        where d.id = #{id}
    </select>
        
    <insert id="insertSmzSspProblemmodifyDraft" parameterType="SmzSspProblemmodifyDraft" useGeneratedKeys="true" keyProperty="id">
        insert into smz_ssp_problemmodify_draft
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">projectId,</if>
            <if test="infoType != null">infoType,</if>
            <if test="marksPicture != null">marks_picture,</if>
            <if test="marksVideo != null">marks_video,</if>
            <if test="problemArea != null">problemArea,</if>
            <if test="workParts != null">workParts,</if>
            <if test="changeInfo != null">changeInfo,</if>
            <if test="lordSent != null">lordSent,</if>
            <if test="lordSentUser != null">lordSentUser,</if>
            <if test="copySend != null">copySend,</if>
            <if test="copySendUser != null">copySendUser,</if>
            <if test="checkState != null">checkState,</if>
            <if test="nickedArea != null">nickedArea,</if>
            <if test="nickedTime != null">nickedTime,</if>
            <if test="projectType != null">projectType,</if>
            <if test="processName != null">processName,</if>
            <if test="projectName != null">projectName,</if>
            <if test="nickedInfo != null">nickedInfo,</if>
            <if test="checkUser != null">checkUser,</if>
            <if test="checkUserPhone != null">checkUserPhone,</if>
            <if test="smarkUrl != null">smark_url,</if>
            <if test="isDel != null">isDel,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
            <if test="dangerType != null">danger_type,</if>
            <if test="recheckSend != null">recheckSend,</if>
            <if test="recheckSendUser != null">recheckSendUser,</if>
            <if test="roleType != null">roleType,</if>
            <if test="problemType != null">problemType,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="infoType != null">#{infoType},</if>
            <if test="marksPicture != null">#{marksPicture},</if>
            <if test="marksVideo != null">#{marksVideo},</if>
            <if test="problemArea != null">#{problemArea},</if>
            <if test="workParts != null">#{workParts},</if>
            <if test="changeInfo != null">#{changeInfo},</if>
            <if test="lordSent != null">#{lordSent},</if>
            <if test="lordSentUser != null">#{lordSentUser},</if>
            <if test="copySend != null">#{copySend},</if>
            <if test="copySendUser != null">#{copySendUser},</if>
            <if test="checkState != null">#{checkState},</if>
            <if test="nickedArea != null">#{nickedArea},</if>
            <if test="nickedTime != null">#{nickedTime},</if>
            <if test="projectType != null">#{projectType},</if>
            <if test="processName != null">#{processName},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="nickedInfo != null">#{nickedInfo},</if>
            <if test="checkUser != null">#{checkUser},</if>
            <if test="checkUserPhone != null">#{checkUserPhone},</if>
            <if test="smarkUrl != null">#{smarkUrl},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="dangerType != null">#{dangerType},</if>
            <if test="recheckSend != null">#{recheckSend},</if>
            <if test="recheckSendUser != null">#{recheckSendUser},</if>
            <if test="roleType != null">#{roleType},</if>
            <if test="problemType != null">#{problemType},</if>
         </trim>
    </insert>

    <update id="updateSmzSspProblemmodifyDraft" parameterType="SmzSspProblemmodifyDraft">
        update smz_ssp_problemmodify_draft
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">projectId = #{projectId},</if>
            <if test="infoType != null">infoType = #{infoType},</if>
            <if test="marksPicture != null">marks_picture = #{marksPicture},</if>
            <if test="marksVideo != null">marks_video = #{marksVideo},</if>
            <if test="problemArea != null">problemArea = #{problemArea},</if>
            <if test="workParts != null">workParts = #{workParts},</if>
            <if test="changeInfo != null">changeInfo = #{changeInfo},</if>
            <if test="lordSent != null">lordSent = #{lordSent},</if>
            <if test="lordSentUser != null">lordSentUser = #{lordSentUser},</if>
            <if test="copySend != null">copySend = #{copySend},</if>
            <if test="copySendUser != null">copySendUser = #{copySendUser},</if>
            <if test="checkState != null">checkState = #{checkState},</if>
            <if test="nickedArea != null">nickedArea = #{nickedArea},</if>
            <if test="nickedTime != null">nickedTime = #{nickedTime},</if>
            <if test="projectType != null">projectType = #{projectType},</if>
            <if test="processName != null">processName = #{processName},</if>
            <if test="projectName != null">projectName = #{projectName},</if>
            <if test="nickedInfo != null">nickedInfo = #{nickedInfo},</if>
            <if test="checkUser != null">checkUser = #{checkUser},</if>
            <if test="checkUserPhone != null">checkUserPhone = #{checkUserPhone},</if>
            <if test="smarkUrl != null">smark_url = #{smarkUrl},</if>
            <if test="isDel != null">isDel = #{isDel},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
            <if test="dangerType != null">danger_type = #{dangerType},</if>
            <if test="recheckSend != null">recheckSend = #{recheckSend},</if>
            <if test="recheckSendUser != null">recheckSendUser = #{recheckSendUser},</if>
            <if test="roleType != null">roleType = #{roleType},</if>
            <if test="problemType != null">problemType = #{problemType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSmzSspProblemmodifyDraftById" parameterType="Long">
        delete from smz_ssp_problemmodify_draft where id = #{id}
    </delete>

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