<?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.dayou.mapper.DyoaHistoryMapper">

       <select id="queryMajorOrder" parameterType="java.lang.String" resultType="map">
        select id,
               name,
               code,
               sourceType,
               assign,
               masterName,
               managerName,
               masterOrgName,
               businessType,
               spec,
               evaluateTarget,
               repeatOrder,
               fhbq,
               oral,
               customerType,
               customerName,
               customerName2,
               contactId,
               cz,
               locations,
               refinance,
               loanMoney,
               loanLimit,
               loanProperty,
               loanUsage,
               loanExpired,
               principal,
               principalAddress,
               principalName,
               principalMobile,
               propertyName,
               propertyMobile,
               urgent,
               terminalName,
               terminalType,
               terminalContactName,
               members,
               description,
                standardPrice,
               createdDatetime,
               needPay,
                 bankContactName
        from dy_order where id = #{id}
    </select>

       <select id="queryMajorHouseTarget" parameterType="java.lang.String" resultType="com.dayou.dto.history.HisMajorProduction">
           select
           d.id,
           doth.id as tId,
           dop.id as pId,
           doth.type,<!--房屋用途 -->
           doth.ownerName, <!--#权利人 -->
           doth.ownerNo , <!--#权证号 -->
           doth.houseName,<!--#项目名称 -->
           doth.locations ,
           doth.landOwnerName,  <!--#土地使用权人 -->
           doth.landNo, <!--#土地证号 -->
           doth.buildYear, <!--#竣工年代 -->
           doth.buildArea, <!--#建筑面积 -->
           doth.useType, <!--#使用权类型 -->
           doth.landArea, <!--#土地面积 -->
           doth.masterName,<!--#项目负责人 -->
           doth.surveyName, <!--#实勘人 -->
           doth.planUsage,<!--#规划用途 -->
           doth.realUsage,<!--#实际用途 -->
           doth.surveyAddress,<!--#实勘地址 -->
           doth.description, <!--#备注 -->
           doth.price, <!--#评估价格 -->
           doth.approvedPrice, <!--#审核价格 -->
           doth.measure, <!--#估价方法 -->
           doth.surveyDate, <!--#实勘日期 -->
           dop.printQuantity , <!--#打印份数 -->
           dop.type AS pType, <!--#产品类型 -->
           d.reportNo, <!--#产品号 -->
           concat(d.signEmpName1,',',d.signEmpName2) as signEmpNames,<!--#签字人1 -->
           d.name,<!--#项目名称 -->
           d.principal, <!--#委托方名称 -->
           d.principalAddress, <!--#委托方地址 -->
           d.principalMobile ,<!--#委托方电话 -->
           d.propertyName, <!--#产权人 -->
           d.priceDate ,<!-- 价值时点-->
           d.area,<!-- 评估面积-->
           (d.money*10000)as money,<!-- 评估总价-->
           d.price as xPrice,<!-- 评估单价-->
           d.specDesc,<!-- 特殊情况说明-->
           d.repo ,<!-- 库存状态-->
           d.archiveTime, <!-- 归档时间-->
           d.standardPrice ,<!-- 标准收费-->
           d.confirmTime, <!-- 报告送达的确认时间-->
           if(d.confirmTime is null,0,1) as deliveryState,
           d.yjsInTime,<!-- 意见书入库时间-->
           d.yjsOutTime,<!-- 意见书出库时间-->
           d.bgInTime,<!-- 报告入库时间-->
           d.bgOutTime<!-- 报告出库时间-->
           from dy_order d left join dy_order_target_house doth on d.id = doth.orderId
           left join dy_order_product dop on dop.orderId = d.id where doth.orderId = #{id}
       </select>

       <select id="queryMajorLandTarget" parameterType="java.lang.String" resultType="com.dayou.dto.history.HisMajorProduction">
              select
                     d.id,
                     dotl.id as tId,
                     dop.id as pId,
                     dotl.type,<!--土地类型 -->
                     dotl.ownerName, <!--#土地所有权人 -->
                     dotl.ownerNo , <!--#国土证号 -->
                     dotl.locations ,
                     dotl.useArea,  <!--#土地使用权面积 -->
                     dotl.lastYear, <!--#剩余年限 -->
                     dotl.plotRate, <!--#容积率 -->
                     dotl.land_usage, <!--#地类用途 -->
                     dotl.useType, <!--#使用权类型 -->
                     dotl.masterName, <!--#项目负责人 -->
                     dotl.surveyName, <!--#实勘人 -->
                     dotl.description, <!--#备注 -->
                     dotl.price, <!--#评估价格 -->
                     dotl.approvedPrice, <!--#审核价格 -->
                     dotl.measure, <!--#估价方法 -->
                     dotl.surveyDate, <!--#土地所有权人 -->
                     dop.printQuantity , <!--#打印份数 -->
                     dop.type AS pType, <!--#产品类型 -->
                        d.reportNo, <!--#产品号 -->
                    concat(d.signEmpName1,',',d.signEmpName2) as signEmpNames,<!--#签字人1 -->
                    d.name,<!--#项目名称 -->
                    d.principal, <!--#委托方名称 -->
                    d.principalAddress, <!--#委托方地址 -->
                    d.principalMobile ,<!--#委托方电话 -->
                    d.propertyName, <!--#产权人 -->
                    d.priceDate ,<!-- 价值时点-->
                    d.area,<!-- 评估面积-->
                    (d.money*10000) as money,<!-- 评估总价-->
                    d.price as xPrice,<!-- 评估单价-->
                    d.specDesc,<!-- 特殊情况说明-->
                    d.repo ,<!-- 库存状态-->
                    d.archiveTime, <!-- 归档时间-->
                    d.standardPrice ,<!-- 标准收费-->
                    d.confirmTime, <!-- 报告送达的确认时间-->
                    if(d.confirmTime is null,0,1) as deliveryState,
                    d.yjsInTime,<!-- 意见书入库时间-->
                    d.yjsOutTime,<!-- 意见书出库时间-->
                    d.bgInTime,<!-- 报告入库时间-->
                    d.bgOutTime<!-- 报告出库时间-->
                    from dy_order d left join dy_order_target_land dotl on d.id = dotl.orderId
                  left join dy_order_product dop on dop.orderId = d.id where dotl.orderId = #{id}

       </select>

    <select id="queryMajorProduction" parameterType="java.lang.String" resultType="com.dayou.dto.history.HisMajorProduction">
        select
        d.id,
        dop.id as pId,
        dop.printQuantity , <!--#打印份数 -->
        dop.type AS pType, <!--#产品类型 -->
        d.reportNo, <!--#产品号 -->
        concat(d.signEmpName1,',',d.signEmpName2) as signEmpNames,<!--#签字人1 -->
        d.name,<!--#项目名称 -->
        d.principal, <!--#委托方名称 -->
        d.principalAddress, <!--#委托方地址 -->
        d.principalMobile ,<!--#委托方电话 -->
        d.propertyName, <!--#产权人 -->
        d.priceDate ,<!-- 价值时点-->
        d.area,<!-- 评估面积-->
        (d.money*10000)as money,<!-- 评估总价-->
        d.price as xPrice,<!-- 评估单价-->
        d.specDesc,<!-- 特殊情况说明-->
        d.repo ,<!-- 库存状态-->
        d.archiveTime, <!-- 归档时间-->
        d.standardPrice ,<!-- 标准收费-->
        d.confirmTime, <!-- 报告送达的确认时间-->
        if(d.confirmTime is null,0,1) as deliveryState,
        d.yjsInTime,<!-- 意见书入库时间-->
        d.yjsOutTime,<!-- 意见书出库时间-->
        d.bgInTime,<!-- 报告入库时间-->
        d.bgOutTime,
        d.code<!-- 报告出库时间-->
        from dy_order d
        left join dy_order_product dop on dop.orderId = d.id where dop.orderId = #{id}
    </select>

    <select id="selectDyoaMajorOrderIds" resultType="java.lang.String">
        select id from dy_order where masterName is not null
    </select>

    <select id="selectDyoaPersonalOrderIds" resultType="java.lang.String">
        select id from dy_order where masterName is not null
    </select>

    <select id="queryPersonalTarget" parameterType="java.lang.String" resultType="map">
        SELECT
            id,
            orderNo,
            locations,
            area,
            money,
            price
        FROM
            dy_order_loan where id = #{id}
    </select>


    <select id="queryPersonalOrder" parameterType="java.lang.String" resultType="map">
        SELECT
            id,
            orderNo,
            locations,
            area,
            money,
            price,
            target,
            purpose,
            loanMaxMoney,
            loanMaxYear,
            masterName ,
            principal1,
            principal1Mobile,
            principal2,
            principal2Mobile,
            description,
            outerEmpName,
            surveyEmpName,
            productEmpName,
            priceEmpName,
            needPay,
            agent,
            loanProperty,
            loanUsage,
            loanExpired,
            customerType,
            customerName,
            customerName2,
            terminalType,
            terminalName,
            terminalContactName,
            terminalContactMobile,
            finished,
            finishTime,
            files,
            createdDatetime,
            bankContactName
        FROM
            dy_order_loan where id = #{id}
    </select>

    <select id="getNewOrderIds" parameterType="java.util.Date" resultType="java.lang.String">
        select id from dy_order_loan
        where  masterName IS NOT NULL
          and deleted = 0
        <if test="max!=null">
            and createdDatetime &gt; #{max}
        </if>
    </select>

    <select id="getNewRealAmount" parameterType="java.util.Date" resultType="java.lang.String">
        select id
        from dy_finance_income
        <where>
            <if test="max!=null">
                and createdDatetime &gt; #{max}
            </if>
        </where>
    </select>

    <select id="getRealAmountInfo" parameterType="java.lang.String" resultType="map">
        select id,incomeTime,companyName,bankName,bankNo,money,description,creatorName,createdDatetime
        from dy_finance_income
      where id = #{id}
    </select>

    <select id="getNewClaimRecordIds" parameterType="java.util.Date" resultType="java.lang.String">
        SELECT
           id
        FROM
            dy_finance_income_order
        <where>
            <if test="max!=null">
                and createdDatetime &gt; #{max}
            </if>
        </where>
    </select>

    <select id="getNewClaimRecord" parameterType="java.lang.String" resultType="map">
        SELECT
            id,
            orderId,
            incomeId,
            money,
            takeEmpName,
            orderType,
            createdDatetime
        FROM
            dy_finance_income_order where id = #{id}
    </select>

    <select id="selectDyoaAssetsOrderIds" resultType="java.lang.String">
        select id from dy_assets where deleted = 0
    </select>

    <select id="queryAssetsOrder" parameterType="java.lang.String" resultType="map">
        SELECT
            id,
            masterName ,
            assign,
            masterOrgName,
            code,
            name,
            businessType,
            managerName,
            companyName,
            principal,
            principalName,
            principalMobile,
            description,
            orderTime,
            needPay,
            standardPrice,
            archiveTime,
            customerType,
            customerName,
            bankContactName,
            terminalType,
            terminalName,
            terminalContactName,
            importantAsset,
            stateOwned,
            abroadAsset,
            cz,
            stock,
            repeatOrder
        FROM
            dy_assets where id = #{id} and deleted = 0

    </select>

    <select id="queryAssetsProduction" parameterType="java.lang.String" resultType="com.dayou.dto.history.HisAssetsProduction">
        SELECT
            da.id,
            dop.id AS pId,
            da.yjsReportNO,
            da.reportNo,
            da.needPay,
            da.standardPrice,
            da.principal,
            da.principalMobile,
            da.money,
            da.area,
            da.price,
            dop.printQuantity,
            da.archiveTime,
            da.finished,
            dop.type,
            dop.createdDatetime
        FROM
            dy_assets da
                LEFT JOIN dy_order_product dop ON da.id = dop.orderId
        WHERE
            da.deleted = 0 and da.id = #{id}
    </select>

    <select id="getNewFinanceInvoice" parameterType="java.util.Date" resultType="java.lang.String">
        SELECT
        id
        FROM
        dy_finance_invoice
        <where>
            <if test="max!=null">
                and createdDatetime &gt; #{max}
            </if>
        </where>
    </select>

    <select id="getInvoiceInfo" parameterType="java.lang.String" resultType="map">
        select
            id,
            incomeId,
            orderId,
            address,
            bankNO,
            bankName,
            companyNO,
            companyName,
            invoiceType,
            project,
            planMoney,
            realMoney,
            taxPoint,
            planDate,
            realDate,
            unit,
            taxAmount,
            status,
            reason,
            description,
            invoiceEmp,
            ticketNo,
            orderType,
            orderReportNO,
            createdDatetime,
            creatorName
            from dy_finance_invoice
        where id = #{id}
    </select>

    <select id="findAllProductionNo" resultType="com.dayou.dto.history.HisMajorProduction">
        select
        d.id,
        doth.id as tId,
        dop.id as pId,
        doth.type,<!--房屋用途 -->
        doth.ownerName, <!--#权利人 -->
        doth.ownerNo , <!--#权证号 -->
        doth.houseName,<!--#项目名称 -->
        doth.locations ,
        doth.landOwnerName,  <!--#土地使用权人 -->
        doth.landNo, <!--#土地证号 -->
        doth.buildYear, <!--#竣工年代 -->
        doth.buildArea, <!--#建筑面积 -->
        doth.useType, <!--#使用权类型 -->
        doth.landArea, <!--#土地面积 -->
        doth.masterName,<!--#项目负责人 -->
        doth.surveyName, <!--#实勘人 -->
        doth.planUsage,<!--#规划用途 -->
        doth.realUsage,<!--#实际用途 -->
        doth.surveyAddress,<!--#实勘地址 -->
        doth.description, <!--#备注 -->
        doth.price, <!--#评估价格 -->
        doth.approvedPrice, <!--#审核价格 -->
        doth.measure, <!--#估价方法 -->
        doth.surveyDate, <!--#实勘日期 -->
        dop.printQuantity , <!--#打印份数 -->
        dop.type AS pType, <!--#产品类型 -->
        d.reportNo, <!--#产品号 -->
        concat(d.signEmpName1,',',d.signEmpName2) as signEmpNames,<!--#签字人1 -->
        d.name,<!--#项目名称 -->
        d.principal, <!--#委托方名称 -->
        d.principalAddress, <!--#委托方地址 -->
        d.principalMobile ,<!--#委托方电话 -->
        d.propertyName, <!--#产权人 -->
        d.priceDate ,<!-- 价值时点-->
        d.area,<!-- 评估面积-->
        (d.money*10000)as money,<!-- 评估总价-->
        d.price as xPrice,<!-- 评估单价-->
        d.specDesc,<!-- 特殊情况说明-->
        d.repo ,<!-- 库存状态-->
        d.archiveTime, <!-- 归档时间-->
        d.standardPrice ,<!-- 标准收费-->
        d.confirmTime, <!-- 报告送达的确认时间-->
        if(d.confirmTime is null,0,1) as deliveryState,
        d.yjsInTime,<!-- 意见书入库时间-->
        d.yjsOutTime,<!-- 意见书出库时间-->
        d.bgInTime,<!-- 报告入库时间-->
        d.bgOutTime<!-- 报告出库时间-->
        from dy_order d left join dy_order_target_house doth on d.id = doth.orderId
        left join dy_order_product dop on dop.orderId = d.id and d.deleted = 0 where d.reportNO is not null

    </select>
</mapper>
