提交 6f08e1da 编写于 作者: wuyunfeng's avatar wuyunfeng

调整menu_code处理逻辑,menu_code不为-1和英文

上级 d458386b
package com.pica.utils;
import java.math.BigDecimal;
/**
* 字符串工具类
* @Author zhenxin.ma
......@@ -17,6 +19,20 @@ public class StringUtils {
return str == null || "".equals(str);
}
/**
* 判断字符串是否为数值
* @param str 字符串
* @return 是否数值
*/
public static boolean isNumeric(String str) {
String bigStr;
try {
bigStr = new BigDecimal(str).toString();
} catch (Exception e) {
return false;//异常 说明包含非数字。
}
return true;
}
/**
* 判断字符串是否不为空
* @param str 字符串
......
......@@ -163,7 +163,8 @@ object SessionProcessTerm {
StructField("first_app_version", StringType, true),
StructField("service_name", StringType, true),
StructField("tag8", StringType, true),
StructField("tag9", StringType, true)
StructField("tag9", StringType, true),
StructField("component_tag", StringType, true)
)
))
println("referResultDF.show()============'")
......@@ -225,7 +226,7 @@ object SessionProcessTerm {
|(cast(c.session_end_time as bigint)-cast(c.session_begin_time as bigint))/1000 session_time_diff,
|a.pre_session_id,
|case when a.user_id=0 then a.device_token else a.user_id end user_identity_id,
|a.view_path, a.alternate_info, a.first_app_version,a.service_name,a.tag8,a.tag9
|a.view_path, a.alternate_info, a.first_app_version,a.service_name,a.tag8,a.tag9,a.component_tag
|from refer_result_table a
|left join refer_menu_table b on a.session_id=b.session_id and a.device_token=b.device_token and a.user_id=b.user_id and a.menu_code=b.menu_code and a.created_time=b.created_time and a.action_type in('ACTION_VIEW','ACTION_HEART')
|left join session_end_table c on a.session_id = c.session_id
......@@ -353,7 +354,7 @@ class SessionProcessTerm {
}
index += 1
}
}else if(component_tag!="0" && component_tag.length<5){ //如果component_tag不为0,且长度在合理区间,则作为menu_code值
}else if(component_tag.length<5 && StringUtils.isNumeric(component_tag) && component_tag.toInt>0 ){ //如果component_tag不为0,且长度在合理区间,则作为menu_code值
tagMap.put("menu_code",component_tag)
}
}
......@@ -638,7 +639,8 @@ class SessionProcessTerm {
row.getAs[String]("first_app_version"),
row.getAs[String]("service_name"),
row.getAs[String]("tag8"),
row.getAs[String]("tag9")
row.getAs[String]("tag9"),
row.getAs[String]("component_tag")
))
}
}
......@@ -682,11 +684,20 @@ class SessionProcessTerm {
| cast(menu_begin_time as string), cast(menu_end_time as string), menu_time_diff,
| action_step,device_type,device_brand,device_model, app_version, net_type ,created_time,date_time,
| cast(session_begin_time as string) , cast(session_end_time as string), session_time_diff,
| pre_session_id, user_identity_id,view_path,alternate_info,first_app_version,service_name,tag8,tag9
| pre_session_id, user_identity_id,view_path,alternate_info,first_app_version,service_name,tag8,tag9,component_tag
| from result_view t1
""".stripMargin
sparkSession.sql(loadDataSql)
}
def strToInt(str: String): Int = {
val regex = """([0-9]+)""".r
val res = str match{
case regex(num) => num
case _ => "0"
}
val resInt = Integer.parseInt(res)
resInt
}
}
case class SessionTerm(pseudo_session: String,
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册