<?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.SmzSspProblemmodifyMapper">
    
    <resultMap type="SmzSspProblemmodify" id="SmzSspProblemmodifyResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="projectId"    />
        <result property="infoType"    column="infoType"    />
        <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="isDel"    column="isDel"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
        <result property="marksPicture"    column="marks_picture"    />
        <result property="marksVideo"    column="marks_video"    />
        <result property="smarkUrl"    column="smark_url"    />
        <result property="dangerType"    column="danger_type"    />
        <result property="dangerTypeName"    column="danger_type_name"    />
        <result property="recheckSend"    column="recheckSend"    />
        <result property="recheckSendUser"    column="recheckSendUser"    />
        <result property="roleType"    column="roleType"    />
        <result property="problemType"    column="problemType"    />
        <result property="vDel"    column="v_del"    />
        <result property="createBy" column="createBy"/>
        <result property="deptName" column="deptName"/>
        <result property="createUserName" column="createUserName"/>
        <result property="flag" column="flag"/>
        <result property="chkLabel" column="chkLabel"></result>
        <result property="dangerLabel" column="dangerLabel"></result>
        <collection property="unitInfos" ofType="SurProjectUnitInfo">
            <id column="unitId" property="id"></id>
            <result property="unitName" column="unitName"></result>
        </collection>
    </resultMap>

    <sql id="selectSmzSspProblemmodifyVo">
        select id, projectId, infoType, problemArea, workParts, changeInfo, lordSent, lordSentUser, copySend, copySendUser, checkState, nickedArea, nickedTime, projectType, processName, projectName, nickedInfo, checkUser, checkUserPhone, isDel, createUser, createTime, updateUser, updateTime, marks_picture, marks_video, smark_url, danger_type,problemType, recheckSend, recheckSendUser, roleType, problemType  from smz_ssp_problemmodify
    </sql>

    <select id="selectSmzSspProblemmodifyList" parameterType="SmzSspProblemmodifyWhere" resultMap="SmzSspProblemmodifyResult">
        select ssp.id, ssp.projectId, ssp.infoType, sp.projectName as problemArea, ssp.workParts, ssp.changeInfo, ssp.lordSent, ssp.lordSentUser, ssp.copySend, ssp.copySendUser, ssp.checkState, ssp.nickedArea, ssp.nickedTime, ssp.projectType, ssp.processName, ssp.projectName, ssp.nickedInfo, ssp.checkUser, ssp.checkUserPhone, ssp.isDel, ssp.createUser, ssp.createTime, ssp.updateUser, ssp.updateTime, ssp.marks_picture, ssp.marks_video, ssp.smark_url, ssp.danger_type, ssp.recheckSend, ssp.recheckSendUser, ssp.roleType, su.nick_name as createBy
        from vw_smz_ssp_problemmodify_audit ssp
        left join sur_project sp on ssp.projectId = sp.id
        left join sys_user su ON su.phonenumber = ssp.createUser
        <!--监理单位/总包公司/分包单位-->
        <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> left join sur_project_unit_info spui on spui.projectId = sp.id</if>
        <where>
            and ssp.isDel=0
            <if test="projectId != null "> and ssp.projectId = #{projectId}</if>
            <if test="infoType != null "> and ssp.infoType = #{infoType}</if>
            <if test="roleType != null and roleType >0 "> and ssp.roleType = #{roleType}</if>
            <if test="problemArea != null  and problemArea != ''"> and ssp.problemArea like concat('%', #{problemArea}, '%')</if>
            <if test="workParts != null  and workParts != ''"> and ssp.workParts like concat('%', #{workParts}, '%')</if>
            <if test="changeInfo != null  and changeInfo != ''"> and ssp.changeInfo like concat('%', #{changeInfo}, '%')</if>
            <if test="lordSent != null  and lordSent != ''"> and (ssp.lordSent like concat('%', #{lordSent}, '%') or ssp.lordSentUser like concat('%', #{lordSent}, '%'))</if>
            <if test="lordSentUser != null  and lordSentUser != ''"> and ssp.lordSentUser = #{lordSentUser}</if>
            <if test="copySend != null  and copySend != ''"> and ssp.copySend = #{copySend}</if>
            <if test="copySendUser != null  and copySendUser != ''"> and ssp.copySendUser = #{copySendUser}</if>
            <if test="checkState != null "> and ssp.checkState = #{checkState}</if>
            <if test="nickedArea != null  and nickedArea != ''"> and nickedArea = #{nickedArea}</if>
            <if test="nickedTime != null "> and ssp.nickedTime = #{nickedTime}</if>
            <if test="problemType != null "> and ssp.problemType = #{problemType}</if>
            <if test="projectType != null  and projectType != ''"> and ssp.projectType = #{projectType}</if>
            <if test="processName != null  and processName != ''"> and ssp.processName like concat('%', #{processName}, '%')</if>
            <if test="projectName != null  and projectName != ''"> and ssp.projectName like concat('%', #{projectName}, '%')</if>
            <if test="nickedInfo != null  and nickedInfo != ''"> and ssp.nickedInfo = #{nickedInfo}</if>
            <if test="checkUser != null  and checkUser != ''"> and ssp.checkUser = #{checkUser}</if>
            <if test="checkUserPhone != null  and checkUserPhone != ''"> and ssp.checkUserPhone = #{checkUserPhone}</if>
            <if test="isDel != null "> and ssp.isDel = #{isDel}</if>
            <if test="startDate!=null">and DATE(ssp.createtime)>=DATE(#{startDate})</if>
            <if test="endDate!=null">and DATE(ssp.createtime) &lt;= DATE(#{endDate})</if>
            <if test="createUser != null  and createUser != ''"> and ssp.createUser like concat('%', #{createUser}, '%')</if>
            <if test="createBy != null  and createBy != ''"> and (ssp.createUser like concat('%', #{createBy}, '%') or su.nick_name like concat('%', #{createBy}, '%'))</if>
            <if test="createTime != null "> and ssp.createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and ssp.updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and ssp.updateTime = #{updateTime}</if>
            <if test="dangerType != null  and dangerType != ''"> and ssp.danger_type = #{dangerType}</if>
            <if test="params.beginMarksTime != null and params.beginMarksTime != '' and params.endMarksTime != null and params.endMarksTime != ''"> and date(ssp.createTime) between #{params.beginMarksTime} and #{params.endMarksTime}</if>
            <!-- 查询条件-项目部门 -->
            <if test="projectDeptId != null "> and sp.deptId = #{projectDeptId}</if>
            <!--子部门数据-->
            <if test='nowRole == "4"'> and sp.deptId = #{nowDept}</if>
            <!--监理单位/总包公司/分包单位查询当前关联数据-->
            <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> and spui.unitId = #{nowDept}</if>
            <!--普通整改人是我，复检人是我，抄送人是我，提交人是我的数据-->
            <if test='nowRole == "15" or nowRole == "16" or nowRole == "17" or nowRole == "99"'> and (ssp.lordSentUser = #{nowUser} or ssp.copySendUser like concat('%', #{nowUser}, '%') or ssp.recheckSendUser = #{nowUser} or ssp.createUser = #{nowUser} )</if>
            <if test='activeName == "dzg"'> and ssp.checkState in (0,3)</if>
            <if test='activeName == "dqr"'> and ssp.checkState in (1)</if>
            <if test='activeName == "ycl"'> and ssp.checkState = 4 </if>
            <if test='activeName == "zgcs"'> and (date(NOW())<![CDATA[ > ]]> date(ssp.nickedTime) and (ssp.updateTime is null or date(ssp.updateTime) <![CDATA[ > ]]> date(ssp.nickedTime))) </if>
            <if test="roleTypes!=null">
                and roleType in
                <foreach collection="roleTypes" item="item" index="index" open="(" close=")" separator=",">${item}</foreach>
            </if>
        </where>
        order by createTime desc
    </select>

    <select id="selectWechatSmzSspProblemmodifyList" parameterType="SmzSspProblemmodify" resultMap="SmzSspProblemmodifyResult">
        select ssp.id, ssp.projectId, ssp.infoType, sp.projectName as problemArea, ssp.workParts, ssp.changeInfo, ssp.lordSent, ssp.lordSentUser, ssp.copySend, ssp.copySendUser, ssp.checkState, ssp.nickedArea, ssp.nickedTime, ssp.projectType, ssp.processName, ssp.projectName, ssp.nickedInfo, ssp.checkUser, ssp.checkUserPhone, ssp.isDel, ssp.createUser, ssp.createTime, ssp.updateUser, ssp.updateTime, ssp.marks_picture, ssp.marks_video, ssp.smark_url, ssp.danger_type, ssp.recheckSend, ssp.recheckSendUser, ssp.roleType, ssp.problemType, su.nick_name as createBy,
        case when ud.type_flag in (1,11) then sd.dept_name else ud.dept_name end as deptName,
        sdd.dict_label as danger_type_name,
        case when ssp.recheckSendUser = #{nowUser} and ssp.checkState=1 then 0
             when ssp.lordSentUser = #{nowUser} then 1
        else 2 end sort
        from smz_ssp_problemmodify ssp
        left join sur_project sp on ssp.projectId = sp.id
        LEFT JOIN sys_user su ON ssp.createUser = su.phonenumber
        left join sys_dept ud on ud.dept_id = su.dept_id
        left join sys_dept sd on sd.dept_id = sp.deptId
        <if test='infoType == "0" '> left join sys_dict_data sdd on sdd.dict_type = 'ssp_aqyhlx' and sdd.dict_value = ssp.danger_type</if>
        <if test='infoType == "1" '> left join sys_dict_data sdd on sdd.dict_type = 'ssp_zlyhlx' and sdd.dict_value = ssp.danger_type</if>
        <!--监理单位/总包公司/分包单位-->
        <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> left join sur_project_unit_info spui on spui.projectId = sp.id</if>
        <where>
            and ssp.isDel=0
            <if test="projectId != null "> and ssp.projectId = #{projectId}</if>
            <if test="infoType != null "> and ssp.infoType = #{infoType}</if>
            <if test="problemType != null "> and ssp.problemType = #{problemType}</if>
            <if test="roleType != null and roleType >0 "> and ssp.roleType = #{roleType}</if>
            <if test="problemArea != null  and problemArea != ''"> and ssp.problemArea like concat('%', #{problemArea}, '%')</if>
            <if test="workParts != null  and workParts != ''"> and ssp.workParts like concat('%', #{workParts}, '%')</if>
            <if test="changeInfo != null  and changeInfo != ''"> and ssp.changeInfo like concat('%', #{changeInfo}, '%')</if>
            <if test="lordSent != null  and lordSent != ''"> and ssp.lordSent = #{lordSent}</if>
            <if test="lordSentUser != null  and lordSentUser != ''"> and ssp.lordSentUser = #{lordSentUser}</if>
            <if test="copySend != null  and copySend != ''"> and ssp.copySend = #{copySend}</if>
            <if test="copySendUser != null  and copySendUser != ''"> and ssp.copySendUser = #{copySendUser}</if>
            <if test="checkState != null "> and ssp.checkState = #{checkState}</if>
            <if test="nickedArea != null  and nickedArea != ''"> and nickedArea = #{nickedArea}</if>
            <if test="nickedTime != null "> and ssp.nickedTime = #{nickedTime}</if>
            <if test="projectType != null  and projectType != ''"> and ssp.projectType = #{projectType}</if>
            <if test="processName != null  and processName != ''"> and ssp.processName like concat('%', #{processName}, '%')</if>
            <if test="projectName != null  and projectName != ''"> and ssp.projectName like concat('%', #{projectName}, '%')</if>
            <if test="nickedInfo != null  and nickedInfo != ''"> and ssp.nickedInfo = #{nickedInfo}</if>
            <if test="checkUser != null  and checkUser != ''"> and ssp.checkUser = #{checkUser}</if>
            <if test="checkUserPhone != null  and checkUserPhone != ''"> and ssp.checkUserPhone = #{checkUserPhone}</if>
            <if test="isDel != null "> and ssp.isDel = #{isDel}</if>
            <if test="createUser != null  and createUser != ''"> and ssp.createUser like concat('%', #{createUser}, '%')</if>
            <if test="createBy != null  and createBy != ''"> and (ssp.createUser like concat('%', #{createBy}, '%') or su.nick_name like concat('%', #{createBy}, '%'))</if>
            <if test="createTime != null "> and ssp.createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and ssp.updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and ssp.updateTime = #{updateTime}</if>
            <if test="dangerType != null  and dangerType != ''"> and ssp.danger_type = #{dangerType}</if>
            <if test="params.beginMarksTime != null and params.beginMarksTime != '' and params.endMarksTime != null and params.endMarksTime != ''"> and date(ssp.createTime) between #{params.beginMarksTime} and #{params.endMarksTime}</if>
            <!-- 查询条件-项目部门 -->
            <if test="projectDeptId != null "> and sp.deptId = #{projectDeptId}</if>
            <!--子部门数据-->
            <if test='nowRole == "4"'> and sp.deptId = #{nowDept}</if>
            <!--监理单位/总包公司/分包单位查询当前关联数据-->
            <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> and spui.unitId = #{nowDept}</if>
            <!--普通整改人是我，复检人是我，抄送人是我，提交人是我的数据-->
            <if test='nowRole == "15" or nowRole == "16" or nowRole == "17" or nowRole == "99"'> and (ssp.lordSentUser = #{nowUser} or ssp.copySendUser like concat('%', #{nowUser}, '%') or ssp.recheckSendUser = #{nowUser} or ssp.createUser = #{nowUser} )</if>
            <if test='activeName == "dzg"'> and ssp.checkState in (0,1,3)</if>
            <if test='activeName == "zg"'> and ssp.checkState in (0,3)</if>
            <if test='activeName == "fj"'> and ssp.checkState = 1 </if>
            <if test='activeName == "ycl"'> and ssp.checkState = 4 </if>
            <if test='activeName == "zgcs"'> and (date(NOW())<![CDATA[ > ]]> date(ssp.nickedTime) and (ssp.updateTime is null or date(ssp.updateTime) <![CDATA[ > ]]> date(ssp.nickedTime))) </if>
        </where>
        order by sort,ssp.createTime desc
    </select>

    <select id="findGroupCountByProjectId" parameterType="SmzSspProblemmodify" resultType="map">
        SELECT
            ssp.problemType,
            count(1) AS total,
            com.total AS comTotal
        FROM
            smz_ssp_problemmodify ssp
            LEFT JOIN (
            SELECT
                ssp2.problemType AS type,
                count(1) AS total
            FROM
                smz_ssp_problemmodify ssp2
            WHERE
                ssp2.checkState = 4
                And ssp2.isDel=0
                AND ssp2.projectId = #{projectId}
                AND ssp2.infoType = #{infoType}
            GROUP BY
            ssp2.problemType
            ) com ON com.type = ssp.problemType
        WHERE ssp.isDel=0
            AND ssp.projectId = #{projectId}
            AND ssp.infoType = #{infoType}
        GROUP BY
            ssp.problemType
    </select>

    <!--根据状态分组查询-->
    <select id="findProblemmodifyGroupByCheckState" parameterType="SmzSspProblemmodify" resultType="map">
        SELECT ssp.checkState,COUNT(ssp.id) total FROM smz_ssp_problemmodify ssp
        left join sur_project sp on ssp.projectId = sp.id
        LEFT JOIN sys_user su ON ssp.createUser = su.phonenumber
        <!--监理单位/总包公司/分包单位-->
        <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> left join sur_project_unit_info spui on spui.projectId = sp.id</if>
        WHERE ssp.isDel=0
        <if test="projectId != null "> and ssp.projectId = #{projectId}</if>
        <if test="infoType !=null">and infoType=#{infoType}</if>
        <if test="problemArea != null  and problemArea != ''"> and ssp.problemArea like concat('%', #{problemArea}, '%')</if>
        <if test="workParts != null  and workParts != ''"> and ssp.workParts like concat('%', #{workParts}, '%')</if>
        <if test="createUser != null  and createUser != ''"> and ssp.createUser like concat('%', #{createUser}, '%')</if>
        <if test="dangerType != null  and dangerType != ''"> and ssp.danger_type = #{dangerType}</if>
        <if test="lordSent != null  and lordSent != ''"> and (ssp.lordSent like concat('%', #{lordSent}, '%') or ssp.lordSentUser like concat('%', #{lordSent}, '%'))</if>
        <if test="createBy != null  and createBy != ''"> and (ssp.createUser like concat('%', #{createBy}, '%') or su.nick_name like concat('%', #{createBy}, '%'))</if>
        <if test="params.beginMarksTime != null and params.beginMarksTime != '' and params.endMarksTime != null and params.endMarksTime != ''"> and date(ssp.createTime) between #{params.beginMarksTime} and #{params.endMarksTime}</if>
        <!-- 查询条件-项目部门 -->
        <if test="projectDeptId != null "> and sp.deptId = #{projectDeptId}</if>
        <!--子部门数据-->
        <if test='nowRole == "4"'> and sp.deptId = #{nowDept}</if>
        <!--监理单位/总包公司/分包单位查询当前关联数据-->
        <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> and spui.unitId = #{nowDept}</if>
        <!--普通整改人是我，复检人是我，抄送人是我，提交人是我的数据-->
        <if test='nowRole == "15" or nowRole == "16" or nowRole == "17" or nowRole == "99"'> and (ssp.lordSentUser = #{nowUser} or ssp.copySendUser like concat('%', #{nowUser}, '%') or ssp.recheckSendUser = #{nowUser} or ssp.createUser = #{nowUser} )</if>
        <if test="roleTypes!=null">
            and roleType in
            <foreach collection="roleTypes" item="item" index="index" open="(" close=")" separator=",">${item}</foreach>
        </if>
        GROUP BY checkState
    </select>

    <!--整改超时数-->
    <select id="findProblemmodifyTimeoutCount" parameterType="SmzSspProblemmodify"  resultType="Integer">
        SELECT COUNT(ssp.id) total FROM smz_ssp_problemmodify ssp
        left join sur_project sp on ssp.projectId = sp.id
        LEFT JOIN sys_user su ON ssp.createUser = su.phonenumber
        <!--监理单位/总包公司/分包单位-->
        <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> left join sur_project_unit_info spui on spui.projectId = sp.id</if>
        WHERE ssp.isDel=0
        <if test="projectId != null "> and ssp.projectId = #{projectId}</if>
        and (date(NOW())<![CDATA[ > ]]> date(ssp.nickedTime) and (ssp.updateTime is null or date(ssp.updateTime) <![CDATA[ > ]]> date(ssp.nickedTime)))
        <if test="infoType !=null">and infoType=#{infoType}</if>
        <if test="lordSent != null  and lordSent != ''"> and (ssp.lordSent like concat('%', #{lordSent}, '%') or ssp.lordSentUser like concat('%', #{lordSent}, '%'))</if>
        <if test="createBy != null  and createBy != ''"> and (ssp.createUser like concat('%', #{createBy}, '%') or su.nick_name like concat('%', #{createBy}, '%'))</if>
        <if test="problemArea != null  and problemArea != ''"> and ssp.problemArea like concat('%', #{problemArea}, '%')</if>
        <if test="workParts != null  and workParts != ''"> and ssp.workParts like concat('%', #{workParts}, '%')</if>
        <if test="createUser != null  and createUser != ''"> and ssp.createUser like concat('%', #{createUser}, '%')</if>
        <if test="dangerType != null  and dangerType != ''"> and ssp.danger_type = #{dangerType}</if>
        <if test="params.beginMarksTime != null and params.beginMarksTime != '' and params.endMarksTime != null and params.endMarksTime != ''"> and date(ssp.createTime) between #{params.beginMarksTime} and #{params.endMarksTime}</if>
        <!-- 查询条件-项目部门 -->
        <if test="projectDeptId != null "> and sp.deptId = #{projectDeptId}</if>
        <!--子部门数据-->
        <if test='nowRole == "4"'> and sp.deptId = #{nowDept}</if>
        <!--监理单位/总包公司/分包单位查询当前关联数据-->
        <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> and spui.unitId = #{nowDept}</if>
        <!--普通整改人是我，复检人是我，抄送人是我，提交人是我的数据-->
        <if test='nowRole == "15" or nowRole == "16" or nowRole == "17" or nowRole == "99"'> and (ssp.lordSentUser = #{nowUser} or ssp.copySendUser like concat('%', #{nowUser}, '%') or ssp.recheckSendUser = #{nowUser} or ssp.createUser = #{nowUser} )</if>
        <if test="roleTypes!=null">
                and roleType in
            <foreach collection="roleTypes" item="item" index="index" open="(" close=")" separator=",">${item}</foreach>
        </if>

    </select>
    
    <select id="selectSmzSspProblemmodifyById" parameterType="Long" resultMap="SmzSspProblemmodifyResult">
        <include refid="selectSmzSspProblemmodifyVo"/>
        where id = #{id}
    </select>

    <select id="selectSmzSspProblemmodifyInfoById" parameterType="Long" resultMap="SmzSspProblemmodifyResult">
        select ssp.id, ssp.projectId, ssp.infoType, sp.projectName as problemArea, ssp.workParts, ssp.changeInfo, ssp.lordSent, ssp.lordSentUser, ssp.copySend, ssp.copySendUser, ssp.checkState, ssp.nickedArea, ssp.nickedTime, ssp.projectType, ssp.processName, ssp.projectName, ssp.nickedInfo, ssp.checkUser, ssp.checkUserPhone, ssp.isDel, ssp.createUser, ssp.createTime, ssp.updateUser, ssp.updateTime, ssp.marks_picture, ssp.marks_video, ssp.smark_url, ssp.danger_type, ssp.recheckSend, ssp.recheckSendUser, ssp.roleType, ssp.problemType, su.nick_name as createBy,
        case when ud.type_flag in (1,11) then concat(sd.dept_name,' ', '[责任主体]') else concat(ud.dept_name, ' ', '[', sdd3.dict_label ,']') end as deptName,
        IFNULL(sdd1.dict_label,sdd2.dict_label) as danger_type_name,
        su.nick_name as createUserName
        from smz_ssp_problemmodify ssp
        left join sur_project sp on ssp.projectId = sp.id
        LEFT JOIN sys_user su ON ssp.createUser = su.phonenumber
        left join sys_dept ud on ud.dept_id = su.dept_id
        left join sys_dept sd on sd.dept_id = sp.deptId
        left join sys_dict_data sdd1 on sdd1.dict_type = 'ssp_aqyhlx' and sdd1.dict_value = ssp.danger_type
        left join sys_dict_data sdd2 on sdd2.dict_type = 'ssp_zlyhlx' and sdd2.dict_value = ssp.danger_type
        left join sur_project_unit_info spui on spui.projectId = sp.id and spui.unitId = su.dept_id
        left join sys_dict_data sdd3 on sdd3.dict_type = 'sys_dept_type' and sdd3.dict_value = spui.unitType
        where ssp.id = #{id}
    </select>

    <!--查询当前用户最后一条隐患数据-->
    <select id="findLastDataByParams" parameterType="SmzSspProblemmodify" resultMap="SmzSspProblemmodifyResult">
        <include refid="selectSmzSspProblemmodifyVo"/>
        <where>
            isDel=0
            <if test="projectId != null "> and projectId = #{projectId}</if>
            <if test="infoType !=null">and infoType=#{infoType}</if>
            <if test="createUser !=null and createUser != ''">and createUser=#{createUser}</if>
            order by createTime desc
            limit 0,1
        </where>
    </select>

    <insert id="insertSmzSspProblemmodify" parameterType="SmzSspProblemmodify" useGeneratedKeys="true" keyProperty="id">
        insert into smz_ssp_problemmodify
        <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="updateSmzSspProblemmodify" parameterType="SmzSspProblemmodify">
        update smz_ssp_problemmodify
        <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="deleteSmzSspProblemmodifyById" parameterType="Long">
        update smz_ssp_problemmodify set isDel=1 where id = #{id}
    </delete>

    <delete id="deleteSmzSspProblemmodifyByIds" parameterType="String">
        update smz_ssp_problemmodify set isDel=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectSummary" parameterType="SmzSspProblemmodifyWhere" resultMap="SmzSspProblemmodifyResult">
        SELECT
        sp.danger_type as id,
        sd.dict_label as problemArea,
        COUNT(1) as roleType
        FROM
        smz_ssp_problemmodify sp
        left join sur_project p on p.id=sp.projectId
        left join sys_dict_data sd on sd.dict_value=sp.danger_type
        <if test="infoType==0">and sd.dict_type = 'ssp_aqyhlx'</if>
        <if test="infoType==1">and sd.dict_type = 'ssp_zlyhlx'</if>
        WHERE sp.isDel = 0
        AND sp.infotype = #{infoType}
        <if test="roleType > 0">AND sp.roletype=#{roleType}</if>
        <if test="startDate!=null">and DATE(sp.createtime) &gt;= DATE(#{startDate})</if>
        <if test="endDate!=null">and DATE(sp.createtime) &lt;= DATE(#{endDate})</if>
        <if test="projectId>0">and sp.projectId=#{projectId}</if>
        <if test="deptId >0 ">AND p.deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and sp.projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY
        sp.danger_type
        ORDER BY
        roleType desc
    </select>

    <select id="selectSummaryByProject" parameterType="SmzSspProblemmodifyWhere" resultMap="SmzSspProblemmodifyResult">
        select a.projectId,a.prjName projectName,a.proble id,if(b.timoutNoComp is null,0,b.timoutNoComp) infoType,
               if(c.timoutComp is null,0,c.timoutComp) checkState,
               if(d.comp is null,0,d.comp) isDel
        from
        (
        select  projectId,prjName,count(1) proble from vw_smz_ssp_problemmodify_audit
        where infoType=#{infoType} AND isDel=0
        <if test="projectId>0">and projectId=#{projectId}</if>
        <if test="deptId >0 ">AND deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="roleType > 0">AND roletype=#{roleType}</if>
        <if test="startDate!=null">and DATE(createtime)>=DATE(#{startDate})</if>
        <if test="endDate!=null">and DATE(createtime) &lt;= DATE(#{endDate})</if>
        group by projectId,prjName
        )
        a
        left join(
        select projectid,count(1) timoutNoComp  from vw_smz_ssp_problemmodify_audit where
        ((updateTime is null and  date(nickedTime) &lt; date(now()) ) or  date(updateTime )>date(nickedTime))
        and infoType=#{infoType} AND isDel=0
        <if test="projectId>0">and projectId=#{projectId}</if>
        <if test="deptId >0 ">AND deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="roleType > 0">AND roletype=#{roleType}</if>
        <if test="startDate!=null">and DATE(createtime)>=DATE(#{startDate})</if>
        <if test="endDate!=null">and DATE(createtime) &lt;= DATE(#{endDate})</if>
        group by projectId

        ) b on a.projectId=b.projectId

        left join (
        SELECT projectid,COUNT(1) timoutComp FROM vw_smz_ssp_problemmodify_audit WHERE   (updateTime is null and  date(nickedTime) &lt; date(now()) )
        and infoType=#{infoType} AND isDel=0
        <if test="projectId>0">and projectId=#{projectId}</if>
        <if test="deptId >0 ">AND deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="roleType > 0">AND roletype=#{roleType}</if>
        <if test="startDate!=null">and DATE(createtime)>=DATE(#{startDate})</if>
        <if test="endDate!=null">and DATE(createtime) &lt;= DATE(#{endDate})</if>
        GROUP BY projectid

        ) c on a.projectId=c.projectId

        left join(
        select projectid,count(1) comp  from vw_smz_ssp_problemmodify_audit where
        checkState=4
        and infoType=#{infoType} AND isDel=0
        <if test="projectId>0">and projectId=#{projectId}</if>
        <if test="deptId >0 ">AND deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="roleType > 0">AND roletype=#{roleType}</if>
        <if test="startDate!=null">and DATE(createtime)>=DATE(#{startDate})</if>
        <if test="endDate!=null">and DATE(createtime) &lt;= DATE(#{endDate})</if>
        group by projectId

        ) d on a.projectId=d.projectId

        order by a.proble desc
    </select>

    <select id="countByDate" parameterType="SmzSspProblemmodifyWhere" resultMap="SmzSspProblemmodifyResult">
        SELECT infotype,COUNT(1) id FROM smz_ssp_problemmodify WHERE isDel=0
        <if test="projectId > 0"> and projectId=#{projectId}</if>
        <if test="projectId &lt;= 0">
            AND  projectId IN (
            SELECT id FROM sur_project WHERE isdel=0
            <if test="deptId >0 ">AND deptid = #{deptId}</if>
        )
        </if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        and DATE(createTime)=Date(#{startDate})
        GROUP BY infotype
    </select>

    <select id="countByDateNew" parameterType="SmzSspProblemmodifyWhere" resultType="map">
        select * from (
        SELECT p.infotype,COUNT(1) as total
        FROM smz_ssp_problemmodify p
        left join sur_project sp on sp.id=p.projectId
        WHERE p.isDel=0
        <if test="projectId > 0"> and p.projectId=#{projectId}</if>
        <if test="deptId &gt; 0 ">AND sp.deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and p.projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        and DATE(p.createTime)=Date(#{startDate})
        GROUP BY p.infotype)s1 where 1=1
        UNION ALL
        select '96' as infotype,count(1) as total from dev_ai_project_data  ad
        left join sur_project sp on ad.project_id=sp.id
        where 1=1
        <if test="projectId &gt; 0"> and ad.project_id=#{projectId}</if>
        <if test="deptId &gt; 0 ">AND sp.deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and ad.project_id in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        and DATE(ad.create_time)=Date(#{startDate})
        and ad.is_del=0
    </select>

    <select id="countByDateRange" parameterType="SmzSspProblemmodifyWhere" resultMap="SmzSspProblemmodifyResult">
        SELECT infotype,COUNT(1) id FROM smz_ssp_problemmodify WHERE isDel=0  and infoType=#{infoType}
        <if test="projectId > 0"> and projectId=#{projectId}</if>
        <if test="projectId &lt;= 0">
        AND  projectId IN (
        SELECT id FROM sur_project WHERE isdel=0
        <if test="deptId >0 ">AND deptid = #{id}</if>
        )
        </if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
       <![CDATA[
        and DATE(createTime)>=Date(#{startDate}) and Date(createTime)<=Date(#{endDate})
       ]]>
        GROUP BY infotype
    </select>

    <select id="countByDateRangeNew" parameterType="SmzSspProblemmodifyWhere" resultType="map">
        select * from (
        SELECT infotype,COUNT(1) as total FROM smz_ssp_problemmodify WHERE isDel=0
        <if test="projectId > 0"> and projectId=#{projectId}</if>
        <if test="projectId &lt;= 0">
            AND  projectId IN (
            SELECT id FROM sur_project WHERE isdel=0
            <if test="deptId >0 ">AND deptid = #{id}</if>
            )
        </if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <![CDATA[
        and DATE(createTime)>=Date(#{startDate}) and Date(createTime)<=Date(#{endDate})
       ]]>
        GROUP BY infotype
        )s1 where 1=1
        UNION ALL
        select '96' as infotype,count(1) as total from dev_ai_project_data  ad
        left join sur_project sp on ad.project_id=sp.id
        where 1=1
        <if test="projectId &gt; 0"> and ad.project_id=#{projectId}</if>
        <if test="deptId &gt; 0 ">AND sp.deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and ad.project_id in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        and DATE(ad.create_time) between Date(#{startDate}) and Date(#{endDate})
        and ad.is_del=0
    </select>
    
    <select id="groupByInfotypeCheckState" parameterType="SmzSspProblemmodifyWhere" resultMap="SmzSspProblemmodifyResult">
        SELECT infotype,checkState,COUNT(1) id FROM vw_smz_ssp_problemmodify_audit WHERE isDel=0
        <if test="infoType !=null">and infoType=#{infoType}</if>
        <if test="roleType !=null and roleType>0">and roleType=#{roleType}</if>
        <if test="startDate!=null">and DATE(createtime)>=DATE(#{startDate})</if>
        <if test="endDate!=null">and DATE(createtime) &lt;= DATE(#{endDate})</if>
        <if test="projectId &gt; 0"> and projectId=#{projectId}</if>
        <if test="projectId &lt;= 0">
        AND  projectId IN (
        SELECT id FROM sur_project WHERE isdel=0
        <if test="deptId >0 ">AND deptid = #{deptId}</if>
        )
        </if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY infotype,checkState
    </select>

    <select id="groupByInfotypeCheckStateNew" parameterType="SmzSspProblemmodifyWhere" resultType="map">
        SELECT p.infotype,p.checkState,COUNT(1) as total
        FROM smz_ssp_problemmodify p
        left join sur_project sp on p.projectId=sp.id
        WHERE p.isDel=0
        <if test="projectId &gt; 0"> and p.projectId=#{projectId}</if>
        <if test="deptId >0 ">AND sp.deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and p.projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY p.infotype,p.checkState
        UNION ALL
        select '96' as infotype,'4' as checkState,count(1) as total from dev_ai_project_data  ad
        left join sur_project sp on ad.project_id=sp.id
        where 1=1
        <if test="projectId &gt; 0"> and ad.project_id=#{projectId}</if>
        <if test="deptId &gt; 0 ">AND sp.deptid = #{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and ad.project_id in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        and ad.is_del=0
    </select>

    <select id="countTimeout" parameterType="SmzSspProblemmodifyWhere"  resultType="Integer">
        select count(1) cnt
        FROM vw_smz_ssp_problemmodify_audit WHERE isDel=0
        <if test="infoType !=null">and infoType=#{infoType}</if>
        <if test="roleType !=null  and roleType>0">and roleType=#{roleType}</if>
        <if test="startDate!=null">and DATE(createtime)>=DATE(#{startDate})</if>
        <if test="endDate!=null">and DATE(createtime) &lt;= DATE(#{endDate})</if>
        and ((updateTime is null and  date(nickedTime) &lt; date(now()) ) or  date(updateTime )>date(nickedTime))
        <if test="projectId > 0"> and projectId=#{projectId}</if>
        <if test="projectId &lt;= 0">
            AND  projectId IN (
            SELECT id FROM sur_project WHERE isdel=0
            <if test="deptId >0 ">AND deptid = #{deptId}</if>
            )
        </if>
        <if test="prjIds !=null and prjIds.size()>0">
            and projectId in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>


    <select id="selectSmzSspProblemmodifyListAndUnitName" parameterType="SmzSspProblemmodifyWhere" resultMap="SmzSspProblemmodifyResult">
        select ssp.id, ssp.projectId, ssp.infoType, ssp.problemArea, ssp.workParts, ssp.changeInfo, ssp.lordSent, ssp.lordSentUser, ssp.copySend, ssp.copySendUser, ssp.checkState, ssp.nickedArea, ssp.nickedTime, ssp.projectType, ssp.processName, ssp.projectName, ssp.nickedInfo, ssp.checkUser, ssp.checkUserPhone, ssp.isDel, ssp.createUser, ssp.createTime, ssp.updateUser, ssp.updateTime, ssp.marks_picture, ssp.marks_video, ssp.smark_url, ssp.danger_type,
        ssp.recheckSend, ssp.recheckSendUser, ssp.roleType, ssp.createBy, ssp.problemType,
        sp.dept_Name deptName,ssp.dangerLabel,ssp.chkLabel
        from (
        SELECT c.*,a.dict_label dangerLabel,b.dict_label chkLabel FROM
        vw_smz_ssp_problemmodify_audit c,sys_dict_data a,sys_dict_data b WHERE c.danger_Type=a.dict_value AND a.dict_type='ssp_aqyhlx'
        AND c.checkState=b.dict_value AND b.dict_type='smz_ssp_checkstate'
        ) ssp
        left join (
        SELECT p.dept_Name,p.dept_id,u.phonenumber
        FROM sys_user u,sur_project_userinfo p WHERE u.user_id=p.user_id AND p.dept_type=2
        ) sp on ssp.lordSentUser = sp.phonenumber
        <!--监理单位/总包公司/分包单位-->
        <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> left join sur_project_unit_info spui on spui.projectId = ssp.projectId</if>
        <where>
            and ssp.isDel=0
            <if test="projectId != null "> and ssp.projectId = #{projectId}</if>
            <if test="prjIds !=null and prjIds.size()>0">
                and ssp.projectId in
                <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="infoType != null "> and ssp.infoType = #{infoType}</if>
            <if test="roleType != null and roleType >0 "> and ssp.roleType = #{roleType}</if>
            <if test="problemArea != null  and problemArea != ''"> and ssp.problemArea like concat('%', #{problemArea}, '%')</if>
            <if test="workParts != null  and workParts != ''"> and ssp.workParts like concat('%', #{workParts}, '%')</if>
            <if test="changeInfo != null  and changeInfo != ''"> and ssp.changeInfo like concat('%', #{changeInfo}, '%')</if>
            <if test="lordSent != null  and lordSent != ''"> and ssp.lordSent = #{lordSent}</if>
            <if test="lordSentUser != null  and lordSentUser != ''"> and ssp.lordSentUser = #{lordSentUser}</if>
            <if test="copySend != null  and copySend != ''"> and ssp.copySend = #{copySend}</if>
            <if test="copySendUser != null  and copySendUser != ''"> and ssp.copySendUser = #{copySendUser}</if>
            <if test="checkState != null "> and ssp.checkState = #{checkState}</if>
            <if test="nickedArea != null  and nickedArea != ''"> and nickedArea = #{nickedArea}</if>
            <if test="nickedTime != null "> and ssp.nickedTime = #{nickedTime}</if>
            <if test="problemType != null "> and ssp.problemType = #{problemType}</if>
            <if test="projectType != null  and projectType != ''"> and ssp.projectType = #{projectType}</if>
            <if test="processName != null  and processName != ''"> and ssp.processName like concat('%', #{processName}, '%')</if>
            <if test="projectName != null  and projectName != ''"> and ssp.projectName like concat('%', #{projectName}, '%')</if>
            <if test="nickedInfo != null  and nickedInfo != ''"> and ssp.nickedInfo = #{nickedInfo}</if>
            <if test="checkUser != null  and checkUser != ''"> and ssp.checkUser = #{checkUser}</if>
            <if test="checkUserPhone != null  and checkUserPhone != ''"> and ssp.checkUserPhone = #{checkUserPhone}</if>
            <if test="isDel != null "> and ssp.isDel = #{isDel}</if>
            <if test="startDate!=null">and DATE(ssp.createtime)>=DATE(#{startDate})</if>
            <if test="endDate!=null">and DATE(ssp.createtime) &lt;= DATE(#{endDate})</if>
            <if test="createUser != null  and createUser != ''"> and ssp.createUser like concat('%', #{createUser}, '%')</if>
            <if test="createTime != null "> and ssp.createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and ssp.updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and ssp.updateTime = #{updateTime}</if>
            <if test="dangerType != null  and dangerType != ''"> and ssp.danger_type = #{dangerType}</if>
            <if test="params.beginMarksTime != null and params.beginMarksTime != '' and params.endMarksTime != null and params.endMarksTime != ''"> and date(ssp.createTime) between #{params.beginMarksTime} and #{params.endMarksTime}</if>
            <!-- 查询条件-项目部门 -->
            <if test="projectDeptId != null "> and sp.deptId = #{projectDeptId}</if>
            <!--子部门数据-->
            <if test='nowRole == "4"'> and sp.deptId = #{nowDept}</if>
            <!--监理单位/总包公司/分包单位查询当前关联数据-->
            <if test='nowRole == "5" or nowRole == "6" or nowRole == "7"'> and spui.unitId = #{nowDept}</if>
            <!--普通整改人是我，复检人是我，抄送人是我，提交人是我的数据-->
            <if test='nowRole == "15" or nowRole == "16" or nowRole == "17" or nowRole == "99"'> and (ssp.lordSentUser = #{nowUser} or ssp.copySendUser like concat('%', #{nowUser}, '%') or ssp.recheckSendUser = #{nowUser} or ssp.createUser = #{nowUser} )</if>
            <if test='activeName == "dzg"'> and ssp.checkState in (0,3)</if>
            <if test='activeName == "dqr"'> and ssp.checkState in (1)</if>
            <if test='activeName == "ycl"'> and ssp.checkState = 4 </if>
            <if test='activeName == "zgcs"'> and (date(NOW())<![CDATA[ > ]]> date(ssp.nickedTime) and (ssp.updateTime is null or date(ssp.updateTime) <![CDATA[ > ]]> date(ssp.nickedTime))) </if>
            <if test="roleTypes!=null">
                and roleType in
                <foreach collection="roleTypes" item="item" index="index" open="(" close=")" separator=",">${item}</foreach>
            </if>
        </where>
        order by createTime desc
    </select>

</mapper>