private static final String SPARK_DMS_SQL ="(SELECT " +"cm.id_car as idCar," +"cm.id_customer as idCustomer," +"c.brand_id as brandId," +"c.factory_id as factoryId," +"c.series_id as seriesId," +"c.year_id as yearId," +"c.main_id as mainId," +"m.NAME as name," +"m.sex as sex," +"m.id_number as idNumber," +"m.customer_source as customerSource," +"m.customer_type as customerType," +"m.company_name as companyName," +"m.cell_phone as cellPhone," +"m.birthday as birthday," +"m.province as province," +"m.city as city," +"m.area as area," +"m.credentials_type as credentialsType," +"c.car_no as carNo," +"c.car_prefix as carPrefix," +"c.vin as vin," +"DATE_FORMAT(c.card_date,'%Y-%m-%d') as cardDate," +"DATE_FORMAT(c.register_date,'%Y-%m-%d') as registerDate," +"c.factory_year as factoryYear," +"c.next_factory_year as nextFactoryYear," +"c.car_model as carModel," +"c.car_model_short as carModelShort," +"c.car_color as carColor," +"c.insurance_expiry_date as insuranceExpiryDate," +"c.insurance_expiry_date_tci as insuranceExpiryDateTci," +"c.insurancepolicy_no as insurancepolicyNo," +"c.insurancepolicy_no_tci as insurancepolicyNoTci," +"c.effect_insurance as effectInsurance," +"c.annual_date as annualDate," +"c.engine_number as engineNumber," +"c.car_brand_name as carBrandName," +"c.car_series_mame as carSeriesName," +"c.contact_name as contactName," +"c.contact_cellphone as contactCellphone," +"c.memo as memo," +"c.contact_credentials_type as contactCredentialsType," +"c.contact_credentials_number as contactCredentialsNumber," +"c.contact_detail_address as contactDetailAddress," +"c.contact_sex as contactSex," +"c.id_employee as idEmployee," +"c.id_own_org as idOwnOrg," +"c.creationtime as creationtime," +"c.creator as creator," +"cm.modifier as modifier," +"cm.modifiedtime as modifiedtime," +"m.points as points," +"m.level as level," +"m.detail_address as detailAddress," +"m.member_card_no as memberCardNo," +"c.car_type as carType," +"c.car_category_id as carCategoryId," +"c.last_enter_mileage as lastEnterMileage," +"date_format(c.last_enter_date,'%Y-%m-%d') as lastEnterDate," +"IFNULL(date_format(c.info_complete_date,'%Y-%m-%d'),date_format(c.creationtime,'%Y-%m-%d')) as infoCompleteDate," +"cs.customer_source as customerSourceName," +"tcc.name as customerLevel," +"cc.name as carCategoryName," +"tib.name as insuranceCompany," +"tic.pk_id as idInsuranceCompany," +"tic.contacts as contacts," +"tic.contact_telephone as contactTelephone," +"tib.id as idInsuranceBase," +"CONCAT(IFNULL(car_prefix, ''), IFNULL(car_no, '')) as showCarNo," +"cm.id_customer as fromIdCustomer," +"c.product_date as productDate," +"c.car_source_id as carSourceId," +"c.car_source_name as carSourceName," +"c.promote_employee_id as carPromoteEmployeeId," +"c.promote_employee_name as carPromoteEmployeeName," +"m.promote_employee_id as customerPromoteEmployeeId," +"m.promote_employee_name as customerPromoteEmployeeName," +"c.id_own_group as idOwnGroup," +"c.car_exclusive_org_name as carExclusiveOrgName," +"c.car_exclusive_org_id as carExclusiveOrgId " +"from tm_car c " +"STRAIGHT_JOIN tm_customer_car cm ON cm.id_car = c.pk_id " +"AND c.is_del = 0 " +"STRAIGHT_JOIN tm_customer m ON cm.id_customer = m.pk_id " +"AND m.is_del = 0 " +"LEFT JOIN tm_customer_source cs ON cs.pk_id = m.customer_source " +"LEFT JOIN member_level tcc ON m.LEVEL = tcc.id " +"LEFT JOIN tb_car_category cc on cc.id = c.car_category_id " +"LEFT JOIN tm_insurance_base tib ON tib.id = c.id_insurance_base " +"LEFT JOIN tm_insurance_company tic ON tic.id_insurance_base = tib.id) dms ";private static final String SPARK_MEMBER_SQL = "(select cso.customer_id as idCustomer, cso.id_own_org as idOwnOrg from customer_service_org cso) member";/*** 通过spark查询** @param so* @return*/public Workbook sparkQuery(CarListSo so) {orgMapTL.set(getOrgNameAsMap());StaffSearchGroupCacheSo staffSearchGroupCacheSo = new StaffSearchGroupCacheSo();staffSearchGroupCacheSo.setGroupId(new BigInteger(F6Static.getGroupId()));staffSearchGroupCacheSo.setIncludeDeletedEmployee(true);staffListTL.set(staffCacheApi.searchStaffInGroup(staffSearchGroupCacheSo));String memberUrl = sparkConfig.getMemberUrl();String memberUser = sparkConfig.getMemberUser();String memberPwd = sparkConfig.getMemberPwd();String memberDriverClass = sparkConfig.getMemberDriverClass();Properties member = new Properties();member.setProperty("user", memberUser);member.setProperty("password", memberPwd);member.setProperty("driver", memberDriverClass);member.setProperty("fetchsize", String.valueOf(sparkConfig.getFetchsize()));Dataset<Row> memberDS = sparkSession.read().jdbc(memberUrl, SPARK_MEMBER_SQL, member).select("idCustomer", "idOwnOrg");Dataset<Row> memberDsc = memberFilter(memberDS, so);List<Row> maps = memberDsc.collectAsList();List<BigInteger> idList = Lists.newArrayList();MultiValueMap<String, String> orgMap = new LinkedMultiValueMap<>();for (Row row : maps) {idList.add(new BigInteger(row.get(0).toString()));orgMap.add(row.get(0).toString(), row.get(1).toString());}serviceOrgMapTL.set(orgMap);String dmsUrl = sparkConfig.getDmsUrl();String dmsUser = sparkConfig.getDmsUser();String dmsPwd = sparkConfig.getDmsPwd();String dmsDriver = sparkConfig.getDmsDriverClass();Properties dms = new Properties();dms.setProperty("user", dmsUser);dms.setProperty("password", dmsPwd);dms.setProperty("driver", dmsDriver);dms.setProperty("fetchsize", String.valueOf(sparkConfig.getFetchsize()));Dataset<Row> dmsDS = sparkSession.read().jdbc(dmsUrl, SPARK_DMS_SQL, dms).select("idCustomer", "idCar", "idCustomer", "brandId", "factoryId", "seriesId", "yearId", "mainId", "name", "sex", "idNumber", "customerSource", "customerType", "companyName", "cellPhone", "birthday", "province", "city", "area", "credentialsType", "carNo", "carPrefix", "vin", "cardDate", "registerDate", "factoryYear", "nextFactoryYear", "carModel", "carModelShort", "carColor", "insuranceExpiryDate", "insuranceExpiryDateTci", "insurancepolicyNo", "insurancepolicyNoTci", "effectInsurance", "annualDate", "engineNumber", "carBrandName", "carSeriesName", "contactName", "contactCellphone", "memo", "contactCredentialsType", "contactCredentialsNumber", "contactDetailAddress", "contactSex", "idEmployee", "idOwnOrg", "creationtime", "creator", "modifier", "modifiedtime", "points", "level", "detailAddress", "memberCardNo", "carType", "carCategoryId", "lastEnterMileage", "lastEnterDate", "infoCompleteDate", "customerSourceName", "customerLevel", "carCategoryName", "insuranceCompany", "idInsuranceCompany", "contactTelephone", "idInsuranceBase", "showCarNo", "fromIdCustomer", "productDate", "carSourceId", "carSourceName", "carPromoteEmployeeId", "carPromoteEmployeeName", "customerPromoteEmployeeId", "customerPromoteEmployeeName", "idOwnGroup", "carExclusiveOrgName", "carExclusiveOrgId");Dataset<Row> dmsDsc = dmsFilter(dmsDS, so, idList);Dataset<Row> rss = handleSort(dmsDsc, so);return this.getWorkbookForSparkBigDataByFilter(so, rss, CarVo.class, "车辆信息", sparkFifoMaxAmount);}
