create view vi_business_affinfo as SELECT O.DISTRIBUTOR_ID                                                                            AS DISTRIBUTOR_ID,
       O.ID                                                                                        AS ID,
       O.CONTRACT_NO                                                                               AS CONTRACT_NO,
       O.CONTRACT_NUMBER                                                                           AS CONTRACT_NUMBER,
       O.CONTRACT_STATUS                                                                           AS CONTRACT_STATUS,
       O.PRODUCT_NAME                                                                              AS PRODUCT_NAME,
       O.PRODUCT_ID                                                                                AS PRODUCT_ID,
       O.PROJECT_ID                                                                                AS PROJECT_ID,
       O.PROJECT_DATE                                                                              AS PROJECT_DATE,
       O.PROJECT_NAME                                                                              AS PROJECT_NAME,
       O.PROJECT_TYPE                                                                              AS PROJECT_TYPE,
       O.RENT_METHOD                                                                               AS RENT_METHOD,
       O.PROJECT_SOURCE                                                                            AS PROJECT_SOURCE,
       O.PROJECT_INDUSTRY                                                                          AS PROJECT_INDUSTRY,
       O.LEAS_FORM                                                                                 AS LEAS_FORM,
       O.LEASE_FORM                                                                                AS LEASE_FORM,
       O.PROJECT_DEPT                                                                              AS PROJECT_DEPT,
       O.PROJECT_REGISTRAR                                                                         AS PROJECT_REGISTRAR,
       O.PROJECT_MANAGE                                                                            AS PROJECT_MANAGE,
       O.PROJECT_ASSIST                                                                            AS PROJECT_ASSIST,
       O.END_DATE                                                                                  AS END_DATE,
       lcc.START_DATE                                                                                AS START_DATE,
       O.ACTUAL_START_DATE                                                                         AS ACTUAL_START_DATE,
       O.ACTUAL_END_DATE                                                                           AS ACTUAL_END_DATE,
       O.ACCOUNTING_START_DATE                                                                     AS ACCOUNTING_START_DATE,
       O.FIVE_CATALOG                                                                              AS FIVE_CATALOG,
       O.FIVE_CATALOG_DATE                                                                         AS FIVE_CATALOG_DATE,
       O.FIVE_CATALOG_MEMO                                                                         AS FIVE_CATALOG_MEMO,
       O.SIGN_PLACE                                                                                AS SIGN_PLACE,
       O.SIGN_DATE                                                                                 AS SIGN_DATE,
       O.SIGN_PEOPLE                                                                               AS SIGN_PEOPLE,
       O.OTHER_CONDITION                                                                           AS OTHER_CONDITION,
       O.FLOWUNID                                                                                  AS FLOWUNID,
       O.INPUTUSERID                                                                               AS INPUTUSERID,
       O.INPUTORGID                                                                                AS INPUTORGID,
       O.INPUTTIME                                                                                 AS INPUTTIME,
       O.UPDATEUSERID                                                                              AS UPDATEUSERID,
       O.UPDATEORGID                                                                               AS UPDATEORGID,
       O.UPDATETIME                                                                                AS UPDATETIME,
       O.DATA_STATE                                                                                AS DATA_STATE,
       O.MODIFY_REASON                                                                             AS MODIFY_REASON,
       O.ISFILEARCHIVED                                                                            AS ISFILEARCHIVED,
       O.IS_PRINT                                                                                  AS IS_PRINT,
       O.ASSET_TYPE                                                                                AS ASSET_TYPE,
       O.RENT_INVOICE_TYPE                                                                         AS RENT_INVOICE_TYPE,
       O.INVOICE_MEMO                                                                              AS INVOICE_MEMO,
       O.CONTRACT_INVOICE_STATUS                                                                   AS CONTRACT_INVOICE_STATUS,
       O.SEAL_TYPE                                                                                 AS SEAL_TYPE,
       O.MORTGAGE_AGENT                                                                            AS MORTGAGE_AGENT,
       O.VERSIONID                                                                                 AS VERSIONID,
       O.BUSINESSTYPE                                                                              AS BUSINESSTYPE,
       O.AREA_CODE                                                                                 AS AREA_CODE,
       O.CAR_TYPE                                                                                  AS CAR_TYPE,
       O.LENDING_TYPE                                                                              AS LENDING_TYPE,
       O.INPUTNAME                                                                                 AS INPUTNAME,
       O.INPUTTEL                                                                                  AS INPUTTEL,
       O.HAVECOMMISSION                                                                            AS HAVECOMMISSION,
       O.IS_NETCAR                                                                                 AS IS_NETCAR,
       O.IS_OPERATION                                                                              AS IS_OPERATION,
       O.IS_AFFILIATED                                                                             AS IS_AFFILIATED,
       O.IS_OPERATION_QUALIFICATION                                                                AS IS_OPERATION_QUALIFICATION,
       O.TRANSPORTCERTID                                                                           AS TRANSPORTCERTID,
       O.AFFILIATEDNAME                                                                            AS AFFILIATEDNAME,
       O.NETCERTNAME                                                                               AS NETCERTNAME,
       O.LEGALPERSONNAME                                                                           AS LEGALPERSONNAME,
       O.AFFILIATEDDATE                                                                            AS AFFILIATEDDATE,
       O.AFFILIATEDENDDATE                                                                         AS AFFILIATEDENDDATE,
       O.REGISTEREDMONEY                                                                           AS REGISTEREDMONEY,
       O.AFFILIATEDACTUALADDRESS                                                                   AS AFFILIATEDACTUALADDRESS,
       O.AFFILIATEDADDRESS                                                                         AS AFFILIATEDADDRESS,
       O.TRANSPORTDATE                                                                             AS TRANSPORTDATE,
       O.NETCERTID                                                                                 AS NETCERTID,
       O.LEGALPERSONID                                                                             AS LEGALPERSONID,
       O.ASSETTRANSFERER                                                                           AS ASSETTRANSFERER,
       O.TRANSFERDATE                                                                              AS TRANSFERDATE,
       O.TURNOUTREMARKS                                                                            AS TURNOUTREMARKS,
       O.HAS_GPS                                                                                   AS HAS_GPS,
       LPI.PROJECT_DEPT_DETAIL                                                                     AS PROJECT_DEPT_DETAIL,
       CL.ITEMNAME                                                                                 AS ITEMNAME,
       LUL.CUSTOMER_NAME                                                                           AS CUSTOMER_NAME,
       LEC.FRAME_NUMBER                                                                            AS FRAME_NUMBER,
       LPI.PROJECT_NO                                                                              AS PROJECT_NO,
       CP.MOBILE                                                                                   AS MOBILE,
       CF.NAME                                                                                     AS NAME,
       LEC.VNDR_NAME                                                                               AS VNDR_NAME,
       LFI.APPLYPAY_DATE                                                                           AS APPLYPAY_DATE,
       (CASE WHEN (O.CONTRACT_STATUS = '21') THEN (LCC.START_DATE = NULL) ELSE LCC.START_DATE END) AS START_DATE_NEW,
       CLL.ITEMNAME                                                                                AS CONTRACT_STAT
