Commit 42bc3ea7 authored by 薛鹏飞's avatar 薛鹏飞

Merge branch 'liuzhe' into 'master'

Liuzhe

See merge request !1
parents cd7e1e9e c561f138
# Lines that start with '#' are comments.
*~
*.diff
*#
.classpath
.project
.settings
.eclipse
target
patchprocess
.idea
*.iml
nb-configuration.xml
.DS_Store
hive_shell/
zl/
export MAVEN_HOME=/opt/apache-maven-3.6.1
$MAVEN_HOME/bin/mvn clean install -DskipTests
$MAVEN_HOME/bin/mvn clean package -DskipTests
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>flink_warehouse_rt</artifactId>
<groupId>com.gmei.flink</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ml_c_et_pe_preciseexposure_dimen_d_rt</artifactId>
</project>
\ No newline at end of file
package com.gmei.bean.bl;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
/**
* ClassName: BlPreciseExposureBean
* TableName: Bl_Et_Mg_PreciseExposure_Inc_D
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/3 下午5:07
*
* @author liuzhe
* @since JDK 1.8
*/
/*
{
"gm_nginx_key":2,
"version":"110",
"params":{
"up_slide_times":0,
"down_loading_times":0,
"exposure_cards":{
},
"up_loading_times":0,
"is_exposure":1,
"tab_name":"精选",
"referrer_id":"",
"down_slide_times":0,
"referrer":"",
"page_name":"home",
"business_id":""
},
"app_session_id":"C3280044-5C8E-459D-AE6C-8E26BBACD6C9",
"gm_nginx_timestamp":1546307958.631,
"create_at":"1546307958",
"app":{
"channel":"AppStore",
"version":"7.7.35",
"serial_id":42,
"current_city_id":"worldwide",
"name":"gengmei_user",
"user_type":{
}
},
"device":{
"is_WiFi":"0",
"device_type":"ios",
"device_id":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"lng":0,
"lat":0,
"ip":"10.156.100.97",
"manufacturer":"Apple",
"idfa":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"idfv":"352A6D64-17CA-4520-831A-2CE9507631D8"
},
"user_id":"30864538",
"type":"home_choiceness_card_exposure"
}
*/
public class BlPreciseExposureAppBean {
@JsonProperty(value = "channel")
private String app_channel;
@JsonProperty(value = "version")
private String app_version;
@JsonProperty(value = "serial_id")
private String app_serial_id;
@JsonProperty(value = "current_city_id")
private String app_current_city_id;
@JsonProperty(value = "name")
private String app_code;
@JsonProperty(value = "user_type")
private BlPreciseExposureAppUserTypeBean app_user_type;
public BlPreciseExposureAppBean() {
}
public String getApp_channel() {
return app_channel;
}
public void setApp_channel(String app_channel) {
this.app_channel = app_channel;
}
public String getApp_version() {
return app_version;
}
public void setApp_version(String app_version) {
this.app_version = app_version;
}
public String getApp_serial_id() {
return app_serial_id;
}
public void setApp_serial_id(String app_serial_id) {
this.app_serial_id = app_serial_id;
}
public String getApp_current_city_id() {
return app_current_city_id;
}
public void setApp_current_city_id(String app_current_city_id) {
this.app_current_city_id = app_current_city_id;
}
public String getApp_code() {
return app_code;
}
public void setApp_code(String app_code) {
this.app_code = app_code;
}
public BlPreciseExposureAppUserTypeBean getApp_user_type() {
return app_user_type;
}
public void setApp_user_type(BlPreciseExposureAppUserTypeBean app_user_type) {
this.app_user_type = app_user_type;
}
public BlPreciseExposureAppBean(String app_channel, String app_version, String app_serial_id, String app_current_city_id, String app_code, BlPreciseExposureAppUserTypeBean app_user_type) {
this.app_channel = app_channel;
this.app_version = app_version;
this.app_serial_id = app_serial_id;
this.app_current_city_id = app_current_city_id;
this.app_code = app_code;
this.app_user_type = app_user_type;
}
@Override
public String toString() {
return "BlPreciseExposureAppBean{" +
"app_channel='" + app_channel + '\'' +
", app_version='" + app_version + '\'' +
", app_serial_id='" + app_serial_id + '\'' +
", app_current_city_id='" + app_current_city_id + '\'' +
", app_code='" + app_code + '\'' +
", app_user_type=" + app_user_type +
'}';
}
}
package com.gmei.bean.bl;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
/**
* ClassName: BlPreciseExposureBean
* TableName: Bl_Et_Mg_PreciseExposure_Inc_D
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/3 下午5:07
*
* @author liuzhe
* @since JDK 1.8
*/
/*
{
"gm_nginx_key":2,
"version":"110",
"params":{
"up_slide_times":0,
"down_loading_times":0,
"exposure_cards":{
},
"up_loading_times":0,
"is_exposure":1,
"tab_name":"精选",
"referrer_id":"",
"down_slide_times":0,
"referrer":"",
"page_name":"home",
"business_id":""
},
"app_session_id":"C3280044-5C8E-459D-AE6C-8E26BBACD6C9",
"gm_nginx_timestamp":1546307958.631,
"create_at":"1546307958",
"app":{
"channel":"AppStore",
"version":"7.7.35",
"serial_id":42,
"current_city_id":"worldwide",
"name":"gengmei_user",
"user_type":{
}
},
"device":{
"is_WiFi":"0",
"device_type":"ios",
"device_id":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"lng":0,
"lat":0,
"ip":"10.156.100.97",
"manufacturer":"Apple",
"idfa":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"idfv":"352A6D64-17CA-4520-831A-2CE9507631D8"
},
"user_id":"30864538",
"type":"home_choiceness_card_exposure"
}
*/
public class BlPreciseExposureAppUserTypeBean {
private String config_type;
public BlPreciseExposureAppUserTypeBean() {
}
public String getConfig_type() {
return config_type;
}
public void setConfig_type(String config_type) {
this.config_type = config_type;
}
public BlPreciseExposureAppUserTypeBean(String config_type) {
this.config_type = config_type;
}
@Override
public String toString() {
return "BlPreciseExposureAppUserTypeBean{" +
"config_type='" + config_type + '\'' +
'}';
}
}
package com.gmei.bean.bl;
import java.util.Date;
import java.util.ArrayList;
/**
* ClassName: BlPreciseExposureBean
* TableName: Bl_Et_Mg_PreciseExposure_Inc_D
* Function:
* Reason: BL层精准曝光BEAN类
* Date: 2019/12/3 下午5:07
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureBean {
private Date day_id;
private String json;
private String gm_nginx_timestamp;
private String create_timestamp;
private String user_id;
private String action;
private Integer down_loading_times;
private Integer down_slide_times;
private Integer up_loading_times;
private Integer up_slide_times;
private String page_code;
private String tab_name;
private String business_id;
private String referrer_code;
private String referrer_id;
private ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards;
private String is_exposure;
private String is_popup;
private String filter;
private String query;
private String app_grey_type;
private String app_channel;
private String app_version;
private String app_current_city_id;
private String app_code;
private String device_os_type;
private String device_model;
private String device_id;
private String device_android_id;
private String device_idfv;
private String gm_nginx_time_date;
private String gm_nginx_time_day;
private String create_time_date;
private String create_time_day;
public BlPreciseExposureBean() {
}
public BlPreciseExposureBean(Date day_id, String json, String gm_nginx_timestamp, String create_timestamp, String user_id, String action, Integer down_loading_times, Integer down_slide_times, Integer up_loading_times, Integer up_slide_times, String page_code, String tab_name, String business_id, String referrer_code, String referrer_id, ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards, String is_exposure, String is_popup, String filter, String query, String app_grey_type, String app_channel, String app_version, String app_current_city_id, String app_code, String device_os_type, String device_model, String device_id, String device_android_id, String device_idfv, String gm_nginx_time_date, String gm_nginx_time_day, String create_time_date, String create_time_day) {
this.day_id = day_id;
this.json = json;
this.gm_nginx_timestamp = gm_nginx_timestamp;
this.create_timestamp = create_timestamp;
this.user_id = user_id;
this.action = action;
this.down_loading_times = down_loading_times;
this.down_slide_times = down_slide_times;
this.up_loading_times = up_loading_times;
this.up_slide_times = up_slide_times;
this.page_code = page_code;
this.tab_name = tab_name;
this.business_id = business_id;
this.referrer_code = referrer_code;
this.referrer_id = referrer_id;
this.exposure_cards = exposure_cards;
this.is_exposure = is_exposure;
this.is_popup = is_popup;
this.filter = filter;
this.query = query;
this.app_grey_type = app_grey_type;
this.app_channel = app_channel;
this.app_version = app_version;
this.app_current_city_id = app_current_city_id;
this.app_code = app_code;
this.device_os_type = device_os_type;
this.device_model = device_model;
this.device_id = device_id;
this.device_android_id = device_android_id;
this.device_idfv = device_idfv;
this.gm_nginx_time_date = gm_nginx_time_date;
this.gm_nginx_time_day = gm_nginx_time_day;
this.create_time_date = create_time_date;
this.create_time_day = create_time_day;
}
public Date getDay_id() {
return day_id;
}
public void setDay_id(Date day_id) {
this.day_id = day_id;
}
public String getJson() {
return json;
}
public void setJson(String json) {
this.json = json;
}
public String getGm_nginx_timestamp() {
return gm_nginx_timestamp;
}
public void setGm_nginx_timestamp(String gm_nginx_timestamp) {
this.gm_nginx_timestamp = gm_nginx_timestamp;
}
public String getCreate_timestamp() {
return create_timestamp;
}
public void setCreate_timestamp(String create_timestamp) {
this.create_timestamp = create_timestamp;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public Integer getDown_loading_times() {
return down_loading_times;
}
public void setDown_loading_times(Integer down_loading_times) {
this.down_loading_times = down_loading_times;
}
public Integer getDown_slide_times() {
return down_slide_times;
}
public void setDown_slide_times(Integer down_slide_times) {
this.down_slide_times = down_slide_times;
}
public Integer getUp_loading_times() {
return up_loading_times;
}
public void setUp_loading_times(Integer up_loading_times) {
this.up_loading_times = up_loading_times;
}
public Integer getUp_slide_times() {
return up_slide_times;
}
public void setUp_slide_times(Integer up_slide_times) {
this.up_slide_times = up_slide_times;
}
public String getPage_code() {
return page_code;
}
public void setPage_code(String page_code) {
this.page_code = page_code;
}
public String getTab_name() {
return tab_name;
}
public void setTab_name(String tab_name) {
this.tab_name = tab_name;
}
public String getBusiness_id() {
return business_id;
}
public void setBusiness_id(String business_id) {
this.business_id = business_id;
}
public String getReferrer_code() {
return referrer_code;
}
public void setReferrer_code(String referrer_code) {
this.referrer_code = referrer_code;
}
public String getReferrer_id() {
return referrer_id;
}
public void setReferrer_id(String referrer_id) {
this.referrer_id = referrer_id;
}
public ArrayList<BlPreciseExposureParamsExposureCardsBean> getExposure_cards() {
return exposure_cards;
}
public void setExposure_cards(ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards) {
this.exposure_cards = exposure_cards;
}
public String getIs_exposure() {
return is_exposure;
}
public void setIs_exposure(String is_exposure) {
this.is_exposure = is_exposure;
}
public String getIs_popup() {
return is_popup;
}
public void setIs_popup(String is_popup) {
this.is_popup = is_popup;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public String getApp_grey_type() {
return app_grey_type;
}
public void setApp_grey_type(String app_grey_type) {
this.app_grey_type = app_grey_type;
}
public String getApp_channel() {
return app_channel;
}
public void setApp_channel(String app_channel) {
this.app_channel = app_channel;
}
public String getApp_version() {
return app_version;
}
public void setApp_version(String app_version) {
this.app_version = app_version;
}
public String getApp_current_city_id() {
return app_current_city_id;
}
public void setApp_current_city_id(String app_current_city_id) {
this.app_current_city_id = app_current_city_id;
}
public String getApp_code() {
return app_code;
}
public void setApp_code(String app_code) {
this.app_code = app_code;
}
public String getDevice_os_type() {
return device_os_type;
}
public void setDevice_os_type(String device_os_type) {
this.device_os_type = device_os_type;
}
public String getDevice_model() {
return device_model;
}
public void setDevice_model(String device_model) {
this.device_model = device_model;
}
public String getDevice_id() {
return device_id;
}
public void setDevice_id(String device_id) {
this.device_id = device_id;
}
public String getDevice_android_id() {
return device_android_id;
}
public void setDevice_android_id(String device_android_id) {
this.device_android_id = device_android_id;
}
public String getDevice_idfv() {
return device_idfv;
}
public void setDevice_idfv(String device_idfv) {
this.device_idfv = device_idfv;
}
public String getGm_nginx_time_date() {
return gm_nginx_time_date;
}
public void setGm_nginx_time_date(String gm_nginx_time_date) {
this.gm_nginx_time_date = gm_nginx_time_date;
}
public String getGm_nginx_time_day() {
return gm_nginx_time_day;
}
public void setGm_nginx_time_day(String gm_nginx_time_day) {
this.gm_nginx_time_day = gm_nginx_time_day;
}
public String getCreate_time_date() {
return create_time_date;
}
public void setCreate_time_date(String create_time_date) {
this.create_time_date = create_time_date;
}
public String getCreate_time_day() {
return create_time_day;
}
public void setCreate_time_day(String create_time_day) {
this.create_time_day = create_time_day;
}
@Override
public String toString() {
return "BlPreciseExposureBean{" +
"day_id='" + day_id + '\'' +
", json='" + json + '\'' +
", gm_nginx_timestamp='" + gm_nginx_timestamp + '\'' +
", create_timestamp='" + create_timestamp + '\'' +
", user_id='" + user_id + '\'' +
", action='" + action + '\'' +
", down_loading_times=" + down_loading_times +
", down_slide_times=" + down_slide_times +
", up_loading_times=" + up_loading_times +
", up_slide_times=" + up_slide_times +
", page_code='" + page_code + '\'' +
", tab_name='" + tab_name + '\'' +
", business_id='" + business_id + '\'' +
", referrer_code='" + referrer_code + '\'' +
", referrer_id='" + referrer_id + '\'' +
", exposure_cards=" + exposure_cards +
", is_exposure='" + is_exposure + '\'' +
", is_popup='" + is_popup + '\'' +
", filter='" + filter + '\'' +
", query='" + query + '\'' +
", app_grey_type='" + app_grey_type + '\'' +
", app_channel='" + app_channel + '\'' +
", app_version='" + app_version + '\'' +
", app_current_city_id='" + app_current_city_id + '\'' +
", app_code='" + app_code + '\'' +
", device_os_type='" + device_os_type + '\'' +
", device_model='" + device_model + '\'' +
", device_id='" + device_id + '\'' +
", device_android_id='" + device_android_id + '\'' +
", device_idfv='" + device_idfv + '\'' +
", gm_nginx_time_date='" + gm_nginx_time_date + '\'' +
", gm_nginx_time_day='" + gm_nginx_time_day + '\'' +
", create_time_date='" + create_time_date + '\'' +
", create_time_day='" + create_time_day + '\'' +
'}';
}
}
package com.gmei.bean.bl;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.HashMap;
/**
* ClassName: BlPreciseExposureBean
* TableName: Bl_Et_Mg_PreciseExposure_Inc_D
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/3 下午5:07
*
* @author liuzhe
* @since JDK 1.8
*/
/*
{
"gm_nginx_key":2,
"version":"110",
"params":{
"up_slide_times":0,
"down_loading_times":0,
"exposure_cards":{
},
"up_loading_times":0,
"is_exposure":1,
"tab_name":"精选",
"referrer_id":"",
"down_slide_times":0,
"referrer":"",
"page_name":"home",
"business_id":""
},
"app_session_id":"C3280044-5C8E-459D-AE6C-8E26BBACD6C9",
"gm_nginx_timestamp":1546307958.631,
"create_at":"1546307958",
"app":{
"channel":"AppStore",
"version":"7.7.35",
"serial_id":42,
"current_city_id":"worldwide",
"name":"gengmei_user",
"user_type":{
}
},
"device":{
"is_WiFi":"0",
"device_type":"ios",
"device_id":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"lng":0,
"lat":0,
"ip":"10.156.100.97",
"manufacturer":"Apple",
"idfa":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"idfv":"352A6D64-17CA-4520-831A-2CE9507631D8"
},
"user_id":"30864538",
"type":"home_choiceness_card_exposure"
}
*/
public class BlPreciseExposureDeviceBean {
@JsonProperty(value = "is_WiFi")
private String device_is_WiFi;
@JsonProperty(value = "device_type")
private String device_os_type;
@JsonProperty(value = "model")
private String device_model;
@JsonProperty(value = "sys_version")
private String device_sys_version;
@JsonProperty(value = "net_type")
private String device_net_type;
@JsonProperty(value = "device_id")
private String device_id;
@JsonProperty(value = "android_device_id")
private String device_android_id;
@JsonProperty(value = "lng")
private String device_lng;
@JsonProperty(value = "lat")
private String device_lat;
@JsonProperty(value = "ip")
private String device_ip;
@JsonProperty(value = "manufacturer")
private String device_manufacturer;
@JsonProperty(value = "idfv")
private String device_idfv;
@JsonProperty(value = "idfa")
private String device_idfa;
public BlPreciseExposureDeviceBean() {
}
public BlPreciseExposureDeviceBean(String device_is_WiFi, String device_os_type, String device_model, String device_sys_version, String device_net_type, String device_id, String device_android_id, String device_lng, String device_lat, String device_ip, String device_manufacturer, String device_idfv, String device_idfa) {
this.device_is_WiFi = device_is_WiFi;
this.device_os_type = device_os_type;
this.device_model = device_model;
this.device_sys_version = device_sys_version;
this.device_net_type = device_net_type;
this.device_id = device_id;
this.device_android_id = device_android_id;
this.device_lng = device_lng;
this.device_lat = device_lat;
this.device_ip = device_ip;
this.device_manufacturer = device_manufacturer;
this.device_idfv = device_idfv;
this.device_idfa = device_idfa;
}
public String getDevice_is_WiFi() {
return device_is_WiFi;
}
public void setDevice_is_WiFi(String device_is_WiFi) {
this.device_is_WiFi = device_is_WiFi;
}
public String getDevice_os_type() {
return device_os_type;
}
public void setDevice_os_type(String device_os_type) {
this.device_os_type = device_os_type;
}
public String getDevice_model() {
return device_model;
}
public void setDevice_model(String device_model) {
this.device_model = device_model;
}
public String getDevice_sys_version() {
return device_sys_version;
}
public void setDevice_sys_version(String device_sys_version) {
this.device_sys_version = device_sys_version;
}
public String getDevice_net_type() {
return device_net_type;
}
public void setDevice_net_type(String device_net_type) {
this.device_net_type = device_net_type;
}
public String getDevice_id() {
return device_id;
}
public void setDevice_id(String device_id) {
this.device_id = device_id;
}
public String getDevice_android_id() {
return device_android_id;
}
public void setDevice_android_id(String device_android_id) {
this.device_android_id = device_android_id;
}
public String getDevice_lng() {
return device_lng;
}
public void setDevice_lng(String device_lng) {
this.device_lng = device_lng;
}
public String getDevice_lat() {
return device_lat;
}
public void setDevice_lat(String device_lat) {
this.device_lat = device_lat;
}
public String getDevice_ip() {
return device_ip;
}
public void setDevice_ip(String device_ip) {
this.device_ip = device_ip;
}
public String getDevice_manufacturer() {
return device_manufacturer;
}
public void setDevice_manufacturer(String device_manufacturer) {
this.device_manufacturer = device_manufacturer;
}
public String getDevice_idfv() {
return device_idfv;
}
public void setDevice_idfv(String device_idfv) {
this.device_idfv = device_idfv;
}
public String getDevice_idfa() {
return device_idfa;
}
public void setDevice_idfa(String device_idfa) {
this.device_idfa = device_idfa;
}
@Override
public String toString() {
return "BlPreciseExposureDeviceBean{" +
"device_is_WiFi='" + device_is_WiFi + '\'' +
", device_os_type='" + device_os_type + '\'' +
", device_model='" + device_model + '\'' +
", device_sys_version='" + device_sys_version + '\'' +
", device_net_type='" + device_net_type + '\'' +
", device_id='" + device_id + '\'' +
", device_android_id='" + device_android_id + '\'' +
", device_lng='" + device_lng + '\'' +
", device_lat='" + device_lat + '\'' +
", device_ip='" + device_ip + '\'' +
", device_manufacturer='" + device_manufacturer + '\'' +
", device_idfv='" + device_idfv + '\'' +
", device_idfa='" + device_idfa + '\'' +
'}';
}
}
package com.gmei.bean.bl;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
/**
* ClassName: BlPreciseExposureBean
* TableName: Bl_Et_Mg_PreciseExposure_Inc_D
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/3 下午5:07
*
* @author liuzhe
* @since JDK 1.8
*/
/*
{
"gm_nginx_key":2,
"version":"110",
"params":{
"up_slide_times":0,
"down_loading_times":0,
"exposure_cards":{
},
"up_loading_times":0,
"is_exposure":1,
"tab_name":"精选",
"referrer_id":"",
"down_slide_times":0,
"referrer":"",
"page_name":"home",
"business_id":""
},
"app_session_id":"C3280044-5C8E-459D-AE6C-8E26BBACD6C9",
"gm_nginx_timestamp":1546307958.631,
"create_at":"1546307958",
"app":{
"channel":"AppStore",
"version":"7.7.35",
"serial_id":42,
"current_city_id":"worldwide",
"name":"gengmei_user",
"user_type":{
}
},
"device":{
"is_WiFi":"0",
"device_type":"ios",
"device_id":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"lng":0,
"lat":0,
"ip":"10.156.100.97",
"manufacturer":"Apple",
"idfa":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"idfv":"352A6D64-17CA-4520-831A-2CE9507631D8"
},
"user_id":"30864538",
"type":"home_choiceness_card_exposure"
}
*/
public class BlPreciseExposureParamsBean {
private Integer down_loading_times;
private Integer down_slide_times;
private Integer up_loading_times;
private Integer up_slide_times;
@JsonProperty(value = "page_name")
private String page_code;
private String tab_name;
private String business_id;
@JsonProperty(value = "referrer")
private String referrer_code;
private String referrer_id;
private BlPreciseExposureParamsExposureCardsBean exposure_cards;
private String is_exposure;
private String filter;
private String query;
public BlPreciseExposureParamsBean() {
}
public Integer getDown_loading_times() {
return down_loading_times;
}
public void setDown_loading_times(Integer down_loading_times) {
this.down_loading_times = down_loading_times;
}
public Integer getDown_slide_times() {
return down_slide_times;
}
public void setDown_slide_times(Integer down_slide_times) {
this.down_slide_times = down_slide_times;
}
public Integer getUp_loading_times() {
return up_loading_times;
}
public void setUp_loading_times(Integer up_loading_times) {
this.up_loading_times = up_loading_times;
}
public Integer getUp_slide_times() {
return up_slide_times;
}
public void setUp_slide_times(Integer up_slide_times) {
this.up_slide_times = up_slide_times;
}
public String getPage_code() {
return page_code;
}
public void setPage_code(String page_code) {
this.page_code = page_code;
}
public String getTab_name() {
return tab_name;
}
public void setTab_name(String tab_name) {
this.tab_name = tab_name;
}
public String getBusiness_id() {
return business_id;
}
public void setBusiness_id(String business_id) {
this.business_id = business_id;
}
public String getReferrer_code() {
return referrer_code;
}
public void setReferrer_code(String referrer_code) {
this.referrer_code = referrer_code;
}
public String getReferrer_id() {
return referrer_id;
}
public void setReferrer_id(String referrer_id) {
this.referrer_id = referrer_id;
}
public BlPreciseExposureParamsExposureCardsBean getExposure_cards() {
return exposure_cards;
}
public void setExposure_cards(BlPreciseExposureParamsExposureCardsBean exposure_cards) {
this.exposure_cards = exposure_cards;
}
public String getIs_exposure() {
return is_exposure;
}
public void setIs_exposure(String is_exposure) {
this.is_exposure = is_exposure;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
public BlPreciseExposureParamsBean(Integer down_loading_times, Integer down_slide_times, Integer up_loading_times, Integer up_slide_times, String page_code, String tab_name, String business_id, String referrer_code, String referrer_id, BlPreciseExposureParamsExposureCardsBean exposure_cards, String is_exposure, String filter, String query) {
this.down_loading_times = down_loading_times;
this.down_slide_times = down_slide_times;
this.up_loading_times = up_loading_times;
this.up_slide_times = up_slide_times;
this.page_code = page_code;
this.tab_name = tab_name;
this.business_id = business_id;
this.referrer_code = referrer_code;
this.referrer_id = referrer_id;
this.exposure_cards = exposure_cards;
this.is_exposure = is_exposure;
this.filter = filter;
this.query = query;
}
@Override
public String toString() {
return "BlPreciseExposureParamsBean{" +
"down_loading_times=" + down_loading_times +
", down_slide_times=" + down_slide_times +
", up_loading_times=" + up_loading_times +
", up_slide_times=" + up_slide_times +
", page_code='" + page_code + '\'' +
", tab_name='" + tab_name + '\'' +
", business_id='" + business_id + '\'' +
", referrer_code='" + referrer_code + '\'' +
", referrer_id='" + referrer_id + '\'' +
", exposure_cards=" + exposure_cards +
", is_exposure='" + is_exposure + '\'' +
", filter='" + filter + '\'' +
", query='" + query + '\'' +
'}';
}
}
package com.gmei.bean.bl;
/**
* ClassName: BlPreciseExposureBean
* TableName: Bl_Et_Mg_PreciseExposure_Inc_D
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/3 下午5:07
*
* @author liuzhe
* @since JDK 1.8
*/
/*
{
"gm_nginx_key":2,
"version":"110",
"params":{
"up_slide_times":0,
"down_loading_times":0,
"exposure_cards":{
},
"up_loading_times":0,
"is_exposure":1,
"tab_name":"精选",
"referrer_id":"",
"down_slide_times":0,
"referrer":"",
"page_name":"home",
"business_id":""
},
"app_session_id":"C3280044-5C8E-459D-AE6C-8E26BBACD6C9",
"gm_nginx_timestamp":1546307958.631,
"create_at":"1546307958",
"app":{
"channel":"AppStore",
"version":"7.7.35",
"serial_id":42,
"current_city_id":"worldwide",
"name":"gengmei_user",
"user_type":{
}
},
"device":{
"is_WiFi":"0",
"device_type":"ios",
"device_id":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"lng":0,
"lat":0,
"ip":"10.156.100.97",
"manufacturer":"Apple",
"idfa":"DE8EA66A-BDE9-47CD-9795-24E444F5BC17",
"idfv":"352A6D64-17CA-4520-831A-2CE9507631D8"
},
"user_id":"30864538",
"type":"home_choiceness_card_exposure"
}
*/
/*
get_json_object(result_card,"$.card_id") as card_id, --卡片id
get_json_object(result_card,"$.card_content_type") as card_content_type, --卡片内容类型
get_json_object(result_card,"$.card_type") as card_type, --卡片类型
get_json_object(result_card,"$.transaction_type") as transaction_type, --卡片业务类型
get_json_object(result_card,"$.absolute_position") as absolute_position, --绝对位置
get_json_object(result_card,"$.relative_position") as relative_position, --相对位置
get_json_object(result_card,"$.filter_f") as filter_f,
get_json_object(result_card,"$.is_cpc") as is_cpc, --是否为cpc收费卡片
get_json_object(result_card,"$.cpc_referer") as cpc_referer, --cpc_referer
get_json_object(result_card,"$.in_page_pose ") as in_page_pose,
get_json_object(result_card,"$.result_status") as result_status, --结果状态
get_json_object(result_card,"$.sec_tab_name") as sec_tab_name, --二级页面名称
--非正常卡片通用参数(banner 豆腐块 icon)
get_json_object(result_card,"$.module_id") as module_id, --模块id
get_json_object(result_card,"$.card_name ") as card_name, --卡片名字
get_json_object(result_card,"$.url") as url, --跳转链接
--豆腐块额外参数
get_json_object(result_card,"$.module_type") as module_type, --模块类型
get_json_object(result_card,"$.grid") as grid, --区域 (a、b、c、d,目前线上最多四张图片)
--icon的额外参数
get_json_object(result_card,"$.total_position") as total_position,--总共有几屏
get_json_object(result_card,"$.current_position") as current_position --icon在第几屏
*/
public class BlPreciseExposureParamsExposureCardsBean {
private String card_id;
private String card_content_type;
private String card_type;
private String card_name;
private String target_name;
private String transaction_type;
private String is_cpc;
private String cpc_referer;
private String absolute_position;
private String relative_position;
public BlPreciseExposureParamsExposureCardsBean() {
}
public String getCard_type() {
return card_type;
}
public void setCard_type(String card_type) {
this.card_type = card_type;
}
public String getCard_name() {
return card_name;
}
public void setCard_name(String card_name) {
this.card_name = card_name;
}
public String getTarget_name() {
return target_name;
}
public void setTarget_name(String target_name) {
this.target_name = target_name;
}
public String getCpc_referer() {
return cpc_referer;
}
public void setCpc_referer(String cpc_referer) {
this.cpc_referer = cpc_referer;
}
public String getCard_id() {
return card_id;
}
public void setCard_id(String card_id) {
this.card_id = card_id;
}
public String getCard_content_type() {
return card_content_type;
}
public void setCard_content_type(String card_content_type) {
this.card_content_type = card_content_type;
}
public String getIs_cpc() {
return is_cpc;
}
public void setIs_cpc(String is_cpc) {
this.is_cpc = is_cpc;
}
public String getAbsolute_position() {
return absolute_position;
}
public void setAbsolute_position(String absolute_position) {
this.absolute_position = absolute_position;
}
public String getTransaction_type() {
return transaction_type;
}
public void setTransaction_type(String transaction_type) {
this.transaction_type = transaction_type;
}
public String getRelative_position() {
return relative_position;
}
public void setRelative_position(String relative_position) {
this.relative_position = relative_position;
}
public BlPreciseExposureParamsExposureCardsBean(String card_id, String card_content_type, String card_type, String card_name, String target_name, String transaction_type, String is_cpc, String cpc_referer, String absolute_position, String relative_position) {
this.card_id = card_id;
this.card_content_type = card_content_type;
this.card_type = card_type;
this.card_name = card_name;
this.target_name = target_name;
this.transaction_type = transaction_type;
this.is_cpc = is_cpc;
this.cpc_referer = cpc_referer;
this.absolute_position = absolute_position;
this.relative_position = relative_position;
}
@Override
public String toString() {
return "BlPreciseExposureParamsExposureCardsBean{" +
"card_id='" + card_id + '\'' +
", card_content_type='" + card_content_type + '\'' +
", card_type='" + card_type + '\'' +
", card_name='" + card_name + '\'' +
", target_name='" + target_name + '\'' +
", transaction_type='" + transaction_type + '\'' +
", is_cpc='" + is_cpc + '\'' +
", cpc_referer='" + cpc_referer + '\'' +
", absolute_position='" + absolute_position + '\'' +
", relative_position='" + relative_position + '\'' +
'}';
}
}
package com.gmei.bean.dim;
/**
* ClassName: DimCardContentType
* Function:
* Reason: 卡片内容类型DIM_CARD_CONTENT_TYPE
* Date: 2019/12/6 下午8:20
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimCardContentType {
private String code; //编码
private String pk; //主键
private String name; //名称
private String memo; //说明
private String new_code; //转换后编码
private Integer oid; //排序
public DimCardContentType() {
}
public DimCardContentType(String code, String pk, String name, String memo, String new_code, Integer oid) {
this.code = code;
this.pk = pk;
this.name = name;
this.memo = memo;
this.new_code = new_code;
this.oid = oid;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPk() {
return pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
public String getNew_code() {
return new_code;
}
public void setNew_code(String new_code) {
this.new_code = new_code;
}
public Integer getOid() {
return oid;
}
public void setOid(Integer oid) {
this.oid = oid;
}
@Override
public String toString() {
return "DimCity{" +
"code='" + code + '\'' +
", pk='" + pk + '\'' +
", name='" + name + '\'' +
", memo='" + memo + '\'' +
", new_code='" + new_code + '\'' +
", oid=" + oid +
'}';
}
}
package com.gmei.bean.dim;
/**
* ClassName: DimCity
* Function:
* Reason: 城市码表DIM_CITY
* Date: 2019/12/6 下午8:20
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimCity {
private String code; //城市编码
private String pk; //城市TAGID
private String name; //城市名称
private String memo; //城市说明
private String parent_province_code; //省份编码
private String parent_province_pk; //省份TAGID
private String parent_province_name; //省份名称
private String parent_province_memo; //省份说明
private String parent_country_code; //国家编码
private String parent_country_pk; //国家TAGID
private String parent_country_name; //国家名称
private String parent_country_memo; //国家说明
private String parent_region_code; //区域编码
private String parent_region_pk; //区域ID
private String parent_region_name; //区域名称
private String parent_region_memo; //区域说明
private Integer oid; //排序
public DimCity() {
}
public DimCity(String code, String pk, String name, String memo, String parent_province_code, String parent_province_pk, String parent_province_name, String parent_province_memo, String parent_country_code, String parent_country_pk, String parent_country_name, String parent_country_memo, String parent_region_code, String parent_region_pk, String parent_region_name, String parent_region_memo, Integer oid) {
this.code = code;
this.pk = pk;
this.name = name;
this.memo = memo;
this.parent_province_code = parent_province_code;
this.parent_province_pk = parent_province_pk;
this.parent_province_name = parent_province_name;
this.parent_province_memo = parent_province_memo;
this.parent_country_code = parent_country_code;
this.parent_country_pk = parent_country_pk;
this.parent_country_name = parent_country_name;
this.parent_country_memo = parent_country_memo;
this.parent_region_code = parent_region_code;
this.parent_region_pk = parent_region_pk;
this.parent_region_name = parent_region_name;
this.parent_region_memo = parent_region_memo;
this.oid = oid;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPk() {
return pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
public String getParent_province_code() {
return parent_province_code;
}
public void setParent_province_code(String parent_province_code) {
this.parent_province_code = parent_province_code;
}
public String getParent_province_pk() {
return parent_province_pk;
}
public void setParent_province_pk(String parent_province_pk) {
this.parent_province_pk = parent_province_pk;
}
public String getParent_province_name() {
return parent_province_name;
}
public void setParent_province_name(String parent_province_name) {
this.parent_province_name = parent_province_name;
}
public String getParent_province_memo() {
return parent_province_memo;
}
public void setParent_province_memo(String parent_province_memo) {
this.parent_province_memo = parent_province_memo;
}
public String getParent_country_code() {
return parent_country_code;
}
public void setParent_country_code(String parent_country_code) {
this.parent_country_code = parent_country_code;
}
public String getParent_country_pk() {
return parent_country_pk;
}
public void setParent_country_pk(String parent_country_pk) {
this.parent_country_pk = parent_country_pk;
}
public String getParent_country_name() {
return parent_country_name;
}
public void setParent_country_name(String parent_country_name) {
this.parent_country_name = parent_country_name;
}
public String getParent_country_memo() {
return parent_country_memo;
}
public void setParent_country_memo(String parent_country_memo) {
this.parent_country_memo = parent_country_memo;
}
public String getParent_region_code() {
return parent_region_code;
}
public void setParent_region_code(String parent_region_code) {
this.parent_region_code = parent_region_code;
}
public String getParent_region_pk() {
return parent_region_pk;
}
public String getParent_region_name() {
return parent_region_name;
}
public void setParent_region_name(String parent_region_name) {
this.parent_region_name = parent_region_name;
}
public String getParent_region_memo() {
return parent_region_memo;
}
public void setParent_region_memo(String parent_region_memo) {
this.parent_region_memo = parent_region_memo;
}
@Override
public String toString() {
return "DimCity{" +
"code='" + code + '\'' +
", pk='" + pk + '\'' +
", name='" + name + '\'' +
", memo='" + memo + '\'' +
", parent_province_code='" + parent_province_code + '\'' +
", parent_province_pk='" + parent_province_pk + '\'' +
", parent_province_name='" + parent_province_name + '\'' +
", parent_province_memo='" + parent_province_memo + '\'' +
", parent_country_code='" + parent_country_code + '\'' +
", parent_country_pk='" + parent_country_pk + '\'' +
", parent_country_name='" + parent_country_name + '\'' +
", parent_country_memo='" + parent_country_memo + '\'' +
", parent_region_code='" + parent_region_code + '\'' +
", parent_region_pk='" + parent_region_pk + '\'' +
", parent_region_name='" + parent_region_name + '\'' +
", parent_region_memo='" + parent_region_memo + '\'' +
", oid=" + oid +
'}';
}
public void setParent_region_pk(String parent_region_pk) {
this.parent_region_pk = parent_region_pk;
}
public Integer getOid() {
return oid;
}
public void setOid(Integer oid) {
this.oid = oid;
}
}
package com.gmei.bean.dim;
/**
* ClassName: DimPageType
* Function:
* Reason: 页面类型码表DIM_PAGE_TYPE
* Date: 2019/12/6 下午8:20
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimPageType {
private String code; //页面编码
private String pk; //页面主键
private String name; //页面名称
private String memo; //页面说明
private String parent_app_code; //上级APP编码
private String parent_app_pk; //上级APP主键
private String parent_app_name; //上级APP名称
private String parent_app_memo; //上级APP说明
private String type_s_code; //页面分类小类编码
private String type_s_name; //页面分类小类名称
private String type_m_code; //页面分类中类编码
private String type_m_name; //页面分类中类名称
private String type_l_code; //页面分类大类编码
private String type_l_name; //页面分类大类名称
private Integer oid; //排序
public DimPageType() {
}
public DimPageType(String code, String pk, String name, String memo, String parent_app_code, String parent_app_pk, String parent_app_name, String parent_app_memo, String type_s_code, String type_s_name, String type_m_code, String type_m_name, String type_l_code, String type_l_name, Integer oid) {
this.code = code;
this.pk = pk;
this.name = name;
this.memo = memo;
this.parent_app_code = parent_app_code;
this.parent_app_pk = parent_app_pk;
this.parent_app_name = parent_app_name;
this.parent_app_memo = parent_app_memo;
this.type_s_code = type_s_code;
this.type_s_name = type_s_name;
this.type_m_code = type_m_code;
this.type_m_name = type_m_name;
this.type_l_code = type_l_code;
this.type_l_name = type_l_name;
this.oid = oid;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPk() {
return pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
public String getParent_app_code() {
return parent_app_code;
}
public void setParent_app_code(String parent_app_code) {
this.parent_app_code = parent_app_code;
}
public String getParent_app_pk() {
return parent_app_pk;
}
public void setParent_app_pk(String parent_app_pk) {
this.parent_app_pk = parent_app_pk;
}
public String getParent_app_name() {
return parent_app_name;
}
public void setParent_app_name(String parent_app_name) {
this.parent_app_name = parent_app_name;
}
public String getParent_app_memo() {
return parent_app_memo;
}
public void setParent_app_memo(String parent_app_memo) {
this.parent_app_memo = parent_app_memo;
}
public String getType_s_code() {
return type_s_code;
}
public void setType_s_code(String type_s_code) {
this.type_s_code = type_s_code;
}
public String getType_s_name() {
return type_s_name;
}
public void setType_s_name(String type_s_name) {
this.type_s_name = type_s_name;
}
public String getType_m_code() {
return type_m_code;
}
public void setType_m_code(String type_m_code) {
this.type_m_code = type_m_code;
}
public String getType_m_name() {
return type_m_name;
}
public void setType_m_name(String type_m_name) {
this.type_m_name = type_m_name;
}
public String getType_l_code() {
return type_l_code;
}
public void setType_l_code(String type_l_code) {
this.type_l_code = type_l_code;
}
public String getType_l_name() {
return type_l_name;
}
public void setType_l_name(String type_l_name) {
this.type_l_name = type_l_name;
}
public Integer getOid() {
return oid;
}
public void setOid(Integer oid) {
this.oid = oid;
}
@Override
public String toString() {
return "DimPageType{" +
"code='" + code + '\'' +
", pk='" + pk + '\'' +
", name='" + name + '\'' +
", memo='" + memo + '\'' +
", parent_app_code='" + parent_app_code + '\'' +
", parent_app_pk='" + parent_app_pk + '\'' +
", parent_app_name='" + parent_app_name + '\'' +
", parent_app_memo='" + parent_app_memo + '\'' +
", type_s_code='" + type_s_code + '\'' +
", type_s_name='" + type_s_name + '\'' +
", type_m_code='" + type_m_code + '\'' +
", type_m_name='" + type_m_name + '\'' +
", type_l_code='" + type_l_code + '\'' +
", type_l_name='" + type_l_name + '\'' +
", oid=" + oid +
'}';
}
}
package com.gmei.bean.dim;
/**
* ClassName: DimTable
* Function:
* Reason: 标准码表共用
* include DIM_CARD_TYPE、DIM_TRANSACTION_TYPE、DIM_CARD_CONTENT_TYPE
* Date: 2019/12/6 下午8:20
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimTable {
private String code; //编码
private String pk; //主键
private String name; //名称
private String memo; //说明
private Integer oid; //排序
public DimTable() {
}
public DimTable(String code, String pk, String name, String memo, Integer oid) {
this.code = code;
this.pk = pk;
this.name = name;
this.memo = memo;
this.oid = oid;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getPk() {
return pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
public Integer getOid() {
return oid;
}
public void setOid(Integer oid) {
this.oid = oid;
}
@Override
public String toString() {
return "DimCity{" +
"code='" + code + '\'' +
", pk='" + pk + '\'' +
", name='" + name + '\'' +
", memo='" + memo + '\'' +
", oid=" + oid +
'}';
}
}
package com.gmei.bean.ml;
import java.util.Date;
/**
* ClassName: MlPreciseExposureBean
* TableName: ML_C_ET_PE_PRECISEEXPOSURE_DIMEN_D_RT
* Function:
* Reason: ML层精准曝光BEAN类
* Date: 2019/12/3 下午5:07
*
* @author liuzhe
* @since JDK 1.8
*/
/*
get_json_object(result_card,"$.card_id") as card_id, --卡片id
get_json_object(result_card,"$.card_content_type") as card_content_type, --卡片内容类型
get_json_object(result_card,"$.card_type") as card_type, --卡片类型
get_json_object(result_card,"$.transaction_type") as transaction_type, --卡片业务类型
get_json_object(result_card,"$.absolute_position") as absolute_position, --绝对位置
get_json_object(result_card,"$.relative_position") as relative_position, --相对位置
get_json_object(result_card,"$.filter_f") as filter_f,
get_json_object(result_card,"$.is_cpc") as is_cpc, --是否为cpc收费卡片
get_json_object(result_card,"$.cpc_referer") as cpc_referer, --cpc_referer
get_json_object(result_card,"$.in_page_pose ") as in_page_pose,
get_json_object(result_card,"$.result_status") as result_status, --结果状态
get_json_object(result_card,"$.sec_tab_name") as sec_tab_name, --二级页面名称
--非正常卡片通用参数(banner 豆腐块 icon)
get_json_object(result_card,"$.module_id") as module_id, --模块id
get_json_object(result_card,"$.card_name ") as card_name, --卡片名字
get_json_object(result_card,"$.url") as url, --跳转链接
--豆腐块额外参数
get_json_object(result_card,"$.module_type") as module_type, --模块类型
get_json_object(result_card,"$.grid") as grid, --区域 (a、b、c、d,目前线上最多四张图片)
--icon的额外参数
get_json_object(result_card,"$.total_position") as total_position,--总共有几屏
get_json_object(result_card,"$.current_position") as current_position --icon在第几屏
*/
public class MlPreciseExposureBean {
private Date day_id;
// private String gm_nginx_timestamp;
// private String create_timestamp;
private String user_id;
private String action;
// private String action_name; //匹配码表DIM_ACTION_TYPE(只有两种不需要关联)
private String page_code;
private String page_name; //匹配码表DIM_PAGE_TYPE
private String tab_name;
private String business_id;
private String referrer_code;
private String referrer_name; //匹配码表DIM_PAGE_TYPE
private String referrer_id;
private String card_id;
private String card_name;
private String card_content_type;
private String card_content_type_name; //匹配码表DIM_CARD_CONTENT_TYPE
private String card_type;
private String card_type_name; //匹配码表DIM_CARD_TYPE
private String is_cpc;
private String cpc_referer;
// private String absolute_position;
// private String relative_position;
private String transaction_type;
private String transaction_type_name; //匹配码表DIM_TRANSACTION_TYPE
private String filter;
private String query;
// private String app_grey_type;
// private String app_channel;
private String app_version;
private String current_city_id;
private String current_city_name; //匹配码表DIM_CITY
private String current_province_id; //匹配码表DIM_CITY
private String current_province_name; //匹配码表DIM_CITY
private String current_country_id; //匹配码表DIM_CITY
private String current_country_name; //匹配码表DIM_CITY
private String current_region_id; //匹配码表DIM_CITY
private String current_region_name; //匹配码表DIM_CITY
private String app_code;
private String device_os_type;
// private String device_model;
private String device_id;
// private String device_android_id;
// private String device_idfv;
// private String gm_nginx_time_date;
// private String create_time_date;
private String create_time_day;
private String gm_nginx_time_day;
private Integer preciseexposure_num;
public MlPreciseExposureBean() {
}
public MlPreciseExposureBean(Date day_id, String user_id, String action, String page_code, String page_name, String tab_name, String business_id, String referrer_code, String referrer_name, String referrer_id, String card_id, String card_name, String card_content_type, String card_content_type_name, String card_type, String card_type_name, String is_cpc, String cpc_referer, String transaction_type, String transaction_type_name, String filter, String query, String app_version, String current_city_id, String current_city_name, String current_province_id, String current_province_name, String current_country_id, String current_country_name, String current_region_id, String current_region_name, String app_code, String device_os_type, String device_id, String create_time_day, String gm_nginx_time_day, Integer preciseexposure_num) {
this.day_id = day_id;
this.user_id = user_id;
this.action = action;
// this.action_name = action_name;
this.page_code = page_code;
this.page_name = page_name;
this.tab_name = tab_name;
this.business_id = business_id;
this.referrer_code = referrer_code;
this.referrer_name = referrer_name;
this.referrer_id = referrer_id;
this.card_id = card_id;
this.card_name = card_name;
this.card_content_type = card_content_type;
this.card_content_type_name = card_content_type_name;
this.card_type = card_type;
this.card_type_name = card_type_name;
this.is_cpc = is_cpc;
this.cpc_referer = cpc_referer;
this.transaction_type = transaction_type;
this.transaction_type_name = transaction_type_name;
this.filter = filter;
this.query = query;
// this.app_channel = app_channel;
this.app_version = app_version;
this.current_city_id = current_city_id;
this.current_city_name = current_city_name;
this.current_province_id = current_province_id;
this.current_province_name = current_province_name;
this.current_country_id = current_country_id;
this.current_country_name = current_country_name;
this.current_region_id = current_region_id;
this.current_region_name = current_region_name;
this.app_code = app_code;
this.device_os_type = device_os_type;
this.device_id = device_id;
this.create_time_day = create_time_day;
this.gm_nginx_time_day = gm_nginx_time_day;
this.preciseexposure_num = preciseexposure_num;
}
public Date getDay_id() {
return day_id;
}
public void setDay_id(Date day_id) {
this.day_id = day_id;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
// public String getAction_name() {
// return action_name;
// }
// public void setAction_name(String action_name) {
// this.action_name = action_name;
// }
public String getPage_code() {
return page_code;
}
public void setPage_code(String page_code) {
this.page_code = page_code;
}
public String getPage_name() {
return page_name;
}
public void setPage_name(String page_name) {
this.page_name = page_name;
}
public String getTab_name() {
return tab_name;
}
public void setTab_name(String tab_name) {
this.tab_name = tab_name;
}
public String getBusiness_id() {
return business_id;
}
public void setBusiness_id(String business_id) {
this.business_id = business_id;
}
public String getReferrer_code() {
return referrer_code;
}
public void setReferrer_code(String referrer_code) {
this.referrer_code = referrer_code;
}
public String getReferrer_name() {
return referrer_name;
}
public void setReferrer_name(String referrer_name) {
this.referrer_name = referrer_name;
}
public String getReferrer_id() {
return referrer_id;
}
public void setReferrer_id(String referrer_id) {
this.referrer_id = referrer_id;
}
public String getCard_id() {
return card_id;
}
public void setCard_id(String card_id) {
this.card_id = card_id;
}
public String getCard_name() {
return card_name;
}
public void setCard_name(String card_name) {
this.card_name = card_name;
}
public String getCard_content_type() {
return card_content_type;
}
public void setCard_content_type(String card_content_type) {
this.card_content_type = card_content_type;
}
public String getCard_content_type_name() {
return card_content_type_name;
}
public void setCard_content_type_name(String card_content_type_name) {
this.card_content_type_name = card_content_type_name;
}
public String getCard_type() {
return card_type;
}
public void setCard_type(String card_type) {
this.card_type = card_type;
}
public String getCard_type_name() {
return card_type_name;
}
public void setCard_type_name(String card_type_name) {
this.card_type_name = card_type_name;
}
public String getIs_cpc() {
return is_cpc;
}
public void setIs_cpc(String is_cpc) {
this.is_cpc = is_cpc;
}
public String getCpc_referer() {
return cpc_referer;
}
public void setCpc_referer(String cpc_referer) {
this.cpc_referer = cpc_referer;
}
// public String getAbsolute_position() {
// return absolute_position;
// }
//
// public void setAbsolute_position(String absolute_position) {
// this.absolute_position = absolute_position;
// }
//
// public String getRelative_position() {
// return relative_position;
// }
//
// public void setRelative_position(String relative_position) {
// this.relative_position = relative_position;
// }
public String getTransaction_type() {
return transaction_type;
}
public void setTransaction_type(String transaction_type) {
this.transaction_type = transaction_type;
}
public String getTransaction_type_name() {
return transaction_type_name;
}
public void setTransaction_type_name(String transaction_type_name) {
this.transaction_type_name = transaction_type_name;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
// public String getApp_channel() {
// return app_channel;
// }
// public void setApp_channel(String app_channel) {
// this.app_channel = app_channel;
// }
public String getApp_version() {
return app_version;
}
public void setApp_version(String app_version) {
this.app_version = app_version;
}
public String getCurrent_city_id() {
return current_city_id;
}
public void setCurrent_city_id(String current_city_id) {
this.current_city_id = current_city_id;
}
public String getCurrent_city_name() {
return current_city_name;
}
public void setCurrent_city_name(String current_city_name) {
this.current_city_name = current_city_name;
}
public String getCurrent_province_id() {
return current_province_id;
}
public void setCurrent_province_id(String current_province_id) {
this.current_province_id = current_province_id;
}
public String getCurrent_province_name() {
return current_province_name;
}
public void setCurrent_province_name(String current_province_name) {
this.current_province_name = current_province_name;
}
public String getCurrent_country_id() {
return current_country_id;
}
public void setCurrent_country_id(String current_country_id) {
this.current_country_id = current_country_id;
}
public String getCurrent_country_name() {
return current_country_name;
}
public void setCurrent_country_name(String current_country_name) {
this.current_country_name = current_country_name;
}
public String getCurrent_region_id() {
return current_region_id;
}
public void setCurrent_region_id(String current_region_id) {
this.current_region_id = current_region_id;
}
public String getCurrent_region_name() {
return current_region_name;
}
public void setCurrent_region_name(String current_region_name) {
this.current_region_name = current_region_name;
}
public String getApp_code() {
return app_code;
}
public void setApp_code(String app_code) {
this.app_code = app_code;
}
public String getDevice_os_type() {
return device_os_type;
}
public void setDevice_os_type(String device_os_type) {
this.device_os_type = device_os_type;
}
public String getDevice_id() {
return device_id;
}
public void setDevice_id(String device_id) {
this.device_id = device_id;
}
public String getCreate_time_day() {
return create_time_day;
}
public void setCreate_time_day(String create_time_day) {
this.create_time_day = create_time_day;
}
public String getGm_nginx_time_day() {
return gm_nginx_time_day;
}
public void setGm_nginx_time_day(String gm_nginx_time_day) {
this.gm_nginx_time_day = gm_nginx_time_day;
}
public Integer getPreciseexposure_num() {
return preciseexposure_num;
}
public void setPreciseexposure_num(Integer preciseexposure_num) {
this.preciseexposure_num = preciseexposure_num;
}
@Override
public String toString() {
return "MlPreciseExposureBean{" +
"day_id='" + day_id + '\'' +
", user_id='" + user_id + '\'' +
", action='" + action + '\'' +
", page_code='" + page_code + '\'' +
", page_name='" + page_name + '\'' +
", tab_name='" + tab_name + '\'' +
", business_id='" + business_id + '\'' +
", referrer_code='" + referrer_code + '\'' +
", referrer_name='" + referrer_name + '\'' +
", referrer_id='" + referrer_id + '\'' +
", card_id='" + card_id + '\'' +
", card_name='" + card_name + '\'' +
", card_content_type='" + card_content_type + '\'' +
", card_content_type_name='" + card_content_type_name + '\'' +
", card_type='" + card_type + '\'' +
", card_type_name='" + card_type_name + '\'' +
", is_cpc='" + is_cpc + '\'' +
", cpc_referer='" + cpc_referer + '\'' +
", transaction_type='" + transaction_type + '\'' +
", transaction_type_name='" + transaction_type_name + '\'' +
", filter='" + filter + '\'' +
", query='" + query + '\'' +
", app_version='" + app_version + '\'' +
", current_city_id='" + current_city_id + '\'' +
", current_city_name='" + current_city_name + '\'' +
", current_province_id='" + current_province_id + '\'' +
", current_province_name='" + current_province_name + '\'' +
", current_country_id='" + current_country_id + '\'' +
", current_country_name='" + current_country_name + '\'' +
", current_region_id='" + current_region_id + '\'' +
", current_region_name='" + current_region_name + '\'' +
", app_code='" + app_code + '\'' +
", device_os_type='" + device_os_type + '\'' +
", device_id='" + device_id + '\'' +
", create_time_day='" + create_time_day + '\'' +
", gm_nginx_time_day='" + gm_nginx_time_day + '\'' +
", preciseexposure_num=" + preciseexposure_num +
'}';
}
}
package com.gmei.cache;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.bl.BlPreciseExposureParamsExposureCardsBean;
import com.gmei.jdbc.MysqlJdbcBl;
import java.util.ArrayList;
import java.util.List;
/**
* ClassName: BlPreciseExposureDao
* Function:
* Reason: bl_et_mg_preciseexposure_inc_d_rt数据下发操作类
* Date: 2019/12/19 上午11:35
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureDao {
private MysqlJdbcBl mysqlJdbcBl;
private String sql;
private String sinkJdbcUrl;
private String sinkTableName;
public BlPreciseExposureDao(String sinkJdbcUrl, String sinkTableName) {
this.sinkJdbcUrl = sinkJdbcUrl;
this.sinkTableName = sinkTableName;
this.mysqlJdbcBl = MysqlJdbcBl.getInstance(sinkJdbcUrl);
}
/**
* Function: insertBlPreciseExposure
* Reason: 向表中插入数据
* Date: 2019/12/25 下午5:38
*
* @author liuzhe
* @since JDK 1.8
*/
public void insertBlPreciseExposure(BlPreciseExposureBean blPreciseExposureBean) throws Exception {
sql = "insert into " + sinkTableName + "\n" +
" (day_id,\n" +
" json,\n" +
" gm_nginx_timestamp,\n" +
" create_timestamp,\n" +
" user_id,\n" +
" action,\n" +
" down_loading_times,\n" +
" down_slide_times,\n" +
" up_loading_times,\n" +
" up_slide_times,\n" +
" page_code,\n" +
" tab_name,\n" +
" business_id,\n" +
" referrer_code,\n" +
" referrer_id,\n" +
" exposure_cards,\n" +
" is_exposure,\n" +
" is_popup,\n" +
" filter,\n" +
" query,\n" +
" app_grey_type,\n" +
" app_channel,\n" +
" app_version,\n" +
" app_current_city_id,\n" +
" app_code,\n" +
" device_os_type,\n" +
" device_model,\n" +
" device_id,\n" +
" device_android_id,\n" +
" device_idfv,\n" +
" gm_nginx_time_date,\n" +
" gm_nginx_time_day,\n" +
" create_time_date,\n" +
" create_time_day)\n" +
"values\n" +
" (?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?)";
List<Object> params = new ArrayList<Object>();
String json = blPreciseExposureBean.getJson();
// Clob clob = connection.createClob();
// clob.setString(1, json);
params.add(blPreciseExposureBean.getDay_id());
params.add(json);
params.add(blPreciseExposureBean.getGm_nginx_timestamp());
params.add(blPreciseExposureBean.getCreate_timestamp());
params.add(blPreciseExposureBean.getUser_id());
params.add(blPreciseExposureBean.getAction());
params.add(blPreciseExposureBean.getDown_loading_times());
params.add(blPreciseExposureBean.getDown_slide_times());
params.add(blPreciseExposureBean.getUp_loading_times());
params.add(blPreciseExposureBean.getUp_slide_times());
params.add(blPreciseExposureBean.getPage_code());
params.add(blPreciseExposureBean.getTab_name());
params.add(blPreciseExposureBean.getBusiness_id());
params.add(blPreciseExposureBean.getReferrer_code());
params.add(blPreciseExposureBean.getReferrer_id());
ArrayList<BlPreciseExposureParamsExposureCardsBean> blPreciseExposureCardsBeans= blPreciseExposureBean.getExposure_cards();
JSONArray jsonArrayCardsBeans= JSONArray.parseArray(JSON.toJSONString(blPreciseExposureCardsBeans));
params.add(jsonArrayCardsBeans.toString());
params.add(blPreciseExposureBean.getIs_exposure());
params.add(blPreciseExposureBean.getIs_popup());
params.add(blPreciseExposureBean.getFilter());
params.add(blPreciseExposureBean.getQuery());
params.add(blPreciseExposureBean.getApp_grey_type());
params.add(blPreciseExposureBean.getApp_channel());
params.add(blPreciseExposureBean.getApp_version());
params.add(blPreciseExposureBean.getApp_current_city_id());
params.add(blPreciseExposureBean.getApp_code());
params.add(blPreciseExposureBean.getDevice_os_type());
params.add(blPreciseExposureBean.getDevice_model());
params.add(blPreciseExposureBean.getDevice_id());
params.add(blPreciseExposureBean.getDevice_android_id());
params.add(blPreciseExposureBean.getDevice_idfv());
params.add(blPreciseExposureBean.getGm_nginx_time_date());
params.add(blPreciseExposureBean.getGm_nginx_time_day());
params.add(blPreciseExposureBean.getCreate_time_date());
params.add(blPreciseExposureBean.getCreate_time_day());
// System.out.println(params.toString());
mysqlJdbcBl.update(sql, params);
}
}
package com.gmei.cache;
import java.util.Map;
import java.util.concurrent.Callable;
/**
* ClassName: CacheServiceAbstract
* Function:
* Reason: 缓存抽象类
* Date: 2019/12/10 下午7:01
*
* @author liuzhe
* @since JDK 1.8
*/
public abstract class CacheServiceAbstract<K, V> {
abstract V getValue(K key, Callable<V> callable);
// abstract V getValue(K key, Callable<Optional<V>> callable);
abstract void clearCache();
abstract Long cacheSize();
abstract void putValue(K key, V value);
abstract void invalidate(Object key);
// abstract void putValues(ArrayList<V> ts);
abstract void putValues(Map<K, V> map);
}
package com.gmei.cache;
import com.gmei.bean.dim.DimCardContentType;
import com.gmei.jdbc.MysqlJdbcDim;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
* ClassName: DimCardContentTypeDao
* Function:
* Reason: dim_card_content_type卡片内容类型数据库操作类
* Date: 2019/12/10 下午7:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimCardContentTypeDao {
private MysqlJdbcDim mysqlJdbcDim;
private ResultSet resultSet;
private String sql;
private String dimJdbcUrl;
public DimCardContentTypeDao() {
}
public DimCardContentTypeDao(String dimJdbcUrl) {
this.dimJdbcUrl = dimJdbcUrl;
this.mysqlJdbcDim = MysqlJdbcDim.getInstance(dimJdbcUrl);
}
/**
* Function: findAllDimCardContentType
* Reason: 查询所有卡片内容类型信息
* Date: 2019/12/25 下午5:32
*
* @author liuzhe
* @since JDK 1.8
*/
public ArrayList<DimCardContentType> findAllDimCardContentType(String tableName) {
sql = String.format(
"select code, pk, name, memo, new_code" +
" from %s", tableName);
ArrayList<DimCardContentType> dimCardContentTypeList = new ArrayList<>();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
DimCardContentType dimCardContentType = new DimCardContentType();
dimCardContentType.setCode(resultSet.getString(1));
dimCardContentType.setPk(resultSet.getString(2));
dimCardContentType.setName(resultSet.getString(3));
dimCardContentType.setMemo(resultSet.getString(4));
dimCardContentType.setNew_code(resultSet.getString(5));
dimCardContentTypeList.add(dimCardContentType);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return dimCardContentTypeList;
}
/**
* Function: findDimCardContentTypeByCode
* Reason: 通过卡片内容类型编码查询信息
* Date: 2019/12/25 下午5:34
*
* @author liuzhe
* @since JDK 1.8
*/
public DimCardContentType findDimCardContentTypeByCode(String tableName, String code){
if (code == null || code.trim().length() == 0) {
return null;
} else {
code = code.trim();
}
String sql = String.format(
"select code, pk, name, memo, new_code " +
" from %s " +
" where code = '%s'", tableName, code);
DimCardContentType dimCardContentType = new DimCardContentType();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
dimCardContentType.setCode(code);
dimCardContentType.setPk(resultSet.getString(2));
dimCardContentType.setName(resultSet.getString(3));
dimCardContentType.setMemo(resultSet.getString(4));
dimCardContentType.setNew_code(resultSet.getString(5));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
mysqlJdbcDim.close(null, null, resultSet);
}
return dimCardContentType;
}
}
\ No newline at end of file
package com.gmei.cache;
import com.gmei.bean.dim.DimCity;
import com.gmei.jdbc.MysqlJdbcDim;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
* ClassName: DimCityDao
* Function:
* Reason: dim_city城市码表数据库操作类
* Date: 2019/12/10 下午7:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimCityDao {
private MysqlJdbcDim mysqlJdbcDim;
private ResultSet resultSet;
private String sql;
private Connection conn;
private String dimJdbcUrl;
public DimCityDao() {
}
public DimCityDao(String dimJdbcUrl) {
this.dimJdbcUrl = dimJdbcUrl;
this.mysqlJdbcDim = MysqlJdbcDim.getInstance(dimJdbcUrl);
}
/**
* Function: findDimCityByCode
* Reason: 根据城市ID查询城市信息
* Date: 2019/12/7 下午7:56
*
* @author liuzhe
* @since JDK 1.8
*/
public DimCity findDimCityByCode(String tableName, String code){
if (code == null || code.trim().length() == 0) {
return null;
} else {
code = code.trim();
}
mysqlJdbcDim.getConnection();
String sql = String.format(
"select code, pk, name, memo, " +
" parent_province_code, parent_province_pk, parent_province_memo," +
" parent_country_code, parent_country_pk, parent_country_name," +
" parent_region_code, parent_region_pk, parent_region_name " +
" from %s " +
" where code = '%s'", tableName, code);
// ArrayList<DimCity> dimCityList = new ArrayList<>();
DimCity dimCity = new DimCity();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
dimCity.setCode(code);
dimCity.setPk(resultSet.getString(2));
dimCity.setName(resultSet.getString(3));
dimCity.setMemo(resultSet.getString(4));
dimCity.setParent_province_code(resultSet.getString(5));
dimCity.setParent_province_pk(resultSet.getString(6));
dimCity.setParent_province_name(resultSet.getString(7));
dimCity.setParent_country_code(resultSet.getString(8));
dimCity.setParent_country_pk(resultSet.getString(9));
dimCity.setParent_country_name(resultSet.getString(10));
dimCity.setParent_region_code(resultSet.getString(11));
dimCity.setParent_region_pk(resultSet.getString(12));
dimCity.setParent_region_name(resultSet.getString(13));
// dimCityList.add(dimCity);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
mysqlJdbcDim.close(null, null, resultSet);
}
return dimCity;
}
/**
* Function: findDimCityByPk
* Reason: 根据城市TAGID查询城市信息
* Date: 2019/12/7 下午7:56
*
* @author liuzhe
* @since JDK 1.8
*/
public DimCity findDimCityByPk(String tableName, String pk){
if (pk == null || pk.trim().length() == 0) {
return null;
}
pk = pk.trim();
mysqlJdbcDim.getConnection();
String sql = String.format(
"select code, pk, name, memo, " +
" parent_province_code, parent_province_pk, parent_province_memo," +
" parent_country_code, parent_country_pk, parent_country_name," +
" parent_region_code, parent_region_pk, parent_region_name " +
" from %s " +
" where pk = '%s'", tableName, pk);
// ArrayList<DimCity> dimCityList = new ArrayList<>();
DimCity dimCity = new DimCity();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
dimCity.setCode(resultSet.getString(1));
dimCity.setPk(pk);
dimCity.setName(resultSet.getString(3));
dimCity.setMemo(resultSet.getString(4));
dimCity.setParent_province_code(resultSet.getString(5));
dimCity.setParent_province_pk(resultSet.getString(6));
dimCity.setParent_province_name(resultSet.getString(7));
dimCity.setParent_country_code(resultSet.getString(8));
dimCity.setParent_country_pk(resultSet.getString(9));
dimCity.setParent_country_name(resultSet.getString(10));
dimCity.setParent_region_code(resultSet.getString(11));
dimCity.setParent_region_pk(resultSet.getString(12));
dimCity.setParent_region_name(resultSet.getString(13));
// dimCityList.add(dimCity);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
mysqlJdbcDim.close(conn, null, resultSet);
}
return dimCity;
}
/**
* Function: findAllDimCity
* Reason: 查询所有城市信息
* Date: 2019/12/25 下午5:21
*
* @author liuzhe
* @since JDK 1.8
*/
public ArrayList<DimCity> findAllDimCity(String tableName) {
mysqlJdbcDim.getConnection();
sql = String.format(
"select code, pk, name, memo, " +
" parent_province_code, parent_province_pk, parent_province_memo," +
" parent_country_code, parent_country_pk, parent_country_name," +
" parent_region_code, parent_region_pk, parent_region_name " +
" from %s", tableName);
ArrayList<DimCity> dimCityList = new ArrayList<>();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
DimCity dimCity = new DimCity();
dimCity.setCode(resultSet.getString(1));
dimCity.setPk(resultSet.getString(2));
dimCity.setName(resultSet.getString(3));
dimCity.setMemo(resultSet.getString(4));
dimCity.setParent_province_code(resultSet.getString(5));
dimCity.setParent_province_pk(resultSet.getString(6));
dimCity.setParent_province_name(resultSet.getString(7));
dimCity.setParent_country_code(resultSet.getString(8));
dimCity.setParent_country_pk(resultSet.getString(9));
dimCity.setParent_country_name(resultSet.getString(10));
dimCity.setParent_region_code(resultSet.getString(11));
dimCity.setParent_region_pk(resultSet.getString(12));
dimCity.setParent_region_name(resultSet.getString(13));
dimCityList.add(dimCity);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return dimCityList;
}
}
package com.gmei.cache;
import com.gmei.bean.dim.DimPageType;
import com.gmei.jdbc.MysqlJdbcDim;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
* ClassName: DimPageTypeDao
* Function:
* Reason: dim_page_type页面名称标准化就三级分类码表数据库操作类
* Date: 2019/12/10 下午7:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimPageTypeDao {
private MysqlJdbcDim mysqlJdbcDim;
private ResultSet resultSet;
private String sql;
private Connection conn;
private String dimJdbcUrl;
public DimPageTypeDao() {
}
public DimPageTypeDao(String dimJdbcUrl) {
this.dimJdbcUrl = dimJdbcUrl;
this.mysqlJdbcDim = MysqlJdbcDim.getInstance(dimJdbcUrl);
}
/**
* Function: findAllDimPageType
* Reason: 查询所有页面信息(gengmei_user)
* Date: 2019/12/25 下午5:23
*
* @author liuzhe
* @since JDK 1.8
*/
public ArrayList<DimPageType> findAllDimPageType(String tableName) {
mysqlJdbcDim.getConnection();
sql = String.format(
"select code, pk, name, memo, " +
" parent_app_code, parent_app_pk, parent_app_name, " +
" type_s_code, type_s_name, " +
" type_m_code, type_m_name, " +
" type_l_code, type_l_name " +
" from %s" +
" where parent_app_code = 'gengmei_user'", tableName);
ArrayList<DimPageType> dimPageTypeList = new ArrayList<>();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
DimPageType dimPageType = new DimPageType();
dimPageType.setCode(resultSet.getString(1));
dimPageType.setPk(resultSet.getString(2));
dimPageType.setName(resultSet.getString(3));
dimPageType.setMemo(resultSet.getString(4));
dimPageType.setParent_app_code(resultSet.getString(5));
dimPageType.setParent_app_pk(resultSet.getString(6));
dimPageType.setParent_app_name(resultSet.getString(7));
dimPageType.setType_s_code(resultSet.getString(8));
dimPageType.setType_s_name(resultSet.getString(9));
dimPageType.setType_m_code(resultSet.getString(10));
dimPageType.setType_m_name(resultSet.getString(11));
dimPageType.setType_l_code(resultSet.getString(12));
dimPageType.setType_l_name(resultSet.getString(13));
dimPageTypeList.add(dimPageType);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
mysqlJdbcDim.close(null, null, resultSet);
}
return dimPageTypeList;
}
/**
* Function: findDimPageTypeByCode
* Reason: 根据页面编码查询页面信息(gengmei_user)
* Date: 2019/12/25 下午5:23
*
* @author liuzhe
* @since JDK 1.8
*/
public DimPageType findDimPageTypeByCode(String tableName, String code){
if (code == null || code.trim().length() == 0) {
return null;
} else {
code = code.trim();
}
mysqlJdbcDim.getConnection();
String sql = String.format(
"select code, pk, name, memo, " +
" parent_app_code, parent_app_pk, parent_app_name, " +
" type_s_code, type_s_name, " +
" type_m_code, type_m_name, " +
" type_l_code, type_l_name " +
" from %s" +
" where parent_app_code = 'gengmei_user'" +
" and code = '%s'", tableName, code);
// ArrayList<DimPageType> dimPageTypeList = new ArrayList<>();
DimPageType dimPageType = new DimPageType();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
dimPageType.setCode(code);
dimPageType.setPk(resultSet.getString(2));
dimPageType.setName(resultSet.getString(3));
dimPageType.setMemo(resultSet.getString(4));
dimPageType.setParent_app_code(resultSet.getString(5));
dimPageType.setParent_app_pk(resultSet.getString(6));
dimPageType.setParent_app_name(resultSet.getString(7));
dimPageType.setType_s_code(resultSet.getString(8));
dimPageType.setType_s_name(resultSet.getString(9));
dimPageType.setType_m_code(resultSet.getString(10));
dimPageType.setType_m_name(resultSet.getString(11));
dimPageType.setType_l_code(resultSet.getString(12));
dimPageType.setType_l_name(resultSet.getString(13));
// dimPageTypeList.add(dimPageType);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
mysqlJdbcDim.close(null, null, resultSet);
}
return dimPageType;
}
}
package com.gmei.cache;
import com.gmei.bean.dim.DimCity;
import com.gmei.utils.DimTableList;
import java.util.concurrent.Callable;
/**
* ClassName: DimTableCallable
* Function:
* Reason: 通用Dim码表多线程调用类
* Date: 2019/12/6 下午9:05t
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimTableCallable<V> implements Callable<V> {
private String code;
private String tableName;
private String dimJdbcUrl;
public DimTableCallable(String code, String tableName, String dimJdbcUrl) {
this.code = code;
this.tableName = tableName;
this.dimJdbcUrl = dimJdbcUrl;
}
public DimTableCallable() {}
@Override
public V call() {
// try {
if(code == null) {
switch(DimTableList.getDimTableByName(tableName)) {
case DIM_CITY:
DimCityDao dimCityDao = new DimCityDao(dimJdbcUrl);
return (V) dimCityDao.findAllDimCity(tableName);
case DIM_CARD_CONTENT_TYPE:
DimCardContentTypeDao dimCardContentTypeDao = new DimCardContentTypeDao(dimJdbcUrl);
return (V) dimCardContentTypeDao.findAllDimCardContentType(tableName);
case DIM_TRANSACTION_TYPE:
DimTableDao dimTransactionTypeDao = new DimTableDao(dimJdbcUrl);
return (V) dimTransactionTypeDao.findAllDimTable(tableName);
case DIM_PAGE_TYPE:
DimPageTypeDao dimPageTypeDao = new DimPageTypeDao(dimJdbcUrl);
return (V) dimPageTypeDao.findAllDimPageType(tableName);
case DIM_CARD_TYPE:
DimTableDao dimCardTypeDao = new DimTableDao(dimJdbcUrl);
return (V) dimCardTypeDao.findAllDimTable(tableName);
default:
return null;
}
} else {
switch(DimTableList.getDimTableByName(tableName)) {
case DIM_CITY:
DimCityDao dimCityDao = new DimCityDao(dimJdbcUrl);
DimCity dimCity = dimCityDao.findDimCityByCode(tableName, code);
if (dimCity == null) {
dimCity = dimCityDao.findDimCityByPk(tableName, code);
}
return (V) dimCity;
case DIM_CARD_CONTENT_TYPE:
DimCardContentTypeDao dimCardContentTypeDao = new DimCardContentTypeDao(dimJdbcUrl);
return (V) dimCardContentTypeDao.findDimCardContentTypeByCode(tableName, code);
case DIM_TRANSACTION_TYPE:
DimTableDao dimTransactionTypeDao = new DimTableDao(dimJdbcUrl);
return (V) dimTransactionTypeDao.findDimTableByCode(tableName, code);
case DIM_PAGE_TYPE:
DimPageTypeDao dimPageTypeDao = new DimPageTypeDao(dimJdbcUrl);
return (V) dimPageTypeDao.findDimPageTypeByCode(tableName, code);
case DIM_CARD_TYPE:
DimTableDao dimCardTypeDao = new DimTableDao(dimJdbcUrl);
return (V) dimCardTypeDao.findDimTableByCode(tableName, code);
default:
return null;
}
}
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// }
}
}
package com.gmei.cache;
import com.gmei.bean.dim.DimTable;
import com.gmei.jdbc.MysqlJdbcDim;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
* ClassName: DimTableDao
* Function:
* Reason: 通用Dim码表
* Date: 2019/12/10 下午7:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimTableDao {
private MysqlJdbcDim mysqlJdbcDim;
private ResultSet resultSet;
private String sql;
private Connection conn;
private String dimJdbcUrl;
public DimTableDao() {
}
public DimTableDao(String dimJdbcUrl) {
this.dimJdbcUrl = dimJdbcUrl;
this.mysqlJdbcDim = MysqlJdbcDim.getInstance(dimJdbcUrl);
}
/**
* Function: findAllDimTable
* Reason: 查询所有码表信息
* Date: 2019/12/25 下午5:26
*
* @author liuzhe
* @since JDK 1.8
*/
public ArrayList<DimTable> findAllDimTable(String tableName) {
mysqlJdbcDim.getConnection();
sql = String.format("select code, pk, name, memo from %s", tableName);
ArrayList<DimTable> dimTableList = new ArrayList<>();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
DimTable dim_table = new DimTable();
dim_table.setCode(resultSet.getString(1));
dim_table.setPk(resultSet.getString(2));
dim_table.setName(resultSet.getString(3));
dim_table.setMemo(resultSet.getString(4));
dimTableList.add(dim_table);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
mysqlJdbcDim.close(null, null, resultSet);
}
return dimTableList;
}
/**
* Function: findDimTableByCode
* Reason: 根据编码查询码表信息
* Date: 2019/12/25 下午5:26
*
* @author liuzhe
* @since JDK 1.8
*/
public DimTable findDimTableByCode(String tableName, String code){
if (code == null || code.trim().length() == 0) {
return null;
} else {
code = code.trim();
}
mysqlJdbcDim.getConnection();
String sql = String.format("select code, pk, name, memo from %s where code = '%s'", tableName, code);
DimTable dimTable = new DimTable();
resultSet = mysqlJdbcDim.query(sql);
try {
while (resultSet.next()) {
dimTable.setCode(code);
dimTable.setPk(resultSet.getString(2));
dimTable.setName(resultSet.getString(3));
dimTable.setMemo(resultSet.getString(4));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
mysqlJdbcDim.close(null, null, resultSet);
}
return dimTable;
}
}
package com.gmei.cache;
import com.gmei.bean.ml.MlPreciseExposureBean;
import com.gmei.jdbc.MysqlJdbcMl;
import java.util.ArrayList;
import java.util.List;
/**
* ClassName: MlPreciseExposureDao
* Function:
* Reason: ml_c_et_pe_preciseexposure_dimen_d_rt数据下发操作类
* Date: 2019/12/19 上午11:35
*
* @author liuzhe
* @since JDK 1.8
*/
public class MlPreciseExposureDao {
private MysqlJdbcMl mysqlJdbcMl;
private String sql;
private String sinkJdbcUrl;
private String sinkTableName;
public MlPreciseExposureDao(String sinkJdbcUrl, String sinkTableName) {
this.sinkJdbcUrl = sinkJdbcUrl;
this.sinkTableName = sinkTableName;
this.mysqlJdbcMl = MysqlJdbcMl.getInstance(sinkJdbcUrl);
}
/**
* Function: insertMlPreciseExposure
* Reason: 向表中插入数据
* Date: 2019/12/25 下午5:38
*
* @author liuzhe
* @since JDK 1.8
*/
public void insertMlPreciseExposure(MlPreciseExposureBean mlPreciseExposureBean) throws Exception {
sql = "insert into " + sinkTableName + "\n" +
" (day_id,\n" +
" action,\n" +
" app_code,\n" +
" page_code,\n" +
" page_name,\n" +
" tab_name,\n" +
" business_id,\n" +
" referrer_code,\n" +
" referrer_name,\n" +
" referrer_id,\n" +
" card_id,\n" +
" card_name,\n" +
" card_content_type,\n" +
" card_content_type_name,\n" +
" card_type,\n" +
" card_type_name,\n" +
" is_cpc,\n" +
" cpc_referer,\n" +
" transaction_type,\n" +
" transaction_type_name,\n" +
" filter,\n" +
" query,\n" +
" app_version,\n" +
" user_id,\n" +
" device_id,\n" +
" device_os_type,\n" +
" current_city_id,\n" +
" current_city_name,\n" +
" current_province_id,\n" +
" current_province_name,\n" +
" current_country_id,\n" +
" current_country_name,\n" +
" current_region_id,\n" +
" current_region_name,\n" +
" create_time_day,\n" +
" gm_nginx_time_day,\n" +
" preciseexposure_num)\n" +
"values\n" +
" (?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?,\n" +
" ?)";
List<Object> params = new ArrayList<Object>();
params.add(mlPreciseExposureBean.getGm_nginx_time_day());
params.add(mlPreciseExposureBean.getAction());
params.add(mlPreciseExposureBean.getApp_code());
params.add(mlPreciseExposureBean.getPage_code());
params.add(mlPreciseExposureBean.getPage_name());
params.add(mlPreciseExposureBean.getTab_name());
params.add(mlPreciseExposureBean.getBusiness_id());
params.add(mlPreciseExposureBean.getReferrer_code());
params.add(mlPreciseExposureBean.getReferrer_name());
params.add(mlPreciseExposureBean.getReferrer_id());
params.add(mlPreciseExposureBean.getCard_id());
params.add(mlPreciseExposureBean.getCard_name());
params.add(mlPreciseExposureBean.getCard_content_type());
params.add(mlPreciseExposureBean.getCard_content_type_name());
params.add(mlPreciseExposureBean.getCard_type());
params.add(mlPreciseExposureBean.getCard_type_name());
params.add(mlPreciseExposureBean.getIs_cpc());
params.add(mlPreciseExposureBean.getCpc_referer());
params.add(mlPreciseExposureBean.getTransaction_type());
params.add(mlPreciseExposureBean.getTransaction_type_name());
params.add(mlPreciseExposureBean.getFilter());
params.add(mlPreciseExposureBean.getQuery());
params.add(mlPreciseExposureBean.getApp_version());
params.add(mlPreciseExposureBean.getUser_id());
params.add(mlPreciseExposureBean.getDevice_id());
params.add(mlPreciseExposureBean.getDevice_os_type());
params.add(mlPreciseExposureBean.getCurrent_city_id());
params.add(mlPreciseExposureBean.getCurrent_city_name());
params.add(mlPreciseExposureBean.getCurrent_province_id());
params.add(mlPreciseExposureBean.getCurrent_province_name());
params.add(mlPreciseExposureBean.getCurrent_country_id());
params.add(mlPreciseExposureBean.getCurrent_country_name());
params.add(mlPreciseExposureBean.getCurrent_region_id());
params.add(mlPreciseExposureBean.getCurrent_region_name());
params.add(mlPreciseExposureBean.getCreate_time_day());
params.add(mlPreciseExposureBean.getGm_nginx_time_day());
params.add(mlPreciseExposureBean.getPreciseexposure_num());
// System.out.println(params.toString());
mysqlJdbcMl.update(sql, params);
}
}
package com.gmei.cache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
/**
* Created by allen on 2017/4/6.
*/
public class SimpleCacheService<K, V> extends CacheServiceAbstract<K, V> implements Serializable {
private Cache<K, V> cache = null;
private int maximumSize = 1000;
private int expireAfterWrite = 1;
public SimpleCacheService() {
createCache();
}
public SimpleCacheService(int maximumSize, int expireAfterWrite) {
this.maximumSize = maximumSize;
this.expireAfterWrite = expireAfterWrite;
createCache();
}
public void createCache() {
cache = CacheBuilder
.newBuilder()
.maximumSize(maximumSize)
.expireAfterWrite(expireAfterWrite, TimeUnit.HOURS)
.build();
}
@Override
public V getValue(final K key, final Callable<V> callable) {
if(key == null) {
return null;
}
try {
return cache.get(key, callable);
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
public Map<K, V> asMap(Cache cache) {
Map cacheMap = cache.asMap();
return cacheMap;
}
@Override
public void putValue(K key, V value) {
cache.put(key, value);
}
@Override
public void invalidate(Object key) {
cache.invalidate(key);
}
@Override
public void clearCache(){
this.cache.invalidateAll();
}
@Override
public Long cacheSize() {
return this.cache.size();
}
@Override
public void putValues(Map<K, V> map) {
cache.putAll(map);
// cache = new CacheLoader() {
// @Override
// public Object load(Object o) throws Exception {
// for (Object o : objects) {
// cache.put(o.getcode(), value);
// }
// return o;
// }
// };
// new CacheLoader<Long, Optional<Object>>() {
//
// @Override
// public Optional<Object> load(Long storeId) throws Exception {
// Object s = null;
//
// List<Object> results = null;
// if (results != null && results.size() > 0) {
// s = results.get(0);
// }
//
// return Optional.ofNullable(s);
// }
//
// }
}
public Cache<K, V> getCache() {
return cache;
}
// public void putValues(Map<K, V> map) {
//
// }
}
package com.gmei.function;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.flink.streaming.api.collector.selector.OutputSelector;
import java.util.ArrayList;
import java.util.List;
/**
* ClassName: BlMaiDianOutputSelector
* Function:
* Reason: BL层数据选择器
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlMaiDianOutputSelector implements OutputSelector<String> {
@Override
public Iterable<String> select(String s) {
List<String> output = new ArrayList<String>();
JSONObject jsonObject = JSON.parseObject(s);
String action = jsonObject.getString("type");
// System.out.println(s);
if ("home_choiceness_card_exposure".equals(action) || "page_precise_exposure".equals(action)) {
output.add("et_pe");
} else if ("page_view".equals(action)) {
output.add("et_le");
} else if (StringUtils.containsIgnoreCase(action,"click")) {
output.add("et_ck");
} else {
output.add("et_ot");
}
return output;
}
}
package com.gmei.function;
import com.gmei.bean.bl.BlPreciseExposureBean;
import org.apache.flink.api.common.functions.FilterFunction;
import java.util.Arrays;
import java.util.List;
/**
* ClassName: BlPreciseExposureFilterFunction
* Function:
* Reason: BL层数据筛选器
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureFilterFunction implements FilterFunction<BlPreciseExposureBean> {
@Override
public boolean filter(BlPreciseExposureBean blPreciseExposureBean) throws Exception {
String app_code = blPreciseExposureBean.getApp_code();
String is_exposure = blPreciseExposureBean.getIs_exposure();
String is_popup = blPreciseExposureBean.getIs_popup();
String app_version = blPreciseExposureBean.getApp_version();
String page_code = blPreciseExposureBean.getPage_code();
Boolean flag = true;
//清洗掉app_code不等于gengmei_user与is_exposure不等于1的
//1.5 Home页精准曝光触发两次
//问题描述:在7.7.70','7.7.71','7.7.72','7.7.75','7.7.76','7.8.0','7.8.1' (7.7.70--7.9.0)版本中的首页精准曝光会触发两次,经确认,需要去除page_name='home'
//1.6 品类聚合页的精准曝光问题
//问题描述:品类聚合页的精准曝光没做,但是数据中却有精准曝光、而且有问题,因此过滤掉,目前还不能确定什么版本可以解决,先暂时根据page_name过滤掉page_name='category'
//1.15 当首页精准曝光是通过弹窗触发或者点击push的时候,会有额外的精准曝光数据,需要去掉这部分数据
List<String> app_version_list = Arrays.asList("7.7.70","7.7.71","7.7.72","7.7.75","7.7.76","7.8.0","7.8.1");
String[] version = app_version.split("\\.");
if(version.length != 3) {
flag = false;
} else if(!"gengmei_user".equals(app_code) || !"1".equals(is_exposure)) {
flag = false;
} else if(app_version_list.contains(app_version) && "home".equals(page_code)) {
flag = false;
} else if("category".equals(page_code) && "7".equals(version[0]) && Integer.parseInt(version[1]) < 14 ) {
flag = false;
} else if("home".equals(page_code) && "1".equals(is_popup)) {
flag = false;
}
return flag;
}
}
package com.gmei.function;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.bl.BlPreciseExposureParamsExposureCardsBean;
import com.gmei.utils.BeanReflectUtil;
import com.gmei.utils.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.common.functions.MapFunction;
import java.util.ArrayList;
import java.util.Date;
/**
* ClassName: BlPreciseExposureMapFunction
* Function:
* Reason: BL层数据清洗转换器(一对一)
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureMapFunction implements MapFunction<String, BlPreciseExposureBean> {
@Override
public BlPreciseExposureBean map(String string) throws Exception {
BlPreciseExposureBean blPreciseExposureBean = new BlPreciseExposureBean();
JSONObject app = null;
String gm_nginx_timestamp = null;
String create_timestamp = null;
String user_id = null;
String action = null;
String app_grey_type = null;
String app_channel = null;
String app_version = null;
String app_current_city_id = null;
String app_code = null;
JSONObject params = null;
Integer down_loading_times = null;
Integer down_slide_times = null;
Integer up_loading_times = null;
Integer up_slide_times = null;
String page_code = null;
String tab_name = null;
String business_id = null;
String referrer_code = null;
String referrer_id = null;
String is_exposure = null;
String is_popup = null;
String filter = null;
String query = null;
JSONArray jsonArrayExposureCards = null;
JSONObject device = null;
String device_os_type = null;
String device_model = null;
String device_id = null;
String device_idfv = null;
String device_android_id = null;
String gm_nginx_time_date = null;
String gm_nginx_time_day = null;
Date day_id = null;
String create_time_date = null;
String create_time_day = null;
//去除掉json中的回车、换行、制表、空格
String jsonString = string.replaceAll("\\s+|\\\\n", "");
JSONObject jsonObject = JSON.parseObject(jsonString);
//一级别JSON
app = jsonObject.getJSONObject("app");
gm_nginx_timestamp = String.valueOf(jsonObject.get("gm_nginx_timestamp"));
create_timestamp = String.valueOf(jsonObject.get("create_at"));
user_id = jsonObject.getString("user_id");
action = jsonObject.getString("type");
//二级别JSON
//APP
if (app != null) {
app_grey_type = app.getString("grey_type");
app_channel = app.getString("channel");
app_version = app.getString("version");
app_current_city_id = app.getString("current_city_id");
app_code = app.getString("name");
}
//1.2 absolute_position参数类型不完整
//问题描述:在'7.7.35', '7.7.36', '7.7.40'params的absolute_position缺少左边引号
String paramsString = String.valueOf(jsonObject.get("params"));
if("7.7.35".equals(app_version) || "7.7.36".equals(app_version) || "7.7.40".equals(app_version)) {
paramsString = paramsString.replace("absolute_position","\\\"absolute_position");
}
//PARAMS
params = JSON.parseObject(paramsString);
if (params != null) {
down_loading_times = params.getInteger("down_loading_times");
down_slide_times = params.getInteger("down_slide_times");
up_loading_times = params.getInteger("up_loading_times");
up_slide_times = params.getInteger("up_slide_times");
page_code = params.getString("page_name");
tab_name = params.getString("tab_name");
business_id = params.getString("business_id");
referrer_code = params.getString("referrer");
referrer_id = params.getString("referrer_id");
is_exposure = params.getString("is_exposure");
is_popup = params.getString("is_popup");
filter = params.getString("filter");
query = params.getString("query");
}
//1.4 初版精准曝光格式错误
//问题描述:在'7.7.60'版本中美购页卡片的card_id和transaction_type这两个参数是数组的形式
// ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards =(ArrayList<BlPreciseExposureParamsExposureCardsBean>)JSONArray.parseArray(params.getJSONArray("exposure_cards").toString(), BlPreciseExposureParamsExposureCardsBean.class);
ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards = new ArrayList<>();
try {
jsonArrayExposureCards = JSONArray.parseArray(params.getJSONArray("exposure_cards").toString());
for (int i = 0; i < jsonArrayExposureCards.size(); i++) {
JSONObject jsonCard = jsonArrayExposureCards.getJSONObject(i);
String card_id = jsonCard.getString("card_id");
String transaction_type = jsonCard.getString("transaction_type");
String card_content_type = jsonCard.getString("card_content_type");
String card_type = jsonCard.getString("card_type");
String card_name = jsonCard.getString("card_name");
String target_name = jsonCard.getString("target_name");
String is_cpc = jsonCard.getString("is_cpc");
String cpc_referer = jsonCard.getString("cpc_referer");
String absolute_posttion = jsonCard.getString("absolute_position");
String relative_position = jsonCard.getString("relative_position");
// if("service".equals(card_content_type) && "7.7.60".equals(app_version)) {
if(StringUtils.startsWithIgnoreCase(card_id, "[") && StringUtils.endsWithIgnoreCase(card_id, "]")) {
JSONArray card_id_list = JSONArray.parseArray(card_id);
JSONArray transaction_type_list = null;
if(StringUtils.startsWithIgnoreCase(transaction_type, "[") && StringUtils.endsWithIgnoreCase(transaction_type, "]")) {
transaction_type_list = JSONArray.parseArray(transaction_type);
}
for (int j = 0; j < card_id_list.size(); j++) {
BlPreciseExposureParamsExposureCardsBean cardsBean = new BlPreciseExposureParamsExposureCardsBean();
cardsBean.setCard_id(card_id_list.getString(j));
try {
cardsBean.setTransaction_type(transaction_type_list.getString(j));
} catch (Exception e) {
cardsBean.setTransaction_type(null);
}
cardsBean.setCard_content_type(card_content_type);
cardsBean.setCard_type(card_type);
cardsBean.setCard_name(card_name);
cardsBean.setTarget_name(target_name);
cardsBean.setIs_cpc(is_cpc);
cardsBean.setCpc_referer(cpc_referer);
cardsBean.setAbsolute_position(absolute_posttion);
cardsBean.setRelative_position(relative_position);
exposure_cards.add(cardsBean);
}
} else {
BlPreciseExposureParamsExposureCardsBean cardsBean = new BlPreciseExposureParamsExposureCardsBean();
cardsBean.setCard_id(card_id);
cardsBean.setTransaction_type(transaction_type);
cardsBean.setCard_content_type(card_content_type);
cardsBean.setCard_type(card_type);
cardsBean.setCard_name(card_name);
cardsBean.setTarget_name(target_name);
cardsBean.setIs_cpc(is_cpc);
cardsBean.setCpc_referer(cpc_referer);
cardsBean.setAbsolute_position(absolute_posttion);
cardsBean.setRelative_position(relative_position);
// BlPreciseExposureParamsExposureCardsBean cardsBean = JSON.toJavaObject(jsonCard, BlPreciseExposureParamsExposureCardsBean.class);
exposure_cards.add(cardsBean);
}
}
} catch (Exception e) {
// System.out.println(JSON.parseObject(params.getString("exposure_cards")).toString());
}
//DEVICE
device = jsonObject.getJSONObject("device");
if (device != null) {
device_os_type = device.getString("device_type");
device_model = device.getString("model");
device_id = device.getString("device_id");
device_idfv = device.getString("idfv");
device_android_id = device.getString("android_device_id");
}
//1.1 ios系统精准曝光埋点channel字段
//问题描述:ios系统精准曝光埋点channel字段AppStore应该修改为App Store
if("AppStore".equals(app_channel)) {
app_channel = "App Store";
}
//日志时间处理
gm_nginx_time_date = DateUtil.timestampFormat(gm_nginx_timestamp, DateUtil.DateType.SECOND);
gm_nginx_time_day = DateUtil.timestampFormat(gm_nginx_timestamp, DateUtil.DateType.DAY);
day_id = DateUtil.stringToDate(gm_nginx_timestamp);
create_time_date = DateUtil.timestampFormat(create_timestamp, DateUtil.DateType.SECOND);
create_time_day = DateUtil.timestampFormat(create_timestamp, DateUtil.DateType.DAY);
//1.7 result_status参数位置问题(未处理)
//问题描述:搜索结果百科(search_result_wiki)和搜索结果美购(search_result_welfare)的result_status埋点埋在exposure_data里面了为了都获得该参数值,因此需要从两处拿取,默认先取exposure_data里的result_satus字段值(数据中发现不只是这两个页面)search_result_diary、search_result_doctor、search_result_hospital也存在
//1.9 搜索结果页tab_name参数不该存在
//问题描述:在搜索结果页出现tab_name参数,参数值和page_name一样,在点击的时候页面有跳转,因此,不应该有tab_name参数
if (StringUtils.containsIgnoreCase(page_code, "search_result")) {
tab_name = null;
}
blPreciseExposureBean.setDay_id(day_id);
blPreciseExposureBean.setJson(jsonString);
blPreciseExposureBean.setGm_nginx_timestamp(gm_nginx_timestamp);
blPreciseExposureBean.setCreate_timestamp(create_timestamp);
blPreciseExposureBean.setUser_id(user_id);
blPreciseExposureBean.setAction(action);
blPreciseExposureBean.setApp_grey_type(app_grey_type);
blPreciseExposureBean.setApp_channel(app_channel);
blPreciseExposureBean.setApp_version(app_version);
blPreciseExposureBean.setApp_current_city_id(app_current_city_id);
blPreciseExposureBean.setApp_code(app_code);
blPreciseExposureBean.setDown_loading_times(down_loading_times);
blPreciseExposureBean.setDown_slide_times(down_slide_times);
blPreciseExposureBean.setUp_loading_times(up_loading_times);
blPreciseExposureBean.setUp_slide_times(up_slide_times);
blPreciseExposureBean.setPage_code(page_code);
blPreciseExposureBean.setTab_name(tab_name);
blPreciseExposureBean.setBusiness_id(business_id);
blPreciseExposureBean.setReferrer_code(referrer_code);
blPreciseExposureBean.setReferrer_id(referrer_id);
blPreciseExposureBean.setExposure_cards(exposure_cards);
blPreciseExposureBean.setIs_exposure(is_exposure);
blPreciseExposureBean.setIs_popup(is_popup);
blPreciseExposureBean.setFilter(filter);
blPreciseExposureBean.setQuery(query);
blPreciseExposureBean.setDevice_os_type(device_os_type);
blPreciseExposureBean.setDevice_model(device_model);
blPreciseExposureBean.setDevice_id(device_id != null && device_id !="" ? device_id : device_idfv);
blPreciseExposureBean.setDevice_android_id(device_android_id);
blPreciseExposureBean.setDevice_idfv(device_idfv);
blPreciseExposureBean.setGm_nginx_time_date(gm_nginx_time_date);
blPreciseExposureBean.setGm_nginx_time_day(gm_nginx_time_day);
blPreciseExposureBean.setCreate_time_date(create_time_date);
blPreciseExposureBean.setCreate_time_day(create_time_day);
return BeanReflectUtil.setNullValue(blPreciseExposureBean);
}
}
package com.gmei.function;
import com.gmei.bean.bl.BlPreciseExposureBean;
import org.apache.flink.streaming.api.functions.windowing.ProcessAllWindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* ClassName: BlPreciseExposureProcessFunction
* Function:
* Reason: BL层数据去重器
* Date: 2020/1/8 下午5:06
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureProcessFunction extends ProcessAllWindowFunction<BlPreciseExposureBean, BlPreciseExposureBean, TimeWindow> {
@Override
public void process(Context context, Iterable<BlPreciseExposureBean> iterable, Collector<BlPreciseExposureBean> collector) throws Exception {
Iterator<BlPreciseExposureBean> blPreciseExposureBeanIterator = iterable.iterator();
Map<String, BlPreciseExposureBean> blPreciseExposureBeanMap = new HashMap<>();
while (blPreciseExposureBeanIterator.hasNext()) {
BlPreciseExposureBean blPreciseExposureBean = blPreciseExposureBeanIterator.next();
blPreciseExposureBeanMap.put(blPreciseExposureBean.getJson(), blPreciseExposureBean);
}
Set<Map.Entry<String, BlPreciseExposureBean>> blPreciseExposureBeanSet = blPreciseExposureBeanMap.entrySet();
for(Map.Entry<String, BlPreciseExposureBean> blPreciseExposureBeanEntry : blPreciseExposureBeanSet) {
collector.collect(blPreciseExposureBeanEntry.getValue());
}
}
}
package com.gmei.function;
import com.gmei.bean.bl.BlPreciseExposureBean;
import org.apache.flink.streaming.api.functions.AssignerWithPeriodicWatermarks;
import org.apache.flink.streaming.api.watermark.Watermark;
import javax.annotation.Nullable;
/**
* ClassName: BlPreciseExposureWatermark
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2020/1/8 下午8:40
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureWatermark implements AssignerWithPeriodicWatermarks<BlPreciseExposureBean> {
private final long maxOutOfOrderness = 10000;
private long currentMaxTimestamp;
@Override
public long extractTimestamp(BlPreciseExposureBean blPreciseExposureBean, long l) {
// Double timestampDouble = Double.parseDouble(blPreciseExposureBean.getGm_nginx_timestamp());
// long timestamp = new Double(timestampDouble * 1000).longValue();
Double timestampDouble = Double.parseDouble(blPreciseExposureBean.getGm_nginx_timestamp()) * 1000;
long timestamp = timestampDouble.longValue();
currentMaxTimestamp = Math.max(timestamp, currentMaxTimestamp);
return timestamp;
}
@Nullable
@Override
public Watermark getCurrentWatermark() {
return new Watermark(currentMaxTimestamp - maxOutOfOrderness);
}
}
package com.gmei.function;
import com.gmei.bean.dim.DimCity;
import com.gmei.bean.dim.DimCardContentType;
import com.gmei.bean.ml.MlPreciseExposureBean;
import com.gmei.bean.dim.DimPageType;
import com.gmei.bean.dim.DimTable;
import com.gmei.cache.DimTableCallable;
import com.gmei.cache.SimpleCacheService;
import com.gmei.utils.DimTableList;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.async.ResultFuture;
import org.apache.flink.streaming.api.functions.async.RichAsyncFunction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* ClassName: DimRichAsyncFunction
* Function:
* Reason: ML层维度关联器(异步调用)
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class DimRichAsyncFunction extends RichAsyncFunction<MlPreciseExposureBean, MlPreciseExposureBean> {
public static final SimpleCacheService<String, DimCity> dimCityCache = new SimpleCacheService<>(2000, 24);
public static final SimpleCacheService<String, DimTable> dimCardTypeCache = new SimpleCacheService<>(2000, 24);
public static final SimpleCacheService<String, DimTable> dimTransactionTypeCache = new SimpleCacheService<>(2000, 24);
public static final SimpleCacheService<String, DimPageType> dimPageTypeCache = new SimpleCacheService<>(2000, 24);
public static final SimpleCacheService<String, DimCardContentType> dimCardContentTypeCache = new SimpleCacheService<>(2000, 24);
public String dimJdbcUrl;
public DimRichAsyncFunction(String dimJdbcUrl) {
this.dimJdbcUrl = dimJdbcUrl;
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
initDimTable();
}
@Override
public void asyncInvoke(MlPreciseExposureBean mlPreciseExposureBean, ResultFuture<MlPreciseExposureBean> resultFuture) throws Exception {
String current_city_id = mlPreciseExposureBean.getCurrent_city_id();
String page_code = mlPreciseExposureBean.getPage_code();
String referrer_code = mlPreciseExposureBean.getReferrer_code();
String card_type = mlPreciseExposureBean.getCard_type();
String card_content_type = mlPreciseExposureBean.getCard_content_type();
String transaction_type= mlPreciseExposureBean.getTransaction_type();
String gm_nginx_time_day = mlPreciseExposureBean.getGm_nginx_time_day();
//刷新一次缓存
// if(gm_nginx_time_day != null){
// if(gm_nginx_time_day.compareTo(gm_nginx_time_day) < 0){
// dimCityCache.clearCache();
// dimCardTypeCache.clearCache();
// dimTransactionTypeCache.clearCache();
// dimPageTypeCache.clearCache();
// dimCardContentTypeCache.clearCache();
// initDimTable();
// }
// }
//1.8 城市字段问题
//问题描述:城市id为数字tagid的修正为正确的拼音,还加了过滤重复的数据
//解决方案:dimCityCache缓存中的key既有城市ID又有城市TAGID,获取到城市对象后将正确的城市ID填充到Current_city_id中
if (current_city_id != null) {
DimCity dimCity = dimCityCache.getValue(current_city_id, new DimTableCallable(current_city_id, DimTableList.DIM_CITY.getTableName(), dimJdbcUrl));
if (dimCity.getName() == null) {
dimCityCache.invalidate(current_city_id);
} else {
mlPreciseExposureBean.setCurrent_city_id(dimCity.getCode());
mlPreciseExposureBean.setCurrent_city_name(dimCity.getName());
mlPreciseExposureBean.setCurrent_province_id(dimCity.getParent_province_code());
mlPreciseExposureBean.setCurrent_province_name(dimCity.getParent_province_name());
mlPreciseExposureBean.setCurrent_country_id(dimCity.getParent_country_code());
mlPreciseExposureBean.setCurrent_country_name(dimCity.getParent_country_name());
mlPreciseExposureBean.setCurrent_region_id(dimCity.getParent_region_code());
mlPreciseExposureBean.setCurrent_region_name(dimCity.getParent_region_name());
}
}
if (page_code != null) {
DimPageType dimPageType = dimPageTypeCache.getValue(page_code, new DimTableCallable(page_code, DimTableList.DIM_PAGE_TYPE.getTableName(), dimJdbcUrl));
if (dimPageType.getName() == null) {
dimPageTypeCache.invalidate(page_code);
} else {
mlPreciseExposureBean.setPage_name(dimPageType.getName());
}
}
if (referrer_code != null) {
DimPageType dimReferrerType = dimPageTypeCache.getValue(referrer_code, new DimTableCallable(referrer_code, DimTableList.DIM_PAGE_TYPE.getTableName(), dimJdbcUrl));
if (dimReferrerType.getName() == null) {
dimPageTypeCache.invalidate(page_code);
} else {
mlPreciseExposureBean.setReferrer_name(dimReferrerType.getName());
}
}
if (card_content_type != null) {
DimCardContentType dimCardContentType = dimCardContentTypeCache.getValue(card_content_type, new DimTableCallable(card_content_type, DimTableList.DIM_CARD_CONTENT_TYPE.getTableName(), dimJdbcUrl));
if (dimCardContentType.getName() == null) {
dimCardContentTypeCache.invalidate(card_content_type);
} else {
mlPreciseExposureBean.setCard_content_type(dimCardContentType.getNew_code());
mlPreciseExposureBean.setCard_content_type_name(dimCardContentType.getName());
}
}
if (card_type != null) {
DimTable dimCardType = dimCardTypeCache.getValue(card_type, new DimTableCallable(card_type, DimTableList.DIM_CARD_TYPE.getTableName(), dimJdbcUrl));
if(dimCardType.getName() == null){
dimCardTypeCache.invalidate(card_type);
} else {
mlPreciseExposureBean.setCard_type_name(dimCardType.getName());
}
}
if (transaction_type != null) {
DimTable dimTransactionType = dimTransactionTypeCache.getValue(transaction_type, new DimTableCallable(transaction_type, DimTableList.DIM_TRANSACTION_TYPE.getTableName(), dimJdbcUrl));
if (dimTransactionType.getName() == null) {
dimTransactionTypeCache.invalidate(transaction_type);
} else {
mlPreciseExposureBean.setTransaction_type_name(dimTransactionType.getName());
}
}
// System.out.println(mlPreciseExposureBean);
resultFuture.complete(Collections.singleton(mlPreciseExposureBean));
}
/**
* Function: initDimTable
* Reason: dim码表缓存初始化
* Date: 2019/12/25 下午5:16
*
* @author liuzhe
* @since JDK 1.8
*/
public void initDimTable() throws Exception {
ExecutorService es = Executors.newFixedThreadPool(DimTableList.values().length);
Future dimCityFuture = es.submit(new DimTableCallable(null, DimTableList.DIM_CITY.getTableName(), dimJdbcUrl));
Future dimCardTypeFuture = es.submit(new DimTableCallable(null, DimTableList.DIM_CARD_TYPE.getTableName(), dimJdbcUrl));
Future dimCardContentTypeFuture = es.submit(new DimTableCallable(null, DimTableList.DIM_CARD_CONTENT_TYPE.getTableName(), dimJdbcUrl));
Future dimPageTypeFuture = es.submit(new DimTableCallable(null, DimTableList.DIM_PAGE_TYPE.getTableName(), dimJdbcUrl));
Future dimTransactionTypeFuture = es.submit(new DimTableCallable(null, DimTableList.DIM_TRANSACTION_TYPE.getTableName(), dimJdbcUrl));
ArrayList<DimCity> dimCityList = (ArrayList<DimCity>) dimCityFuture.get();
ArrayList<DimTable> dimCardTypeList = (ArrayList<DimTable>) dimCardTypeFuture.get();
ArrayList<DimCardContentType> dimCardContentList = (ArrayList<DimCardContentType>) dimCardContentTypeFuture.get();
ArrayList<DimPageType> dimPageTypeList = (ArrayList<DimPageType>) dimPageTypeFuture.get();
ArrayList<DimTable> dimTransactionTypeList = (ArrayList<DimTable>) dimTransactionTypeFuture.get();
ImmutableMap<String, DimCity> dimCityCodeMap = Maps.uniqueIndex(dimCityList, new Function<DimCity, String>() {
@Override
public String apply(DimCity dimCity) {
return dimCity.getCode();
}
});
ImmutableMap<String, DimCity> dimCityTagMap = Maps.uniqueIndex(dimCityList, new Function<DimCity, String>() {
@Override
public String apply(DimCity dimCity) {
return dimCity.getPk();
}
});
ImmutableMap<String, DimTable> dimCardTypeMap = Maps.uniqueIndex(dimCardTypeList, new Function<DimTable, String>() {
@Override
public String apply(DimTable dimTable) {
return dimTable.getCode();
}
});
ImmutableMap<String, DimCardContentType> dimCardContentMap = Maps.uniqueIndex(dimCardContentList, new Function<DimCardContentType, String>() {
@Override
public String apply(DimCardContentType dimTableTransForm) {
return dimTableTransForm.getCode();
}
});
ImmutableMap<String, DimPageType> dimPageTypeMap = Maps.uniqueIndex(dimPageTypeList, new Function<DimPageType, String>() {
@Override
public String apply(DimPageType dimPageType) {
return dimPageType.getCode();
}
});
ImmutableMap<String, DimTable> dimTransactionTypeMap = Maps.uniqueIndex(dimTransactionTypeList, new Function<DimTable, String>() {
@Override
public String apply(DimTable dimTable) {
return dimTable.getCode();
}
});
dimCityCache.putValues(dimCityCodeMap); //根据city_id匹配城市
dimCityCache.putValues(dimCityTagMap); //根据tag_id匹配城市
dimCardTypeCache.putValues(dimCardTypeMap);
dimCardContentTypeCache.putValues(dimCardContentMap);
dimPageTypeCache.putValues(dimPageTypeMap);
dimTransactionTypeCache.putValues(dimTransactionTypeMap);
System.out.println("dimCityCache:"+dimCityCache.cacheSize());
System.out.println("dimCardTypeCache:"+dimCardTypeCache.cacheSize());
System.out.println("dimCardContentTypeCache:"+dimCardContentTypeCache.cacheSize());
System.out.println("dimPageTypeCache:"+dimPageTypeCache.cacheSize());
System.out.println("dimTransactionTypeCache:"+dimTransactionTypeCache.cacheSize());
}
}
package com.gmei.function;
import com.gmei.bean.ml.MlPreciseExposureBean;
import org.apache.flink.api.java.functions.KeySelector;
import java.util.ArrayList;
/**
* ClassName: MlPreciseExposureKeySelector
* Function:
* Reason: ML层数据聚合分组器
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class MlPreciseExposureKeySelector implements KeySelector<MlPreciseExposureBean, Object> {
@Override
public Object getKey(MlPreciseExposureBean mlPreciseExposureBean) throws Exception {
ArrayList list = groupByFields(mlPreciseExposureBean);
return list;
}
/**
* Function: groupByFields
* Reason: 分组字段(GROUP BY)
* Date: 2019/12/25 下午5:17
*
* @author liuzhe
* @since JDK 1.8
*/
public ArrayList groupByFields(MlPreciseExposureBean mlPreciseExposureBean) {
ArrayList groupByFields = new ArrayList();
groupByFields.add(mlPreciseExposureBean.getUser_id());
groupByFields.add(mlPreciseExposureBean.getAction());
groupByFields.add(mlPreciseExposureBean.getApp_code());
groupByFields.add(mlPreciseExposureBean.getTab_name());
groupByFields.add(mlPreciseExposureBean.getBusiness_id());
groupByFields.add(mlPreciseExposureBean.getReferrer_code());
groupByFields.add(mlPreciseExposureBean.getReferrer_id());
groupByFields.add(mlPreciseExposureBean.getCard_id());
groupByFields.add(mlPreciseExposureBean.getCard_name());
groupByFields.add(mlPreciseExposureBean.getCard_content_type());
groupByFields.add(mlPreciseExposureBean.getCard_type());
groupByFields.add(mlPreciseExposureBean.getIs_cpc());
groupByFields.add(mlPreciseExposureBean.getCpc_referer());
// groupByFields.add(mlPreciseExposureBean.getAbsolute_position());
// groupByFields.add(mlPreciseExposureBean.getRelative_position());
groupByFields.add(mlPreciseExposureBean.getTransaction_type());
groupByFields.add(mlPreciseExposureBean.getFilter());
groupByFields.add(mlPreciseExposureBean.getQuery());
// groupByFields.add(mlPreciseExposureBean.getChannel_id());
groupByFields.add(mlPreciseExposureBean.getApp_version());
groupByFields.add(mlPreciseExposureBean.getCurrent_city_id());
groupByFields.add(mlPreciseExposureBean.getApp_code());
groupByFields.add(mlPreciseExposureBean.getDevice_os_type());
groupByFields.add(mlPreciseExposureBean.getDevice_id());
groupByFields.add(mlPreciseExposureBean.getCreate_time_day());
groupByFields.add(mlPreciseExposureBean.getGm_nginx_time_day());
return groupByFields;
}
}
package com.gmei.function;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.bl.BlPreciseExposureParamsExposureCardsBean;
import com.gmei.bean.ml.MlPreciseExposureBean;
import com.gmei.utils.BeanReflectUtil;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.util.Collector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* ClassName: MlpreciseExposureFlatMapFunction
* Function:
* Reason: ML层数据清洗转换器(一对多)
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class MlpreciseExposureFlatMapFunction implements FlatMapFunction<BlPreciseExposureBean, MlPreciseExposureBean> {
@Override
public void flatMap(BlPreciseExposureBean blPreciseExposureBean, Collector<MlPreciseExposureBean> collector) throws Exception {
ArrayList<MlPreciseExposureBean> mlPreciseExposureBeanList = flatmapBlPreciseExposure(blPreciseExposureBean);
// System.out.println("MlpreciseExposureFlatMapFunction" + blPreciseExposureBean);
for (MlPreciseExposureBean mlPreciseExposureBean : mlPreciseExposureBeanList) {
collector.collect(mlPreciseExposureBean);
}
}
/**
* Function: flatmapBlPreciseExposure
* Reason: 数据爆炸(LATERAL VIEW EXPLODE)
* Date: 2019/12/25 下午5:14
*
* @author liuzhe
* @since JDK 1.8
*/
public ArrayList<MlPreciseExposureBean> flatmapBlPreciseExposure(BlPreciseExposureBean blPreciseExposureBean) throws Exception {
ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards = blPreciseExposureBean.getExposure_cards();
String app_version = blPreciseExposureBean.getApp_version();
String device_os_type = blPreciseExposureBean.getDevice_os_type();
ArrayList<MlPreciseExposureBean> mlPreciseExposureBeanList = new ArrayList<>();
for(BlPreciseExposureParamsExposureCardsBean exposureCardsBean: exposure_cards) {
String card_id = exposureCardsBean.getCard_id();
String card_content_type = exposureCardsBean.getCard_content_type();
String card_type = exposureCardsBean.getCard_type();
String card_name = exposureCardsBean.getCard_name();
String target_name = exposureCardsBean.getTarget_name();
String is_cpc = exposureCardsBean.getIs_cpc();
String cpc_referer = exposureCardsBean.getCpc_referer();
String absolute_position = exposureCardsBean.getAbsolute_position();
String relative_position = exposureCardsBean.getRelative_position();
String transaction_type = exposureCardsBean.getTransaction_type();
//1.3 绝对位置和相对位置位置错误
//问题描述:在'7.7.35','7.7.36' android的绝对位置和相对位置写反
if("android".equals(device_os_type) && ("7.7.35".equals(app_version) || "7.7.36".equals(app_version))) {
String change = absolute_position;
absolute_position = relative_position;
relative_position = change;
}
//1.10 banner、豆腐块、icon、搜索词和功能区入口的card_type参数问题
//问题描述:当卡片类型为豆腐块、icon、banner、搜索词和功能区入口的时候的时候正确的card_type的参数值被赋给了card_content_type(banner、icon、gadget、search_query、function_entrance)
List<String> card_content_type_list = Arrays.asList("banner","icon","gadget","search_query","function_entrance");
if (card_content_type_list.contains(card_content_type)) {
card_type = card_content_type;
card_content_type = null;
}
if ("search_query".equals(card_type)) {
card_type = "search_word";
}
//1.14 百科卡片曝光新增参数wiki_type
//问题:从7.19.0版本开始,百科卡片曝光,新增了wiki_type参数
//1.12 card_content_type的qa值应该被换成q_a
if ("qa".equals(card_content_type)) {
card_content_type = card_content_type.replace("qa","q_a");
}
//card_type为card的标准码值为common_card,数据中为card
if("card".equals(card_type)) {
card_type = "common_card";
}
//card_type为banner的标准码值为common_banner,数据中为banner
if("banner".equals(card_type)) {
card_type = "common_banner";
}
//card_type为video的标准码值为video_card,数据中为video
if("video".equals(card_type)) {
card_type = "video_card";
}
//1.16 初期的搜索词曝光业务类型运营有promote,operating字段,需要修正为operation
if("promote".equals(transaction_type) || "operating".equals(transaction_type)) {
transaction_type = "operation";
}
MlPreciseExposureBean mlPreciseExposureBean = new MlPreciseExposureBean();
mlPreciseExposureBean.setDay_id(blPreciseExposureBean.getDay_id());
mlPreciseExposureBean.setUser_id(blPreciseExposureBean.getUser_id());
mlPreciseExposureBean.setAction(blPreciseExposureBean.getAction());
mlPreciseExposureBean.setPage_code(blPreciseExposureBean.getPage_code());
mlPreciseExposureBean.setTab_name(blPreciseExposureBean.getTab_name());
mlPreciseExposureBean.setBusiness_id(blPreciseExposureBean.getBusiness_id());
mlPreciseExposureBean.setReferrer_code(blPreciseExposureBean.getReferrer_code());
mlPreciseExposureBean.setReferrer_id(blPreciseExposureBean.getReferrer_id());
mlPreciseExposureBean.setCard_id(card_id);
mlPreciseExposureBean.setCard_content_type(card_content_type);
//1.13 target_name与card_name的参数的统一
//问题描述:将target_name参数的值赋给card_name
mlPreciseExposureBean.setCard_name(card_name == null ? target_name : card_name);
mlPreciseExposureBean.setCard_type(card_type);
mlPreciseExposureBean.setIs_cpc(is_cpc);
mlPreciseExposureBean.setCpc_referer(cpc_referer);
// mlPreciseExposureBean.setAbsolute_position(absolute_position);
// mlPreciseExposureBean.setRelative_position(relative_position);
mlPreciseExposureBean.setTransaction_type(transaction_type);
mlPreciseExposureBean.setFilter(blPreciseExposureBean.getFilter());
mlPreciseExposureBean.setQuery(blPreciseExposureBean.getQuery());
// mlPreciseExposureBean.setChannel_id(blPreciseExposureBean.getApp_channel());
mlPreciseExposureBean.setApp_version(blPreciseExposureBean.getApp_version());
mlPreciseExposureBean.setCurrent_city_id(blPreciseExposureBean.getApp_current_city_id());
mlPreciseExposureBean.setApp_code(blPreciseExposureBean.getApp_code());
mlPreciseExposureBean.setDevice_os_type(blPreciseExposureBean.getDevice_os_type());
mlPreciseExposureBean.setDevice_id(blPreciseExposureBean.getDevice_id());
mlPreciseExposureBean.setCreate_time_day(blPreciseExposureBean.getCreate_time_day());
mlPreciseExposureBean.setGm_nginx_time_day(blPreciseExposureBean.getGm_nginx_time_day());
mlPreciseExposureBean.setPreciseexposure_num(1);
//1.11 transaction_type的空值需要被修正
//问题描述:transaction_type='' 需要替换为NULL
mlPreciseExposureBeanList.add(BeanReflectUtil.setNullValue(mlPreciseExposureBean));
}
return mlPreciseExposureBeanList;
}
}
package com.gmei.jdbc;
import java.sql.*;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* ClassName: MysqlJdbcBl
* Function:
* Reason: 单例模式的数据下发jdbc工具
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class MysqlJdbcBl {
private volatile static MysqlJdbcBl mysqlJdbcBl = null;
// private static String driver = "com.mysql.cj.jdbc.Driver";
// public static String url = "jdbc:mysql://localhost:3306/zhengxing?useSSL=false&serverTimezone=UTC";
// //?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&allowMultiQueries=true&useSSL=false
// public static String username = "jayden";
// public static String password = "jayden548493";
// private String driver = "com.mysql.jdbc.Driver";
// private String url = "jdbc:mysql://172.22.30.12:3506/test?useUnicode=true&characterEncoding=UTF-8";//设置连接字符串
// //rewriteBatchedStatements=true
// private String username = "work";
// private String password = "zJnxVEhyyxeC7ciqxdMITVyWqOFc2mew";
private String driver = "com.mysql.jdbc.Driver";
private String url;
private Connection conn;
private MysqlJdbcBl(String url) {
this.url = url;
}
public static MysqlJdbcBl getInstance(String url) {
if (mysqlJdbcBl == null) {
synchronized (MysqlJdbcBl.class) {
if(mysqlJdbcBl == null) {
mysqlJdbcBl = new MysqlJdbcBl(url);
}
}
}
return mysqlJdbcBl;
}
public Connection getConnection() {
try {
Class.forName(driver);
if(conn == null || conn.isClosed()) {
// conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/zhengxing?useSSL=false&serverTimezone=UTC", "jayden", "jayden548943");
// conn = DriverManager.getConnection(url, username, password);
conn = DriverManager.getConnection(url);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void update(String sql, List<Object> params) throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(sql);
if (params != null && params.size() > 0) {
for (int i = 0; i < params.size(); i++) {
ps.setObject(i + 1, params.get(i));
}
}
int resultNum = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
ps.close();
}
// System.out.println(printRealSql(sql, params).replaceAll("(\\s+|\\\\n)", ""));
}
public void insert(String sql) throws SQLException {
Statement st = null;
try {
st = conn.createStatement();
st.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
st.close();
}
}
public String printRealSql(String sql, List<Object> params) {
if(params == null || params.size() == 0) {
// System.out.println("The SQL is------------>\n" + sql);
return sql;
}
if (!match(sql, params)) {
System.out.println("SQL 语句中的占位符与参数个数不匹配。SQL:" + sql);
return null;
}
int cols = params.size();
// values = params.toArray(index, count);
// Object[] values = new Object[cols];
// System.arraycopy(params, 0, values, 0, cols);
Object[] values = params.toArray(new Object[cols]);
for (int i = 0; i < cols; i++) {
Object value = values[i];
if (value instanceof Date) {
values[i] = "'" + value + "'";
} else if (value instanceof String) {
values[i] = "'" + value + "'";
} else if (value instanceof Boolean) {
values[i] = (Boolean) value ? 1 : 0;
}
}
String statement = String.format(sql.replaceAll("\\?", "%s"), values);
// System.out.println("The SQL is------------>\n" + statement);
return statement;
}
private static boolean match(String sql, List<Object> params) {
if(params == null || params.size() == 0) return true; // 没有参数,完整输出
Matcher m = Pattern.compile("(\\?)").matcher(sql);
int count = 0;
while (m.find()) {
count++;
}
return count == params.size();
}
// public ResultSet query(String sql, List<Object> param) {
// try {
// ps = conn.prepareStatement(sql);
//
// if (param != null && param.size() > 0) {
// for (int i = 0; i < param.size(); i++) {
// ps.setObject(i + 1, param.get(i));
// }
// }
// if(!ps.isClosed())
// System.out.println("Succeeded connecting to the prepareStatement!");
// rs = ps.executeQuery();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// return rs;
// }
public ResultSet query(String sql) {
// System.out.println(sql);
if(conn == null){
conn = getConnection();
}
ResultSet rs = null;
Statement st = null;
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public void close(Connection con, Statement st, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
package com.gmei.jdbc;
import java.sql.*;
import java.util.List;
/**
* ClassName: MysqlJdbcDim
* Function:
* Reason: 单例模式的码表层jdbc工具
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class MysqlJdbcDim {
private volatile static MysqlJdbcDim mysqlJdbcDim = null;
// public static String driver = "com.mysql.cj.jdbc.Driver";
// public static String url = "jdbc:mysql://localhost:3306/zhengxing?useSSL=false&serverTimezone=UTC";
// //?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&allowMultiQueries=true&useSSL=false
// public static String username = "jayden";
// public static String password = "jayden548493";
// private String driver = "com.mysql.jdbc.Driver";
// private String url = "jdbc:mysql://172.22.30.12:3506/test?useUnicode=true&characterEncoding=UTF-8";//设置连接字符串
// private String username = "work";
// private String password = "zJnxVEhyyxeC7ciqxdMITVyWqOFc2mew";
private String driver = "com.mysql.jdbc.Driver";
private String url;
private Connection conn;
private PreparedStatement ps;
private MysqlJdbcDim(String url) {
this.url = url;
}
public static MysqlJdbcDim getInstance(String url) {
if (mysqlJdbcDim == null) {
synchronized (MysqlJdbcDim.class) {
if(mysqlJdbcDim == null) {
mysqlJdbcDim = new MysqlJdbcDim(url);
}
}
}
return mysqlJdbcDim;
}
public Connection getConnection() {
try {
Class.forName(driver);
if(conn == null || conn.isClosed()) {
// conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/zhengxing?useSSL=false&serverTimezone=UTC", "jayden", "jayden548943");
// conn = DriverManager.getConnection(url, username, password);
conn = DriverManager.getConnection(url);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void insert(String sql, List<Object> param) throws SQLException {
ps = conn.prepareStatement(sql);
if (param != null && param.size() > 0) {
for (int i = 0; i < param.size(); i++) {
ps.setObject(i + 1, param.get(i));
}
}
ps.executeUpdate();
}
public void insert(String sql) throws SQLException {
Statement st = null;
st = conn.createStatement();
st.executeUpdate(sql);
}
public ResultSet query(String sql, List<Object> param) {
Statement st = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(sql);
if (param != null && param.size() > 0) {
for (int i = 0; i < param.size(); i++) {
ps.setObject(i + 1, param.get(i));
}
}
if(!ps.isClosed())
System.out.println("Succeeded connecting to the prepareStatement!");
rs = ps.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public ResultSet query(String sql) {
if(conn == null){
conn = getConnection();
}
ResultSet rs = null;
Statement st = null;
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public static void close(Connection con, Statement st, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
package com.gmei.jdbc;
import java.sql.*;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* ClassName: MysqlJdbcBl
* Function:
* Reason: 单例模式的数据下发jdbc工具
* Date: 2019/12/7 上午11:01
*
* @author liuzhe
* @since JDK 1.8
*/
public class MysqlJdbcMl {
private volatile static MysqlJdbcMl mysqlJdbcSink = null;
// private static String driver = "com.mysql.cj.jdbc.Driver";
// public static String url = "jdbc:mysql://localhost:3306/zhengxing?useSSL=false&serverTimezone=UTC";
// //?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&allowMultiQueries=true&useSSL=false
// public static String username = "jayden";
// public static String password = "jayden548493";
// private String driver = "com.mysql.jdbc.Driver";
// private String url = "jdbc:mysql://172.22.30.12:3506/test?useUnicode=true&characterEncoding=UTF-8";//设置连接字符串
// //rewriteBatchedStatements=true
// private String username = "work";
// private String password = "zJnxVEhyyxeC7ciqxdMITVyWqOFc2mew";
private String driver = "com.mysql.jdbc.Driver";
private String url;
private Connection conn;
private MysqlJdbcMl(String url) {
this.url = url;
}
public static MysqlJdbcMl getInstance(String url) {
if (mysqlJdbcSink == null) {
synchronized (MysqlJdbcMl.class) {
if(mysqlJdbcSink == null) {
mysqlJdbcSink = new MysqlJdbcMl(url);
}
}
}
return mysqlJdbcSink;
}
public Connection getConnection() {
try {
Class.forName(driver);
if(conn == null || conn.isClosed()) {
// conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/zhengxing?useSSL=false&serverTimezone=UTC", "jayden", "jayden548943");
// conn = DriverManager.getConnection(url, username, password);
conn = DriverManager.getConnection(url);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void update(String sql, List<Object> params) throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(sql);
if (params != null && params.size() > 0) {
for (int i = 0; i < params.size(); i++) {
ps.setObject(i + 1, params.get(i));
}
}
int resultNum = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
ps.close();
}
// System.out.println(printRealSql(sql, params).replaceAll("(\\s+|\\\\n)", ""));
}
public void insert(String sql) throws SQLException {
Statement st = null;
try {
st = conn.createStatement();
st.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally {
st.close();
}
}
public String printRealSql(String sql, List<Object> params) {
if(params == null || params.size() == 0) {
// System.out.println("The SQL is------------>\n" + sql);
return sql;
}
if (!match(sql, params)) {
System.out.println("SQL 语句中的占位符与参数个数不匹配。SQL:" + sql);
return null;
}
int cols = params.size();
// values = params.toArray(index, count);
// Object[] values = new Object[cols];
// System.arraycopy(params, 0, values, 0, cols);
Object[] values = params.toArray(new Object[cols]);
for (int i = 0; i < cols; i++) {
Object value = values[i];
if (value instanceof Date) {
values[i] = "'" + value + "'";
} else if (value instanceof String) {
values[i] = "'" + value + "'";
} else if (value instanceof Boolean) {
values[i] = (Boolean) value ? 1 : 0;
}
}
String statement = String.format(sql.replaceAll("\\?", "%s"), values);
// System.out.println("The SQL is------------>\n" + statement);
return statement;
}
private static boolean match(String sql, List<Object> params) {
if(params == null || params.size() == 0) return true; // 没有参数,完整输出
Matcher m = Pattern.compile("(\\?)").matcher(sql);
int count = 0;
while (m.find()) {
count++;
}
return count == params.size();
}
// public ResultSet query(String sql, List<Object> param) {
// try {
// ps = conn.prepareStatement(sql);
//
// if (param != null && param.size() > 0) {
// for (int i = 0; i < param.size(); i++) {
// ps.setObject(i + 1, param.get(i));
// }
// }
// if(!ps.isClosed())
// System.out.println("Succeeded connecting to the prepareStatement!");
// rs = ps.executeQuery();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// return rs;
// }
public ResultSet query(String sql) {
// System.out.println(sql);
if(conn == null){
conn = getConnection();
}
ResultSet rs = null;
Statement st = null;
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public void close(Connection con, Statement st, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
package com.gmei.schema;
import com.gmei.bean.bl.BlPreciseExposureBean;
import org.apache.flink.api.common.serialization.DeserializationSchema;
import org.apache.flink.api.common.serialization.SerializationSchema;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.msgpack.MessagePack;
import org.msgpack.type.Value;
import org.msgpack.type.ValueFactory;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
* ClassName: BlPreciseExposureSchema
* Function:
* Reason: 暂时未用到
* Date: 2019/12/17 下午4:51
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureSchema implements DeserializationSchema<String>, SerializationSchema<String> {
private static final long serialVersionUID = 1L;
private transient Charset charset;
public BlPreciseExposureSchema() {
this(StandardCharsets.UTF_8);
}
public BlPreciseExposureSchema(Charset charset) {
this.charset = checkNotNull(charset);
}
public Charset getCharset() {
return charset;
}
private void writeObject (ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeUTF(charset.name());
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
String charsetName = in.readUTF();
this.charset = Charset.forName(charsetName);
}
@Override
public String deserialize(byte[] bytes) throws IOException {
String msg = new String(bytes, StandardCharsets.UTF_8);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(msg);
BlPreciseExposureBean blPreciseExposureBean = mapper.readValue(msg, BlPreciseExposureBean.class);
MessagePack msgpack = new MessagePack();
Value MSGPACK_STRING_VALUE_CONTENT = ValueFactory.createRawValue("content".getBytes(StandardCharsets.US_ASCII));
String contentString = "";
try {
contentString = msgpack.read(bytes).asMapValue().get(MSGPACK_STRING_VALUE_CONTENT).asRawValue().getString();
} catch (IOException e) {
e.printStackTrace();
}
return contentString;
}
@Override
public boolean isEndOfStream(String s) {
return false;
}
@Override
public byte[] serialize(String s) {
return s.getBytes(charset);
}
@Override
public TypeInformation<String> getProducedType() {
return BasicTypeInfo.STRING_TYPE_INFO;
}
}
package com.gmei.sink;
import com.alibaba.fastjson.JSON;
import com.gmei.bean.bl.BlPreciseExposureBean;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
/**
* ClassName: BlPreciseExposureMysqlSink
* Function:
* Reason: 数据下发mysql
* Date: 2019/12/16 下午6:45
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureKafkaSink extends RichSinkFunction<BlPreciseExposureBean> {
private String outBrokers;
private String outTopic;
private Properties props;
private KafkaProducer<String,String> kafkaProducer;
public BlPreciseExposureKafkaSink(String outBrokers, String outTopic) {
this.outBrokers = outBrokers;
this.outTopic = outTopic;
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
init();
}
@Override
public void invoke(BlPreciseExposureBean value, Context context) throws Exception {
kafkaProducer.send(new ProducerRecord<String,String>(outTopic, JSON.toJSONString(value)));
}
@Override
public void close() throws Exception {
super.close();
kafkaProducer.close();
}
private void init() throws Exception {
props = new Properties();
props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,outBrokers);
props.setProperty(ProducerConfig.COMPRESSION_TYPE_CONFIG,"lz4");
props.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
props.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
kafkaProducer = new KafkaProducer(props);
}
}
\ No newline at end of file
package com.gmei.sink;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.cache.BlPreciseExposureDao;
import com.gmei.jdbc.MysqlJdbcBl;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import java.sql.Connection;
/**
* ClassName: BlPreciseExposureMysqlSink
* Function:
* Reason: 数据下发mysql
* Date: 2019/12/16 下午6:45
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureMysqlSink extends RichSinkFunction<BlPreciseExposureBean> {
private MysqlJdbcBl mysqlJdbcBl;
private Connection conn;
private BlPreciseExposureDao blPreciseExposureDao;
private int maxRetry = 1;
private long retryTime = 3000;
private String sinkJdbcUrl;
private String sinkTableName;
public BlPreciseExposureMysqlSink(String sinkJdbcUrl, String sinkTableName) {
this.sinkJdbcUrl = sinkJdbcUrl;
this.sinkTableName = sinkTableName;
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
mysqlJdbcBl = MysqlJdbcBl.getInstance(sinkJdbcUrl);
blPreciseExposureDao = new BlPreciseExposureDao(sinkJdbcUrl, sinkTableName);
conn = mysqlJdbcBl.getConnection();
}
@Override
public void invoke(BlPreciseExposureBean value, Context context) throws Exception {
try {
conn.setAutoCommit(false);
blPreciseExposureDao.insertBlPreciseExposure(value);
conn.commit();
} catch (Exception e) {
conn.rollback();
int numRetry = 1;
Exception lastException = e;
while (numRetry <= maxRetry) {
try {
numRetry ++;
Thread.sleep(retryTime);
mysqlJdbcBl.close(conn, null, null);
conn = mysqlJdbcBl.getConnection();
conn.setAutoCommit(false);
blPreciseExposureDao.insertBlPreciseExposure(value);
conn.commit();
} catch (Exception e1) {
conn.rollback();
lastException = e1;
continue;
}
return;
}
throw lastException;
}
}
@Override
public void close() throws Exception {
super.close();
mysqlJdbcBl.close(conn, null, null);
}
}
package com.gmei.sink;
import com.gmei.bean.ml.MlPreciseExposureBean;
import org.apache.flink.core.io.SimpleVersionedSerializer;
import org.apache.flink.streaming.api.functions.sink.filesystem.BucketAssigner;
import org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.SimpleVersionedStringSerializer;
/**
* ClassName: DayBucketAssigner
* Function:
* Reason: 按照日期分区
* Date: 2019/12/17 下午7:49
*
* @author liuzhe
* @since JDK 1.8
*/
public class DayBucketAssigner implements BucketAssigner<MlPreciseExposureBean, String> {
@Override
public String getBucketId(MlPreciseExposureBean mlPreciseExposureBean, Context context) {
String gm_nginx_time_day = mlPreciseExposureBean.getGm_nginx_time_day();
return gm_nginx_time_day;
}
@Override
public SimpleVersionedSerializer<String> getSerializer() {
return SimpleVersionedStringSerializer.INSTANCE;
}
}
package com.gmei.sink;
import com.gmei.bean.ml.MlPreciseExposureBean;
import com.gmei.cache.MlPreciseExposureDao;
import com.gmei.jdbc.MysqlJdbcMl;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import java.sql.Connection;
/**
* ClassName: MlPreciseExposureMysqlSink
* Function:
* Reason: 数据下发mysql
* Date: 2019/12/16 下午6:45
*
* @author liuzhe
* @since JDK 1.8
*/
public class MlPreciseExposureMysqlSink extends RichSinkFunction<MlPreciseExposureBean> {
private MysqlJdbcMl mysqlJdbcMl;
private Connection conn;
private MlPreciseExposureDao mlPreciseExposureDao;
private int maxRetry = 1;
private long retryTime = 3000;
private String sinkJdbcUrl;
private String sinkTableName;
public MlPreciseExposureMysqlSink(String sinkJdbcUrl, String sinkTableName) {
this.sinkJdbcUrl = sinkJdbcUrl;
this.sinkTableName = sinkTableName;
}
@Override
public void open(Configuration parameters) throws Exception {
super.open(parameters);
mysqlJdbcMl = MysqlJdbcMl.getInstance(sinkJdbcUrl);
mlPreciseExposureDao = new MlPreciseExposureDao(sinkJdbcUrl, sinkTableName);
conn = mysqlJdbcMl.getConnection();
}
@Override
public void invoke(MlPreciseExposureBean value, Context context) throws Exception {
try {
conn.setAutoCommit(false);
mlPreciseExposureDao.insertMlPreciseExposure(value);
conn.commit();
} catch (Exception e) {
conn.rollback();
int numRetry = 1;
Exception lastException = e;
while (numRetry <= maxRetry) {
try {
numRetry ++;
Thread.sleep(retryTime);
mysqlJdbcMl.close(conn, null, null);
conn = mysqlJdbcMl.getConnection();
conn.setAutoCommit(false);
mlPreciseExposureDao.insertMlPreciseExposure(value);
conn.commit();
} catch (Exception e1) {
conn.rollback();
lastException = e1;
continue;
}
return;
}
throw lastException;
}
}
@Override
public void close() throws Exception {
super.close();
mysqlJdbcMl.close(conn, null, null);
}
}
package com.gmei.source;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer011;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Properties;
/**
* ClassName: BlMaiDianKafkaSource
* Function:
* Reason: 获取kafka资源
* Date: 2019/12/5 下午3:54
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlMaiDianKafkaSource {
private String brokers;
private String topic;
private String groupId;
private String startTime;
public BlMaiDianKafkaSource() {
}
public BlMaiDianKafkaSource(String brokers, String topic, String groupId, String startTime) {
this.brokers = brokers;
this.topic = topic;
this.groupId = groupId;
this.startTime = startTime;
}
/**
* Function: addSource
* Reason: 获取kafka资源
* Date: 2019/12/25 下午4:49
*
* @author liuzhe
* @since JDK 1.8
*/
public FlinkKafkaConsumer011<String> addSource() throws Exception{
Properties props = new Properties();
props.put("bootstrap.servers", brokers);
props.put("group.id", groupId);
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
// props.put("auto.offset.reset", "earliest");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
FlinkKafkaConsumer011<String> flinkKafkaConsumer = new FlinkKafkaConsumer011<String>(topic, new SimpleStringSchema(Charset.forName("UTF-8")), props);
//
if(startTime != null){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
flinkKafkaConsumer.setStartFromTimestamp(simpleDateFormat.parse(startTime).getTime());
} else {
flinkKafkaConsumer.setStartFromGroupOffsets();//默认消费策略
}
// flinkKafkaConsumer.setStartFromEarliest();
return flinkKafkaConsumer;
}
public DataStreamSource<String> addSource(StreamExecutionEnvironment streamExecutionEnvironment) {
StreamExecutionEnvironment env = streamExecutionEnvironment;
String topicName = "test";
String groupId = "group1";
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", groupId);
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
props.put("auto.offset.reset", "earliest");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
FlinkKafkaConsumer011<String> flinkKafkaConsumer = new FlinkKafkaConsumer011<String>(topicName, new SimpleStringSchema(), props);
flinkKafkaConsumer.setStartFromGroupOffsets();//默认消费策略
// flinkKafkaConsumer.setStartFromEarliest();
DataStreamSource<String> dataStreamSource = env.addSource(flinkKafkaConsumer);
return dataStreamSource;
}
}
INSERT OVERWRITE TABLE BL_ET_MG_PRECISEEXPOSURE_INC_D PARTITION (PARTITION_DAY = '${partition_day}')
SELECT T1.JSON AS JSON, --原始日志
T1.GM_NGINX_KEY AS GM_NGINX_KEY,
T1.VERSION AS VERSION,
T1.PARAMS AS PARAMS, --埋点参数字段
T1.APP_SESSION_ID AS APP_SESSION_ID, --客户端会话ID
T1.GM_NGINX_TIMESTAMP AS GM_NGINX_TIMESTAMP, --服务端接收时间戳
T1.CREATE_TIMESTAMP AS CREATE_TIMESTAMP, --时间戳
T1.APP AS APP, --埋点APP字段
T1.DEVICE AS DEVICE, --埋点DEVICE字段
T1.USER_ID AS USER_ID, --用户ID
T1.ACTION AS TYPE, --事件名称
T1.PARAMS_DOWN_LOADING_TIMES AS PARAMS_DOWN_LOADING_TIMES, --下拉加载次数
T1.PARAMS_DOWN_SLIDE_TIMES AS PARAMS_DOWN_SLIDE_TIMES, --下拉滑动次数
T1.PARAMS_UP_LOADING_TIMES AS PARAMS_UP_LOADING_TIMES, --上拉加载次数
T1.PARAMS_UP_SLIDE_TIMES AS PARAMS_UP_SLIDE_TIMES, --上拉滑动次数
T1.PARAMS_PAGE_NAME AS PARAMS_PAGE_NAME, --页面编码
T1.PARAMS_TAB_NAME AS PARAMS_TAB_NAME, --页面TAB名称
T1.PARAMS_BUSINESS_ID AS PARAMS_BUSINESS_ID, --页面ID
T1.PARAMS_REFERRER AS PARAMS_REFERRER, --来源页面编码
T1.PARAMS_REFERRER_ID AS PARAMS_REFERRER_ID, --来源页面ID
T1.PARAMS_EXPOSURE_CARDS AS PARAMS_EXPOSURE_CARDS, --精准曝光数据块
T1.PARAMS_IS_EXPOSURE AS PARAMS_IS_EXPOSURE, --是否是精准曝光
T1.PARAMS_FILTER AS PARAMS_FILTER, --筛选器内容
T1.PARAMS_QUERY AS PARAMS_QUERY, --搜索词
T1.APP_GREY_TYPE AS APP_GREY_TYPE, --灰度组类型
T1.APP_CHANNEL AS APP_CHANNEL, --渠道ID
T1.APP_VERSION AS APP_VERSION, --客户端版本
T1.APP_SERIAL_ID AS APP_SERIAL_ID, --埋点序列ID
NVL(T2.CITY_ID,T1.APP_CURRENT_CITY_ID) AS APP_CURRENT_CITY_ID, --当前城市ID
T1.APP_NAME AS APP_NAME, --APP名称
T1.APP_USER_TYPE AS APP_USER_TYPE, --APP用户类型
T1.DEVICE_IS_WIFI AS DEVICE_IS_WIFI, --是否WIFI
T1.DEVICE_TYPE AS DEVICE_TYPE, --设备类型
T1.DEVICE_MODEL AS DEVICE_MODEL, --设备型号
T1.DEVICE_SYS_VERSION AS DEVICE_SYS_VERSION, --设备系统版本
T1.DEVICE_NET_TYPE AS DEVICE_NET_TYPE, --设备网络类型
T1.DEVICE_ID AS DEVICE_ID, --设备ID
T1.DEVICE_ANDROID_ID AS DEVICE_ANDROID_ID, --设备安卓ID
T1.DEVICE_LNG AS DEVICE_LNG, --设备经度
T1.DEVICE_LAT AS DEVICE_LAT, --设备纬度
T1.DEVICE_IP AS DEVICE_IP, --设备IP
T1.DEVICE_MANUFACTURER AS DEVICE_MANUFACTURER, --设备制造商
T1.DEVICE_IDFV AS DEVICE_IDFV, --设备IDFV
T1.DEVICE_IDFA AS DEVICE_IDFA, --设备IDFA
T1.GM_NGINX_TIME_DATE AS GM_NGINX_TIME_DATE, --服务端接收时间
T1.GM_NGINX_TIME_DAY AS GM_NGINX_TIME_DAY, --服务端接收日期
T1.TIME_DATE AS CREATE_TIME_DATE, --时间戳格式化后的时间
T1.TIME_DAY AS CREATE_TIME_DAY --时间戳格式化后的日期
FROM (SELECT REGEXP_REPLACE(REGEXP_REPLACE(T.JSON,'\\s+',''), '\\\\\\\\n', '') JSON, --原始JSON
--第一级别JSON
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.gm_nginx_key')) = '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.gm_nginx_key'))) GM_NGINX_KEY,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.version')) = '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.version'))) VERSION,
CASE
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.params')) = '' OR GET_JSON_OBJECT(LV.RAW, '$.params') IS NULL THEN
JSON_MAP('{}', 'string,string')
WHEN IS_JSON(GET_JSON_OBJECT(LV.RAW, '$.params')) = 'true' THEN
JSON_MAP(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params')), 'string,string')
ELSE JSON_MAP(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(TRIM(GET_JSON_OBJECT(LV.RAW,'$.params')),'("){2}','"'),':",',':"",'),':"}',':""}'),'string,string')
END PARAMS,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app_session_id')) = '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.app_session_id'))) APP_SESSION_ID,
CAST(CAST(TRIM(GET_JSON_OBJECT(LV.RAW, '$.gm_nginx_timestamp')) AS DOUBLE) AS BIGINT) GM_NGINX_TIMESTAMP,
CAST(CAST(TRIM(GET_JSON_OBJECT(LV.RAW, '$.create_at')) AS DOUBLE) AS BIGINT) CREATE_TIMESTAMP,
CASE
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.app')) = '' OR GET_JSON_OBJECT(LV.RAW, '$.app') IS NULL THEN
JSON_MAP('{}', 'string,string')
ELSE
JSON_MAP(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app')), 'string,string')
END AS APP,
CASE
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.device')) = '' OR GET_JSON_OBJECT(LV.RAW, '$.device') IS NULL THEN
JSON_MAP('{}', 'string,string')
ELSE
JSON_MAP(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device')), 'string,string')
END AS DEVICE,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.user_id'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.user_id'))) AS USER_ID,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.type'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.type'))) AS ACTION,
--第二级别JSON
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.down_loading_times'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.down_loading_times'))) AS PARAMS_DOWN_LOADING_TIMES,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.down_slide_times'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.down_slide_times'))) AS PARAMS_DOWN_SLIDE_TIMES,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.up_loading_times'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.up_loading_times'))) AS PARAMS_UP_LOADING_TIMES,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.up_slide_times'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.up_slide_times'))) AS PARAMS_UP_SLIDE_TIMES,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.page_name'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.page_name'))) AS PARAMS_PAGE_NAME,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.tab_name'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.tab_name'))) AS PARAMS_TAB_NAME,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.business_id'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.business_id'))) AS PARAMS_BUSINESS_ID,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.referrer'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.referrer'))) AS PARAMS_REFERRER,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.referrer_id'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.referrer_id'))) AS PARAMS_REFERRER_ID,
CASE
WHEN IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_type'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_type'))) = 'android' AND
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.version'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.version'))) IN ('7.7.35', '7.7.36', '7.7.40') THEN
JSON_SPLIT(REGEXP_REPLACE(TO_JSON(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.exposure_cards'))), 'absolute_position', '\\\\"absolute_position'))
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.exposure_cards')) = '' OR GET_JSON_OBJECT(LV.RAW, '$.params.exposure_cards') IS NULL THEN
ARRAY()
ELSE
JSON_SPLIT(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.exposure_cards')))
END PARAMS_EXPOSURE_CARDS,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.is_exposure'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.is_exposure'))) PARAMS_IS_EXPOSURE,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.filter'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.filter'))) PARAMS_FILTER,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.query'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.query'))) PARAMS_QUERY,
CASE
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.grey_type')) IN ('', 'unknown') OR GET_JSON_OBJECT(LV.RAW, '$.app.grey_type') IS NULL THEN
JSON_MAP('{}', 'string,string')
ELSE
JSON_MAP(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.grey_type')), 'string,string')
END APP_GREY_TYPE,
CASE
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.channel'))= '' THEN
NULL
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.channel'))= 'AppStore' THEN
'App Store'
ELSE
TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.channel'))
END AS APP_CHANNEL,
-- IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.channel'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.channel'))) APP_CHANNEL,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.version'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.version'))) APP_VERSION,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.serial_id'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.serial_id'))) APP_SERIAL_ID,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.current_city_id'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.current_city_id'))) APP_CURRENT_CITY_ID,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.name'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.name'))) APP_NAME,
CASE
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.user_type')) = ''
OR GET_JSON_OBJECT(LV.RAW, '$.app.user_type') IS NULL THEN JSON_MAP('{}', 'string,string')
ELSE JSON_MAP(TRIM(GET_JSON_OBJECT(LV.RAW, '$.app.user_type')), 'string,string')
END AS APP_USER_TYPE,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.is_WiFi'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.is_WiFi'))) DEVICE_IS_WIFI,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_type'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_type'))) DEVICE_TYPE,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.model'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.model'))) DEVICE_MODEL,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.sys_version'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.sys_version'))) DEVICE_SYS_VERSION,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.net_type'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.net_type'))) DEVICE_NET_TYPE,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.android_device_id'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.android_device_id'))) DEVICE_ANDROID_ID,
CASE
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_id'))= '' AND TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.idfv'))<> '' THEN
TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.idfv'))
WHEN TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_id'))= '' AND TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.idfv'))= '' THEN
NULL
ELSE
TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_id'))
END AS DEVICE_ID,
-- IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_id'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.device_id'))) DEVICE_ID,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.lng'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.lng'))) DEVICE_LNG,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.lat'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.lat'))) DEVICE_LAT,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.ip'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.ip'))) DEVICE_IP,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.manufacturer'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.manufacturer'))) DEVICE_MANUFACTURER,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.idfv'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.idfv'))) DEVICE_IDFV,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.idfa'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.device.idfa'))) DEVICE_IDFA,
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.gm_nginx_timestamp'))= '', NULL, FROM_UNIXTIME(CAST(CAST(TRIM(GET_JSON_OBJECT(LV.RAW, '$.gm_nginx_timestamp')) AS DOUBLE) AS BIGINT),'yyyy-MM-dd HH:mm:ss')) GM_NGINX_TIME_DATE, --服务端接收时间
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.gm_nginx_timestamp'))= '', NULL, FROM_UNIXTIME(CAST(CAST(TRIM(GET_JSON_OBJECT(LV.RAW, '$.gm_nginx_timestamp')) AS DOUBLE) AS BIGINT),'yyyyMMdd')) GM_NGINX_TIME_DAY, --服务端接收日期
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.create_at'))= '', NULL, FROM_UNIXTIME(CAST(CAST(TRIM(GET_JSON_OBJECT(LV.RAW, '$.create_at')) AS DOUBLE) AS BIGINT),'yyyy-MM-dd HH:mm:ss')) TIME_DATE, --时间戳格式化后的时间
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.create_at'))= '', NULL, FROM_UNIXTIME(CAST(CAST(TRIM(GET_JSON_OBJECT(LV.RAW, '$.create_at')) AS DOUBLE) AS BIGINT),'yyyyMMdd')) TIME_DAY, --时间戳格式化后的日期
ROW_NUMBER() OVER(PARTITION BY T.JSON) AS RANK_NUM
FROM TL.TL_LOG_PRECISE_EXPOSURE T
LATERAL VIEW JSON_TUPLE(REGEXP_REPLACE(REGEXP_REPLACE(T.JSON, '\\\\\\\\n', ''), '\\s+', ''), '@raw') LV AS RAW
WHERE T.PARTITION_DAY = '${partition_day}'
AND (CASE
WHEN IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.page_name'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.page_name')))='home' AND
IF(TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.is_popup'))= '', NULL, TRIM(GET_JSON_OBJECT(LV.RAW, '$.params.is_popup'))) IN (1, '1') THEN
0
ELSE
1
END) = 1) T1
LEFT JOIN (SELECT T.ID AS CITY_ID,
T.TAG_ID AS TAG_ID
FROM TL.TL_ZX_API_CITY T
WHERE T.PARTITION_DAY = '${partition_day}'
AND T.IS_ONLINE = 'true') T2
ON T1.APP_CURRENT_CITY_ID = T2.TAG_ID
WHERE RANK_NUM=1;
\ No newline at end of file
CREATE TABLE `dim_city` (
`code` varchar(100) COMMENT '城市编码' PRIMARY KEY,
`pk` varchar(100) COMMENT '城市TAGID' DEFAULT NULL,
`name` varchar(100) COMMENT '城市名称' DEFAULT NULL,
`memo` varchar(100) COMMENT '城市说明' DEFAULT NULL,
`parent_province_code` varchar(100) COMMENT '省份编码' DEFAULT NULL,
`parent_province_pk` varchar(100) COMMENT '省份TAGID' DEFAULT NULL,
`parent_province_name` varchar(100) COMMENT '省份名称' DEFAULT NULL,
`parent_province_memo` varchar(100) COMMENT '省份说明' DEFAULT NULL,
`parent_country_code` varchar(100) COMMENT '国家编码' DEFAULT NULL,
`parent_country_pk` varchar(100) COMMENT '国家TAGID' DEFAULT NULL,
`parent_country_name` varchar(100) COMMENT '国家名称' DEFAULT NULL,
`parent_country_memo` varchar(100) COMMENT '国家说明' DEFAULT NULL,
`parent_region_code` varchar(100) COMMENT '区域编码' DEFAULT NULL,
`parent_region_pk` varchar(100) COMMENT '区域ID' DEFAULT NULL,
`parent_region_name` varchar(100) COMMENT '区域名称' DEFAULT NULL,
`parent_region_memo` varchar(100) COMMENT '区域说明' DEFAULT NULL,
`oid` int COMMENT '排序' DEFAULT NULL
) COMMENT '城市码表' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
;
CREATE TABLE `dim_page_type` (
`code` varchar(100) COMMENT '页面编码' NOT NULL,
`pk` varchar(100) COMMENT '页面主键' DEFAULT NULL,
`name` varchar(100) COMMENT '页面名称' DEFAULT NULL,
`memo` varchar(100) COMMENT '页面说明' DEFAULT NULL,
`parent_app_code` varchar(100) COMMENT '上级APP编码',
`parent_app_pk` varchar(100) COMMENT '上级APP主键' DEFAULT NULL,
`parent_app_name` varchar(100) COMMENT '上级APP名称' DEFAULT NULL,
`parent_app_memo` varchar(100) COMMENT '上级APP说明' DEFAULT NULL,
`type_s_code` varchar(100) COMMENT '页面分类小类编码' DEFAULT NULL,
`type_s_name` varchar(100) COMMENT '页面分类小类名称' DEFAULT NULL,
`type_m_code` varchar(100) COMMENT '页面分类中类编码' DEFAULT NULL,
`type_m_name` varchar(100) COMMENT '页面分类中类名称' DEFAULT NULL,
`type_l_code` varchar(100) COMMENT '页面分类大类编码' DEFAULT NULL,
`type_l_name` varchar(100) COMMENT '页面分类大类名称' DEFAULT NULL,
`oid` int COMMENT '排序' DEFAULT NULL,
PRIMARY KEY (`code`,`parent_app_code`)
) COMMENT '页面分类码表' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
;
CREATE TABLE `dim_card_content_type` (
`code` varchar(100) COMMENT '编码' PRIMARY KEY,
`pk` varchar(100) COMMENT '主键' DEFAULT NULL,
`name` varchar(100) COMMENT '名称' DEFAULT NULL,
`memo` varchar(100) COMMENT '说明' DEFAULT NULL,
`new_code` varchar(100) COMMENT '转换后编码' DEFAULT NULL,
`oid` int COMMENT '排序' DEFAULT NULL
) COMMENT '卡片内容类型码表' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
;
CREATE TABLE `dim_card_type` (
`code` varchar(100) COMMENT '编码' PRIMARY KEY,
`pk` varchar(100) COMMENT '主键' DEFAULT NULL,
`name` varchar(100) COMMENT '名称' DEFAULT NULL,
`memo` varchar(100) COMMENT '说明' DEFAULT NULL,
`new_code` varchar(100) COMMENT '转换后编码' DEFAULT NULL,
`oid` int COMMENT '排序' DEFAULT NULL
) COMMENT '卡片类型码表' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
;
CREATE TABLE `dim_transaction_type` (
`code` varchar(100) COMMENT '编码' PRIMARY KEY,
`pk` varchar(100) COMMENT '主键' DEFAULT NULL,
`name` varchar(100) COMMENT '名称' DEFAULT NULL,
`memo` varchar(100) COMMENT '说明' DEFAULT NULL,
`oid` int COMMENT '排序' DEFAULT NULL
) COMMENT '业务类型码表' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
;
CREATE TABLE `bl_et_mg_preciseexposure_inc_d_rt` (
`day_id` date DEFAULT NULL COMMENT '账期日',
`json` longtext COMMENT '原始JSON',
`gm_nginx_timestamp` varchar(50) DEFAULT NULL COMMENT '接受日志时间戳',
`create_timestamp` varchar(50) DEFAULT NULL COMMENT '创建日志时间戳',
`user_id` varchar(20) DEFAULT NULL COMMENT '用户ID',
`action` varchar(30) DEFAULT NULL COMMENT '事件接口',
`down_loading_times` int(11) DEFAULT NULL COMMENT '下拉加载次数',
`down_slide_times` int(11) DEFAULT NULL COMMENT '下拉滑动次数',
`up_loading_times` int(11) DEFAULT NULL COMMENT '上拉加载次数',
`up_slide_times` int(11) DEFAULT NULL COMMENT '上拉滑动次数',
`page_code` varchar(50) DEFAULT NULL COMMENT '页面编码',
`tab_name` varchar(50) DEFAULT NULL COMMENT 'TAB名称',
`business_id` varchar(50) DEFAULT NULL COMMENT '业务ID',
`referrer_code` varchar(50) DEFAULT NULL COMMENT '来源页编码',
`referrer_id` varchar(50) DEFAULT NULL COMMENT '来源页业务ID',
`exposure_cards` longtext COMMENT '卡片列表',
`is_exposure` varchar(20) DEFAULT NULL COMMENT '是否精准曝光',
`is_popup` varchar(20) DEFAULT NULL COMMENT '是否弹窗',
`filter` varchar(50) DEFAULT NULL COMMENT '筛选器',
`query` varchar(200) DEFAULT NULL COMMENT '搜索词',
`app_grey_type` varchar(200) DEFAULT NULL COMMENT '灰度列表',
`app_channel` varchar(20) DEFAULT NULL COMMENT 'APP渠道',
`app_version` varchar(20) DEFAULT NULL COMMENT 'APP版本',
`app_current_city_id` varchar(20) DEFAULT NULL COMMENT '当前城市ID',
`app_code` varchar(20) DEFAULT NULL COMMENT 'APP编码',
`device_os_type` varchar(200) DEFAULT NULL COMMENT '设备系统类型',
`device_model` varchar(200) DEFAULT NULL COMMENT '设备型号',
`device_id` varchar(50) DEFAULT NULL COMMENT '设备ID',
`device_android_id` varchar(50) DEFAULT NULL COMMENT '设备安卓ID',
`device_idfv` varchar(50) DEFAULT NULL COMMENT '设备IDFV',
`gm_nginx_time_date` varchar(30) DEFAULT NULL COMMENT '日志接收时间',
`gm_nginx_time_day` varchar(30) DEFAULT NULL COMMENT '日志接收日期',
`create_time_date` varchar(30) DEFAULT NULL COMMENT '日志创建时间',
`create_time_day` varchar(30) DEFAULT NULL COMMENT '日志创建日期',
KEY `idx_bl_preciseexposure` (`day_id`,`page_code`,`referrer_code`,`app_channel`,`app_version`,`app_current_city_id`,`device_os_type`)
) COMMENT='BL层精准曝光实时表' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
;
CREATE TABLE `ml_c_et_pe_preciseexposure_dimen_d_rt` (
`day_id` date DEFAULT NULL COMMENT '账期日',
`user_id` varchar(20) DEFAULT NULL COMMENT '用户ID',
`action` varchar(30) DEFAULT NULL COMMENT '事件接口',
`page_code` varchar(50) DEFAULT NULL COMMENT '页面编码',
`page_name` varchar(50) DEFAULT NULL COMMENT '页面名称',
`tab_name` varchar(50) DEFAULT NULL COMMENT 'TAB名称',
`business_id` varchar(50) DEFAULT NULL COMMENT '业务ID',
`referrer_code` varchar(50) DEFAULT NULL COMMENT '来源页编码',
`referrer_name` varchar(50) DEFAULT NULL COMMENT '来源页名称',
`referrer_id` varchar(50) DEFAULT NULL COMMENT '来源页业务ID',
`card_id` varchar(100) DEFAULT NULL COMMENT '卡片ID',
`card_name` varchar(200) DEFAULT NULL COMMENT '卡片名称',
`card_content_type` varchar(50) DEFAULT NULL COMMENT '卡片内容类型',
`card_content_type_name` varchar(50) DEFAULT NULL COMMENT '卡片内容类型名称',
`card_type` varchar(50) DEFAULT NULL COMMENT '卡片类型',
`card_type_name` varchar(50) DEFAULT NULL COMMENT '卡片类型',
`is_cpc` varchar(20) DEFAULT NULL COMMENT '是否CPC',
`cpc_referer` varchar(50) DEFAULT NULL COMMENT 'CPC来源',
`transaction_type` varchar(50) DEFAULT NULL COMMENT '业务类型',
`transaction_type_name` varchar(50) DEFAULT NULL COMMENT '业务类型名称',
`filter` varchar(50) DEFAULT NULL COMMENT '筛选器',
`query` varchar(200) DEFAULT NULL COMMENT '搜索词',
`app_version` varchar(20) DEFAULT NULL COMMENT 'APP版本',
`current_city_id` varchar(20) DEFAULT NULL COMMENT '当前城市ID',
`current_city_name` varchar(20) DEFAULT NULL COMMENT '当前城市名称',
`current_province_id` varchar(20) DEFAULT NULL COMMENT '当前省份ID',
`current_province_name` varchar(20) DEFAULT NULL COMMENT '当前省份名称',
`current_country_id` varchar(20) DEFAULT NULL COMMENT '当前国家ID',
`current_country_name` varchar(20) DEFAULT NULL COMMENT '当前国家名称',
`current_region_id` varchar(20) DEFAULT NULL COMMENT '当前区域ID',
`current_region_name` varchar(20) DEFAULT NULL COMMENT '当前区域名称',
`app_code` varchar(20) DEFAULT NULL COMMENT 'APP编码',
`device_os_type` varchar(20) DEFAULT NULL COMMENT '设备系统类型',
`device_id` varchar(50) DEFAULT NULL COMMENT '设备ID',
`create_time_day` varchar(30) DEFAULT NULL COMMENT '日志创建时间',
`gm_nginx_time_day` varchar(30) DEFAULT NULL COMMENT '日志接收时间',
`preciseexposure_num` int(11) DEFAULT NULL COMMENT '精准曝光数量',
KEY `idx_ml_preciseexposure` (`day_id`,`page_code`,`page_name`,`referrer_code`,`referrer_name`,`card_content_type`,`card_content_type_name`,`card_type`,`card_type_name`,`transaction_type`,`transaction_type_name`,`current_city_id`,`device_os_type`)
) COMMENT='ML层精准曝光实时表' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
;
SELECT t1.CODE,
t1.pk,
t1.NAME,
t1.memo,
t1.parent_app_code,
t1.parent_app_pk,
t2.NAME parent_app_name,
t2.memo parent_app_memo,
t1.type_l_code,
t1.type_l_name,
t1.type_m_code,
t1.type_m_name,
t1.type_s_code,
t1.type_s_name,
t1.oid
FROM dim.dim_page_type t1
LEFT JOIN dim.dim_app_name t2
ON t1.parent_app_code = t2.CODE;
SELECT t1.CODE,
t1.pk,
t1.NAME,
t1.memo,
t1.parent_code parent_province_code,
t1.parent_pk parent_province_pk,
t2.NAME parent_province_name,
t2.memo parent_province_memo,
t2.parent_country_code,
t2.parent_country_pk,
t3.NAME parent_country_name,
t3.memo parent_country_memo,
t2.parent_region_code,
t2.parent_region_pk,
t4.NAME parent_region_name,
t4.memo parent_region_memo,
t1.oid
FROM dim.dim_city t1
LEFT JOIN dim.dim_province t2
ON t1.parent_code = t2.CODE
LEFT JOIN dim.dim_country t3
ON t2.parent_country_code = t3.CODE
LEFT JOIN dim.dim_region t4
ON t2.parent_region_code = t4.CODE;
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
INSERT OVERWRITE TABLE ML_C_ET_PE_PRECISEEXPOSURE_DIMEN_D PARTITION (PARTITION_DAY = '${partition_day}')
SELECT T8.JSON, --原始日志
T8.APP, --APP字段(MAP)
T8.PARAMS, --埋点参数字段(MAP)
T8.DEVICE, --埋点device字段(MAP)
T8.GM_NGINX_KEY,
T8.CREATE_TIMESTAMP, --时间戳
T8.GM_NGINX_TIMESTAMP, --服务端接收时间戳
T8.VERSION, --版本信息
T8.APP_SESSION_ID, --客户端回话id
T8.APP_SERIAL_ID, --埋点序列id
T8.APP_USER_TYPE, --app用户类型
T8.CHANNEL_ID, --渠道id
T8.CURRENT_CITY_ID, --当前城市id
T8.APP_CODE, --app名称
T8.APP_VERSION, --app版本
T8.APP_GREY_TYPE, --灰度组
T8.USER_ID, --用户id
T8.DEVICE_ID, --设备id
T8.DEVICE_MANUFACTURER, --设备制造商
T8.DEVICE_OS_TYPE, --设备类型
T8.DEVICE_MODEL, --设备型号
T8.DEVICE_SYS_VERSION, --设备系统版本
T8.DEVICE_NET_TYPE, --设备网络类型
T8.DEVICE_ANDROID_ID, --设备安卓ID
T8.DEVICE_IP, --设备IP
T8.DEVICE_IDFV, --设备IDFV
T8.DEVICE_IDFA, --设备IDFA
T8.LOCATION, --位置
T8.ACTION, --事件名称
T8.PAGE_CODE, --页面名称
T8.BUSINESS_ID, --业务ID
T8.TAB_CODE, --tab编码
T8.REFERRER_CODE, --上级页面编码
T8.REFERRER_ID, --上级页面ID
T8.UP_LOADING_TIMES, --上拉加载次数
T8.DOWN_LOADING_TIMES, --下拉加载次数
T8.UP_SLIDE_TIMES, --上拉滑动次数
T8.DOWN_SLIDE_TIMES, --下拉滑动次数
T8.IS_EXPOSURE, --是否曝光
T8.EXPOSURE_CARDS, --曝光所有卡片
T8.MODULE_ID, --模块id
T8.MODULE_TYPE, --模块类型,豆腐块才有该参数
T8.CARD_ID, --卡片ID
T8.CARD_TYPE, --卡片类型
NVL(T8.CARD_NAME,T8.QUERY) CARD_NAME, --卡片名称
T8.CARD_CONTENT_TYPE, --卡片内容类型
T8.TRANSACTION_TYPE,
T8.IS_CPC, --是否cpc计费
T8.CPC_REFERER, --cpc_referer值
T8.ABSOLUTE_POSITION, --绝对位置
T8.RELATIVE_POSITION, --相对位置
T8.FILTER, --筛选条件
NVL(T12.NEW_CODE,T8.GRID) AS PAGE_POSITION, --卡片上的业务区域
T8.RESULT_STATUS, --结果状态
T8.URL, --跳转链接
T8.CURRENT_POSITION, --点击icon在第几屏
T8.TOTAL_POSITION, --总共有几屏
T8.WIKI_WORD, --wiki卡片上的关键字
T8.GM_NGINX_TIME_DATE, --服务端接收时间
T8.GM_NGINX_TIME_DAY, --服务端接收日期
T8.CREATE_TIME_DATE, --时间戳格式化后的时间
T8.CREATE_TIME_DAY, --时间戳格式化后的日期
T8.DOCTOR_ID, --医生ID
T9.HOSPITAL_ID, --医院ID
T9.BUSINESS_PARTNER_ID, --商务ID
T10.MERCHANT_ID, --商户ID
T11.MERCHANT_DOCTOR_ID, --机构管理者ID
'pe' AS EVENT_TYPE,--事件类型
1 AS PRECISEEXPOSURE_NUM
FROM (SELECT T3.*,
CASE
WHEN T3.CARD_CONTENT_TYPE = 'service' THEN
T4.DOCTOR_ID
WHEN T3.CARD_CONTENT_TYPE = 'doctor' THEN
T3.CARD_ID
WHEN T3.CARD_CONTENT_TYPE = 'hospital' THEN
T5.DOCTOR_ID
WHEN T3.CARD_CONTENT_TYPE = 'diary' THEN
T6.DOCTOR_ID
WHEN T3.CARD_CONTENT_TYPE = 'topic' THEN
T7.DOCTOR_ID
ELSE
NULL
END AS DOCTOR_ID
FROM (SELECT T2.JSON AS JSON, --原始日志
T2.APP AS APP, --APP字段(MAP)
T2.PARAMS AS PARAMS, --埋点参数字段(MAP)
T2.DEVICE AS DEVICE, --埋点device字段(MAP)
T2.GM_NGINX_KEY AS GM_NGINX_KEY,
T2.CREATE_TIMESTAMP AS CREATE_TIMESTAMP, --时间戳
T2.GM_NGINX_TIMESTAMP AS GM_NGINX_TIMESTAMP, --服务端接收时间戳
T2.VERSION AS VERSION, --版本信息
T2.APP_SESSION_ID AS APP_SESSION_ID, --客户端回话id
T2.APP_SERIAL_ID AS APP_SERIAL_ID, --埋点序列id
T2.APP_USER_TYPE AS APP_USER_TYPE, --app用户类型
T2.APP_CHANNEL AS CHANNEL_ID, --渠道id
T2.APP_CURRENT_CITY_ID AS CURRENT_CITY_ID, --当前城市id
T2.APP_NAME AS APP_CODE, --app名称
T2.APP_VERSION AS APP_VERSION, --app版本
T2.APP_GREY_TYPE AS APP_GREY_TYPE, --灰度组
T2.USER_ID AS USER_ID, --用户id
T2.DEVICE_ID AS DEVICE_ID, --设备id
T2.DEVICE_MANUFACTURER AS DEVICE_MANUFACTURER, --设备制造商
T2.DEVICE_TYPE AS DEVICE_OS_TYPE, --设备类型
T2.DEVICE_MODEL AS DEVICE_MODEL, --设备型号
T2.DEVICE_SYS_VERSION AS DEVICE_SYS_VERSION, --设备系统版本
T2.DEVICE_NET_TYPE AS DEVICE_NET_TYPE, --设备网络类型
T2.DEVICE_ANDROID_ID AS DEVICE_ANDROID_ID, --设备安卓ID
T2.DEVICE_IP AS DEVICE_IP, --设备IP
T2.DEVICE_IDFV AS DEVICE_IDFV, --设备IDFV
T2.DEVICE_IDFA AS DEVICE_IDFA, --设备IDFA
ARRAY(T2.DEVICE_LAT, T2.DEVICE_LNG) AS LOCATION, --位置
T2.TYPE AS ACTION, --事件名称
T2.PARAMS_PAGE_NAME AS PAGE_CODE, --页面名称
T2.PARAMS_BUSINESS_ID AS BUSINESS_ID, --业务ID
T2.PARAMS_TAB_NAME AS TAB_CODE, --tab编码
T2.PARAMS_REFERRER AS REFERRER_CODE, --上级页面编码
T2.PARAMS_REFERRER_ID AS REFERRER_ID, --上级页面ID
T2.PARAMS_UP_LOADING_TIMES AS UP_LOADING_TIMES, --上拉加载次数
T2.PARAMS_DOWN_LOADING_TIMES AS DOWN_LOADING_TIMES, --下拉加载次数
T2.PARAMS_UP_SLIDE_TIMES AS UP_SLIDE_TIMES, --上拉滑动次数
T2.PARAMS_DOWN_SLIDE_TIMES AS DOWN_SLIDE_TIMES, --下拉滑动次数
T2.PARAMS_IS_EXPOSURE AS IS_EXPOSURE, --是否曝光
T2.PARAMS_EXPOSURE_CARDS AS EXPOSURE_CARDS, --曝光所有卡片
T2.MODULE_ID AS MODULE_ID, --模块id
T2.MODULE_TYPE AS MODULE_TYPE, --模块类型,豆腐块才有该参数
STRING(CARD_ID) AS CARD_ID, --卡片ID
T2.CARD_TYPE AS CARD_TYPE, --卡片类型
T2.CARD_NAME AS CARD_NAME, --卡片名称
T2.CARD_CONTENT_TYPE AS CARD_CONTENT_TYPE, --卡片内容类型
T2.TRANSACTION_TYPE_LIST [ POS ] AS TRANSACTION_TYPE,
T2.PARAMS_QUERY AS QUERY, --搜索词
T2.IS_CPC AS IS_CPC, --是否cpc计费
T2.CPC_REFERER AS CPC_REFERER, --cpc_referer值
T2.ABSOLUTE_POSITION AS ABSOLUTE_POSITION, --绝对位置
T2.RELATIVE_POSITION AS RELATIVE_POSITION, --相对位置
T2.FILTER AS FILTER, --筛选条件
T2.IN_PAGE_POS AS PAGE_POSITION, --卡片上的业务区域
T2.RESULT_STATUS AS RESULT_STATUS, --结果状态
T2.URL AS URL, --跳转链接
T2.GRID AS GRID, --那个区域(a、b、c、d,目前线上最多四张图片)
T2.CURRENT_POSITION AS CURRENT_POSITION, --点击icon在第几屏
T2.TOTAL_POSITION AS TOTAL_POSITION, --总共有几屏
T2.WIKI_WORD AS WIKI_WORD, --wiki卡片上的关键字
T2.GM_NGINX_TIME_DATE AS GM_NGINX_TIME_DATE, --服务端接收时间
T2.GM_NGINX_TIME_DAY AS GM_NGINX_TIME_DAY, --服务端接收日期
T2.CREATE_TIME_DATE AS CREATE_TIME_DATE, --时间戳格式化后的时间
T2.CREATE_TIME_DAY AS CREATE_TIME_DAY --时间戳格式化后的日期
FROM (SELECT T1.JSON,
T1.GM_NGINX_KEY,
T1.VERSION,
T1.PARAMS,
T1.APP_SESSION_ID,
T1.GM_NGINX_TIMESTAMP,
T1.CREATE_TIMESTAMP,
T1.APP,
T1.DEVICE,
T1.USER_ID,
T1.TYPE,
T1.PARAMS_DOWN_LOADING_TIMES,
T1.PARAMS_UP_LOADING_TIMES,
T1.PARAMS_DOWN_SLIDE_TIMES,
T1.PARAMS_UP_SLIDE_TIMES,
T1.PARAMS_PAGE_NAME,
T1.PARAMS_TAB_NAME,
T1.PARAMS_BUSINESS_ID,
T1.PARAMS_REFERRER,
T1.PARAMS_REFERRER_ID,
T1.PARAMS_EXPOSURE_CARDS,
T1.PARAMS_IS_EXPOSURE,
T1.PARAMS_QUERY,
T1.APP_GREY_TYPE,
T1.APP_CHANNEL,
T1.APP_VERSION,
T1.APP_SERIAL_ID,
T1.APP_CURRENT_CITY_ID,
T1.APP_NAME,
T1.APP_USER_TYPE,
T1.DEVICE_TYPE,
T1.DEVICE_MODEL,
T1.DEVICE_SYS_VERSION,
T1.DEVICE_NET_TYPE,
T1.DEVICE_ID,
T1.DEVICE_ANDROID_ID,
T1.DEVICE_LNG,
T1.DEVICE_LAT,
T1.DEVICE_IP,
T1.DEVICE_MANUFACTURER,
T1.DEVICE_IDFV,
T1.DEVICE_IDFA,
T1.GM_NGINX_TIME_DATE,
T1.GM_NGINX_TIME_DAY,
T1.CREATE_TIME_DATE,
T1.CREATE_TIME_DAY,
RESULT_CARD, --将card_id拼成数组形式['1001']
CASE
WHEN INSTR(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_id")),
'[') = 1 AND
INSTR(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_id")),
']') =
LENGTH(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_id"))) THEN
JSON_SPLIT(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_id")))
ELSE
ARRAY(IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_id")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_id"))))
END AS CARD_ID_LIST, --将transaction_type拼成数组的形式['-1']
CASE
WHEN INSTR(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.transaction_type")),
'[') = 1 AND
INSTR(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.transaction_type")),
']') =
LENGTH(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.transaction_type"))) THEN
JSON_SPLIT(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.transaction_type")))
ELSE
ARRAY(IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.transaction_type")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.transaction_type"))))
END AS TRANSACTION_TYPE_LIST, --card_content_type为'banner','icon','gadget','search_query','function_entrance'置空,切为qa替换称q_a
CASE
WHEN TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")) IN
('banner',
'static_banner' 'icon',
'gadget',
'search_query',
'function_entrance') THEN
NULL
WHEN TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")) = 'qa' THEN
'q_a'
ELSE
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")))
END AS CARD_CONTENT_TYPE, --card_content_type为'banner','icon','gadget','search_query','function_entrance' card_type取值为card_content_type
--切当card_content_type为search_query时card_type为search_word
CASE
WHEN TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")) IN
('static_banner',
'icon',
'gadget',
'function_entrance') THEN
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")))
WHEN TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")) =
'search_query' THEN
'search_word'
WHEN TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_content_type")) =
'banner' THEN
'common_banner'
WHEN TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_type")) =
'card' THEN
'common_card'
WHEN TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_type")) =
'video' THEN
'video_card'
ELSE
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_type")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_type")))
END AS CARD_TYPE, --当版本为7.7.35和7.7.36的时候相对位置转换成绝对位置
CASE
WHEN T1.DEVICE_TYPE = 'android' AND
T1.APP_VERSION IN ('7.7.35', '7.7.36') THEN
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.relative_position")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.relative_position")))
ELSE
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.absolute_position")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.absolute_position")))
END AS ABSOLUTE_POSITION, --当版本为7.7.35和7.7.36的时候绝对位置转换成相对位置
CASE
WHEN T1.DEVICE_TYPE = 'android' AND
T1.APP_VERSION IN ('7.7.35', '7.7.36') THEN
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.absolute_position")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.absolute_position")))
ELSE
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.relative_position")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.relative_position")))
END AS RELATIVE_POSITION, --result_status先取exposure_cards 再选params
CASE
WHEN IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.result_status")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.result_status"))) IS NULL AND
IF(TRIM(GET_JSON_OBJECT(TO_JSON(T1.PARAMS),
"$.result_status")) = '',
NULL,
TRIM(GET_JSON_OBJECT(TO_JSON(T1.PARAMS),
"$.result_status"))) IS NOT NULL THEN
IF(TRIM(GET_JSON_OBJECT(TO_JSON(T1.PARAMS),
"$.result_status")) = '',
NULL,
TRIM(GET_JSON_OBJECT(TO_JSON(T1.PARAMS),
"$.result_status")))
ELSE
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.result_status")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.result_status")))
END AS RESULT_STATUS, --filter和filer_f的参数统一
CASE
WHEN T1.PARAMS_FILTER IS NOT NULL AND
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.filter_f")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.filter_f"))) IS NULL THEN
T1.PARAMS_FILTER
WHEN T1.PARAMS_FILTER IS NULL AND
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.filter_f")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.filter_f"))) IS NULL THEN
NULL
ELSE
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.filter_f")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.filter_f")))
END AS FILTER, --if(trim(get_json_object(result_card,"$.filter_f"))='',NULL,trim(get_json_object(result_card,"$.filter_f"))) as filter_f,
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD, "$.is_cpc")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD, "$.is_cpc"))) AS IS_CPC,
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.cpc_referer")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.cpc_referer"))) AS CPC_REFERER,
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.in_page_pos")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.in_page_pos"))) AS IN_PAGE_POS,
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.sec_tab_name")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.sec_tab_name"))) AS SEC_TAB_NAME, --二级页面名称
--非正常卡片通用参数(banner 豆腐块 icon)
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.module_id")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.module_id"))) AS MODULE_ID, --模块id
--target_name与card_name的参数统一
CASE
WHEN IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_name ")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_name "))) IS NULL AND
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.target_name")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.target_name"))) IS NOT NULL THEN
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.target_name")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.target_name")))
WHEN IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_name ")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_name "))) IS NULL AND
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.target_name")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.target_name"))) IS NULL THEN
NULL
ELSE
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_name ")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.card_name ")))
END AS CARD_NAME,
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD, "$.url")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD, "$.url"))) AS URL, --跳转链接
--豆腐块额外参数
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.module_type")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.module_type"))) AS MODULE_TYPE, --模块类型
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD, "$.grid")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD, "$.grid"))) AS GRID, --区域 (a、b、c、d,目前线上最多四张图片)
--icon的额外参数
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.total_position")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.total_position"))) AS TOTAL_POSITION, --总共有几屏
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.current_position")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.current_position"))) AS CURRENT_POSITION, --icon在第几屏
--百科卡片独有的参数
IF(TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.wiki_word")) = '',
NULL,
TRIM(GET_JSON_OBJECT(RESULT_CARD,
"$.wiki_word"))) AS WIKI_WORD --wiki关键字
FROM (SELECT T.JSON,
T.GM_NGINX_KEY,
T.VERSION,
T.PARAMS,
T.APP_SESSION_ID,
T.GM_NGINX_TIMESTAMP,
T.CREATE_TIMESTAMP,
T.APP,
T.DEVICE,
T.USER_ID,
T.TYPE,
T.PARAMS_DOWN_LOADING_TIMES,
T.PARAMS_DOWN_SLIDE_TIMES,
T.PARAMS_UP_LOADING_TIMES,
T.PARAMS_UP_SLIDE_TIMES,
T.PARAMS_PAGE_NAME,
IF(T.PARAMS_PAGE_NAME RLIKE
'search_result_',
NULL,
T.PARAMS_TAB_NAME) AS PARAMS_TAB_NAME,
T.PARAMS_BUSINESS_ID,
T.PARAMS_REFERRER,
T.PARAMS_REFERRER_ID,
T.PARAMS_EXPOSURE_CARDS,
STRING(T.PARAMS_IS_EXPOSURE) PARAMS_IS_EXPOSURE,
T.PARAMS_FILTER,
T.PARAMS_QUERY,
T.APP_GREY_TYPE,
T.APP_CHANNEL,
T.APP_VERSION,
T.APP_SERIAL_ID,
T.APP_CURRENT_CITY_ID,
T.APP_NAME,
T.APP_USER_TYPE,
T.DEVICE_IS_WIFI,
T.DEVICE_TYPE,
T.DEVICE_MODEL,
T.DEVICE_SYS_VERSION,
T.DEVICE_NET_TYPE,
T.DEVICE_ID,
T.DEVICE_ANDROID_ID,
T.DEVICE_LNG,
T.DEVICE_LAT,
T.DEVICE_IP,
T.DEVICE_MANUFACTURER,
T.DEVICE_IDFV,
T.DEVICE_IDFA,
T.GM_NGINX_TIME_DATE,
T.GM_NGINX_TIME_DAY,
T.CREATE_TIME_DATE,
T.CREATE_TIME_DAY
FROM BL.BL_ET_MG_PRECISEEXPOSURE_INC_D T
WHERE T.PARTITION_DAY = '${partition_day}'
AND STRING(T.PARAMS_IS_EXPOSURE) = '1'
AND (CASE
WHEN ((INT(SPLIT(T.APP_VERSION, '\\.') [ 0 ]) = 7 AND
INT(SPLIT(T.APP_VERSION, '\\.') [ 1 ]) = 7 AND
INT(SPLIT(T.APP_VERSION, '\\.') [ 2 ]) >= 70) OR
(INT(SPLIT(T.APP_VERSION, '\\.') [ 0 ]) = 7 AND
INT(SPLIT(T.APP_VERSION, '\\.') [ 1 ]) = 8)) AND
T.PARAMS_PAGE_NAME = 'home' THEN
T.PARAMS_PAGE_NAME <> 'home'
WHEN T.PARAMS_PAGE_NAME = 'category' AND
(INT(SPLIT(T.APP_VERSION, '\\.') [ 0 ]) = 7 AND
INT(SPLIT(T.APP_VERSION, '\\.') [ 1 ]) < 14) THEN
T.PARAMS_PAGE_NAME <> 'category'
ELSE
1 = 1
END)) T1 LATERAL VIEW EXPLODE(T1.PARAMS_EXPOSURE_CARDS) CARD AS RESULT_CARD) T2 LATERAL VIEW POSEXPLODE(T2.CARD_ID_LIST) CARD1 AS POS,
CARD_ID) T3 --美购 card_id = service_id
LEFT JOIN (SELECT T.SERVICE_ID, T.DOCTOR_ID
FROM BL.BL_PT_SV_SERVICEINFO_D T
WHERE T.PARTITION_DAY = '${partition_day}') T4
ON T3.CARD_ID = T4.SERVICE_ID --医院 card_id=hospital_id
LEFT JOIN (SELECT T.DOCTOR_ID,
T.DOCTOR_TYPE,
T.HOSPITAL_ID,
T.BUSINESS_PARTNER_ID
FROM BL.BL_CT_DT_DOCTORINFO_D T
WHERE T.PARTITION_DAY = '${partition_day}'
AND DOCTOR_TYPE = '1') T5
ON T3.CARD_ID = T5.HOSPITAL_ID --日记本 card_id=diary_id
LEFT JOIN (SELECT T.DIARY_ID, T.ORIGINAL_DOCTOR_ID AS DOCTOR_ID
FROM BL.BL_OP_CO_DIARYINFO_D T
WHERE T.PARTITION_DAY = '${partition_day}') T6
ON T3.CARD_ID = T6.DIARY_ID --日记贴 card_id=topic_id
LEFT JOIN (SELECT T7_1.TOPIC_ID, T7_2.DOCTOR_ID
FROM (SELECT T.TOPIC_ID, T.DIARY_ID
FROM BL.BL_OP_CO_TOPICINFO_D T
WHERE T.PARTITION_DAY = '${partition_day}'
AND T.TABLE_TYPE IN ('topic', 'article')) T7_1
LEFT JOIN (SELECT T.DIARY_ID,
T.ORIGINAL_DOCTOR_ID AS DOCTOR_ID
FROM BL.BL_OP_CO_DIARYINFO_D T
WHERE T.PARTITION_DAY = '${partition_day}') T7_2
ON T7_1.DIARY_ID = T7_2.DIARY_ID) T7
ON T3.CARD_ID = T7.TOPIC_ID) T8
LEFT JOIN (SELECT T.DOCTOR_ID AS DOCTOR_ID,
T.DOCTOR_TYPE AS DOCTOR_TYPE,
T.HOSPITAL_ID AS HOSPITAL_ID,
T.BUSINESS_PARTNER_ID AS BUSINESS_PARTNER_ID
FROM BL.BL_CT_DT_DOCTORINFO_D T
WHERE T.PARTITION_DAY = '${partition_day}') T9
ON T8.DOCTOR_ID = T9.DOCTOR_ID
LEFT JOIN (SELECT T.DOCTOR_ID AS DOCTOR_ID, T.MERCHANT_ID AS MERCHANT_ID
FROM BL.BL_CT_MC_MERCHANTDOCTORRELATION_D T
WHERE T.PARTITION_DAY = '${partition_day}') T10
ON T9.DOCTOR_ID = T10.DOCTOR_ID
LEFT JOIN (SELECT T.MERCHANT_ID AS MERCHANT_ID,
T.DOCTOR_ID AS MERCHANT_DOCTOR_ID
FROM BL.BL_CT_MC_MERCHANTINFO_D T
WHERE T.PARTITION_DAY = '${partition_day}') T11
ON T10.MERCHANT_ID = T11.MERCHANT_ID
LEFT JOIN (SELECT T.CODE, T.NEW_CODE
FROM DIM.DIM_PAGE_POSITION_TRANSFORM T) T12
ON T8.PAGE_POSITION = T12.CODE;
\ No newline at end of file
package com.gmei.streaming;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.ml.MlPreciseExposureBean;
import com.gmei.function.*;
import com.gmei.sink.BlPreciseExposureMysqlSink;
import com.gmei.sink.MlPreciseExposureMysqlSink;
import com.gmei.source.BlMaiDianKafkaSource;
import org.apache.flink.api.common.restartstrategy.RestartStrategies;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.streaming.api.CheckpointingMode;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.*;
import org.apache.flink.streaming.api.environment.CheckpointConfig;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.triggers.CountTrigger;
import org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer011;
import org.apache.flink.util.OutputTag;
import java.util.concurrent.*;
/**
* ClassName: PreciseExposureStreaming
* Function:
* Reason: flink主类
* Date: 2019/12/5 下午3:54
*
* @author liuzhe
* @since JDK 1.8
*/
public class PreciseExposureStreaming {
/**
* Function: main
* Reason: 执行入口
* Date: 2019/12/24 上午11:03
* args: inBrokes、inTopic、inzk、groupId、sinkBlTableName、sinkMlTableName、outBrokers、outTopic、dimJdbcUrl、sinkJdbcUrl
* 运行参数设置:
* 时间属性: ProcessingTime
* 聚合窗口时间: 1分钟
* 并行度: 1
* 异步查询最长等待时间: 1分钟
* 缓存大小: 2000
* 缓存过期时间: 24小时
* @author liuzhe
* @since JDK 1.8
*/
public static void main(String[] args) throws Exception {
String inBrokers = null;
String inTopic = null;
String groupId = null;
String dimJdbcUrl = null;
String sinkBlJdbcUrl = null;
String sinkMlJdbcUrl = null;
String sinkBlTableName = null;
String sinkMlTableName = null;
Integer windowSize = null;
Integer parallelism = null;
String startTime = null;
String checkpointPath = null;
ParameterTool parameterTool = null;
try {
// ./flink run flink-stat-1.0-SNAPSHOT.jar -brokers kafka.dev.gengmei:9092 -topic gm-logging-test -sinkUrl jdbc:phoenix:localhost:2181 -sinkTable data.device_for_flink -zxUrl jdbc:mysql://localhost/seven?user=root&password=123123 -zxTable statistic_promotion_channel
// ./flink run flink-stat-1.0-SNAPSHOT.jar -brokers 172.21.40.14:9092 -topic gm-precise_exposure-test
parameterTool = ParameterTool.fromArgs(args);
inBrokers = parameterTool.getRequired("inBrokers");
inTopic = parameterTool.getRequired("inTopic");
groupId = parameterTool.get("groupId", "flink_preciseexposure_group");
dimJdbcUrl = parameterTool.getRequired("dimJdbcUrl");
sinkBlJdbcUrl = parameterTool.getRequired("sinkBlJdbcUrl");
sinkMlJdbcUrl = parameterTool.getRequired("sinkMlJdbcUrl");
sinkBlTableName = parameterTool.getRequired("sinkBlTableName");
sinkMlTableName = parameterTool.getRequired("sinkMlTableName");
// Boolean startFromLatest = parameterTool.getBoolean("startFromLatest", false);
windowSize = parameterTool.getInt("windowSize", 30);
parallelism = parameterTool.getInt("parallelism", 1);
startTime = parameterTool.get("startTime", null);
checkpointPath = parameterTool.getRequired("checkpointPath");
printUsage(parameterTool);
} catch (Exception e) {
e.printStackTrace();
printUsage();
}
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
/*
checkpoint设置
*/
//start a checkpoint every 1000 ms
env.enableCheckpointing(1000);
//set mode to exactly-once (this is the default)
env.getCheckpointConfig().setCheckpointingMode(CheckpointingMode.EXACTLY_ONCE);
//make sure 500 ms of progress happen between checkpoints
env.getCheckpointConfig().setMinPauseBetweenCheckpoints(500);
//checkpoints have to complete within one minute, or are discarded
env.getCheckpointConfig().setCheckpointTimeout(60000);
//allow only one checkpoint to be in progress at the same time
env.getCheckpointConfig().setMaxConcurrentCheckpoints(1);
//enable externalized checkpoints which are retained after job cancellation
env.getCheckpointConfig().enableExternalizedCheckpoints(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
//This determines if a task will be failed if an error occurs in the execution of the task’s checkpoint procedure.
env.getCheckpointConfig().setFailOnCheckpointingErrors(true);
//设置statebackend
env.setStateBackend(new FsStateBackend(checkpointPath,true));
//重试次数1,重试间隔时间30s
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 3000));
//设置时间属性(EventTime:事件时间;IngestionTime:接入时间;ProcessingTime:处理时间(默认))
env.setStreamTimeCharacteristic(TimeCharacteristic.ProcessingTime);
// DataStream<String> blMaiDianDataStream = env.socketTextStream("MacdeMacBook-Pro-9.local", 9000, "\n");
//正式环境
BlMaiDianKafkaSource blMaiDianKafkaSource = new BlMaiDianKafkaSource(inBrokers, inTopic, groupId, startTime);
//测试环境
// BlMaiDianKafkaSource blMaiDianKafkaSource = new BlMaiDianKafkaSource("localhost:9092", "test", "group1");
FlinkKafkaConsumer011<String> flinkKafkaConsumer = blMaiDianKafkaSource.addSource();
//maidian流分发
SplitStream<String> blMaiDianDataStream = env
.addSource(flinkKafkaConsumer).uid("id_blmaidiandata_source").setParallelism(parallelism)
.split(new BlMaiDianOutputSelector());
OutputTag<BlPreciseExposureBean> outputTag = new OutputTag<BlPreciseExposureBean>("bl_preciseexposure_late_data"){};
/*
BL层数据清洗、转换、去重
Time.of(windowSize, TimeUnit.SECONDS)等价与Time.seconds(windowSize):30秒
*/
@SuppressWarnings("unchecked")
SingleOutputStreamOperator<BlPreciseExposureBean> blPreciseExposureStream = blMaiDianDataStream
.select("et_pe")
.map(new BlPreciseExposureMapFunction()).uid("id_blpreciseexposure_map").setParallelism(parallelism)
.filter(new BlPreciseExposureFilterFunction()).uid("id_blpreciseexposure_filter").setParallelism(parallelism)
// .assignTimestampsAndWatermarks(new BlPreciseExposureWatermark())
.timeWindowAll(Time.of(windowSize, TimeUnit.SECONDS))
// .allowedLateness(Time.of(windowSize, TimeUnit.SECONDS))
// .trigger(EventTimeTrigger.create())
// .sideOutputLateData(outputTag)
.process(new BlPreciseExposureProcessFunction()).uid("id_blpreciseexposure_distinct_window").setParallelism(parallelism);
/*
BL层延迟到达数据
*/
// DataStream<BlPreciseExposureBean> blPreciseExposureLateStream = blPreciseExposureStream.getSideOutput(outputTag);
/*
BL层数据下发
*/
blPreciseExposureStream
// .union(blPreciseExposureLateStream)
.addSink(new BlPreciseExposureMysqlSink(sinkBlJdbcUrl, sinkBlTableName))
.uid("id_blpreciseexposure_sink")
.setParallelism(parallelism);
/*
Ml层数据爆炸、聚合
*/
DataStream<MlPreciseExposureBean> mlPreciseExposureStream = blPreciseExposureStream
// .union(blPreciseExposureLateStream)
.flatMap(new MlpreciseExposureFlatMapFunction()).uid("id_mlpreciseexposure_flatmap").setParallelism(parallelism)
.keyBy(new MlPreciseExposureKeySelector())
.timeWindow(Time.of(windowSize, TimeUnit.SECONDS))
.sum("preciseexposure_num").uid("id_mlpreciseexposure_aggregate_window").setParallelism(parallelism);
/*
乱序异步调用关联维度码表
timeout:请求最长等待时间;capacity:请求最大并发数
*/
DataStream<MlPreciseExposureBean> mlPreciseExposureJoinDimStream = AsyncDataStream
.unorderedWait(mlPreciseExposureStream, new DimRichAsyncFunction(dimJdbcUrl), 1, TimeUnit.MINUTES, 1000)
.uid("id_mlpreciseexposure_joindim")
.setParallelism(parallelism);
// //测试打印
// mlPreciseExposureJoinDimStream.print();
// mlPreciseExposureJoinDimStream.addSink(new PrintSinkFunction<>());
/*
ML层数据下发
*/
mlPreciseExposureJoinDimStream
.addSink(new MlPreciseExposureMysqlSink(sinkMlJdbcUrl, sinkMlTableName))
.uid("id_mlpreciseexposure_sink")
.setParallelism(parallelism);
env.execute("ml_c_et_pe_preciseexposure_dimen_d_rt");
}
/**
* Function: printUsage
* Reason: 打印参数说明
* Date: 2019/12/26 下午2:39
*
* @author liuzhe
* @since JDK 1.8
*/
public static void printUsage(){
System.out.println("Missing parameters!\n" +
"Usage:\n" +
" --inBrokers <source kafka brokers> \n" +
" --inTopic <source kafka topic>\n" +
" --groupid <source kafka groupid, default: flink_preciseexposure_group> \n" +
" --startFromLatest <start from the latest kafka record, default: false> \n" +
" --windowSize <window size(second), default: 30 (s)> \n" +
" --dimJdbcUrl <source dim database url> \n" +
" --sinkBlJdbcUrl <target bl database url> \n" +
" --sinkMlJdbcUrl <target ml database url> \n" +
" --sinkBlTableName <target bl table name> \n" +
" --sinkMlTableName <target ml table name> \n" +
" --parallelism <parallelism, default 1> \n" +
" --startTime <kafka startTime, default null> \n" +
" --checkpointPath <checkpointPath, hdfs> \n"
);
}
/**
* Function: printUsage
* Reason: 打印参数
* Date: 2019/12/25 下午5:00
*
* @author liuzhe
* @since JDK 1.8
*/
public static void printUsage(ParameterTool args){
ParameterTool parameterTool = args;
System.out.println("Print parameters!\n" +
"Usage:\n" +
" --inBrokers " + parameterTool.getRequired("inBrokers") + " \n" +
" --inTopic " + parameterTool.getRequired("inTopic") + "\n" +
" --groupid " + parameterTool.get("groupId", "flink_preciseexposure_group") + " \n" +
" --startFromLatest <start from the latest kafka record, default: false> \n" +
" --windowSize " + parameterTool.getInt("windowSize", 30) + " \n" +
" --dimJdbcUrl " + parameterTool.getRequired("dimJdbcUrl") + " \n" +
" --sinkBlJdbcUrl " + parameterTool.getRequired("sinkBlJdbcUrl") + " \n" +
" --sinkMlJdbcUrl " + parameterTool.getRequired("sinkMlJdbcUrl") + " \n" +
" --sinkBlTableName " + parameterTool.getRequired("sinkBlTableName") + " \n" +
" --sinkMlTableName " + parameterTool.getRequired("sinkMlTableName") + " \n" +
" --parallelism "+ parameterTool.getInt("parallelism", 1) + " \n" +
" --startTime " + parameterTool.get("startTime", null) + " \n" +
" --checkpointPath " + parameterTool.getRequired("checkpointPath") + " \n"
);
}
}
package com.gmei.utils;
import java.lang.reflect.Field;
/**
* ClassName: BeanReflectUtil
* Function:
* Reason: 类反射工具类
* Date: 2019/12/5 下午3:54
*
* @author liuzhe
* @since JDK 1.8
*/
public class BeanReflectUtil {
/**
* Function: getFieldValue
* Reason: 通过类反射获取属性值
* Date: 2019/12/25 下午4:41
*
* @author liuzhe
* @since JDK 1.8
*/
public static <T> Object getFieldValue(T obj, String field) throws Exception {
Class<?> claz = obj.getClass();
Field f = null;
Object fieldValue = null;
Field[] fields = claz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i].getName().equals(field)) {
f = claz.getDeclaredField(field);
f.setAccessible(true);
fieldValue = f.get(obj);
}
}
return fieldValue;
}
/**
* Function: setFieldValue
* Reason: 通过类反射设置属性值
* Date: 2019/12/25 下午4:41
*
* @author liuzhe
* @since JDK 1.8
*/
public static <T> void setFieldValue(T obj, String field, Object value) {
Class<?> claz = obj.getClass();
Field f = null;
try {
Field[] fields = claz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i].getName().equals(field)) {
f = claz.getDeclaredField(field);
f.setAccessible(true);
f.set(obj, value);
}
}
} catch (Exception e) {
e.getStackTrace();
}
}
/**
* Function: setNullValue
* Reason: 通过类反射设置所有空字符串为NULL
* Date: 2019/12/25 下午4:42
*
* @author liuzhe
* @since JDK 1.8
*/
public static <T> T setNullValue(T source) throws IllegalArgumentException, IllegalAccessException, SecurityException {
Field[] fields = source.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getGenericType().toString().equals("class java.lang.String")) {
field.setAccessible(true);
Object obj = field.get(source);
if (obj != null && obj.equals("")) {
field.set(source, null);
}
}
}
return source;
}
}
package com.gmei.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* ClassName: DateUtil
* Function:
* Reason: 日期格式工具类
* Date: 2019/12/17 下午4:51
*
* @author liuzhe
* @since JDK 1.8
*/
public class DateUtil {
static SimpleDateFormat secDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
static SimpleDateFormat dayDate = new SimpleDateFormat("yyyyMMdd");
static SimpleDateFormat day_idDate = new SimpleDateFormat("yyyy-MM-dd");
public enum DateType {
DAY,
SECOND,
DAY_ID;
}
/**
* Function: timestampFormat.
* DAY:yyyyMMdd
* SECOND:yyyy-MM-dd HH:mm:ss
* Reason: timestamp时间戳格式化.
* Date: 2019/12/25 下午4:43
*
* @author liuzhe
* @since JDK 1.8
*/
public static String timestampFormat(String timestamp, DateType type) {
Double timestampDouble = Double.parseDouble(timestamp);
Long timestampLong = new Double(timestampDouble * 1000).longValue();
Date date= new Date(timestampLong);
switch (type) {
case DAY:
return dayDate.format(date);
case SECOND:
return secDate.format(date);
case DAY_ID:
return day_idDate.format(date);
default:
return null;
}
}
public static Date stringToDate(String timestamp) {
Double timestampDouble = Double.parseDouble(timestamp);
Long timestampLong = new Double(timestampDouble * 1000).longValue();
Date date= new Date(timestampLong);
return date;
}
}
package com.gmei.utils;
/**
* ClassName: DimTableList
* Function:
* Reason: 维度码表列表枚举类
* Date: 2019/12/12 上午11:34
*
* @author liuzhe
* @since JDK 1.8
*/
public enum DimTableList {
DIM_CITY("dim_city", "城市码表"),
DIM_CARD_TYPE("dim_card_type", "卡片类型码表"),
DIM_CARD_CONTENT_TYPE("dim_card_content_type", "卡片内容类型码表"),
DIM_PAGE_TYPE("dim_page_type", "页面分类编码"),
DIM_TRANSACTION_TYPE("dim_transaction_type", "业务类型码表"),
;
private String tableName;
private String tableComment;
DimTableList(String tableName, String tableComment) {
this.tableName = tableName;
this.tableComment = tableComment;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getTableComment() {
return tableComment;
}
public void setTableComment(String tableComment) {
this.tableComment = tableComment;
}
public static DimTableList getDimTableByName(String tableName) {
for(DimTableList dimTable : values()) {
if(dimTable.getTableName().equals(tableName)) {
return dimTable;
}
}
return null;
}
}
\ No newline at end of file
package com.gmei.cache;
import com.gmei.bean.dim.DimCardContentType;
import org.junit.Test;
import java.util.ArrayList;
public class DimCardContentTypeDaoTest {
@Test
public void findAlldimTableTransFormTest() {
DimCardContentTypeDao dimCardContentTypeDao = new DimCardContentTypeDao();
ArrayList<DimCardContentType> dimCardContentTypeList;
try {
dimCardContentTypeList = dimCardContentTypeDao.findAllDimCardContentType("dim_card_content_type");
for (DimCardContentType dimCardContentType : dimCardContentTypeList)
System.out.println(dimCardContentType);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void finddimTableTransFormByCodeTest() {
DimCardContentTypeDao dimCardContentTypeDao = new DimCardContentTypeDao();
DimCardContentType dimCardContentType;
try {
dimCardContentType = dimCardContentTypeDao.findDimCardContentTypeByCode("dim_card_content_type", "diary");
System.out.println(dimCardContentType);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.gmei.cache;
import com.gmei.bean.dim.DimCity;
import org.junit.Test;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class DimCityDaoTest {
@Test
public void findAllDimCityTest() {
SimpleCacheService<String, DimCity> dimCityCache = null;
DimTableCallable dimCityCallable = new DimTableCallable("beijing", "dim_city", null);
ExecutorService es = Executors.newFixedThreadPool(2);
Future future = es.submit(dimCityCallable);
try {
ArrayList<DimCity> dimCityList = (ArrayList<DimCity>) future.get();
for (DimCity dimCity : dimCityList) {
System.out.println(dimCity);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
// DimCity dimCity = dimCityCache.getValue("beijing", dimCityCallable);
//
// new DimCityCallable("beijing", "multi");
// ArrayList<DimCity> dimCityList;
// try {
// dimCityList = findAllDimCity("dim_city");
// for (DimCity dimCity : dimCityList)
// } catch (Exception e) {
// e.printStackTrace();
// }
}
@Test
public void findDimCityByCodeTest() {
SimpleCacheService<String, DimCity> dimCityCache = null;
DimTableCallable dimCityCallable = new DimTableCallable("beijing", "dim_city", null);
ExecutorService es = Executors.newFixedThreadPool(2);
Future future = es.submit(dimCityCallable);
try {
DimCity dimCity = (DimCity)future.get();
// for (DimCity dimCity : dimCityList) {
System.out.println(dimCity);
// }
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
// ArrayList<DimCity> dimCityList;
// try {
// dimCityList = findDimCityByCode("dim_city", "beijing");
// for (DimCity dimCity : dimCityList) {
// System.out.println(dimCity);
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
}
}
package com.gmei.cache;
import com.gmei.bean.dim.DimPageType;
import org.junit.Test;
import java.util.ArrayList;
public class DimPageTypeDaoTest {
@Test
public void findAllDimPageTypeTest() {
DimPageTypeDao dimPageTypeDao = new DimPageTypeDao();
ArrayList<DimPageType> dimPageTypeList;
try {
dimPageTypeList = dimPageTypeDao.findAllDimPageType("dim_page_type");
for (DimPageType dimPageType : dimPageTypeList)
System.out.println(dimPageType);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void findDimPageTypeByCodeTest() {
DimPageTypeDao dimPageTypeDao = new DimPageTypeDao();
DimPageType dimPageType;
// ArrayList<DimPageType> dimPageTypeList;
try {
dimPageType = dimPageTypeDao.findDimPageTypeByCode("dim_page_type", "home");
// for (DimPageType dimPageType : dimPageTypeList)
System.out.println(dimPageType);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.gmei.cache;
import com.gmei.bean.dim.DimCity;
import com.gmei.bean.dim.DimPageType;
import com.gmei.bean.dim.DimTable;
import com.gmei.utils.DimTableList;
import org.junit.Test;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class DimTableDaoTest {
@Test
public void findAllDimTableTest() {
// DimTableDao dimTableDao = new DimTableDao();
// ArrayList<DimTable> dimTableList;
// try {
// dimTableList = dimTableDao.findAllDimTable("dim_city");
// for (DimTable dimTable : dimTableList)
// System.out.println(dimTable);
// } catch (Exception e) {
// e.printStackTrace();
// }
SimpleCacheService<String, DimCity> dimCityCache = null;
DimTableCallable dimTableCallable = new DimTableCallable(null, DimTableList.DIM_CITY.getTableName(), null);
ExecutorService es = Executors.newFixedThreadPool(2);
Future future = es.submit(dimTableCallable);
try {
ArrayList<DimCity> dimCityList = (ArrayList<DimCity>) future.get();
for (DimCity dimCity : dimCityList) {
System.out.println(dimCity);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
@Test
public void findDimTableByCodeTest() {
// DimTableDao dimTableDao = new DimTableDao();
// DimTable dimTable;
// try {
// dimTable = dimTableDao.findDimTableByCode("dim_city", "beijing");
// System.out.println(dimTable);
// } catch (Exception e) {
// e.printStackTrace();
// }
SimpleCacheService<String, DimCity> dimCityCache = null;
DimTableCallable dimCityCallable = new DimTableCallable("beijing", DimTableList.DIM_CITY.getTableName(), null);
DimTableCallable dimPageTypeCallable = new DimTableCallable("home", DimTableList.DIM_PAGE_TYPE.getTableName(), null);
DimTableCallable dimCardContentTypeCallable = new DimTableCallable("diary", DimTableList.DIM_CARD_CONTENT_TYPE.getTableName(), null);
ExecutorService es = Executors.newFixedThreadPool(3);
Future future1 = es.submit(dimCityCallable);
Future future2 = es.submit(dimPageTypeCallable);
Future future3 = es.submit(dimCardContentTypeCallable);
System.out.println("start");
try {
DimCity dimCity = (DimCity)future1.get();
DimPageType dimPageType = (DimPageType) future2.get();
DimTable dimCardContentType = (DimTable)future3.get();
System.out.println(dimCity);
System.out.println(dimPageType);
System.out.println(dimCardContentType);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
@Test
public void findCacheTest() {
SimpleCacheService<String, DimCity> dimCityCache = new SimpleCacheService<>(2000, 24);
DimTableCallable dimCityCallable = new DimTableCallable("beijing", DimTableList.DIM_CITY.getTableName(), null);
ExecutorService es = Executors.newFixedThreadPool(2);
Future future1 = es.submit(dimCityCallable);
DimCity dimCity = null;
try {
dimCity = (DimCity)future1.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
// dimCityCache.putValue("beijing",dimCity);
DimCity dimCityCacheValue = null;
try {
dimCityCacheValue = dimCityCache.getValue("beijing", new DimTableCallable<DimCity>("beijing", DimTableList.DIM_CITY.getTableName(), null));
} catch (Exception e) {
dimCityCacheValue = null;
e.printStackTrace();
}
System.out.println(dimCityCacheValue);
// ExecutorService es = Executors.newFixedThreadPool(2);
// Future future = es.submit(dimTableCallable);
// System.out.println("start");
// try {
// DimCity dimCity = (DimCity)future.get();
// System.out.println(dimCity);
// } catch (InterruptedException e) {
// e.printStackTrace();
// } catch (ExecutionException e) {
// e.printStackTrace();
// }
}
}
package com.gmei.etl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.bl.BlPreciseExposureParamsExposureCardsBean;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationFeature;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.io.IOException;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* ClassName: BlMaiDianSplitEtl
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/4 下午4:58
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlMaiDianSplitEtl implements Serializable {
/**
* Function: split流
* Reason: TODO ADD REASON.
* Date: 2019/12/7 下午7:56
*
* @author liuzhe
* @since JDK 1.8
*/
public String mapBlPreciseExposureBean(String string) throws Exception {
return null;
}
}
package com.gmei.etl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.bl.BlPreciseExposureParamsExposureCardsBean;
import com.gmei.utils.BeanReflectUtil;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationFeature;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import java.io.IOException;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* ClassName: BlPreciseExposureEtl
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/4 下午4:58
*
* @author liuzhe
* @since JDK 1.8
*/
public class BlPreciseExposureEtl implements Serializable {
/**
* Function: 废弃.
* Reason: TODO ADD REASON.
* Date: 2019/12/7 下午7:54
*
* @author liuzhe
* @since JDK 1.8
*/
public BlPreciseExposureBean getBlPreciseExposureBeanJackJson(String string) throws IOException {
ObjectMapper mapper = new ObjectMapper();
// System.out.println(string);
// JsonNode jsonNode = mapper.readTree(string);
// JsonNode jsonNode = mapper.readTree(string);
// String data = jsonNode.findValue("@raw").asText();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
BlPreciseExposureBean blPreciseExposureBean = mapper.readValue(string, BlPreciseExposureBean.class);
// mapper.readValue()
// System.out.println(blPreciseExposureBean.toString());
return blPreciseExposureBean;
}
/**
* Function: mapBlPreciseExposureBean
* Reason: map一对一
* Date: 2019/12/7 下午7:56
*
* @author liuzhe
* @since JDK 1.8
*/
public BlPreciseExposureBean mapBlPreciseExposureBean(String string) throws Exception {
BlPreciseExposureBean blPreciseExposureBean = new BlPreciseExposureBean();
JSONObject jsonObject = JSON.parseObject(string);
//一级别JSON
JSONObject app = jsonObject.getJSONObject("app");
String gm_nginx_timestamp = String.valueOf(jsonObject.get("gm_nginx_timestamp"));
String create_timestamp = String.valueOf(jsonObject.get("create_at"));
String user_id = jsonObject.getString("user_id");
String action = jsonObject.getString("type");
//二级别JSON
//APP
String app_grey_type = app.getString("grey_type");
String app_channel = app.getString("channel");
String app_version = app.getString("version");
String app_current_city_id= app.getString("current_city_id");
String app_code = app.getString("name");
//1.2 absolute_position参数类型不完整
//问题描述:在'7.7.35', '7.7.36', '7.7.40'params的absolute_position缺少左边引号
String paramsString = String.valueOf(jsonObject.get("params"));
if("7.7.35".equals(app_version) || "7.7.36".equals(app_version) || "7.7.40".equals(app_version)) {
paramsString = paramsString.replace("absolute_position","\\\"absolute_position");
}
//PARAMS
JSONObject params = JSON.parseObject(paramsString);
Integer down_loading_times = params.getInteger("down_loading_times");
Integer down_slide_times = params.getInteger("down_slide_times");
Integer up_loading_times = params.getInteger("up_loading_times");
Integer up_slide_times = params.getInteger("up_slide_times");
String page_code = params.getString("page_name");
String tab_name = params.getString("tab_name");
String business_id = params.getString("business_id");
String referrer_code = params.getString("referrer");
String referrer_id = params.getString("referrer_id");
//1.4 初版精准曝光格式错误
//问题描述:在'7.7.60'版本中美购页卡片的card_id和transaction_type这两个参数是数组的形式
// ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards =(ArrayList<BlPreciseExposureParamsExposureCardsBean>)JSONArray.parseArray(params.getJSONArray("exposure_cards").toString(), BlPreciseExposureParamsExposureCardsBean.class);
ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards = new ArrayList<>();
JSONArray jsonArray = JSONArray.parseArray(params.getJSONArray("exposure_cards").toString());
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonCard = jsonArray.getJSONObject(i);
String card_id = jsonCard.getString("card_id");
String transaction_type = jsonCard.getString("transaction_type");
String card_content_type = jsonCard.getString("card_content_type");
if("service".equals(card_content_type) && "7.7.60".equals(app_version)) {
JSONArray card_id_list = JSONArray.parseArray(card_id);
JSONArray transaction_type_list = JSONArray.parseArray(transaction_type);
for (int j = 0; j < card_id_list.size(); j++) {
BlPreciseExposureParamsExposureCardsBean cardsBean = new BlPreciseExposureParamsExposureCardsBean();
cardsBean.setCard_id(card_id_list.getString(j));
cardsBean.setTransaction_type(transaction_type_list.getString(j));
cardsBean.setCard_content_type(card_content_type);
cardsBean.setCard_type(jsonCard.getString("card_type"));
cardsBean.setIs_cpc(jsonCard.getString("is_cpc"));
cardsBean.setCpc_referer(jsonCard.getString("cpc_referer"));
cardsBean.setAbsolute_position(jsonCard.getString("absolute_position"));
cardsBean.setRelative_position(jsonCard.getString("relative_position"));
exposure_cards.add(cardsBean);
}
} else {
BlPreciseExposureParamsExposureCardsBean cardsBean = JSON.toJavaObject(jsonCard, BlPreciseExposureParamsExposureCardsBean.class);
exposure_cards.add(cardsBean);
}
}
String is_exposure = params.getString("is_exposure");
String filter = params.getString("filter");
String query = params.getString("query");
//DEVICE
JSONObject device = jsonObject.getJSONObject("device");
String device_os_type = device.getString("device_type");
String device_model = device.getString("model");
String device_id = device.getString("device_id");
String device_idfv = device.getString("idfv");
String device_android_id = device.getString("android_device_id");
//1.1 ios系统精准曝光埋点channel字段
//问题描述:ios系统精准曝光埋点channel字段AppStore应该修改为App Store
if("AppStore".equals(app_channel)) {
app_channel = "App Store";
}
//日志时间处理
SimpleDateFormat secDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat dayDate = new SimpleDateFormat("yyyyMMdd");
Double gm_nginx_timestampDouble = Double.parseDouble(gm_nginx_timestamp);
Long gm_nginx_timestampLong = new Double(gm_nginx_timestampDouble * 1000).longValue();
Date gmDate= new Date(gm_nginx_timestampLong);
Date createDate= new Date(Long.parseLong(create_timestamp) * 1000);
String gm_nginx_time_date = secDate.format(gmDate);
String gm_nginx_time_day = dayDate.format(gmDate);
String create_time_date = secDate.format(createDate);
String create_time_day = dayDate.format(createDate);
//1.7 result_status参数位置问题(未处理)
//问题描述:搜索结果百科(search_result_wiki)和搜索结果美购(search_result_welfare)的result_status埋点埋在exposure_data里面了为了都获得该参数值,因此需要从两处拿取,默认先取exposure_data里的result_satus字段值(数据中发现不只是这两个页面)search_result_diary、search_result_doctor、search_result_hospital也存在
//1.9 搜索结果页tab_name参数不该存在
//问题描述:在搜索结果页出现tab_name参数,参数值和page_name一样,在点击的时候页面有跳转,因此,不应该有tab_name参数
if (page_code.contains("search_result")) {
tab_name = null;
}
blPreciseExposureBean.setGm_nginx_timestamp(gm_nginx_timestamp);
blPreciseExposureBean.setCreate_timestamp(create_timestamp);
blPreciseExposureBean.setUser_id(user_id);
blPreciseExposureBean.setAction(action);
blPreciseExposureBean.setApp_grey_type(app_grey_type);
blPreciseExposureBean.setApp_channel(app_channel);
blPreciseExposureBean.setApp_version(app_version);
blPreciseExposureBean.setApp_current_city_id(app_current_city_id);
blPreciseExposureBean.setApp_code(app_code);
blPreciseExposureBean.setDown_loading_times(down_loading_times);
blPreciseExposureBean.setDown_slide_times(down_slide_times);
blPreciseExposureBean.setUp_loading_times(up_loading_times);
blPreciseExposureBean.setUp_slide_times(up_slide_times);
blPreciseExposureBean.setPage_code(page_code);
blPreciseExposureBean.setTab_name(tab_name);
blPreciseExposureBean.setBusiness_id(business_id);
blPreciseExposureBean.setReferrer_code(referrer_code);
blPreciseExposureBean.setReferrer_id(referrer_id);
blPreciseExposureBean.setExposure_cards(exposure_cards);
blPreciseExposureBean.setIs_exposure(is_exposure);
blPreciseExposureBean.setFilter(filter);
blPreciseExposureBean.setQuery(query);
blPreciseExposureBean.setDevice_os_type(device_os_type);
blPreciseExposureBean.setDevice_model(device_model);
blPreciseExposureBean.setDevice_id(device_id == null|| device_id =="" ? device_id : device_idfv);
blPreciseExposureBean.setDevice_android_id(device_android_id);
blPreciseExposureBean.setDevice_idfv(device_idfv);
blPreciseExposureBean.setGm_nginx_time_date(gm_nginx_time_date);
blPreciseExposureBean.setGm_nginx_time_day(gm_nginx_time_day);
blPreciseExposureBean.setCreate_time_date(create_time_date);
blPreciseExposureBean.setCreate_time_day(create_time_day);
return BeanReflectUtil.setNullValue(blPreciseExposureBean);
}
/**
* Function: filterBlPreciseExposureBean
* Reason: 筛选数据
* Date: 2019/12/7 下午7:57
*
* @author liuzhe
* @since JDK 1.8
*/
public Boolean filterBlPreciseExposureBean(BlPreciseExposureBean blPreciseExposureBean) throws Exception {
String app_code = blPreciseExposureBean.getApp_code();
String is_exposure = blPreciseExposureBean.getIs_exposure();
String app_version = blPreciseExposureBean.getApp_version();
String page_code = blPreciseExposureBean.getPage_code();
//清洗掉app_code不等于gengmei_user与is_exposure不等于1的
//1.5 Home页精准曝光触发两次
//问题描述:在7.7.70','7.7.71','7.7.72','7.7.75','7.7.76','7.8.0','7.8.1' (7.7.70--7.9.0)版本中的首页精准曝光会触发两次,经确认,需要去除page_name='home'
//1.6 品类聚合页的精准曝光问题
//问题描述:品类聚合页的精准曝光没做,但是数据中却有精准曝光、而且有问题,因此过滤掉,目前还不能确定什么版本可以解决,先暂时根据page_name过滤掉page_name='category'
List<String> app_version_list = Arrays.asList("7.7.70","7.7.71","7.7.72","7.7.75","7.7.76","7.8.0","7.8.1");
String[] version = app_version.split(".");
if(!"gengmei_user".equals(app_code) || !"1".equals(is_exposure)) {
return false;
} else if(app_version_list.contains(app_version) && "home".equals(page_code)) {
return false;
} else if("category".equals(page_code) && "7".equals(version[0]) && Integer.parseInt(version[1]) < 14 ) {
return false;
}
return true;
}
@Test
public void getBlPreciseExposureBeanTest() {
BlPreciseExposureEtl blPreciseExposureEtl = new BlPreciseExposureEtl();
// String json = "{\"create_at\":\"1575134961\",\"gm_nginx_timestamp\":1575134961.718,\"user_id\":\"31665831\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":\"0\",\"exposure_cards\":[{\"absolute_position\":\"0\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"0\",\"card_id\":2},{\"absolute_position\":\"1\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"1\",\"card_id\":2},{\"absolute_position\":\"2\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"2\",\"card_id\":2},{\"absolute_position\":\"3\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"3\",\"card_id\":2},{\"absolute_position\":\"4\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"4\",\"card_id\":2}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"is_exposure\":\"1\",\"referrer\":\"\",\"business_id\":\"\",\"referrer_id\":\"\"},\"app_session_id\":\"FE675C8B-4FD4-4FC6-9EC7-415F715A750B\",\"app\":{\"version\":\"7.18.2\",\"grey_type\":\"{\\\"report_result\\\":0,\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"post_detail\\\":\\\"0\\\",\\\"video_steep\\\":1,\\\"face_scan\\\":0}\",\"current_city_id\":\"nanjing\",\"name\":\"gengmei_user\",\"user_type\":{\"config_type\":1},\"serial_id\":12,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"5F193A07-781F-4EF1-86B4-452251307081\",\"sys_version\":\"13.2.3\",\"lng\":118.93133562169,\"is_WiFi\":\"0\",\"manufacturer\":\"Apple\",\"device_id\":\"F88745FE-DF54-4639-B7E2-28554C7DFAAF\",\"device_type\":\"ios\",\"ip\":\"10.190.42.125\",\"idfa\":\"F88745FE-DF54-4639-B7E2-28554C7DFAAF\",\"lat\":32.121287439102,\"model\":\"iPhone8,2\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"gm_nginx_key\":1,\"version\":\"205\",\"params\":{\"up_slide_times\":\"2\",\"down_loading_times\":\"0\",\"exposure_cards\":\"[{\\\"card_id\\\":\\\"16449302\\\",\\\"card_source_type\\\":\\\"doris\\\",\\\"card_content_type\\\":\\\"diary\\\",\\\"card_type\\\":\\\"card\\\",absolute_position\\\":\\\"0\\\",\\\"relative_position\\\":\\\"0\\\"}]\",\"up_loading_times\":\"0\",\"is_exposure\":\"1\",\"tab_name\":\"精选\",\"page_name\":\"home\",\"business_id\":\"\",\"referrer\":\"\",\"referrer_id\":\"\",\"down_slide_times\":\"1\"},\"app_session_id\":\"f3d24a27-27f0-4545-b132-51030765cf49\",\"gm_nginx_timestamp\":1546307958.444,\"create_at\":\"1546307958\",\"type\":\"home_choiceness_card_exposure\",\"device\":{\"is_WiFi\":\"1\",\"ip\":\"192.168.1.100\",\"manufacturer\":\"vivo\",\"device_type\":\"android\",\"lat\":\"0.0\",\"device_id\":\"863208034156179\",\"lng\":\"0.0\"},\"app\":{\"channel\":\"vivo\",\"user_type\":{\"config_type\":\"1\"},\"serial_id\":6,\"current_city_id\":\"worldwide\",\"name\":\"gengmei_user\",\"version\":\"7.7.36\"},\"user_id\":\"\"}";
String json = "{\"create_at\":\"1576128422\",\"gm_nginx_timestamp\":1576128422.463,\"user_id\":\"31038796\",\"version\":\"110\",\"params\":{\"down_loading_times\":1,\"up_slide_times\":5,\"exposure_cards\":[{\"absolute_position\":0,\"result_status\":\"1\",\"card_content_type\":\"service\",\"transaction_type\":\"[\\\"-1\\\",\\\"-1\\\",\\\"-1\\\"]\",\"card_type\":\"card\",\"card_source_type\":\"[\\\"\\\",\\\"\\\",\\\"\\\"]\",\"relative_position\":0,\"card_id\":\"[\\\"5821997\\\",\\\"5762189\\\",\\\"5671097\\\"]\"},{\"absolute_position\":1,\"card_content_type\":\"wiki_collect\",\"card_type\":\"card\",\"relative_position\":1,\"wiki_word\":{},\"card_id\":\"127\"},{\"absolute_position\":2,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":3,\"card_id\":\"15337295\"},{\"absolute_position\":3,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":4,\"card_id\":\"15635897\"},{\"absolute_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"16082820\"},{\"absolute_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"16082820\"},{\"absolute_position\":5,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":4,\"card_id\":\"699299\"},{\"absolute_position\":6,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"article\",\"relative_position\":5,\"card_id\":\"19589790\"},{\"absolute_position\":7,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":6,\"card_id\":\"15764401\"},{\"absolute_position\":8,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":4,\"card_id\":\"15633799\"},{\"absolute_position\":9,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"16622540\"},{\"absolute_position\":10,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":6,\"card_id\":\"699573\"},{\"absolute_position\":11,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":4,\"card_id\":\"686812\"},{\"absolute_position\":12,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"15328675\"},{\"absolute_position\":13,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":6,\"card_id\":\"11201557\"},{\"absolute_position\":14,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":4,\"card_id\":\"700888\"},{\"absolute_position\":15,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":5,\"card_id\":\"706569\"}],\"tab_name\":\"综合\",\"down_slide_times\":8,\"query\":\"玻尿酸\",\"up_loading_times\":0,\"is_exposure\":1,\"referrer\":\"search_home\",\"business_id\":\"\",\"page_name\":\"search_result_more\",\"referrer_id\":\"\"},\"app_session_id\":\"559D8BA2-7FC1-402C-BB12-F860EFA26925\",\"app\":{\"user_type\":{\"config_type\":1},\"current_city_id\":\"chengdu\",\"version\":\"7.7.60\",\"name\":\"gengmei_user\",\"serial_id\":14,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"CD8D7E3B-B833-49EE-B509-6B9F1B3963B9\",\"lng\":104.07933463616,\"is_WiFi\":\"0\",\"manufacturer\":\"Apple\",\"ip\":\"10.187.49.153\",\"device_id\":\"4A0275C1-4734-404A-93DD-BAA272401A27\",\"device_type\":\"ios\",\"lat\":30.654052050073,\"idfa\":\"4A0275C1-4734-404A-93DD-BAA272401A27\"},\"type\":\"page_precise_exposure\"}";
BlPreciseExposureBean blPreciseExposureBean = null;
try {
blPreciseExposureBean = blPreciseExposureEtl.mapBlPreciseExposureBean(json);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(blPreciseExposureBean.toString());
}
@Test
public void filterBlPreciseExposureBeanTest() {
BlPreciseExposureEtl blPreciseExposureEtl = new BlPreciseExposureEtl();
// String json = "{\"create_at\":\"1575134961\",\"gm_nginx_timestamp\":1575134961.718,\"user_id\":\"31665831\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":\"0\",\"exposure_cards\":[{\"absolute_position\":\"0\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"0\",\"card_id\":2},{\"absolute_position\":\"1\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"1\",\"card_id\":2},{\"absolute_position\":\"2\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"2\",\"card_id\":2},{\"absolute_position\":\"3\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"3\",\"card_id\":2},{\"absolute_position\":\"4\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"4\",\"card_id\":2}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"is_exposure\":\"1\",\"referrer\":\"\",\"business_id\":\"\",\"referrer_id\":\"\"},\"app_session_id\":\"FE675C8B-4FD4-4FC6-9EC7-415F715A750B\",\"app\":{\"version\":\"7.18.2\",\"grey_type\":\"{\\\"report_result\\\":0,\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"post_detail\\\":\\\"0\\\",\\\"video_steep\\\":1,\\\"face_scan\\\":0}\",\"current_city_id\":\"nanjing\",\"name\":\"gengmei_user\",\"user_type\":{\"config_type\":1},\"serial_id\":12,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"5F193A07-781F-4EF1-86B4-452251307081\",\"sys_version\":\"13.2.3\",\"lng\":118.93133562169,\"is_WiFi\":\"0\",\"manufacturer\":\"Apple\",\"device_id\":\"F88745FE-DF54-4639-B7E2-28554C7DFAAF\",\"device_type\":\"ios\",\"ip\":\"10.190.42.125\",\"idfa\":\"F88745FE-DF54-4639-B7E2-28554C7DFAAF\",\"lat\":32.121287439102,\"model\":\"iPhone8,2\"},\"type\":\"page_precise_exposure\"}";
String json = "{\"gm_nginx_key\":1,\"version\":\"205\",\"params\":{\"up_slide_times\":\"2\",\"down_loading_times\":\"0\",\"exposure_cards\":\"[{\\\"card_id\\\":\\\"16449302\\\",\\\"card_source_type\\\":\\\"doris\\\",\\\"card_content_type\\\":\\\"diary\\\",\\\"card_type\\\":\\\"card\\\",absolute_position\\\":\\\"0\\\",\\\"relative_position\\\":\\\"0\\\"}]\",\"up_loading_times\":\"0\",\"is_exposure\":\"1\",\"tab_name\":\"精选\",\"page_name\":\"home\",\"business_id\":\"\",\"referrer\":\"\",\"referrer_id\":\"\",\"down_slide_times\":\"1\"},\"app_session_id\":\"f3d24a27-27f0-4545-b132-51030765cf49\",\"gm_nginx_timestamp\":1546307958.444,\"create_at\":\"1546307958\",\"type\":\"home_choiceness_card_exposure\",\"device\":{\"is_WiFi\":\"1\",\"ip\":\"192.168.1.100\",\"manufacturer\":\"vivo\",\"device_type\":\"android\",\"lat\":\"0.0\",\"device_id\":\"863208034156179\",\"lng\":\"0.0\"},\"app\":{\"channel\":\"vivo\",\"user_type\":{\"config_type\":\"1\"},\"serial_id\":6,\"current_city_id\":\"worldwide\",\"name\":\"gengmei_user\",\"version\":\"7.7.36\"},\"user_id\":\"\"}";
BlPreciseExposureBean blPreciseExposureBean = null;
Boolean flag = null;
try {
blPreciseExposureBean = blPreciseExposureEtl.mapBlPreciseExposureBean(json);
flag = blPreciseExposureEtl.filterBlPreciseExposureBean(blPreciseExposureBean);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(blPreciseExposureBean.getIs_exposure());
System.out.println(flag);
}
}
package com.gmei.etl;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.bl.BlPreciseExposureParamsExposureCardsBean;
import com.gmei.bean.dim.DimCity;
import com.gmei.bean.ml.MlPreciseExposureBean;
import com.gmei.cache.SimpleCacheService;
import com.gmei.jdbc.MysqlJdbcDim;
import com.gmei.utils.BeanReflectUtil;
import org.junit.Test;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* ClassName: BlPreciseExposureEtl
* Function: TODO ADD FUNCTION.
* Reason: TODO ADD REASON.
* Date: 2019/12/4 下午4:58
*
* @author liuzhe
* @since JDK 1.8
*/
public class MlPreciseExposureEtl implements Serializable {
/**
* Function: flatmapMlPreciseExposureBean
* Reason: 数据一对多
* Date: 2019/12/7 下午7:57
*
* @author liuzhe
* @since JDK 1.8
*/
public ArrayList<MlPreciseExposureBean> flatmapMlPreciseExposureBean (BlPreciseExposureBean blPreciseExposureBean) throws Exception {
ArrayList<BlPreciseExposureParamsExposureCardsBean> exposure_cards = blPreciseExposureBean.getExposure_cards();
String app_version = blPreciseExposureBean.getApp_version();
String device_os_type = blPreciseExposureBean.getDevice_os_type();
ArrayList<MlPreciseExposureBean> mlPreciseExposureBeanList = new ArrayList<>();
for(BlPreciseExposureParamsExposureCardsBean exposureCardsBean: exposure_cards) {
String card_id = exposureCardsBean.getCard_id();
String card_content_type = exposureCardsBean.getCard_content_type();
String card_type = exposureCardsBean.getCard_type();
String is_cpc = exposureCardsBean.getIs_cpc();
String cpc_referer = exposureCardsBean.getCpc_referer();
String absolute_position = exposureCardsBean.getAbsolute_position();
String relative_position = exposureCardsBean.getRelative_position();
String transaction_type = exposureCardsBean.getTransaction_type();
//1.3 绝对位置和相对位置位置错误
//问题描述:在'7.7.35','7.7.36' android的绝对位置和相对位置写反
if("android".equals(device_os_type) && ("7.7.35".equals(app_version) || "7.7.36".equals(app_version))) {
String change = absolute_position;
absolute_position = relative_position;
relative_position = change;
}
//1.10 banner、豆腐块、icon、搜索词和功能区入口的card_type参数问题
//问题描述:当卡片类型为豆腐块、icon、banner、搜索词和功能区入口的时候的时候正确的card_type的参数值被赋给了card_content_type(banner、icon、gadget、search_query、function_entrance)
List<String> card_content_type_list = Arrays.asList("banner","icon","gadget","search_query","function_entrance");
if (card_content_type_list.contains(card_content_type)) {
card_type = card_content_type;
card_content_type = null;
}
if ("search_query".equals(card_content_type)) {
card_type = "search_word";
}
//1.12 card_content_type的qa值应该被换成q_a
card_content_type = card_content_type.replace("qa","q_a");
//1.13 target_name与card_name的参数的统一
//问题描述:将target_name参数的值赋给card_name
//1.14 百科卡片曝光新增参数wiki_type
//问题:从7.19.0版本开始,百科卡片曝光,新增了wiki_type参数
MlPreciseExposureBean mlPreciseExposureBean = new MlPreciseExposureBean();
mlPreciseExposureBean.setUser_id(blPreciseExposureBean.getUser_id());
mlPreciseExposureBean.setAction(blPreciseExposureBean.getAction());
mlPreciseExposureBean.setPage_code(blPreciseExposureBean.getPage_code());
mlPreciseExposureBean.setTab_name(blPreciseExposureBean.getTab_name());
mlPreciseExposureBean.setBusiness_id(blPreciseExposureBean.getBusiness_id());
mlPreciseExposureBean.setReferrer_code(blPreciseExposureBean.getReferrer_code());
mlPreciseExposureBean.setReferrer_id(blPreciseExposureBean.getReferrer_id());
mlPreciseExposureBean.setCard_id(card_id);
mlPreciseExposureBean.setCard_content_type(card_content_type);
mlPreciseExposureBean.setCard_type(card_type);
mlPreciseExposureBean.setIs_cpc(is_cpc);
mlPreciseExposureBean.setCpc_referer(cpc_referer);
// mlPreciseExposureBean.setAbsolute_position(absolute_position);
// mlPreciseExposureBean.setRelative_position(relative_position);
mlPreciseExposureBean.setTransaction_type(transaction_type);
// mlPreciseExposureBean.setApp_channel(blPreciseExposureBean.getApp_channel());
mlPreciseExposureBean.setApp_version(blPreciseExposureBean.getApp_version());
mlPreciseExposureBean.setCurrent_city_id(blPreciseExposureBean.getApp_current_city_id());
mlPreciseExposureBean.setApp_code(blPreciseExposureBean.getApp_code());
mlPreciseExposureBean.setDevice_os_type(blPreciseExposureBean.getDevice_os_type());
mlPreciseExposureBean.setDevice_id(blPreciseExposureBean.getDevice_id());
mlPreciseExposureBean.setCreate_time_day(blPreciseExposureBean.getCreate_time_day());
mlPreciseExposureBean.setPreciseexposure_num(1);
//1.11 transaction_type的空值需要被修正
//问题描述:transaction_type='' 需要替换为NULL
mlPreciseExposureBeanList.add(BeanReflectUtil.setNullValue(mlPreciseExposureBean));
}
return mlPreciseExposureBeanList;
}
/**
* Function: groupByFields
* Reason: groupBy字段
* Date: 2019/12/7 下午7:57
*
* @author liuzhe
* @since JDK 1.8
*/
public Object groupByFields(MlPreciseExposureBean mlPreciseExposureBean) {
ArrayList groupByFields = new ArrayList();
groupByFields.add(mlPreciseExposureBean.getUser_id());
groupByFields.add(mlPreciseExposureBean.getAction());
groupByFields.add(mlPreciseExposureBean.getApp_code());
groupByFields.add(mlPreciseExposureBean.getTab_name());
groupByFields.add(mlPreciseExposureBean.getBusiness_id());
groupByFields.add(mlPreciseExposureBean.getReferrer_code());
groupByFields.add(mlPreciseExposureBean.getReferrer_id());
groupByFields.add(mlPreciseExposureBean.getCard_id());
groupByFields.add(mlPreciseExposureBean.getCard_content_type());
groupByFields.add(mlPreciseExposureBean.getCard_type());
groupByFields.add(mlPreciseExposureBean.getIs_cpc());
groupByFields.add(mlPreciseExposureBean.getCpc_referer());
// groupByFields.add(mlPreciseExposureBean.getAbsolute_position());
// groupByFields.add(mlPreciseExposureBean.getRelative_position());
groupByFields.add(mlPreciseExposureBean.getTransaction_type());
groupByFields.add(mlPreciseExposureBean.getFilter());
groupByFields.add(mlPreciseExposureBean.getQuery());
// groupByFields.add(mlPreciseExposureBean.getApp_channel());
groupByFields.add(mlPreciseExposureBean.getApp_version());
groupByFields.add(mlPreciseExposureBean.getCurrent_city_id());
groupByFields.add(mlPreciseExposureBean.getApp_code());
groupByFields.add(mlPreciseExposureBean.getDevice_os_type());
groupByFields.add(mlPreciseExposureBean.getDevice_id());
groupByFields.add(mlPreciseExposureBean.getCreate_time_day());
return groupByFields;
}
public MlPreciseExposureBean leftJoinDimTable(MlPreciseExposureBean mlPreciseExposureBean, String field, Object dim) {
SimpleCacheService<String, Object> dimCityCache;
// CityInfo cityInfo = cityInfoCache.getValue(city_id, new CityCallable(city_id));
dimCityCache = new SimpleCacheService<>(2000, 24);
// dimCityCache.putValue(code, new DimCity(code, pk, name, memo));
// Object dimCity = dimCityCache.getValue(field, new DimCityCallable(field, "single"));
// mlPreciseExposureBean.setCityId2(cityInfo.getCity_id(),cityInfo.getId());
// BeanReflectUtil.setFieldValue(mlPreciseExposureBean, field, dimCity.getCode());
return mlPreciseExposureBean;
}
private ArrayList<DimCity> findAllCity() throws Exception{
String sinkJdbcUrl = "";
MysqlJdbcDim mysqlJdbcDim = MysqlJdbcDim.getInstance(sinkJdbcUrl);
Connection connection ;
// connection = mysqlJdbcDim.getConnection();
String sql = "select code, pk, name, memo from dim_city";
ArrayList<DimCity> dimCityList = new ArrayList<>();
ResultSet resultSet = null;
try {
resultSet = mysqlJdbcDim.query(sql);
while (resultSet.next()){
DimCity dim_city = new DimCity();
dim_city.setCode(resultSet.getString(0));
dim_city.setPk(resultSet.getString(1));
dim_city.setName(resultSet.getString(2));
dim_city.setMemo(resultSet.getString(3));
dimCityList.add(dim_city);
}
} catch (Exception e) {
e.printStackTrace();
}
resultSet.close();
return dimCityList;
}
@Test
public void flatmapMlPreciseExposureBeanTest() {
BlPreciseExposureEtl blPreciseExposureEtl = new BlPreciseExposureEtl();
MlPreciseExposureEtl mlPreciseExposureEtl = new MlPreciseExposureEtl();
// String json = "{\"create_at\":\"1575134961\",\"gm_nginx_timestamp\":1575134961.718,\"user_id\":\"31665831\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":\"0\",\"exposure_cards\":[{\"absolute_position\":\"0\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"0\",\"card_id\":2},{\"absolute_position\":\"1\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"1\",\"card_id\":2},{\"absolute_position\":\"2\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"2\",\"card_id\":2},{\"absolute_position\":\"3\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"3\",\"card_id\":2},{\"absolute_position\":\"4\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"4\",\"card_id\":2}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"is_exposure\":\"1\",\"referrer\":\"\",\"business_id\":\"\",\"referrer_id\":\"\"},\"app_session_id\":\"FE675C8B-4FD4-4FC6-9EC7-415F715A750B\",\"app\":{\"version\":\"7.18.2\",\"grey_type\":\"{\\\"report_result\\\":0,\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"post_detail\\\":\\\"0\\\",\\\"video_steep\\\":1,\\\"face_scan\\\":0}\",\"current_city_id\":\"nanjing\",\"name\":\"gengmei_user\",\"user_type\":{\"config_type\":1},\"serial_id\":12,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"5F193A07-781F-4EF1-86B4-452251307081\",\"sys_version\":\"13.2.3\",\"lng\":118.93133562169,\"is_WiFi\":\"0\",\"manufacturer\":\"Apple\",\"device_id\":\"F88745FE-DF54-4639-B7E2-28554C7DFAAF\",\"device_type\":\"ios\",\"ip\":\"10.190.42.125\",\"idfa\":\"F88745FE-DF54-4639-B7E2-28554C7DFAAF\",\"lat\":32.121287439102,\"model\":\"iPhone8,2\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"gm_nginx_key\":1,\"version\":\"205\",\"params\":{\"up_slide_times\":\"2\",\"down_loading_times\":\"0\",\"exposure_cards\":\"[{\\\"card_id\\\":\\\"16449302\\\",\\\"card_source_type\\\":\\\"doris\\\",\\\"card_content_type\\\":\\\"diary\\\",\\\"card_type\\\":\\\"card\\\",absolute_position\\\":\\\"0\\\",\\\"relative_position\\\":\\\"0\\\"}]\",\"up_loading_times\":\"0\",\"is_exposure\":\"1\",\"tab_name\":\"精选\",\"page_name\":\"home\",\"business_id\":\"\",\"referrer\":\"\",\"referrer_id\":\"\",\"down_slide_times\":\"1\"},\"app_session_id\":\"f3d24a27-27f0-4545-b132-51030765cf49\",\"gm_nginx_timestamp\":1546307958.444,\"create_at\":\"1546307958\",\"type\":\"home_choiceness_card_exposure\",\"device\":{\"is_WiFi\":\"1\",\"ip\":\"192.168.1.100\",\"manufacturer\":\"vivo\",\"device_type\":\"android\",\"lat\":\"0.0\",\"device_id\":\"863208034156179\",\"lng\":\"0.0\"},\"app\":{\"channel\":\"vivo\",\"user_type\":{\"config_type\":\"1\"},\"serial_id\":6,\"current_city_id\":\"worldwide\",\"name\":\"gengmei_user\",\"version\":\"7.7.36\"},\"user_id\":\"\"}";
String json = "{\"create_at\":\"1575135041\",\"gm_nginx_timestamp\":1575135040.498,\"user_id\":\"\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":6,\"is_exposure\":\"1\",\"exposure_cards\":[{\"absolute_position\":0,\"relative_position\":0,\"card_type\":\"card\",\"wiki_word\":[\"项目档案:1\",\"手术锦囊:2\",\"相近项目:3\"],\"card_content_type\":\"qa\",\"card_id\":\"7\"},{\"cpc_referer\":\"1\",\"relative_position\":0,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"answer\",\"card_id\":\"684889\"},{\"cpc_referer\":\"1\",\"relative_position\":1,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"answer\",\"card_id\":\"692624\"},{\"cpc_referer\":\"1\",\"relative_position\":2,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"user_post\",\"card_id\":66263},{\"cpc_referer\":\"1\",\"relative_position\":3,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":3,\"card_content_type\":\"user_post\",\"card_id\":70670},{\"cpc_referer\":\"1\",\"relative_position\":4,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":4,\"card_content_type\":\"diary\",\"card_id\":15329391},{\"cpc_referer\":\"1\",\"relative_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":5,\"card_content_type\":\"article\",\"card_id\":\"19507071\"},{\"cpc_referer\":\"1\",\"relative_position\":5,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":6,\"card_content_type\":\"answer\",\"card_id\":\"518138\"},{\"cpc_referer\":\"1\",\"relative_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":7,\"card_content_type\":\"answer\",\"card_id\":\"684319\"},{\"cpc_referer\":\"1\",\"relative_position\":5,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":8,\"card_content_type\":\"user_post\",\"card_id\":69002}],\"tab_name\":\"综合\",\"down_slide_times\":0,\"query\":\"纹眉\",\"filter\":\"\",\"referrer_id\":\"\",\"referrer\":\"search_home\",\"up_loading_times\":0,\"business_id\":\"\",\"page_name\":\"search_result_more\"},\"app_session_id\":\"424bcbcf-3b6e-4331-89b3-9fcd0c7bfbaf\",\"app\":{\"version\":\"7.18.4\",\"grey_type\":\"{\\\"video_steep\\\":1,\\\"post_detail\\\":\\\"0\\\",\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"face_scan\\\":0,\\\"report_result\\\":0}\",\"current_city_id\":\"chongqing\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":35,\"channel\":\"huawei\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_b49fb6a87b10bad0\",\"sys_version\":\"9\",\"lng\":\"106.618722\",\"is_WiFi\":\"0\",\"lat\":\"29.720561\",\"device_id\":\"861198041466947\",\"manufacturer\":\"HUAWEI\",\"net_type\":\"4G\",\"device_type\":\"android\",\"ip\":\"192.168.3.3\",\"model\":\"LYA-AL00\"},\"type\":\"page_precise_exposure\"}";
BlPreciseExposureBean blPreciseExposureBean = null;
ArrayList<MlPreciseExposureBean> mlPreciseExposureBeanList;
Boolean flag = null;
System.out.println(json);
try {
blPreciseExposureBean = blPreciseExposureEtl.mapBlPreciseExposureBean(json);
mlPreciseExposureBeanList = mlPreciseExposureEtl.flatmapMlPreciseExposureBean(blPreciseExposureBean);
for (MlPreciseExposureBean mlPreciseExposureBean : mlPreciseExposureBeanList) {
System.out.println(mlPreciseExposureBean.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.gmei.function;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.ml.MlPreciseExposureBean;
import org.junit.Test;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Stack;
public class BlPreciseExposureMapFunctionTest {
@Test
public void testMap() {
String json = "{\"create_at\":\"1577447031\",\"gm_nginx_timestamp\":1577447032.059,\"user_id\":\"\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":0,\"exposure_cards\":[{\"absolute_position\":0,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":1,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":2,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":3,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":4,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"target_name\":\"\",\"relative_position\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"gadget\",\"card_id\":923},{\"target_name\":\"眼部双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type \":\"新专题聚合\",\"card_id\":38},{\"target_name\":\"鼻部-双旦大促-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type \":\"新专题聚合\",\"card_id\":46},{\"absolute_position\":0,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":1,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":2,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":3,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":4,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"target_name\":\"\",\"relative_position\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"gadget\",\"card_id\":923},{\"target_name\":\"12.26社区\",\"relative_position\":0,\"transaction_type\":\"operation\",\"card_type\":\"card\",\"in_page_pos\":\"top\",\"card_content_type \":\"指定网页\",\"absolute_position\":3},{\"target_name\":\"吸脂填充-双旦\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":4,\"card_content_type \":\"新专题聚合\",\"card_id\":42},{\"target_name\":\"美肤三针双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":5,\"card_content_type \":\"新专题聚合\",\"card_id\":39},{\"target_name\":\"轮廓双旦banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":6,\"card_content_type \":\"新专题聚合\",\"card_id\":36},{\"target_name\":\"齿科-双旦大促-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":7,\"card_content_type \":\"新专题聚合\",\"card_id\":41}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"referrer_id\":\"\",\"referrer\":\"\",\"is_exposure\":\"1\",\"business_id\":\"\"},\"app_session_id\":\"168871fb-1471-43ac-b4da-e07009d88be7\",\"app\":{\"version\":\"7.19.2\",\"grey_type\":\"{\\\"video_steep\\\": 1, \\\"post_detail\\\": \\\"0\\\", \\\"face_detect_result\\\": \\\"B\\\", \\\"home\\\": \\\"0\\\", \\\"face_scan\\\": 0, \\\"report_result\\\": 0}\",\"current_city_id\":\"\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":31,\"channel\":\"yiba5202\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_80a2a60d59729bda\",\"sys_version\":\"8.0.0\",\"lng\":\"0.0\",\"is_WiFi\":\"0\",\"lat\":\"0.0\",\"device_id\":\"869712034003715\",\"manufacturer\":\"HUAWEI\",\"net_type\":\"4G\",\"device_type\":\"android\",\"ip\":\"10.138.25.16\",\"model\":\"LDN-AL20\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1576355745\",\"gm_nginx_timestamp\":1577283386.396,\"user_id\":\"30374524\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":\"0\",\"exposure_cards\":[{\"absolute_position\":\"0\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"0\",\"card_id\":2},{\"absolute_position\":\"0\",\"target_name\":\"\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"gadget\",\"relative_position\":\"\",\"card_id\":916},{\"absolute_position\":\"1\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"1\",\"card_id\":2},{\"target_name\":\"双12大促-主会场\",\"absolute_position\":\"1\",\"card_content_type\":\"指定网页\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"relative_position\":\"\",\"in_page_pos\":\"top\",\"card_id\":null},{\"absolute_position\":\"2\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"2\",\"card_id\":2},{\"absolute_position\":\"3\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"3\",\"card_id\":2},{\"absolute_position\":\"4\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"4\",\"card_id\":2}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"is_exposure\":\"1\",\"referrer\":\"\",\"business_id\":\"\",\"referrer_id\":\"\"},\"app_session_id\":\"386FA2C1-F140-408A-BC05-7085446D6A18\",\"app\":{\"name\":\"gengmei_user\",\"grey_type\":\"{\\\"report_result\\\":0,\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"post_detail\\\":\\\"0\\\",\\\"video_steep\\\":1,\\\"face_scan\\\":0}\",\"current_city_id\":\"weifang\",\"version\":\"7.19.1\",\"user_type\":{\"config_type\":1},\"serial_id\":1,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"D4BC83F7-82DE-42A2-8B51-61841D3572B4\",\"sys_version\":\"12.4.1\",\"lng\":0,\"is_WiFi\":\"1\",\"lat\":0,\"device_id\":\"D4BC83F7-82DE-42A2-8B51-61841D3572B4\",\"idfa\":\"00000000-0000-0000-0000-000000000000\",\"ip\":\"192.168.0.101\",\"device_type\":\"ios\",\"manufacturer\":\"Apple\",\"model\":\"iPhone10,2\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1576347089\",\"gm_nginx_timestamp\":1576347089.299,\"user_id\":\"31961883\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":5,\"exposure_cards\":{},\"tab_name\":\"service\",\"down_slide_times\":1,\"page_name\":\"category\",\"up_loading_times\":1,\"is_exposure\":\"1\",\"referrer\":\"home\",\"business_id\":\"9\",\"filter\":\"智能排序\",\"referrer_id\":\"\"},\"app_session_id\":\"0092AC31-EF72-44FF-AE1E-8BB6F8448A08\",\"app\":{\"version\":\"7.19.1\",\"grey_type\":\"{\\n \\\"report_result\\\" : 0,\\n \\\"face_detect_result\\\" : \\\"B\\\",\\n \\\"home\\\" : \\\"0\\\",\\n \\\"post_detail\\\" : \\\"0\\\",\\n \\\"video_steep\\\" : 0,\\n \\\"face_scan\\\" : 0\\n}\",\"current_city_id\":\"liuan\",\"name\":\"gengmei_user\",\"user_type\":{\"config_type\":1},\"serial_id\":28,\"channel\":\"App Store\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"51E1C5FD-B710-4820-91A6-E54C77AA4C60\",\"sys_version\":\"12.4.1\",\"lng\":116.48697900811,\"is_WiFi\":\"1\",\"manufacturer\":\"Apple\",\"device_id\":\"CD1187A7-091C-4497-96A3-A716BE510905\",\"device_type\":\"ios\",\"ip\":\"192.168.0.101\",\"idfa\":\"CD1187A7-091C-4497-96A3-A716BE510905\",\"lat\":31.757989657248,\"model\":\"iPhone10,1\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"app\":{\"user_type\":{\"config_type\":1},\"serial_id\":5,\"name\":\"gengmei_user\",\"channel\":\"App Store\",\"version\":\"7.7.40\",\"current_city_id\":\"beijin\n" +
// "g\"},\"app_session_id\":\"805E7CE4-0FB1-44E1-B32F-837B62D11D91\",\"gm_nginx_timestamp\":1576347092.686,\"user_id\":\"29105318\",\"gm_nginx_key\":1,\"creat\n" +
// "e_at\":\"1576347092\",\"params\":{\"exposure_cards\":{ },\"referrer\":\"\",\"referrer_id\":\"\",\"up_slide_times\":0,\"down_loading_times\":0,\"page_name\":\"home\"\n" +
// ",\"tab_name\":\"精选\",\"business_id\":\"\",\"up_loading_times\":0,\"down_slide_times\":0,\"is_exposure\":1},\"type\":\"home_choiceness_card_exposure\",\"versi\n" +
// "on\":\"110\",\"device\":{\"lng\":116.25638817524,\"device_id\":\"00DB1D03-3116-4084-AD86-0596EDFA2E3D\",\"is_WiFi\":\"1\",\"ip\":\"10.10.62.107\",\"idfa\":\"00DB1\n" +
// "D03-3116-4084-AD86-0596EDFA2E3D\",\"idfv\":\"1E6E56F7-3E3C-4F62-83EB-E9DBE7BC1AD1\",\"device_type\":\"ios\",\"lat\":40.073574956895,\"manufacturer\":\"Apple\"}}";
BlPreciseExposureMapFunction blPreciseExposureMapFunction = new BlPreciseExposureMapFunction();
MlpreciseExposureFlatMapFunction mlpreciseExposureFlatMapFunction = new MlpreciseExposureFlatMapFunction();
BlPreciseExposureBean blPreciseExposureBean = null;
try {
blPreciseExposureBean = blPreciseExposureMapFunction.map(json);
ArrayList<MlPreciseExposureBean> mlPreciseExposureBeanArrayList = mlpreciseExposureFlatMapFunction.flatmapBlPreciseExposure(blPreciseExposureBean);
for (MlPreciseExposureBean mlPreciseExposureBean : mlPreciseExposureBeanArrayList) {
System.out.println(mlPreciseExposureBean);
}
} catch (Exception e) {
e.printStackTrace();
}
// System.out.println(blPreciseExposureBean);
}
@Test
public void testReplace() {
// String json = "{\"{\n} \t\" }";
String json = "{\"create_at\":\"1576854504\",\"gm_nginx_timestamp\":1578502215.724,\"user_id\":\"\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":\"0\",\"exposure_cards\":[{\"absolute_position\":\"0\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"0\",\"card_id\":2},{\"absolute_position\":\"0\",\"target_name\":\"\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"gadget\",\"relative_position\":\"\",\"card_id\":923},{\"absolute_position\":\"1\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"1\",\"card_id\":2},{\"absolute_position\":\"2\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"2\",\"card_id\":2},{\"target_name\":\"鼻部-双旦大促-banner\",\"absolute_position\":\"2\",\"card_content_type \":\"新专题聚合\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"relative_position\":\"\",\"in_page_pos\":\"top\",\"card_id\":46},{\"absolute_position\":\"3\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"3\",\"card_id\":2},{\"absolute_position\":\"4\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"4\",\"card_id\":2}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"is_exposure\":\"1\",\"referrer\":\"\",\"business_id\":\"\",\"referrer_id\":\"\"},\"app_session_id\":\"CCA64F08-C9F1-47FE-87ED-2B2993ADD067\",\"app\":{\"name\":\"gengmei_user\",\"grey_type\":\"{\\n \\\"report_result\\\" : 0,\\n \\\"face_detect_result\\\" : \\\"B\\\",\\n \\\"home\\\" : \\\"0\\\",\\n \\\"post_detail\\\" : \\\"0\\\",\\n \\\"video_steep\\\" : 0,\\n \\\"face_scan\\\" : 0\\n}\",\"current_city_id\":\"worldwide\",\"version\":\"7.19.1\",\"user_type\":{\"config_type\":1},\"serial_id\":75,\"channel\":\"App Store\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"EB72DED5-75C3-410E-A759-388261BD232B\",\"sys_version\":\"13.3\",\"lng\":0,\"is_WiFi\":\"1\",\"manufacturer\":\"Apple\",\"device_id\":\"EB72DED5-75C3-410E-A759-388261BD232B\",\"lat\":0,\"ip\":\"192.168.0.167\",\"idfa\":\"00000000-0000-0000-0000-000000000000\",\"device_type\":\"ios\",\"model\":\"iPhone9,3\"},\"type\":\"page_precise_exposure\"}";
System.out.println(json);
// String jsonOnly = json.replace("\n", "").replace("\r","");
String jsonAll = json.replaceAll("\\s+|\\\\n", "");
// System.out.println(jsonOnly);
System.out.println("------------");
System.out.println(jsonAll);
}
@Test
public void testHex2Int() {
String hex = "356a192b7913b04c54574d18c28d46e6395428ab";
int number = 5;
number = number % 3;
System.out.println(number);
}
}
package com.gmei.kafka;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import java.util.*;
public class MyConsumer {
public static void main(String[] args) {
String topicName = "test";
String groupId = "group1";
//构造java.util.Properties对象
Properties props = new Properties();
// 必须指定属性。
props.put("bootstrap.servers", "localhost:9092");
// 必须指定属性。
props.put("group.id", groupId);
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
// 从最早的消息开始读取
props.put("auto.offset.reset", "earliest");
// 必须指定
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
// 必须指定
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
// 使用创建的Properties实例构造consumer实例
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
// 订阅topic。调用kafkaConsumer.subscribe方法订阅consumer group所需的topic列表
consumer.subscribe(Arrays.asList(topicName));
try {
while (true) {
//循环调用kafkaConsumer.poll方法获取封装在ConsumerRecord的topic消息。
ConsumerRecords<String, String> records = consumer.poll(1000);
//获取到封装在ConsumerRecords消息以后,处理获取到ConsumerRecord对象。
for (ConsumerRecord<String, String> record : records) {
//简单的打印输出
System.out.println(
"offset = " + record.offset()
+ ",key = " + record.key()
+ ",value =" + record.value());
}
}
} catch (Exception e) {
//关闭kafkaConsumer
System.out.println("消息消费结束......");
consumer.close();
}
System.out.println("关闭消费者......");
}
}
package com.gmei.kafka;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
public class MyProducter {
public static void main(String[] args) {
// 构造一个java.util.Properties对象
Properties props = new Properties();
// 指定bootstrap.servers属性。必填,无默认值。用于创建向kafka broker服务器的连接。
props.put("bootstrap.servers", "localhost:9092");
// 指定key.serializer属性。必填,无默认值。被发送到broker端的任何消息的格式都必须是字节数组。
// 因此消息的各个组件都必须首先做序列化,然后才能发送到broker。该参数就是为消息的key做序列化只用的。
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
// 指定value.serializer属性。必填,无默认值。和key.serializer类似。此被用来对消息体即消息value部分做序列化。
// 将消息value部分转换成字节数组。
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
//acks参数用于控制producer生产消息的持久性(durability)。参数可选值,0、1、-1(all)。
props.put("acks", "-1");
//props.put(ProducerConfig.ACKS_CONFIG, "1");
//在producer内部自动实现了消息重新发送。默认值0代表不进行重试。
props.put("retries", 3);
//props.put(ProducerConfig.RETRIES_CONFIG, 3);
//调优producer吞吐量和延时性能指标都有非常重要作用。默认值16384即16KB。
props.put("batch.size", 16384);
// props.put("batch.size", 323840);
//props.put(ProducerConfig.BATCH_SIZE_CONFIG, 323840);
//控制消息发送延时行为的,该参数默认值是0。表示消息需要被立即发送,无须关系batch是否被填满。
// props.put("linger.ms", 10);
props.put("linger.ms", 0);
//props.put(ProducerConfig.LINGER_MS_CONFIG, 10);
//指定了producer端用于缓存消息的缓冲区的大小,单位是字节,默认值是33554432即32M。
props.put("buffer.memory", 16384);
// props.put("buffer.memory", 33554432);
//props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, 33554432);
props.put("max.block.ms", 1000);
// props.put("max.block.ms", 3000);
//props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 3000);
//设置producer段是否压缩消息,默认值是none。即不压缩消息。GZIP、Snappy、LZ4
//props.put("compression.type", "none");
//props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "none");
//该参数用于控制producer发送请求的大小。producer端能够发送的最大消息大小。
//props.put("max.request.size", 10485760);
//props.put(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, 10485760);
//producer发送请求给broker后,broker需要在规定时间范围内将处理结果返还给producer。默认30s
//props.put("request.timeout.ms", 60000);
//props.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 60000);
// Properties props = new Properties();
// props.setProperty("metadata.broker.list","10.10.10.100:9090");
// props.setProperty("serializer.class","kafka.serializer.StringEncoder");
// props.put("request.required.acks","1");
// ProducerConfig config = new ProducerConfig(props);
//创建生产这对象
Producer<String, String> producer = new KafkaProducer<String, String>(props);
String json = "{\"create_at\":\"1579242641\",\"gm_nginx_timestamp\":1579242640.509,\"user_id\":\"\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_exposure\":\"1\",\"up_loading_times\":0,\"referrer_link\":[\"home\",\"search_home\"],\"tab_name\":\"综合\",\"down_slide_times\":0,\"query\":\"腹݄製¥FxGo6d9bEuoXH5IXDhEW¥\uD83D\uDC50開˙\uD83D\uDC49【Fаceu】\uD83D\uDC48,就能送我一张“发”卡,急急急!快来㠍佧,有机会额外得10000元葒枹\uD83E\uDDE7️,除夕再分5亿奨鑫\uD83D\uDCB0!\",\"filter\":\"\",\"referrer_id\":\"\",\"referrer\":\"search_home\",\"business_id\":\"\",\"page_name\":\"search_result_more\",\"exposure_cards\":[{\"cpc_referer\":\"1\",\"relative_position\":0,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"answer\",\"card_id\":\"517789\"},{\"cpc_referer\":\"1\",\"relative_position\":1,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"answer\",\"card_id\":\"541639\"},{\"cpc_referer\":\"1\",\"relative_position\":2,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"diary\",\"card_id\":16858137},{\"is_cpc\":1,\"result_status\":\"1\",\"card_id\":\"5856326\",\"cpc_referer\":\"2\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"relative_position\":0,\"card_content_type\":\"service\",\"absolute_position\":0},{\"is_cpc\":0,\"result_status\":\"1\",\"card_id\":\"5820784\",\"cpc_referer\":\"2\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"relative_position\":0,\"card_content_type\":\"service\",\"absolute_position\":0},{\"is_cpc\":1,\"result_status\":\"1\",\"card_id\":\"5776196\",\"cpc_referer\":\"2\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"relative_position\":0,\"card_content_type\":\"service\",\"absolute_position\":1},{\"is_cpc\":0,\"result_status\":\"1\",\"card_id\":\"5825049\",\"cpc_referer\":\"2\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"relative_position\":0,\"card_content_type\":\"service\",\"absolute_position\":1}]},\"app_session_id\":\"1e75a090-15a9-4ba5-81c0-c124adc7e752\",\"app\":{\"version\":\"7.22.1\",\"grey_type\":\"{\\\"post_detail\\\": \\\"0\\\", \\\"search_gray\\\": false, \\\"search_result_welfare\\\": false, \\\"face_detect_result\\\": \\\"B\\\", \\\"home\\\": \\\"0\\\", \\\"face_scan\\\": 0, \\\"launch_gray\\\": false, \\\"video_steep\\\": 1, \\\"report_result\\\": 0}\",\"current_city_id\":\"xianning\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":52,\"channel\":\"vivo\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_cf3ae256f301e962\",\"sys_version\":\"8.1.0\",\"lng\":\"114.060301\",\"is_WiFi\":\"1\",\"lat\":\"29.534923\",\"device_id\":\"866934039264497\",\"manufacturer\":\"vivo\",\"net_type\":\"wifi\",\"device_type\":\"android\",\"ip\":\"192.168.1.2\",\"model\":\"vivo X20A\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1576854504\",\"gm_nginx_timestamp\":1579165739.724,\"user_id\":\"\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":\"0\",\"exposure_cards\":[{\"absolute_position\":\"0\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"0\",\"card_id\":2},{\"absolute_position\":\"0\",\"target_name\":\"\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"gadget\",\"relative_position\":\"\",\"card_id\":923},{\"absolute_position\":\"1\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"1\",\"card_id\":2},{\"absolute_position\":\"2\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"2\",\"card_id\":2},{\"target_name\":\"鼻部-双旦大促-banner\",\"absolute_position\":\"2\",\"card_content_type \":\"新专题聚合\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"relative_position\":\"\",\"in_page_pos\":\"top\",\"card_id\":46},{\"absolute_position\":\"3\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"3\",\"card_id\":2},{\"absolute_position\":\"4\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"4\",\"card_id\":2}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"is_exposure\":\"1\",\"referrer\":\"\",\"business_id\":\"\",\"referrer_id\":\"\"},\"app_session_id\":\"CCA64F08-C9F1-47FE-87ED-2B2993ADD067\",\"app\":{\"name\":\"gengmei_user\",\"grey_type\":\"{\\n \\\"report_result\\\" : 0,\\n \\\"face_detect_result\\\" : \\\"B\\\",\\n \\\"home\\\" : \\\"0\\\",\\n \\\"post_detail\\\" : \\\"0\\\",\\n \\\"video_steep\\\" : 0,\\n \\\"face_scan\\\" : 0\\n}\",\"current_city_id\":\"worldwide\",\"version\":\"7.19.1\",\"user_type\":{\"config_type\":1},\"serial_id\":75,\"channel\":\"App Store\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"EB72DED5-75C3-410E-A759-388261BD232B\",\"sys_version\":\"13.3\",\"lng\":0,\"is_WiFi\":\"1\",\"manufacturer\":\"Apple\",\"device_id\":\"EB72DED5-75C3-410E-A759-388261BD232B\",\"lat\":0,\"ip\":\"192.168.0.167\",\"idfa\":\"00000000-0000-0000-0000-000000000000\",\"device_type\":\"ios\",\"model\":\"iPhone9,3\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1578102778\",\"gm_nginx_timestamp\":1578102780.541,\"user_id\":\"32085659\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"business_id\":\"\",\"exposure_cards\":[{\"is_cpc\":1,\"result_status\":\"1\",\"card_id\":\"5754050\",\"absolute_position\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"relative_position\":0,\"card_content_type\":\"service\",\"cpc_referer\":\"0\"},{\"is_cpc\":1,\"result_status\":\"1\",\"card_id\":\"5760019\",\"absolute_position\":1,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"relative_position\":1,\"card_content_type\":\"service\",\"cpc_referer\":\"0\"},{\"is_cpc\":1,\"result_status\":\"1\",\"card_id\":\"5833115\",\"absolute_position\":2,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"relative_position\":2,\"card_content_type\":\"service\",\"cpc_referer\":\"0\"}],\"up_loading_times\":0,\"referrer_link\":[\"home\",\"search_home\"],\"tab_name\":\"美购\",\"down_slide_times\":0,\"query\":\"眼综合\",\"filter\":\"综合排序\",\"is_exposure\":\"1\",\"referrer\":\"search_result_more\",\"up_slide_times\":0,\"referrer_id\":\"\",\"page_name\":\"search_result_welfare\"},\"app_session_id\":\"dc92c61b-f9bf-4378-8ca1-e6c0d9bee116\",\"app\":{\"version\":\"7.20.1\",\"grey_type\":\"{\\\"video_steep\\\":0,\\\"post_detail\\\":\\\"0\\\",\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"face_scan\\\":0,\\\"report_result\\\":0}\",\"current_city_id\":\"jincheng\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":25,\"channel\":\"oppo\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_c60514a82b1f4f68\",\"sys_version\":\"7.1.1\",\"lng\":\"112.31146\",\"is_WiFi\":\"0\",\"lat\":\"35.622659\",\"device_id\":\"861271049370690\",\"manufacturer\":\"OPPO\",\"net_type\":\"4G\",\"device_type\":\"android\",\"ip\":\"10.102.127.227\",\"model\":\"OPPOA83\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1577447031\",\"gm_nginx_timestamp\":1577447032.059,\"user_id\":\"\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":0,\"exposure_cards\":[{\"absolute_position\":0,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":1,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":2,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":3,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":4,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"target_name\":\"\",\"relative_position\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"gadget\",\"card_id\":923},{\"target_name\":\"眼部双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type \":\"新专题聚合\",\"card_id\":38},{\"target_name\":\"鼻部-双旦大促-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type \":\"新专题聚合\",\"card_id\":46},{\"absolute_position\":0,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":1,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":2,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":3,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"absolute_position\":4,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":1},{\"target_name\":\"\",\"relative_position\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"gadget\",\"card_id\":923},{\"target_name\":\"12.26社区\",\"relative_position\":0,\"transaction_type\":\"operation\",\"card_type\":\"card\",\"in_page_pos\":\"top\",\"card_content_type \":\"指定网页\",\"absolute_position\":3},{\"target_name\":\"吸脂填充-双旦\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":4,\"card_content_type \":\"新专题聚合\",\"card_id\":42},{\"target_name\":\"美肤三针双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":5,\"card_content_type \":\"新专题聚合\",\"card_id\":39},{\"target_name\":\"轮廓双旦banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":6,\"card_content_type \":\"新专题聚合\",\"card_id\":36},{\"target_name\":\"齿科-双旦大促-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":7,\"card_content_type \":\"新专题聚合\",\"card_id\":41}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"referrer_id\":\"\",\"referrer\":\"\",\"is_exposure\":\"1\",\"business_id\":\"\"},\"app_session_id\":\"168871fb-1471-43ac-b4da-e07009d88be7\",\"app\":{\"version\":\"7.19.2\",\"grey_type\":\"{\\\"video_steep\\\": 1, \\\"post_detail\\\": \\\"0\\\", \\\"face_detect_result\\\": \\\"B\\\", \\\"home\\\": \\\"0\\\", \\\"face_scan\\\": 0, \\\"report_result\\\": 0}\",\"current_city_id\":\"\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":31,\"channel\":\"yiba5202\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_80a2a60d59729bda\",\"sys_version\":\"8.0.0\",\"lng\":\"0.0\",\"is_WiFi\":\"0\",\"lat\":\"0.0\",\"device_id\":\"869712034003715\",\"manufacturer\":\"HUAWEI\",\"net_type\":\"4G\",\"device_type\":\"android\",\"ip\":\"10.138.25.16\",\"model\":\"LDN-AL20\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1577364648\",\"gm_nginx_timestamp\":1577364646.542,\"user_id\":\"\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":0,\"exposure_cards\":[{\"absolute_position\":0,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":2},{\"absolute_position\":1,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":2},{\"absolute_position\":2,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":2},{\"absolute_position\":3,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":2},{\"absolute_position\":4,\"transaction_type\":\"\",\"relative_position\":0,\"card_content_type\":\"function_entrance\",\"card_id\":2},{\"target_name\":\"\",\"relative_position\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"gadget\",\"card_id\":923},{\"target_name\":\"12月新人专场\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"福利专题列表\",\"card_id\":6377},{\"target_name\":\"双旦大促-主会场-华西\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"福利专题列表\",\"card_id\":6565},{\"target_name\":\"眼部双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"新专题聚合\",\"card_id\":38},{\"target_name\":\"鼻部-双旦大促-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":3,\"card_content_type\":\"新专题聚合\",\"card_id\":46},{\"target_name\":\"12.26社区\",\"relative_position\":0,\"transaction_type\":\"operation\",\"card_type\":\"card\",\"in_page_pos\":\"top\",\"card_content_type\":\"指定网页\",\"absolute_position\":4},{\"target_name\":\"吸脂填充-双旦\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":5,\"card_content_type\":\"新专题聚合\",\"card_id\":42},{\"target_name\":\"美肤三针双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":6,\"card_content_type\":\"新专题聚合\",\"card_id\":39},{\"target_name\":\"轮廓双旦banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":7,\"card_content_type\":\"新专题聚合\",\"card_id\":36},{\"target_name\":\"12月新人专场\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"福利专题列表\",\"card_id\":6377},{\"target_name\":\"双旦大促-主会场-华西\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"福利专题列表\",\"card_id\":6565},{\"target_name\":\"眼部双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"新专题聚合\",\"card_id\":38},{\"target_name\":\"鼻部-双旦大促-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":3,\"card_content_type\":\"新专题聚合\",\"card_id\":46},{\"target_name\":\"12.26社区\",\"relative_position\":0,\"transaction_type\":\"operation\",\"card_type\":\"card\",\"in_page_pos\":\"top\",\"card_content_type\":\"指定网页\",\"absolute_position\":4},{\"target_name\":\"吸脂填充-双旦\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":5,\"card_content_type\":\"新专题聚合\",\"card_id\":42},{\"target_name\":\"美肤三针双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":6,\"card_content_type\":\"新专题聚合\",\"card_id\":39},{\"target_name\":\"轮廓双旦banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":7,\"card_content_type\":\"新专题聚合\",\"card_id\":36},{\"target_name\":\"12月新人专场\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"福利专题列表\",\"card_id\":6377},{\"target_name\":\"双旦大促-主会场-华西\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"福利专题列表\",\"card_id\":6565},{\"target_name\":\"眼部双旦-banner\",\"relative_position\":0,\"in_page_pos\":\"top\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"新专题聚合\",\"card_id\":38}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"referrer_id\":\"\",\"referrer\":\"\",\"is_exposure\":\"1\",\"business_id\":\"\"},\"app_session_id\":\"6d167db8-147d-4ded-b7a8-0d9f176f91a1\",\"app\":{\"version\":\"7.19.2\",\"grey_type\":\"unknown\",\"current_city_id\":\"chongqing\",\"user_type\":{},\"name\":\"gengmei_user\",\"serial_id\":1,\"channel\":\"huawei\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_99a0301553dc4f12\",\"sys_version\":\"10\",\"lng\":\"106.56958\",\"is_WiFi\":\"1\",\"lat\":\"29.680635\",\"device_id\":\"864674045613095\",\"manufacturer\":\"HUAWEI\",\"net_type\":\"wifi\",\"device_type\":\"android\",\"ip\":\"192.168.0.100\",\"model\":\"VOG-AL00\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1577324083\",\"gm_nginx_timestamp\":1577324083.74,\"user_id\":\"32339790\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":13,\"exposure_cards\":[{\"absolute_position\":\"23\",\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":\"0\",\"card_id\":\"689089\"},{\"absolute_position\":\"26\",\"transaction_type\":\"\",\"relative_position\":\"3\",\"card_content_type\":\"search_query\",\"in_page_pos\":\"related_search\",\"card_id\":[\"注射美容\",\"硅胶丰额头\",\"祛颊脂垫\",\"胶原蛋白填充垫下巴\",\"面部不对称改善\",\"膨体丰额头\"]},{\"absolute_position\":\"27\",\"cpc_referer\":1,\"relative_position\":\"1\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"is_cpc\":0,\"card_content_type\":\"diary\",\"card_id\":15804523},{\"absolute_position\":\"28\",\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"article\",\"relative_position\":\"2\",\"card_id\":\"19514087\"},{\"absolute_position\":\"29\",\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":\"3\",\"card_id\":\"696977\"},{\"absolute_position\":\"30\",\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":\"4\",\"card_id\":\"686606\"},{\"absolute_position\":\"33\",\"cpc_referer\":1,\"relative_position\":\"4\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"is_cpc\":0,\"card_content_type\":\"diary\",\"card_id\":15965971},{\"absolute_position\":\"34\",\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"article\",\"relative_position\":\"2\",\"card_id\":\"19515896\"},{\"absolute_position\":\"35\",\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":\"3\",\"card_id\":\"700587\"},{\"absolute_position\":\"36\",\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":\"4\",\"card_id\":\"700403\"},{\"absolute_position\":\"39\",\"transaction_type\":\"\",\"relative_position\":\"3\",\"card_content_type\":\"search_query\",\"in_page_pos\":\"related_search\",\"card_id\":[\"长下巴矫正\",\"激光溶脂瘦脸\",\"额头\",\"人工骨垫下巴\",\"下巴截骨前移\",\"玻尿酸丰耳垂\"]},{\"absolute_position\":\"40\",\"cpc_referer\":1,\"relative_position\":\"4\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"is_cpc\":0,\"card_content_type\":\"diary\",\"card_id\":15953555}],\"tab_name\":\"综合\",\"down_slide_times\":1,\"query\":\"瘦脸针\",\"up_loading_times\":1,\"is_exposure\":\"1\",\"referrer\":\"search_home\",\"business_id\":\"\",\"page_name\":\"search_result_more\",\"referrer_id\":\"\"},\"app_session_id\":\"5A18488E-0965-45EE-B35A-BE82266B785B\",\"app\":{\"version\":\"7.19.1\",\"grey_type\":\"{\\\"report_result\\\":0,\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"post_detail\\\":\\\"0\\\",\\\"video_steep\\\":1,\\\"face_scan\\\":0}\",\"current_city_id\":\"qingdao\",\"name\":\"gengmei_user\",\"user_type\":{\"config_type\":1},\"serial_id\":14,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"F7B0BC42-DCDD-4AE8-A0A1-C205233A94A4\",\"sys_version\":\"12.4\",\"lng\":120.38120711884,\"is_WiFi\":\"0\",\"manufacturer\":\"Apple\",\"device_id\":\"BD96C788-434E-46EB-898C-DF2941882425\",\"device_type\":\"ios\",\"ip\":\"10.171.24.14\",\"idfa\":\"BD96C788-434E-46EB-898C-DF2941882425\",\"lat\":36.08928448005,\"model\":\"iPhone11,6\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1577275915\",\"gm_nginx_timestamp\":1577275916.509,\"user_id\":\"32368787\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_exposure\":\"1\",\"exposure_cards\":[{\"absolute_position\":0,\"transaction_type\":\"\",\"card_type\":\"card\",\"relative_position\":0,\"card_content_type\":\"banner\",\"card_id\":\"\"},{\"cpc_referer\":\"2\",\"relative_position\":0,\"absolute_position\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"service\",\"result_status\":\"1\",\"card_id\":\"5785839\"},{\"cpc_referer\":\"2\",\"relative_position\":0,\"absolute_position\":1,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"service\",\"result_status\":\"1\",\"card_id\":\"5785492\"},{\"cpc_referer\":\"2\",\"relative_position\":0,\"absolute_position\":2,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"service\",\"result_status\":\"1\",\"card_id\":\"5742979\"},{\"cpc_referer\":\"2\",\"relative_position\":0,\"absolute_position\":3,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"service\",\"result_status\":\"1\",\"card_id\":\"5750757\"},{\"cpc_referer\":\"1\",\"relative_position\":0,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"answer\",\"card_id\":\"332510\"},{\"cpc_referer\":\"1\",\"relative_position\":1,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"answer\",\"card_id\":\"307094\"},{\"cpc_referer\":\"1\",\"relative_position\":2,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"user_post\",\"card_id\":70366}],\"tab_name\":\"综合\",\"down_slide_times\":0,\"query\":\"魔镜\",\"filter\":\"\",\"referrer_id\":\"\",\"referrer\":\"search_home\",\"up_loading_times\":0,\"business_id\":\"\",\"page_name\":\"search_result_more\"},\"app_session_id\":\"7c55ad0f-a0a8-46c8-ad21-bd9f3f12449f\",\"app\":{\"version\":\"7.19.2\",\"grey_type\":\"{\\\"video_steep\\\":0,\\\"post_detail\\\":\\\"0\\\",\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"face_scan\\\":0,\\\"report_result\\\":0}\",\"current_city_id\":\"xining\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":32,\"channel\":\"guangdiantongand05\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_2117151825754036\",\"sys_version\":\"9\",\"lng\":\"101.689229\",\"is_WiFi\":\"1\",\"lat\":\"36.944768\",\"device_id\":\"865787042243564\",\"manufacturer\":\"Xiaomi\",\"net_type\":\"wifi\",\"device_type\":\"android\",\"ip\":\"192.168.0.10\",\"model\":\"RedmiNote7Pro\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1576355745\",\"gm_nginx_timestamp\":1577283386.396,\"user_id\":\"30374524\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":0,\"is_popup\":\"0\",\"exposure_cards\":[{\"absolute_position\":\"0\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"0\",\"card_id\":2},{\"absolute_position\":\"0\",\"target_name\":\"\",\"transaction_type\":\"-1\",\"card_type\":\"card\",\"card_content_type\":\"gadget\",\"relative_position\":\"\",\"card_id\":916},{\"absolute_position\":\"1\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"1\",\"card_id\":2},{\"target_name\":\"双12大促-主会场\",\"absolute_position\":\"1\",\"card_content_type\":\"指定网页\",\"transaction_type\":\"operation\",\"card_type\":\"card\",\"relative_position\":\"\",\"in_page_pos\":\"top\",\"card_id\":null},{\"absolute_position\":\"2\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"2\",\"card_id\":2},{\"absolute_position\":\"3\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"3\",\"card_id\":2},{\"absolute_position\":\"4\",\"transaction_type\":\"\",\"card_content_type\":\"function_entrance\",\"relative_position\":\"4\",\"card_id\":2}],\"tab_name\":\"\",\"down_slide_times\":0,\"page_name\":\"home\",\"up_loading_times\":0,\"is_exposure\":\"1\",\"referrer\":\"\",\"business_id\":\"\",\"referrer_id\":\"\"},\"app_session_id\":\"386FA2C1-F140-408A-BC05-7085446D6A18\",\"app\":{\"name\":\"gengmei_user\",\"grey_type\":\"{\\\"report_result\\\":0,\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"post_detail\\\":\\\"0\\\",\\\"video_steep\\\":1,\\\"face_scan\\\":0}\",\"current_city_id\":\"weifang\",\"version\":\"7.19.1\",\"user_type\":{\"config_type\":1},\"serial_id\":1,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"D4BC83F7-82DE-42A2-8B51-61841D3572B4\",\"sys_version\":\"12.4.1\",\"lng\":0,\"is_WiFi\":\"1\",\"lat\":0,\"device_id\":\"D4BC83F7-82DE-42A2-8B51-61841D3572B4\",\"idfa\":\"00000000-0000-0000-0000-000000000000\",\"ip\":\"192.168.0.101\",\"device_type\":\"ios\",\"manufacturer\":\"Apple\",\"model\":\"iPhone10,2\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1576128422\",\"gm_nginx_timestamp\":1576128422.463,\"user_id\":\"31038796\",\"version\":\"110\",\"params\":{\"down_loading_times\":1,\"up_slide_times\":5,\"exposure_cards\":[{\"absolute_position\":0,\"result_status\":\"1\",\"card_content_type\":\"service\",\"transaction_type\":\"[\\\"-1\\\",\\\"-1\\\",\\\"-1\\\"]\",\"card_type\":\"card\",\"card_source_type\":\"[\\\"\\\",\\\"\\\",\\\"\\\"]\",\"relative_position\":0,\"card_id\":\"[\\\"5821997\\\",\\\"5762189\\\",\\\"5671097\\\"]\"},{\"absolute_position\":1,\"card_content_type\":\"wiki_collect\",\"card_type\":\"card\",\"relative_position\":1,\"wiki_word\":{},\"card_id\":\"127\"},{\"absolute_position\":2,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":3,\"card_id\":\"15337295\"},{\"absolute_position\":3,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":4,\"card_id\":\"15635897\"},{\"absolute_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"16082820\"},{\"absolute_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"16082820\"},{\"absolute_position\":5,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":4,\"card_id\":\"699299\"},{\"absolute_position\":6,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"article\",\"relative_position\":5,\"card_id\":\"19589790\"},{\"absolute_position\":7,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":6,\"card_id\":\"15764401\"},{\"absolute_position\":8,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":4,\"card_id\":\"15633799\"},{\"absolute_position\":9,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"16622540\"},{\"absolute_position\":10,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":6,\"card_id\":\"699573\"},{\"absolute_position\":11,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":4,\"card_id\":\"686812\"},{\"absolute_position\":12,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":5,\"card_id\":\"15328675\"},{\"absolute_position\":13,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"diary\",\"relative_position\":6,\"card_id\":\"11201557\"},{\"absolute_position\":14,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":4,\"card_id\":\"700888\"},{\"absolute_position\":15,\"transaction_type\":\"\",\"card_type\":\"card\",\"card_content_type\":\"answer\",\"relative_position\":5,\"card_id\":\"706569\"}],\"tab_name\":\"综合\",\"down_slide_times\":8,\"query\":\"玻尿酸\",\"up_loading_times\":0,\"is_exposure\":1,\"referrer\":\"search_home\",\"business_id\":\"\",\"page_name\":\"search_result_more\",\"referrer_id\":\"\"},\"app_session_id\":\"559D8BA2-7FC1-402C-BB12-F860EFA26925\",\"app\":{\"user_type\":{\"config_type\":1},\"current_city_id\":\"chengdu\",\"version\":\"7.7.60\",\"name\":\"gengmei_user\",\"serial_id\":14,\"channel\":\"AppStore\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"CD8D7E3B-B833-49EE-B509-6B9F1B3963B9\",\"lng\":104.07933463616,\"is_WiFi\":\"0\",\"manufacturer\":\"Apple\",\"ip\":\"10.187.49.153\",\"device_id\":\"4A0275C1-4734-404A-93DD-BAA272401A27\",\"device_type\":\"ios\",\"lat\":30.654052050073,\"idfa\":\"4A0275C1-4734-404A-93DD-BAA272401A27\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1575135041\",\"gm_nginx_timestamp\":1575135040.498,\"user_id\":\"\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":6,\"is_exposure\":\"1\",\"exposure_cards\":[{\"absolute_position\":0,\"relative_position\":0,\"card_type\":\"card\",\"wiki_word\":[\"项目档案:1\",\"手术锦囊:2\",\"相近项目:3\"],\"card_content_type\":\"wiki_item\",\"card_id\":\"7\"},{\"cpc_referer\":\"1\",\"relative_position\":0,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"answer\",\"card_id\":\"684889\"},{\"cpc_referer\":\"1\",\"relative_position\":1,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"answer\",\"card_id\":\"692624\"},{\"cpc_referer\":\"1\",\"relative_position\":2,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"user_post\",\"card_id\":66263},{\"cpc_referer\":\"1\",\"relative_position\":3,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":3,\"card_content_type\":\"user_post\",\"card_id\":66263},{\"cpc_referer\":\"1\",\"relative_position\":4,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":4,\"card_content_type\":\"diary\",\"card_id\":15329391},{\"cpc_referer\":\"1\",\"relative_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":5,\"card_content_type\":\"article\",\"card_id\":\"19507071\"},{\"cpc_referer\":\"1\",\"relative_position\":5,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":6,\"card_content_type\":\"answer\",\"card_id\":\"518138\"},{\"cpc_referer\":\"1\",\"relative_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":7,\"card_content_type\":\"answer\",\"card_id\":\"684319\"},{\"cpc_referer\":\"1\",\"relative_position\":5,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":8,\"card_content_type\":\"user_post\",\"card_id\":69002}],\"tab_name\":\"综合\",\"down_slide_times\":0,\"query\":\"纹眉\",\"filter\":\"\",\"referrer_id\":\"\",\"referrer\":\"search_home\",\"up_loading_times\":0,\"business_id\":\"\",\"page_name\":\"search_result_more\"},\"app_session_id\":\"424bcbcf-3b6e-4331-89b3-9fcd0c7bfbaf\",\"app\":{\"version\":\"7.18.4\",\"grey_type\":\"{\\\"video_steep\\\":1,\\\"post_detail\\\":\\\"0\\\",\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"face_scan\\\":0,\\\"report_result\\\":0}\",\"current_city_id\":\"chongqing\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":35,\"channel\":\"huawei\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_b49fb6a87b10bad0\",\"sys_version\":\"9\",\"lng\":\"106.618722\",\"is_WiFi\":\"0\",\"lat\":\"29.720561\",\"device_id\":\"861198041466947\",\"manufacturer\":\"HUAWEI\",\"net_type\":\"4G\",\"device_type\":\"android\",\"ip\":\"192.168.3.3\",\"model\":\"LYA-AL00\"},\"type\":\"page_precise_exposure\"}";
//生成消息
try {
boolean flag = true;
while (flag) {
//发送消息
// producer.send(new ProducerRecord<String, String>("test", Integer.toString(1), Integer.toString(2)));
// String message=getDate("dim_sigtyp","seqnum","code","name");
// KeyedMessage<String, String> data = new KeyedMessage<String, String>("test3",message);
// 构造待发送的消息对象ProduceRecord的对象,指定消息要发送到的topic主题,分区以及对应的key和value键值对。
// 注意,分区和key信息可以不用指定,由kafka自行确定目标分区。
// ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>("test",
// Integer.toString("row"), Integer.toString("{\"@raw\":\"{\\\"create_at\\\":\\\"1575129599\\\",\\\"gm_nginx_timestamp\\\":1575129600.382,\\\"user_id\\\":\\\"\\\",\\\"version\\\":\\\"147\\\",\\\"params\\\":{\\\"down_loading_times\\\":0,\\\"up_slide_times\\\":0,\\\"is_popup\\\":0,\\\"exposure_cards\\\":[{\\\"absolute_position\\\":0,\\\"transaction_type\\\":\\\"\\\",\\\"relative_position\\\":0,\\\"card_content_type\\\":\\\"function_entrance\\\",\\\"card_id\\\":1},{\\\"absolute_position\\\":1,\\\"transaction_type\\\":\\\"\\\",\\\"relative_position\\\":0,\\\"card_content_type\\\":\\\"function_entrance\\\",\\\"card_id\\\":1},{\\\"absolute_position\\\":2,\\\"transaction_type\\\":\\\"\\\",\\\"relative_position\\\":0,\\\"card_content_type\\\":\\\"function_entrance\\\",\\\"card_id\\\":1},{\\\"absolute_position\\\":3,\\\"transaction_type\\\":\\\"\\\",\\\"relative_position\\\":0,\\\"card_content_type\\\":\\\"function_entrance\\\",\\\"card_id\\\":1},{\\\"absolute_position\\\":4,\\\"transaction_type\\\":\\\"\\\",\\\"relative_position\\\":0,\\\"card_content_type\\\":\\\"function_entrance\\\",\\\"card_id\\\":1}],\\\"tab_name\\\":\\\"\\\",\\\"down_slide_times\\\":0,\\\"page_name\\\":\\\"home\\\",\\\"up_loading_times\\\":0,\\\"referrer_id\\\":\\\"\\\",\\\"referrer\\\":\\\"\\\",\\\"is_exposure\\\":\\\"1\\\",\\\"business_id\\\":\\\"\\\"},\\\"app_session_id\\\":\\\"cb2cf436-183a-4f4c-a3ac-0f8f54759f37\\\",\\\"app\\\":{\\\"version\\\":\\\"7.19.0\\\",\\\"grey_type\\\":\\\"{\\\\\\\"video_steep\\\\\\\": 0, \\\\\\\"post_detail\\\\\\\": \\\\\\\"0\\\\\\\", \\\\\\\"face_detect_result\\\\\\\": \\\\\\\"B\\\\\\\", \\\\\\\"home\\\\\\\": \\\\\\\"0\\\\\\\", \\\\\\\"face_scan\\\\\\\": 0, \\\\\\\"report_result\\\\\\\": 0}\\\",\\\"current_city_id\\\":\\\"zibo\\\",\\\"user_type\\\":{\\\"config_type\\\":\\\"1\\\"},\\\"name\\\":\\\"gengmei_user\\\",\\\"serial_id\\\":14,\\\"channel\\\":\\\"xiaomi\\\"},\\\"gm_nginx_key\\\":1,\\\"device\\\":{\\\"android_device_id\\\":\\\"androidid_e645aab7a96734d6\\\",\\\"sys_version\\\":\\\"9\\\",\\\"lng\\\":\\\"117.901306\\\",\\\"is_WiFi\\\":\\\"0\\\",\\\"lat\\\":\\\"36.658066\\\",\\\"device_id\\\":\\\"863976043011292\\\",\\\"manufacturer\\\":\\\"Xiaomi\\\",\\\"net_type\\\":\\\"4G\\\",\\\"device_type\\\":\\\"android\\\",\\\"ip\\\":\\\"10.117.57.93\\\",\\\"model\\\":\\\"MI 8\\\"},\\\"type\\\":\\\"page_precise_exposure\\\"}\"}\n"));
// 调用kafkaProduce的send方法发送消息
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>("test",
// "raw", "{\"@raw\":\"{\"gm_nginx_key\":2,\"version\":\"110\",\"params\":{\"up_slide_times\":0,\"down_loading_times\":0,\"exposure_cards\":{},\"up_loading_times\":0,\"is_exposure\":1,\"tab_name\":\"精选\",\"referrer_id\":\"\",\"down_slide_times\":0,\"referrer\":\"\",\"page_name\":\"home\",\"business_id\":\"\"},\"app_session_id\":\"C3280044-5C8E-459D-AE6C-8E26BBACD6C9\",\"gm_nginx_timestamp\":1546307958.631,\"create_at\":\"1546307958\",\"app\":{\"channel\":\"AppStore\",\"version\":\"7.7.35\",\"serial_id\":42,\"current_city_id\":\"worldwide\",\"name\":\"gengmei_user\",\"user_type\":{}},\"device\":{\"is_WiFi\":\"0\",\"device_type\":\"ios\",\"device_id\":\"DE8EA66A-BDE9-47CD-9795-24E444F5BC17\",\"lng\":0,\"lat\":0,\"ip\":\"10.156.100.97\",\"manufacturer\":\"Apple\",\"idfa\":\"DE8EA66A-BDE9-47CD-9795-24E444F5BC17\",\"idfv\":\"352A6D64-17CA-4520-831A-2CE9507631D8\"},\"user_id\":\"30864538\",\"type\":\"home_choiceness_card_exposure\"}\"}");
// "test","{\"gm_nginx_key\":2,\"version\":\"110\",\"params\":{\"up_slide_times\":0,\"down_loading_times\":0,\"exposure_cards\":{},\"up_loading_times\":0,\"is_exposure\":1,\"tab_name\":\"精选\",\"referrer_id\":\"\",\"down_slide_times\":0,\"referrer\":\"\",\"page_name\":\"home\",\"business_id\":\"\"},\"app_session_id\":\"C3280044-5C8E-459D-AE6C-8E26BBACD6C9\",\"gm_nginx_timestamp\":1546307958.631,\"create_at\":\"1546307958\",\"app\":{\"channel\":\"AppStore\",\"version\":\"7.7.35\",\"serial_id\":42,\"current_city_id\":\"worldwide\",\"name\":\"gengmei_user\",\"user_type\":{}},\"device\":{\"is_WiFi\":\"0\",\"device_type\":\"ios\",\"device_id\":\"DE8EA66A-BDE9-47CD-9795-24E444F5BC17\",\"lng\":0,\"lat\":0,\"ip\":\"10.156.100.97\",\"manufacturer\":\"Apple\",\"idfa\":\"DE8EA66A-BDE9-47CD-9795-24E444F5BC17\",\"idfv\":\"352A6D64-17CA-4520-831A-2CE9507631D8\"},\"user_id\":\"30864538\",\"type\":\"home_choiceness_card_exposure\"}");
"test", json);
producer.send(producerRecord);
Thread.sleep(20000);
System.out.println("======================");
}
} catch (Exception e) {
e.printStackTrace();
}
producer.close();
}
}
package com.gmei.sink;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.CheckpointingMode;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.CheckpointConfig;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaProducer011;
import org.apache.flink.streaming.connectors.kafka.internals.KeyedSerializationSchemaWrapper;
import java.util.Properties;
public class BlPreciseExposureKafkaSink {
public static void main(String[] args) throws Exception {
//获取Flink的运行环境
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//checkpoint配置
env.enableCheckpointing(5000);
env.getCheckpointConfig().setCheckpointingMode(CheckpointingMode.EXACTLY_ONCE);
env.getCheckpointConfig().setMinPauseBetweenCheckpoints(500);
env.getCheckpointConfig().setCheckpointTimeout(60000);
env.getCheckpointConfig().setMaxConcurrentCheckpoints(1);
env.getCheckpointConfig().enableExternalizedCheckpoints(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
//设置statebackend
//env.setStateBackend(new RocksDBStateBackend("hdfs://hadoop100:9000/flink/checkpoints",true));
DataStreamSource<String> text = env.socketTextStream("hadoop100", 9001, "\n");
// String brokerList = "localhost:9092";
String brokerList = "172.21.40.14:9092";
// String topic = "test";
String topic = "gm-precise_exposure-test";
Properties prop = new Properties();
prop.setProperty("bootstrap.servers",brokerList);
//第一种解决方案,设置FlinkKafkaProducer011里面的事务超时时间
//设置事务超时时间
//prop.setProperty("transaction.timeout.ms",60000*15+"");
//第二种解决方案,设置kafka的最大事务超时时间
//FlinkKafkaProducer011<String> myProducer = new FlinkKafkaProducer011<>(brokerList, topic, new SimpleStringSchema());
//使用仅一次语义的kafkaProducer
FlinkKafkaProducer011<String> myProducer = new FlinkKafkaProducer011<String>(topic, new KeyedSerializationSchemaWrapper<String>(new SimpleStringSchema()), prop, FlinkKafkaProducer011.Semantic.EXACTLY_ONCE);
text.addSink(myProducer);
env.execute("BL_ET_MG_PRECISEEXPOSURE_INC_D_RT");
}
}
package com.gmei.sink;
import com.gmei.bean.bl.BlPreciseExposureBean;
import com.gmei.bean.ml.MlPreciseExposureBean;
import com.gmei.cache.MlPreciseExposureDao;
import com.gmei.function.BlPreciseExposureMapFunction;
import com.gmei.function.MlpreciseExposureFlatMapFunction;
import com.gmei.jdbc.MysqlJdbcBl;
import org.junit.Test;
import java.util.ArrayList;
public class MlPreciseExposureMysqlSinkTest {
@Test
public void mlMysqlSinkTest() {
String sinkJdbcUrl = "";
String sinkTableName = "";
String json = "{\"create_at\":\"1575135041\",\"gm_nginx_timestamp\":1575135040.498,\"user_id\":\"\",\"version\":\"147\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":6,\"is_exposure\":\"1\",\"exposure_cards\":[{\"absolute_position\":0,\"relative_position\":0,\"card_type\":\"card\",\"wiki_word\":[\"项目档案:1\",\"手术锦囊:2\",\"相近项目:3\"],\"card_content_type\":\"qa\",\"card_id\":\"7\"},{\"cpc_referer\":\"1\",\"relative_position\":0,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":0,\"card_content_type\":\"answer\",\"card_id\":\"684889\"},{\"cpc_referer\":\"1\",\"relative_position\":1,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":1,\"card_content_type\":\"answer\",\"card_id\":\"692624\"},{\"cpc_referer\":\"1\",\"relative_position\":2,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":2,\"card_content_type\":\"user_post\",\"card_id\":66263},{\"cpc_referer\":\"1\",\"relative_position\":3,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":3,\"card_content_type\":\"user_post\",\"card_id\":70670},{\"cpc_referer\":\"1\",\"relative_position\":4,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":4,\"card_content_type\":\"diary\",\"card_id\":15329391},{\"cpc_referer\":\"1\",\"relative_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":5,\"card_content_type\":\"article\",\"card_id\":\"19507071\"},{\"cpc_referer\":\"1\",\"relative_position\":5,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":6,\"card_content_type\":\"answer\",\"card_id\":\"518138\"},{\"cpc_referer\":\"1\",\"relative_position\":4,\"transaction_type\":\"\",\"card_type\":\"card\",\"absolute_position\":7,\"card_content_type\":\"answer\",\"card_id\":\"684319\"},{\"cpc_referer\":\"1\",\"relative_position\":5,\"is_cpc\":0,\"transaction_type\":\"-1\",\"card_type\":\"card\",\"absolute_position\":8,\"card_content_type\":\"user_post\",\"card_id\":69002}],\"tab_name\":\"综合\",\"down_slide_times\":0,\"query\":\"纹眉\",\"filter\":\"\",\"referrer_id\":\"\",\"referrer\":\"search_home\",\"up_loading_times\":0,\"business_id\":\"\",\"page_name\":\"search_result_more\"},\"app_session_id\":\"424bcbcf-3b6e-4331-89b3-9fcd0c7bfbaf\",\"app\":{\"version\":\"7.18.4\",\"grey_type\":\"{\\\"video_steep\\\":1,\\\"post_detail\\\":\\\"0\\\",\\\"face_detect_result\\\":\\\"B\\\",\\\"home\\\":\\\"0\\\",\\\"face_scan\\\":0,\\\"report_result\\\":0}\",\"current_city_id\":\"chongqing\",\"user_type\":{\"config_type\":\"1\"},\"name\":\"gengmei_user\",\"serial_id\":35,\"channel\":\"huawei\"},\"gm_nginx_key\":1,\"device\":{\"android_device_id\":\"androidid_b49fb6a87b10bad0\",\"sys_version\":\"9\",\"lng\":\"106.618722\",\"is_WiFi\":\"0\",\"lat\":\"29.720561\",\"device_id\":\"861198041466947\",\"manufacturer\":\"HUAWEI\",\"net_type\":\"4G\",\"device_type\":\"android\",\"ip\":\"192.168.3.3\",\"model\":\"LYA-AL00\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"create_at\":\"1576347089\",\"gm_nginx_timestamp\":1576347089.299,\"user_id\":\"31961883\",\"version\":\"110\",\"params\":{\"down_loading_times\":0,\"up_slide_times\":5,\"exposure_cards\":{},\"tab_name\":\"service\",\"down_slide_times\":1,\"page_name\":\"category\",\"up_loading_times\":1,\"is_exposure\":\"1\",\"referrer\":\"home\",\"business_id\":\"9\",\"filter\":\"智能排序\",\"referrer_id\":\"\"},\"app_session_id\":\"0092AC31-EF72-44FF-AE1E-8BB6F8448A08\",\"app\":{\"version\":\"7.19.1\",\"grey_type\":\"{\\n \\\"report_result\\\" : 0,\\n \\\"face_detect_result\\\" : \\\"B\\\",\\n \\\"home\\\" : \\\"0\\\",\\n \\\"post_detail\\\" : \\\"0\\\",\\n \\\"video_steep\\\" : 0,\\n \\\"face_scan\\\" : 0\\n}\",\"current_city_id\":\"liuan\",\"name\":\"gengmei_user\",\"user_type\":{\"config_type\":1},\"serial_id\":28,\"channel\":\"App Store\"},\"gm_nginx_key\":1,\"device\":{\"idfv\":\"51E1C5FD-B710-4820-91A6-E54C77AA4C60\",\"sys_version\":\"12.4.1\",\"lng\":116.48697900811,\"is_WiFi\":\"1\",\"manufacturer\":\"Apple\",\"device_id\":\"CD1187A7-091C-4497-96A3-A716BE510905\",\"device_type\":\"ios\",\"ip\":\"192.168.0.101\",\"idfa\":\"CD1187A7-091C-4497-96A3-A716BE510905\",\"lat\":31.757989657248,\"model\":\"iPhone10,1\"},\"type\":\"page_precise_exposure\"}";
// String json = "{\"app\":{\"user_type\":{\"config_type\":1},\"serial_id\":5,\"name\":\"gengmei_user\",\"channel\":\"App Store\",\"version\":\"7.7.40\",\"current_city_id\":\"beijin\n" +
// "g\"},\"app_session_id\":\"805E7CE4-0FB1-44E1-B32F-837B62D11D91\",\"gm_nginx_timestamp\":1576347092.686,\"user_id\":\"29105318\",\"gm_nginx_key\":1,\"creat\n" +
// "e_at\":\"1576347092\",\"params\":{\"exposure_cards\":{ },\"referrer\":\"\",\"referrer_id\":\"\",\"up_slide_times\":0,\"down_loading_times\":0,\"page_name\":\"home\"\n" +
// ",\"tab_name\":\"精选\",\"business_id\":\"\",\"up_loading_times\":0,\"down_slide_times\":0,\"is_exposure\":1},\"type\":\"home_choiceness_card_exposure\",\"versi\n" +
// "on\":\"110\",\"device\":{\"lng\":116.25638817524,\"device_id\":\"00DB1D03-3116-4084-AD86-0596EDFA2E3D\",\"is_WiFi\":\"1\",\"ip\":\"10.10.62.107\",\"idfa\":\"00DB1\n" +
// "D03-3116-4084-AD86-0596EDFA2E3D\",\"idfv\":\"1E6E56F7-3E3C-4F62-83EB-E9DBE7BC1AD1\",\"device_type\":\"ios\",\"lat\":40.073574956895,\"manufacturer\":\"Apple\"}}";
BlPreciseExposureMapFunction blPreciseExposureMapFunction = new BlPreciseExposureMapFunction();
MlpreciseExposureFlatMapFunction mlpreciseExposureFlatMapFunction = new MlpreciseExposureFlatMapFunction();
BlPreciseExposureBean blPreciseExposureBean = null;
MysqlJdbcBl mysqlJdbcBl = MysqlJdbcBl.getInstance(sinkJdbcUrl);
MlPreciseExposureDao mlPreciseExposureDao = new MlPreciseExposureDao(sinkJdbcUrl, sinkTableName);
try {
blPreciseExposureBean = blPreciseExposureMapFunction.map(json);
// conn = mysqlJdbcBl.getConnection();
// conn.setAutoCommit(false);
ArrayList<MlPreciseExposureBean> mlPreciseExposureBeanArrayList = mlpreciseExposureFlatMapFunction.flatmapBlPreciseExposure(blPreciseExposureBean);
for (MlPreciseExposureBean mlPreciseExposureBean : mlPreciseExposureBeanArrayList) {
mlPreciseExposureDao.insertMlPreciseExposure(mlPreciseExposureBean);
}
// conn.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.gmei.source;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer011;
import java.util.Properties;
public class BlMaiDianKafkaSourceTest {
public static void main(String[] args) throws Exception {
//获取Flink的运行环境
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// //checkpoint配置
// env.enableCheckpointing(5000);
// env.getCheckpointConfig().setCheckpointingMode(CheckpointingMode.EXACTLY_ONCE);
// env.getCheckpointConfig().setMinPauseBetweenCheckpoints(500);
// env.getCheckpointConfig().setCheckpointTimeout(60000);
// env.getCheckpointConfig().setMaxConcurrentCheckpoints(1);
// env.getCheckpointConfig().enableExternalizedCheckpoints(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
//
// //设置statebackend
//
// env.setStateBackend(new Sta("file:///Users/mac/opt/flink/checkpoints",true));
String brokers = "172.16.44.25:2181/gengmei";
String topicName = "test";
String groupId = "group1";
String startTime = "2019-12-31 00:01:02";
//构造java.util.Properties对象
Properties props = new Properties();
// 必须指定属性。
props.put("bootstrap.servers", "localhost:9092");
// 必须指定属性。
props.put("group.id", groupId);
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
// 从最早的消息开始读取
// props.put("auto.offset.reset", "earliest");
props.put("auto.offset.reset", "latest");
// 必须指定
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
// 必须指定
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
// FlinkKafkaConsumer011<ObjectNode> MyConsumer = new FlinkKafkaConsumer011<ObjectNode>(topicName, new JSONDeserializationSchema(), props);
FlinkKafkaConsumer011<String> myConsumer = new BlMaiDianKafkaSource(brokers, topicName, groupId, startTime).addSource();
myConsumer.setStartFromGroupOffsets();//默认消费策略
DataStreamSource<String> text = env.addSource(myConsumer);
text.print().setParallelism(1);
env.execute("BL_ET_MG_PRECISEEXPOSURE_INC_D_RT");
}
}
package com.gmei.utils;
import com.gmei.bean.bl.BlPreciseExposureParamsExposureCardsBean;
import org.junit.Test;
public class BeanReflectUtilTest {
@Test
public void setNullValueTest() {
BlPreciseExposureParamsExposureCardsBean cardBean = new BlPreciseExposureParamsExposureCardsBean(
"123","diary","card",null,null,"",null,null,"1","2"
);
try {
BeanReflectUtil.setNullValue(cardBean);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
System.out.println(cardBean);
}
@Test
public void setFieldValueTest() {
BlPreciseExposureParamsExposureCardsBean cardBean = new BlPreciseExposureParamsExposureCardsBean(
"123","diary","card",null,null,"",null,null,"1","2"
);
BeanReflectUtil.setFieldValue(cardBean, "transaction_type", "-1");
System.out.println(cardBean);
}
@Test
public void getFieldValueTest() throws Exception {
BlPreciseExposureParamsExposureCardsBean cardBean = new BlPreciseExposureParamsExposureCardsBean(
"123","diary","card",null,null,"",null,null,"1","2"
);
String transaction_type = (String) BeanReflectUtil.getFieldValue(cardBean, "card_type");
System.out.println(transaction_type);
}
}
package com.gmei.utils;
import org.junit.Test;
public class DateUtilTest {
@Test
public void timestamp2StringTest() {
String timestamp = "1576347089.299";
String timestampYMD = DateUtil.timestampFormat(timestamp, DateUtil.DateType.SECOND);
String timestampY = DateUtil.timestampFormat(timestamp, DateUtil.DateType.DAY);
System.out.println(timestampYMD);
System.out.println(timestampY);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmei.flink</groupId>
<artifactId>flink_warehouse_rt</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>ml_c_et_pe_preciseexposure_dimen_d_rt</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<flink.version>1.9.0</flink.version>
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<scala.binary.version>2.10</scala.binary.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-kafka-0.11_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.11</artifactId>
<version>${flink.version}</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
<!-- provided在这表示此依赖只在代码编译的时候使用,运行和打包的时候不使用 -->
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-statebackend-rocksdb_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-json</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack</artifactId>
<version>0.6.11</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.8.8</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!--<version>5.1.38</version>-->
<version>8.0.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source> <!-- If you want to use Java 8, change this to "1.8" -->
<target>1.8</target> <!-- If you want to use Java 8, change this to "1.8" -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.gmei.streaming.PreciseExposureStreaming</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
<!--使单元测试不影响项目的编译-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip><!--跳过单元测试-->
<!--<testFailureIgnore>true</testFailureIgnore>--><!--这个网上很多的解决方式是这个,其实这个,其实这个配置后打包还是会编译单元测试类的,只是忽略编译单元测试类的错误.-->
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment