REPLACE INTO dispatch.rd_company_summary (
	id,
	NAME,
	STATUS,
	legal,
	legal_telephone,
	institutional,
	register_address,
	business_address,
	service_scope,
	organization_id,
	supervise_domain_id,
	supervise_depart_id,
	last_sync_time,
	last_updated_time,
	supervise_region_code,
	lon_lat
) SELECT DISTINCT
              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,
              ci.ITEM_businessScope,
              o.id,
              '#',
              '#supervise_depart_id',
              ci.LASTMODIFIED,
              ci.LASTMODIFIED,
              '0423',
              CONCAT("{""lat"":",o.latitude,",""lon"":",o.longitude,"}")AS lonlat
  FROM
              obpm2.tenant_organizations o
                  LEFT JOIN  baibaodunflow.tlk_companyinformation ci ON o.id = ci.DOMAINID