FROM ((((((((((APZL.LB_CONTRACT_INFO O LEFT JOIN APZL.LB_PROJECT_INFO LPI ON ((convert(O.PROJECT_ID USING UTF8) = LPI.ID))) LEFT JOIN APZL.LB_UNION_LESSEE LUL ON ((O.PROJECT_ID = LUL.PROJECT_ID))) LEFT JOIN APZL.CUSTOMER_PERSON CP ON ((CP.CUSTOMERID = LUL.CUSTOMER_ID))) LEFT JOIN APZL.CUSTOMER_FAMILY CF ON (((O.PROJECT_ID = CF.PROJECT_ID) AND (CF.PARTNER_ = 'Y')))) LEFT JOIN APZL.LB_EQUIPMENT_CAR LEC ON ((convert(O.PROJECT_ID USING UTF8) = LEC.PROJECT_ID))) 
LEFT JOIN (
    SELECT CONTRACT_ID AS contract_id,LEFT(inputtime,10) AS APPLYPAY_DATE FROM flow_bussiness_object WHERE flow_name='付款申请(汽车)'
GROUP BY contract_id) LFI ON ((O.id = LFI.contract_id))) LEFT JOIN APZL.LC_CALC_CONDITION LCC ON ((O.ID = LCC.CONTRACT_ID))) LEFT JOIN APZL.PRD_SPECIFIC_LIBRARY PSL ON ((LPI.PRODUCT_ID = PSL.PRODUCTID))) LEFT JOIN APZL.CODE_LIBRARY CL ON (((convert(CL.ITEMNO USING UTF8) = PSL.OPERATIONTYPE) AND (CL.CODENO = 'operationType'))))
LEFT JOIN (
    SELECT BS.CONTRACT_NUMBER AS CONTRACT_NUMBER, BS.INPUTTIME AS INPUTTIME, CL.ITEMNAME AS ITEMNAME
    FROM (APZL.BUSINESS_STATUS BS
    LEFT JOIN APZL.CODE_LIBRARY CL ON (((CL.ITEMNO = BS.BUSINESS_STATUS) AND (CL.CODENO = 'BusinessStatus'))))
    WHERE ((length(BS.CONTRACT_NUMBER) > 13) AND BS.INPUTTIME IN (
        SELECT max(B.INPUTTIME)
        FROM APZL.BUSINESS_STATUS B
        WHERE ((B.CONTRACT_NUMBER IS NOT NULL) AND (B.CONTRACT_NUMBER <> '') AND (length(B.CONTRACT_NUMBER) > 13) AND
               (B.CONTRACT_NUMBER = BS.CONTRACT_NUMBER))
        GROUP BY B.CONTRACT_NUMBER
    ))
    GROUP BY BS.CONTRACT_NUMBER
) CLL ON ((CLL.CONTRACT_NUMBER = O.CONTRACT_NO)))
WHERE (O.BUSINESSTYPE = 1);

