<?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.testor.module.hazard.dao.TContractorAccessLogApprovalDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.hazard.model.domain.TContractorAccessLogApproval">
        <id column="id" property="id"/>
        <result column="access_log_id" property="accessLogId"/>
        <result column="name" property="name"/>
        <result column="approval_content" property="approvalContent"/>
        <result column="approval_status" property="approvalStatus"/>
        <result column="status" property="status"/>
        <result column="remarks" property="remarks"/>
        <result column="contractor_allow_id" property="contractorAllowId"/>

        <!-- 继承父类的字段 -->
        <result column="create_by" property="createBy"/>
        <result column="create_date" property="createDate"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_date" property="updateDate"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, access_log_id, name, approval_content, approval_status, status, remarks,
        create_by, create_date, update_by, update_date, del_flag, remark
    </sql>

    <select id="selectByContractorAllowIdAndCreateBy" resultMap="BaseResultMap">
        select * from t_contractor_access_log_approval
        where approval_status = '2' and contractor_allow_id =#{contractorAllowId} and create_by = #{createBy}
    </select>

    <select id="selectByContractorAllowIdAndNameBy" resultMap="BaseResultMap">
        select * from t_contractor_access_log_approval
        where approval_status = '2' and contractor_allow_id =#{contractorAllowId} and name_by = #{nameBy}
    </select>


    <update id="updateApprovalStatus">
        update t_contractor_access_log_approval
        set approval_status = #{approvalStatus},
        approval_time = now()
        where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>

</mapper>