<?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.entrust.mapper.BizEntrustMapper">

    <resultMap type="cn.ezhizao.project.business.entrust.domain.BizEntrust" id="BizEntrustResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizEntrust" resultMap="BizEntrustResult">
        SELECT t1.* FROM biz_entrust t1 left join biz_company t2 on t2.id = t1.company_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="companyId != null ">AND t1.company_id = #{companyId}</if>
            <if test="taskTypeId != null ">AND t1.task_type_id = #{taskTypeId}</if>
            <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
            <if test="isZero != null ">AND t2.is_zero = #{isZero}</if>
            <if test="ticketFinished == 0">
                <!-- 判断是否已经收票完成 -->
                AND not exists (select 1 from biz_archive_receive_ticket_finished t2 where t2.company_id = t1.company_id and t2.is_finished = 1 and date_format(t1.current_month, '%Y%m') = concat(t2.year, t2.month))
            </if>
        </trim>
    </select>

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