<?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="cn.ezhizao.project.business.history.mapper.BizHistoryMapper">

    <resultMap type="cn.ezhizao.project.business.history.domain.BizHistory" id="BizHistoryResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizHistory" resultMap="BizHistoryResult">
        SELECT t1.* ,t2.nick_name as userName,t3.account_name as tenantName  FROM biz_history t1
            left join sys_user t2 on t1.creator_id = t2.user_id
            left join biz_tenant t3 on t1.tenant_id = t3.id

        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="companyId != null">AND t1.company_id = #{companyId}</if>
            <if test="tableName != null">AND t1.table_name = #{tableName}</if>
            <if test="currentMonth != null and currentMonth != ''">AND t1.belong_period = DATE_FORMAT(#{currentMonth}, '%Y-%m')</if>
            <if test="dateFilter != null and dateFilter.size()>0 ">
                AND (
                DATE_FORMAT(t1.create_time,'%Y-%m-%d') &gt;= #{dateFilter[0]}
                AND
                DATE_FORMAT(t1.create_time,'%Y-%m-%d') &lt;= #{dateFilter[1]}
                )
            </if>
        </trim>
        order by create_time desc
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_history
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
            <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
