INSERT INTO dispatch.rd_company_summary (
    ID,
    NAME,
    STATUS,
    legal,
    legal_telephone,
    institutional,
    register_address,
    business_address,
    count_of_activity_station,
    count_of_security_man,
    service_scope,
    organization_id,
    supervise_domain_id,
    supervise_depart_id,
    last_sync_time,
    last_updated_time,
    supervise_region_code
) SELECT
      o.ID,
      o.`name`,(
          CASE

              WHEN ITEM_companyStatus = '注销' THEN
                  2
              WHEN ITEM_companyStatus = '撤销' THEN
                  1 ELSE 0
              END
          ) AS ITEM_companyStatus,
      ci.ITEM_legalPerson,
      ci.ITEM_legalPersonPhone,
      ifnull( o.institutional_code, '' ),
      o.place_of_register_address,
      o.place_of_business_address,
      1,
      1,
      ci.ITEM_businessScope,
      o.ID,
      '#supervise_domain_id',
      '#supervise_depart_id',
      ci.LASTMODIFIED,
      ci.LASTMODIFIED,
      '110000'
FROM
    obpm2.tenant_organizations o
        LEFT JOIN baibaodunflow.tlk_companyinformation ci ON o.ID = ci.DOMAINID