<?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.upgrade.mapper.BizArchiveInputDetailUpdateMapper">
    <resultMap type="cn.ezhizao.project.business.upgrade.domain.BizArchiveInputDetailUpdate"
               id="BizArchiveInputDetailUpdateResult">
        <id column="id" property="id"/>
    </resultMap>
    <resultMap type="cn.ezhizao.project.business.upgrade.domain.BizArchiveInputDetailUpdate" id="BizArchiveInputDetailResult">
        <id column="id" property="id"/>
    </resultMap>

    <select id="getList" parameterType="BizArchiveInputDetailUpdate" resultMap="BizArchiveInputDetailResult">
        SELECT t1.*, t2.name as task_type_name, t2.pay_address,t3.dict_label as regionName,t4.dict_label as
        fictionAddress
        FROM biz_archive_input_detail_update t1
        left join biz_task_type t2 on t2.id = t1.task_type_id
        left join sys_dict_data t3 on t1.belong_region = t3.dict_code
        left join sys_dict_data t4 on t1.fiction_address_id = t4.dict_code
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="companyId != null ">
                AND t1.company_id = #{companyId}
            </if>
            <if test="contractId != null ">
                AND t1.contract_id = #{contractId}
            </if>
            <if test="serviceNum != null ">
                AND t1.service_num = #{serviceNum}
            </if>
            <if test="price != null ">
                AND t1.price = #{price}
            </if>
            <if test="amount != null ">
                AND t1.amount = #{amount}
            </if>
        </trim>
    </select>
    <select id="selectByUpgradeId" parameterType="cn.ezhizao.project.business.upgrade.domain.BizArchiveInputDetailUpdate" resultType="cn.ezhizao.project.business.order.domain.BizArchiveInputDetail">
        select * from biz_archive_input_detail_update where tenant_id = #{tenantId} and deleted = 0
    </select>
    <select id="getDetail" parameterType="BizArchiveInputDetailUpdate" resultMap="BizArchiveInputDetailResult">
        SELECT *
        FROM biz_archive_input_detail_update
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="contractId != null ">
                AND contract_id = #{contractId}
            </if>
            <if test="taskTypeId != null ">
                AND task_type_id = #{taskTypeId}
            </if>
            <if test="fromId  !=  null ">
                AND from_id = #{fromId}
            </if>
            <if test="companyId  !=  null ">
                AND company_id = #{companyId}
            </if>
        </trim>
    </select>
    <delete id="physicalDelete">
        DELETE FROM biz_archive_input_detail_update
        <where>
            AND contract_id = #{contractId}
        </where>
        <!-- 删除条件为其他外键可以在这里加 -->
    </delete>
    <select id="selectByTaskIdAndCompanyId" resultType="java.lang.Long">
        select contract_id from biz_archive_input_detail_update t1
        left join biz_archive_input_update t2 on t1.contract_id = t1.id
        where t2.company_id = #{companyId}
        and t1.task_type_id in
        <foreach item="taskId" index="index" collection="taskIds" open="(" separator="," close=")">
            #{taskId}
        </foreach>
    </select>
</mapper>
