<?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.jeeplus.business.project.mapper.JyProjectAuditMapper">
    <resultMap id="BaseResultMap" type="com.jeeplus.business.project.service.dto.JyProjectAuditDTO">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="createBy.id" column="create_by_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy.id" column="update_by_id" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
        <result property="projectId" column="project_id" jdbcType="VARCHAR"/>
        <result property="auditLevel" column="audit_level" jdbcType="VARCHAR"/>
        <result property="auditPeople" column="audit_people" jdbcType="VARCHAR"/>
        <result property="projectAgreeTime" column="project_agree_time" jdbcType="TIMESTAMP"/>
        <result property="initialAuditOpinion" column="initial_audit_opinion" jdbcType="VARCHAR"/>
        <result property="initialEditOpinion" column="initial_edit_opinion" jdbcType="VARCHAR"/>
        <result property="editOpinion" column="edit_opinion" jdbcType="VARCHAR"/>
        <result property="auditOpinion" column="audit_opinion" jdbcType="VARCHAR"/>
        <result property="procInsId" column="proc_ins_id" jdbcType="VARCHAR"/>
        <result property="processDefinitionId" column="process_definition_id" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Audit_Column_List">
        pa.id,
        pa.create_by_id,
        pa.create_time,
        pa.update_by_id,
        pa.update_time,
        pa.del_flag,
        pa.project_id,
        pa.audit_level,
        pa.audit_people,
        pa.project_agree_time,
        pa.initial_audit_opinion,
        pa.initial_edit_opinion,
        pa.edit_opinion,
        pa.audit_opinion,
        pa.proc_ins_id,
        pa.process_definition_id,
        pa.status,
        pa.exceed_time_status
    </sql>


    <select id="findByIdAudit" resultMap="BaseResultMap">
        select
            <include refid="Audit_Column_List"></include>
        from jy_project_audit pa
        where pa.del_flag = '0' and pa.id = #{id}
    </select>


    <select id="getIDsByProId" resultType="string">
        SELECT id
        FROM jy_project_audit
        WHERE project_id = #{projectId} and del_flag = '0'
        ORDER BY
        CASE WHEN project_agree_time IS NULL THEN 1 ELSE 0 END,
        project_agree_time ASC
    </select>

    <select id="getIdByProId" resultType="com.jeeplus.business.project.domain.JyProjectAudit">
        select
        <include refid="Audit_Column_List"></include>
        from jy_project_audit pa
        where pa.del_flag = '0' and pa.project_id = #{id} and pa.audit_level = '1'
    </select>

    <select id="findFirstLevel" resultType="com.jeeplus.business.project.domain.JyProjectAudit">
        select
        <include refid="Audit_Column_List"></include>
        from jy_project_audit pa
        where pa.del_flag = '0' and pa.audit_level = '1'
    </select>
    
    <update id="updateStatus">
        update
            jy_project_audit
        set status=#{status} , exceed_time_status =#{exceedTimeStatus} where id=#{id}
    </update>

    <update id="updateStatus2">
        update
            jy_project_audit
        set status='7' where id=#{id}
    </update>

    <select id="selectAudit" resultType="com.jeeplus.business.project.domain.JyProjectAudit">
        select
        <include refid="Audit_Column_List"></include>,
        pr.name as projectName,
        art.ID_ as task_id,
        pr.proc_ins_id as projectProId,
        pr.process_definition_id as projectDeId
        from jy_project_audit pa
        left join jy_project_record pr on pa.project_id = pr.id
        LEFT JOIN act_ru_task art ON pa.proc_ins_id = art.PROC_INST_ID_
        LEFT JOIN act_ru_task art1 ON pr.proc_ins_id = art1.PROC_INST_ID_
        where pa.del_flag = '0'
              and pa.audit_level = '1'
              and pr.status = '5'
              and (pa.status = '0' or pa.status = null)
              and pa.project_agree_time &lt; #{newDate}
    </select>

    <select id="selectAuditInTime" resultType="com.jeeplus.business.project.domain.JyProjectAudit">
        select
        <include refid="Audit_Column_List"></include>,
        pr.name as projectName,
        art.ID_ as task_id,
        pr.proc_ins_id as projectProId,
        pr.process_definition_id as projectDeId
        from jy_project_audit pa
        left join jy_project_record pr on pa.project_id = pr.id
        LEFT JOIN act_ru_task art ON pa.proc_ins_id = art.PROC_INST_ID_
        LEFT JOIN act_ru_task art1 ON pr.proc_ins_id = art1.PROC_INST_ID_
        where pa.del_flag = '0'
        and pa.audit_level = '1'
        and pr.status = '5'
        and (pa.status = '0' or pa.status = null)
        and pa.project_agree_time &gt;= #{newDate}
    </select>


    <select id="getByProjectId" resultType="com.jeeplus.business.project.service.dto.JyProjectAuditDTO">
        select
        <include refid="Audit_Column_List"></include>
        from jy_project_audit pa
        where pa.del_flag = '0' and pa.project_id=#{projectId}
    </select>

















</mapper>