<?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.hzya.frame.plugin.contract.dao.impl.ContractAuditDaoImpl">
    <resultMap id="get-ContractAuditEntity-result" type="com.hzya.frame.plugin.contract.entity.ContractAuditEntity">
        <!--主键 -->
        <result property="id" column="id"/>
        <result property="field0168" column="field0168"/>
        <result property="field0239" column="field0239"/>
        <result property="field0005" column="field0005"/>
        <result property="field0005" column="field0005"/>
        <result property="subject" column="subject"/>
        <result property="col_summary_id" column="col_summary_id"/>
        <result property="affairId" column="affairId"/>
        <result property="node_name" column="node_name"/>
        <result property="node_policy" column="node_policy"/>
        <result property="receive_time" column="receive_time"/>
        <result property="complete_time" column="complete_time"/>
        <result property="state" column="state"/>
        <result property="login_name" column="login_name"/>
    </resultMap>





    <!-- 查询 超期60天没审批的合同 -->
    <select id="entity_list_base" resultMap="get-ContractAuditEntity-result" parameterType="com.hzya.frame.plugin.contract.entity.ContractAuditEntity">
        SELECT
        formmain_0325.id,
        formmain_0325.field0168,
        formmain_0325.field0239,
        formmain_0325.field0005,
        COL_SUMMARY.subject,
        COL_SUMMARY.id as col_summary_id,
        CTP_AFFAIR.id as affairId,
        CTP_AFFAIR.node_name,
        CTP_AFFAIR.node_policy,
        CTP_AFFAIR.receive_time,
        CTP_AFFAIR.complete_time,
        CTP_AFFAIR.state,
        ORG_PRINCIPAL.login_name
        FROM
        formmain_0325
        LEFT JOIN COL_SUMMARY ON COL_SUMMARY.FORM_RECORDID = formmain_0325.id
        LEFT JOIN CTP_AFFAIR ON CTP_AFFAIR.OBJECT_ID = COL_SUMMARY.id
        LEFT JOIN ORG_PRINCIPAL on ORG_PRINCIPAL.member_id = CTP_AFFAIR.MEMBER_ID
        <trim prefix="where" prefixOverrides="and">
            <if test="id != null and id != ''">id = #{id}</if>
            <if test="field0168 != null and field0168 != ''">and formmain_0325.field0168 = #{field0168}</if>
            and CTP_AFFAIR.NODE_POLICY = '印章管理员'
            and CTP_AFFAIR.state = 3
            and DATEDIFF(DAY, CTP_AFFAIR.RECEIVE_TIME, GETDATE()) > 60
        </trim>
    </select>


</mapper>