-- comment on column vi_business_affinfo.distributor_id not supported: 经销商IDid

-- comment on column vi_business_affinfo.ID not supported: 编号

-- comment on column vi_business_affinfo.CONTRACT_NO not supported: 合同号

-- comment on column vi_business_affinfo.CONTRACT_NUMBER not supported: 业务合同号

-- comment on column vi_business_affinfo.CONTRACT_STATUS not supported: 合同状态

-- comment on column vi_business_affinfo.PRODUCT_NAME not supported: 产品名称

-- comment on column vi_business_affinfo.PRODUCT_ID not supported: 产品ID

-- comment on column vi_business_affinfo.PROJECT_ID not supported: 项目编号

-- comment on column vi_business_affinfo.PROJECT_DATE not supported: 项目日期

-- comment on column vi_business_affinfo.PROJECT_NAME not supported: 项目名称

-- comment on column vi_business_affinfo.PROJECT_TYPE not supported: 项目类型

-- comment on column vi_business_affinfo.RENT_METHOD not supported: 起租方式

-- comment on column vi_business_affinfo.PROJECT_SOURCE not supported: 项目来源

-- comment on column vi_business_affinfo.PROJECT_INDUSTRY not supported: 内部行业

-- comment on column vi_business_affinfo.LEAS_FORM not supported: 业务形式

-- comment on column vi_business_affinfo.LEASE_FORM not supported: 租赁形式

-- comment on column vi_business_affinfo.PROJECT_DEPT not supported: 出单部门

-- comment on column vi_business_affinfo.PROJECT_REGISTRAR not supported: 经办人

-- comment on column vi_business_affinfo.PROJECT_MANAGE not supported: 项目经理

-- comment on column vi_business_affinfo.PROJECT_ASSIST not supported: 项目协办

-- comment on column vi_business_affinfo.END_DATE not supported: 预计结束日期

-- comment on column vi_business_affinfo.START_DATE not supported: 起租日

-- comment on column vi_business_affinfo.ACTUAL_START_DATE not supported: 实际起租日

-- comment on column vi_business_affinfo.ACTUAL_END_DATE not supported: 实际结束日

-- comment on column vi_business_affinfo.ACCOUNTING_START_DATE not supported: 财务起租日

-- comment on column vi_business_affinfo.FIVE_CATALOG not supported: 五级分类

-- comment on column vi_business_affinfo.FIVE_CATALOG_DATE not supported: 五级分类日期

-- comment on column vi_business_affinfo.FIVE_CATALOG_MEMO not supported: 五级分类说明

-- comment on column vi_business_affinfo.SIGN_PLACE not supported: 签约地点

-- comment on column vi_business_affinfo.SIGN_DATE not supported: 签约日期

-- comment on column vi_business_affinfo.SIGN_PEOPLE not supported: 签约人

-- comment on column vi_business_affinfo.OTHER_CONDITION not supported: 其他商务条件

-- comment on column vi_business_affinfo.FLOWUNID not supported: 流程标识

-- comment on column vi_business_affinfo.INPUTUSERID not supported: 登记人

-- comment on column vi_business_affinfo.INPUTORGID not supported: 登记部门

-- comment on column vi_business_affinfo.INPUTTIME not supported: 登记时间

-- comment on column vi_business_affinfo.UPDATEUSERID not supported: 更新人

