<?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.workflow.mapper.BizWorkFlowContentMapper">
    <!-- 基础的返回map 多表复杂的 自行组合 -->
    <resultMap id="BaseResultMap" type="cn.ezhizao.project.business.workflow.domain.BizWorkFlowContent" />

    <!--根据主表id，删除 为的是表单保存时，明细统一物理删除后，再统一插入-->
    <delete id="physicallyDelete">
        DELETE FROM
        biz_work_flow_content
        WHERE id > 0
        <if test="id != null">
            AND id = #{id}
        </if>
    </delete>

    <!--带条件的List查询-->
    <select id="getList" resultMap="BaseResultMap">
        <include refid="getListSql" />
    </select>

    <!--带条件的List查询 数据总条数-->
    <select id="getTotal" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM (<include refid="getListSql" />) AS t
    </select>

    <sql id="getListSql">
        SELECT
        t1.*, e.name as verifier_name, e.id as verifier_id
        FROM biz_work_flow_content t1
        left join sys_user su on su.user_id = t1.creator_id
        WHERE t1.deleted = 0
        <if test="id != null">
            AND t1.id = #{id}
        </if>
        <if test="tenantId != null">
            AND t1.tenant_id = #{tenantId}
        </if>
        <if test="masterTableName != null">
            AND t1.master_table_name = #{masterTableName}
        </if>
        <if test="masterId != null">
            AND t1.master_id = #{masterId}
        </if>
        <if test="result != null">
            AND t1.result = #{result}
        </if>
        ORDER BY t1.id DESC
    </sql>
</mapper>
