Ver código fonte

增加 快手激活、当月退订、高频退订标签

huaerzx 2 anos atrás
pai
commit
ddd4711156

+ 59 - 9
src/main/java/com/platomix/userprofile/handler/core/XxhOrderTagHandler.java

@@ -47,7 +47,25 @@ public class XxhOrderTagHandler extends AbstractTagHandler {
 		// 获取开始日期
 		String theLeftDay = month + "01";
 		String theRightDay = LocalDate.parse(theLeftDay, DateTimeFormatter.BASIC_ISO_DATE).plusMonths(1).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
-		
+
+		LocalDate monthStartDate = LocalDate.parse(month.substring(0, 4) + "-" + month.substring(4) + "-01", DateTimeFormatter.ISO_LOCAL_DATE);
+		String theRightDay2 = monthStartDate.plusMonths(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+
+
+		StrBuilder sqlCancelM6 = new StrBuilder();
+		for(Integer i=0;i<6;i++){
+			sqlCancelM6.appendLn(String.format("select USERID,SPID,%d as MONTH_CANCEL from  ads.ETL_TD_ORDER_RELATIONS_YEAR ",i))
+					.appendLn(String.format("  where  THEMONTH ='%s' and ORDERTIME >='%s' and CANCELTIME!='1970-01-01' and  CANCELTIME<'%s'  %s",
+							monthStartDate.plusMonths(-i).format(DateTimeFormatter.ofPattern("yyyyMM")),
+							monthStartDate.plusMonths(-i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
+							monthStartDate.plusMonths(1-i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
+							lrMobileSql));
+			if(i!=5){
+				sqlCancelM6.appendLn(" union all ");
+			}
+		}
+
+
 		StrBuilder sqlBuilder = new StrBuilder();
 		sqlBuilder.appendLn(super.buildTableSql(ZT_TABLE_NAME, "THEMONTH", "USERID"));
 		sqlBuilder.appendLn("with toYYYYMM(ORDERTIME) as OTSTR, toYYYYMM(CANCELTIME) as CTSTR")
@@ -111,8 +129,18 @@ public class XxhOrderTagHandler extends AbstractTagHandler {
 		
 		//免流流量使用量【20220609_aokunsang_新增标签】
 		appendEventFreeLimitFlow(sqlBuilder, tagListMap);
-		sqlBuilder.appendLn("");
-		
+		sqlBuilder.appendLn(",");
+
+		//--new 2022-06-27 退订时间
+		String ksActiveSql = userprofileTagService.genSelectSql("快手激活", "KA_IS_JIHUO", "KA_IS_JIHUO", null, "","tagValue");
+		sqlBuilder.append(ksActiveSql).appendLn(",");
+		//当月退订
+		String m0CancelSql = userprofileTagService.genSelectSql("当月退订", "M0_CANCEL", "M0_CANCEL", null, "","tagValue");
+		sqlBuilder.append(m0CancelSql).appendLn(",");
+		//高频退订
+		String m6CancelSql = userprofileTagService.genSelectSql("高频当月订退", "M6_CANCEL", "M6_CANCEL", null, "","tagValue");
+		sqlBuilder.append(m6CancelSql).appendLn("");
+
 		sqlBuilder.appendLn("from (").appendLn(
 				"with toDate(concat(SUBSTRING(toString(THEMONTH),1,4),'-' ,SUBSTRING(toString(THEMONTH),5,2),'-01')) as mstr").appendLn(
 				"select THEMONTH ,USERID,PROVINCE,AREA,ORDERTIME,CANCELTIME,ENDTIME,").appendLn(
@@ -121,8 +149,9 @@ public class XxhOrderTagHandler extends AbstractTagHandler {
 				"ORDERTIME,CANCELTIME,ORDER_TIME2,CANCELTIME2,").appendLn(
 				"dateDiff('month', ORDERTIME,mstr) DIFF_MONYH,").appendLn(
 				"dateDiff('month', if(CANCELTIME='1970-01-01',addMonths(mstr,1),CANCELTIME),mstr) DIFF_CANCEL_MONYH,").appendLn(
-				"USERID2,LLCP,FLOW,if(MAXFLOW=='',0,FLOW/toFloat64OrNull(MAXFLOW))*100 as flow_P").appendLn(
-				"from").appendLn(
+				"USERID2,LLCP,FLOW,if(MAXFLOW=='',0,FLOW/toFloat64OrNull(MAXFLOW))*100 as flow_P")
+				.appendLn(",KA_IS_JIHUO,M0_CANCEL,M6_CANCEL")
+				.appendLn("from").appendLn(
 				"(").appendLn(
 				"	select").appendLn(
 				"	if(o1.THEMONTH=0,toString(o2.THEMONTH),toString(o1.THEMONTH)) as THEMONTH,").appendLn(
@@ -140,8 +169,11 @@ public class XxhOrderTagHandler extends AbstractTagHandler {
 				"	LLCP,VIPID, if(VIPID='','未领取',VIP_SPNAME) as VIP_SPNAME,").appendLn(
 				"	if(o2.USERID='',-1,FLOW) as FLOW,").appendLn(
 				"	o1.USERID USERID1,").appendLn(
-				"	o2.USERID USERID2").appendLn(
-				"	from").appendLn(
+				"	o2.USERID USERID2,")
+				.appendLn("	multiIf(CPID ='kuaishou' and ka.USERID!='',1,CPID ='kuaishou' and ka.USERID='',0,2) as KA_IS_JIHUO,")
+				.appendLn("	if(c0.USERID=='',0,1) as M0_CANCEL,")
+				.appendLn("	if(c_all.USERID=='',0,1)  as M6_CANCEL")
+				.appendLn("	from").appendLn(
 				" (").append(
 				" select * from ads.ETL_TD_ORDER_RELATIONS_YEAR where THEMONTH ='"+month+"'").appendLn(lrMobileSql).appendLn(
 				" ) o1").appendLn(
@@ -162,8 +194,26 @@ public class XxhOrderTagHandler extends AbstractTagHandler {
 				"		on a1.VIPID =ds.VIPID").append(
 				"		where THEDAY >='"+theLeftDay+"' and THEDAY<'"+theRightDay+"'").appendLn(lrUserIdSql).appendLn(
 //				"		--and VIPID in(select VIPID from ads.DIM_SXXHY where SETID =1)").appendLn(
-				"	) o3 on o1.USERID=o3.USERVAL").appendLn(
-				"   left join ads.DIM_TB_CHANNELS d1 on o1.CHANNEL=d1.ID").appendLn(
+				"	) o3 on o1.USERID=o3.USERVAL")
+				//--new 2022-06-27 快手激活 当月退订 高频退订标签
+				.appendLn("  left join (")
+				.appendLn("  select USERID,SPID ,toDate(ORDERTIME) as ORDERDATE from ads.TD_KUAISHOU_ACTIVATE")
+				.appendLn(String.format("  where STATUS ='1' and CANCELTIME <'%s' and ORDERTIME <'%s'",theRightDay2,theRightDay2))
+				.appendLn("  ) ka on o1.USERID=ka.USERID and o1.SPID=ka.SPID and o1.ORDERTIME=ka.ORDERDATE")
+				//--new
+				.appendLn("  left join (")
+				.appendLn("  select USERID,SPID from ads.ETL_TD_ORDER_RELATIONS_YEAR ")
+				.appendLn(String.format("  where  THEMONTH ='%s' and ORDERTIME >='%s' and CANCELTIME!='1970-01-01' and  CANCELTIME<'%s'  %s",
+						month,monthStartDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),theRightDay2,lrMobileSql))
+				.appendLn("  ) c0 on  o1.USERID=c0.USERID and o1.SPID=c0.SPID")
+				//--new
+				.appendLn("  left join (")
+				.appendLn("  select USERID ,SPID from (")
+				.appendLn(sqlCancelM6.toString())
+				.appendLn("  ) group by USERID ,SPID having COUNT()>1")
+				.appendLn("  ) c_all on  o1.USERID=c_all.USERID and o1.SPID=c_all.SPID ")
+
+				.appendLn("   left join ads.DIM_TB_CHANNELS d1 on o1.CHANNEL=d1.ID").appendLn(
 				") s1").appendLn(
 				"left join ads.ETL_V_TB_SP_INFO d  on s1.SPID=d.SPID").appendLn(
 				") s");