-- comment on column vi_business_affinfo.UPDATEORGID not supported: 更新部门

-- comment on column vi_business_affinfo.UPDATETIME not supported: 更新日期

-- comment on column vi_business_affinfo.DATA_STATE not supported: 数据状态

-- comment on column vi_business_affinfo.MODIFY_REASON not supported: 修改原因

-- comment on column vi_business_affinfo.ISFILEARCHIVED not supported: 是否归档

-- comment on column vi_business_affinfo.IS_PRINT not supported: 导出状态(打印快递单)

-- comment on column vi_business_affinfo.ASSET_TYPE not supported: 资产类型

-- comment on column vi_business_affinfo.RENT_INVOICE_TYPE not supported: 租金开票类型

-- comment on column vi_business_affinfo.INVOICE_MEMO not supported: 开票说明

-- comment on column vi_business_affinfo.CONTRACT_INVOICE_STATUS not supported: 合同开票状态

-- comment on column vi_business_affinfo.seal_type not supported: 印章类型

-- comment on column vi_business_affinfo.mortgage_agent not supported: 抵押代理人

-- comment on column vi_business_affinfo.VERSIONID not supported: 版本号

-- comment on column vi_business_affinfo.BUSINESSTYPE not supported: 业务类型

-- comment on column vi_business_affinfo.AREA_CODE not supported: 车牌号对应所在区号

-- comment on column vi_business_affinfo.CAR_TYPE not supported: 车辆类型

-- comment on column vi_business_affinfo.LENDING_TYPE not supported: 保单放款方法

-- comment on column vi_business_affinfo.inputName not supported: 报单人姓名

-- comment on column vi_business_affinfo.inputTel not supported: 报单人电话

-- comment on column vi_business_affinfo.IS_NETCAR not supported: 是否网约车

-- comment on column vi_business_affinfo.IS_OPERATION not supported: 车辆是否为营运性质

-- comment on column vi_business_affinfo.IS_AFFILIATED not supported: 是否挂靠/上牌在第三方名下

-- comment on column vi_business_affinfo.IS_OPERATION_QUALIFICATION not supported: 承租人/挂靠方是否已取得车辆营运资质

-- comment on column vi_business_affinfo.TRANSPORTCERTID not supported: 道路运输许可证照号码

-- comment on column vi_business_affinfo.AFFILIATEDNAME not supported: 挂靠方名称

-- comment on column vi_business_affinfo.NETCERTNAME not supported: 证照名称

-- comment on column vi_business_affinfo.LEGALPERSONNAME not supported: 法定代表人/经营者名称

-- comment on column vi_business_affinfo.AFFILIATEDDATE not supported: 挂靠方注册成立时间

-- comment on column vi_business_affinfo.AFFILIATEDENDDATE not supported: 经营期限至

-- comment on column vi_business_affinfo.REGISTEREDMONEY not supported: 注册资本

-- comment on column vi_business_affinfo.AFFILIATEDACTUALADDRESS not supported: 挂靠方实际经营地址

-- comment on column vi_business_affinfo.AFFILIATEDADDRESS not supported: 挂靠方注册地址

-- comment on column vi_business_affinfo.TRANSPORTDATE not supported: 道路运输许可证照有效期

-- comment on column vi_business_affinfo.NETCERTID not supported: 证照号码

-- comment on column vi_business_affinfo.LEGALPERSONID not supported: 法定代表人/经营者身份证号

-- comment on column vi_business_affinfo.ASSETTRANSFERER not supported: 资产转出方

-- comment on column vi_business_affinfo.TRANSFERDATE not supported: 转出日期

-- comment on column vi_business_affinfo.TURNOUTREMARKS not supported: 转出备注

-- comment on column vi_business_affinfo.has_gps not supported: 是否已安装GPS

-- comment on column vi_business_affinfo.PROJECT_DEPT_DETAIL not supported: 部门层级名称

-- comment on column vi_business_affinfo.CUSTOMER_NAME not supported: 承租人名称

-- comment on column vi_business_affinfo.FRAME_NUMBER not supported: 车架号

-- comment on column vi_business_affinfo.PROJECT_NO not supported: 项目编号

-- comment on column vi_business_affinfo.mobile not supported: 手机号

-- comment on column vi_business_affinfo.NAME not supported: 姓名

-- comment on column vi_business_affinfo.VNDR_NAME not supported: 供应商

-- comment on column vi_business_affinfo.APPLYPAY_DATE not supported: 申请支付日期

