<?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.chinaweal.aiccs.aiccs.force.cancel.mapper.CancelRevokeApproveMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.force.cancel.entity.CancelRevokeApprove">
        <id column="APPROVE_ID" property="approveId"/>
        <result column="BIZ_ID" property="bizId"/>
        <result column="NODE" property="node"/>
        <result column="APPROVER_ID" property="approverId"/>
        <result column="APPROVER_NAME" property="approverName"/>
        <result column="APPROVE_STATUS" property="approveStatus"/>
        <result column="APPROVE_OPINION" property="approveOpinion"/>
        <result column="APPROVE_TIME" property="approveTime"/>
        <result column="CREATE_TIME" property="createTime"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        APPROVE_ID, BIZ_ID, NODE, APPROVER_ID, APPROVER_NAME, APPROVE_STATUS, APPROVE_OPINION, APPROVE_TIME, CREATE_TIME
    </sql>

    <!-- 新增 -->
    <insert id="insert" parameterType="com.chinaweal.aiccs.aiccs.force.cancel.entity.CancelRevokeApprove">
        INSERT INTO AICCS.TS_CANCEL_REVOKE_APPROVE (
            APPROVE_ID, BIZ_ID, NODE, APPROVER_ID, APPROVER_NAME, APPROVE_STATUS, APPROVE_OPINION, APPROVE_TIME, CREATE_TIME
        ) VALUES (
            #{approveId}, #{bizId}, #{node}, #{approverId}, #{approverName}, #{approveStatus}, #{approveOpinion}, #{approveTime}, #{createTime}
        )
    </insert>

    <!-- 根据业务ID查询审批记录列表 -->
    <select id="selectByBizId" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM AICCS.TS_CANCEL_REVOKE_APPROVE
        WHERE BIZ_ID = #{bizId}
        ORDER BY CREATE_TIME ASC
    </select>

    <!-- 查询最新审批记录 -->
    <select id="selectLatestByBizId" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM AICCS.TS_CANCEL_REVOKE_APPROVE
        WHERE BIZ_ID = #{bizId}
        ORDER BY CREATE_TIME DESC
        FETCH FIRST 1 ROWS ONLY
    </select>

</mapper>
