|
@@ -1,6 +1,9 @@
|
|
|
package com.tzld.piaoquan.api.job;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.odps.data.Record;
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.piaoquan.api.common.enums.contentplatform.BussinessTypeEnum;
|
|
|
import com.tzld.piaoquan.api.component.AigcApiService;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.contentplatform.*;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformDataStatMapperExt;
|
|
@@ -53,6 +56,12 @@ public class ContentPlatformDatastatJob {
|
|
|
@Autowired
|
|
|
private ContentPlatformPlanService planService;
|
|
|
|
|
|
+ @ApolloJsonValue("${unit.price.min:{\"gzh_autoReply\":0.1,\"fwh_push\":0.1,\"qw\":0.15}}")
|
|
|
+ private Map<String, Double> unitPriceMinConfig;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${unit.price.max:{\"gzh_autoReply\":0.2,\"fwh_push\":0.2,\"qw\":0.3}}")
|
|
|
+ private Map<String, Double> unitPriceMaxConfig;
|
|
|
+
|
|
|
|
|
|
@XxlJob("syncContentPlatformGzhDatastatJob")
|
|
|
public ReturnT<String> syncContentPlatformGzhDatastatJob(String param) {
|
|
@@ -66,19 +75,21 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
Long now = System.currentTimeMillis();
|
|
|
// 公众号自动回复数据统计
|
|
|
- String sql = String.format("SELECT first_level.channel_shortname, first_level.subchannel, first_level.first_uv, fission.split_uv " +
|
|
|
- "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
+ String sql = String.format(
|
|
|
+ "SELECT first_level.channel_shortname, first_level.subchannel, first_level.first_uv, fission.split_uv " +
|
|
|
+ "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
"left join loghubods.out_channel_mid_split_total fission " +
|
|
|
- "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
|
|
|
- "and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
- "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '分投放渠道客户分账号去重';", dt);
|
|
|
+ "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel " +
|
|
|
+ "and first_level.dt = fission.dt and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
+ "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '分投放渠道客户分账号去重';", dt);
|
|
|
List<Record> dataList = OdpsUtil.getOdpsData(sql);
|
|
|
// 所有公众号
|
|
|
List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
|
|
|
Map<String, ContentPlatformGzhAccount> accountMap = accountList.stream()
|
|
|
.collect(Collectors.toMap(ContentPlatformGzhAccount::getGhId, account -> account));
|
|
|
List<String> ghIds = accountList.stream().map(ContentPlatformGzhAccount::getGhId).collect(Collectors.toList());
|
|
|
- List<String> accountExternalIds = accountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
|
|
|
+ List<String> accountExternalIds = accountList.stream().map(ContentPlatformGzhAccount::getExternalId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
|
|
|
List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
|
|
|
Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
|
|
@@ -88,7 +99,7 @@ public class ContentPlatformDatastatJob {
|
|
|
for (Record record : dataList) {
|
|
|
ContentPlatformGzhDataStat item = new ContentPlatformGzhDataStat();
|
|
|
String ghId = (String) record.get(1);
|
|
|
- Integer firstLevelCount = Integer.valueOf((String) record.get(2));
|
|
|
+ int firstLevelCount = Integer.parseInt((String) record.get(2));
|
|
|
Integer fissionCount = parseInteger(record.get(3));
|
|
|
item.setDateStr(dt);
|
|
|
if (!ghIds.contains(ghId)) {
|
|
@@ -102,7 +113,7 @@ public class ContentPlatformDatastatJob {
|
|
|
item.setFansIncreaseCount(wxAccountDatastatVO.getFansIncreaseCount());
|
|
|
}
|
|
|
|
|
|
- if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
|
|
|
+ if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
|
|
|
BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
item.setScore(rounded.doubleValue());
|
|
@@ -125,12 +136,16 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
Long now = System.currentTimeMillis();
|
|
|
// 公众号自动回复数据统计
|
|
|
- String sql = String.format("SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv " +
|
|
|
- "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
+ String sql = String.format(
|
|
|
+ "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, price.arpu " +
|
|
|
+ "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
"left join loghubods.out_channel_mid_split_total fission " +
|
|
|
"on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
|
|
|
"and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
- "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '投放渠道内去重' ;", dt);
|
|
|
+ "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
|
|
|
+ "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
|
|
|
+ "and first_level.type = price.type and first_level.tag = price.tag " +
|
|
|
+ "WHERE first_level.dt = %s and first_level.type = '公众号即时回复' and first_level.tag = '投放渠道内去重' ;", dt);
|
|
|
List<Record> dataList = OdpsUtil.getOdpsData(sql);
|
|
|
// 所有公众号
|
|
|
List<ContentPlatformAccount> accountList = getAllAccount();
|
|
@@ -139,7 +154,8 @@ public class ContentPlatformDatastatJob {
|
|
|
List<ContentPlatformGzhAccount> gzhAccountList = getAllGzhAccount();
|
|
|
Map<Long, List<ContentPlatformGzhAccount>> gzhAccountMap = gzhAccountList.stream()
|
|
|
.collect(Collectors.groupingBy(ContentPlatformGzhAccount::getCreateAccountId));
|
|
|
- List<String> accountExternalIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
|
|
|
+ List<String> accountExternalIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getExternalId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
|
|
|
List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
|
|
|
Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
|
|
@@ -149,8 +165,9 @@ public class ContentPlatformDatastatJob {
|
|
|
for (Record record : dataList) {
|
|
|
ContentPlatformGzhDataStatTotal item = new ContentPlatformGzhDataStatTotal();
|
|
|
String channel = record.getString(0);
|
|
|
- Integer firstLevelCount = Integer.valueOf((String) record.get(1));
|
|
|
+ int firstLevelCount = Integer.parseInt((String) record.get(1));
|
|
|
Integer fissionCount = parseInteger(record.get(2));
|
|
|
+ Double arpu = parseDouble(record.get(3));
|
|
|
item.setDateStr(dt);
|
|
|
item.setChannel(channel);
|
|
|
item.setFirstLevelCount(firstLevelCount);
|
|
@@ -168,10 +185,16 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
item.setFansIncreaseCount(fansIncreaseCount);
|
|
|
|
|
|
- if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
|
|
|
- BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
+ BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
+ BigDecimal rounded = fissionRate.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
item.setScore(rounded.doubleValue());
|
|
|
+ BigDecimal unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.GZH_AUTO_REPLY);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ item.setUnitPrice(unitPrice.doubleValue());
|
|
|
+ BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ }
|
|
|
}
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
@@ -196,19 +219,21 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
Long now = System.currentTimeMillis();
|
|
|
// 公众号自动回复数据统计
|
|
|
- String sql = String.format("SELECT first_level.subchannel, first_level.first_uv, fission.split_uv " +
|
|
|
- "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
+ String sql = String.format(
|
|
|
+ "SELECT first_level.subchannel, first_level.first_uv, fission.split_uv " +
|
|
|
+ "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
"left join loghubods.out_channel_mid_split_total fission " +
|
|
|
"on first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
|
|
|
"and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
- "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
|
|
|
+ "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
|
|
|
List<Record> dataList = OdpsUtil.getOdpsData(sql);
|
|
|
// 所有公众号
|
|
|
List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
|
|
|
Map<String, ContentPlatformGzhAccount> accountMap = accountList.stream()
|
|
|
.collect(Collectors.toMap(ContentPlatformGzhAccount::getGhId, account -> account));
|
|
|
List<String> ghIds = accountList.stream().map(ContentPlatformGzhAccount::getGhId).collect(Collectors.toList());
|
|
|
- List<String> accountExternalIds = accountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
|
|
|
+ List<String> accountExternalIds = accountList.stream().map(ContentPlatformGzhAccount::getExternalId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
|
|
|
List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
|
|
|
Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
|
|
@@ -218,7 +243,7 @@ public class ContentPlatformDatastatJob {
|
|
|
for (Record record : dataList) {
|
|
|
ContentPlatformFwhDataStat item = new ContentPlatformFwhDataStat();
|
|
|
String ghId = (String) record.get(0);
|
|
|
- Integer firstLevelCount = Integer.valueOf((String) record.get(1));
|
|
|
+ int firstLevelCount = Integer.parseInt((String) record.get(1));
|
|
|
Integer fissionCount = parseInteger(record.get(2));
|
|
|
item.setDateStr(dt);
|
|
|
if (!ghIds.contains(ghId)) {
|
|
@@ -232,7 +257,7 @@ public class ContentPlatformDatastatJob {
|
|
|
item.setFansIncreaseCount(wxAccountDatastatVO.getFansIncreaseCount());
|
|
|
}
|
|
|
|
|
|
- if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
|
|
|
+ if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
|
|
|
BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
item.setScore(rounded.doubleValue());
|
|
@@ -255,12 +280,16 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
Long now = System.currentTimeMillis();
|
|
|
// 公众号自动回复数据统计
|
|
|
- String sql = String.format("SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv " +
|
|
|
- "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
+ String sql = String.format(
|
|
|
+ "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, price.arpu " +
|
|
|
+ "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
"left join loghubods.out_channel_mid_split_total fission " +
|
|
|
"on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
|
|
|
"and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
- "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '投放渠道内去重' ;", dt);
|
|
|
+ "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
|
|
|
+ "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
|
|
|
+ "and first_level.type = price.type and first_level.tag = price.tag " +
|
|
|
+ "WHERE first_level.dt = %s and first_level.type = '服务号代运营' and first_level.tag = '投放渠道内去重' ;", dt);
|
|
|
List<Record> dataList = OdpsUtil.getOdpsData(sql);
|
|
|
// 所有公众号
|
|
|
List<ContentPlatformAccount> accountList = getAllAccount();
|
|
@@ -269,7 +298,8 @@ public class ContentPlatformDatastatJob {
|
|
|
List<ContentPlatformGzhAccount> gzhAccountList = getAllGzhAccount();
|
|
|
Map<Long, List<ContentPlatformGzhAccount>> gzhAccountMap = gzhAccountList.stream()
|
|
|
.collect(Collectors.groupingBy(ContentPlatformGzhAccount::getCreateAccountId));
|
|
|
- List<String> accountExternalIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
|
|
|
+ List<String> accountExternalIds = gzhAccountList.stream().map(ContentPlatformGzhAccount::getExternalId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
String dateStr = dt.substring(0, 4) + "-" + dt.substring(4, 6) + "-" + dt.substring(6, 8);
|
|
|
List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
|
|
|
Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
|
|
@@ -279,8 +309,9 @@ public class ContentPlatformDatastatJob {
|
|
|
for (Record record : dataList) {
|
|
|
ContentPlatformFwhDataStatTotal item = new ContentPlatformFwhDataStatTotal();
|
|
|
String channel = record.getString(0);
|
|
|
- Integer firstLevelCount = Integer.valueOf((String) record.get(1));
|
|
|
+ int firstLevelCount = Integer.parseInt((String) record.get(1));
|
|
|
Integer fissionCount = parseInteger(record.get(2));
|
|
|
+ Double arpu = parseDouble(record.get(3));
|
|
|
item.setDateStr(dt);
|
|
|
item.setChannel(channel);
|
|
|
item.setFirstLevelCount(firstLevelCount);
|
|
@@ -298,10 +329,16 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
item.setFansIncreaseCount(fansIncreaseCount);
|
|
|
|
|
|
- if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
|
|
|
- BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
+ BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
+ BigDecimal rounded = fissionRate.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
item.setScore(rounded.doubleValue());
|
|
|
+ BigDecimal unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.FWH_PUSH);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ item.setUnitPrice(unitPrice.doubleValue());
|
|
|
+ BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ }
|
|
|
}
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
@@ -355,7 +392,8 @@ public class ContentPlatformDatastatJob {
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
List<ContentPlatformQwDataStat> existList = getQwDatastatCount(dt);
|
|
|
- List<String> existRootSourceIds = existList.stream().map(ContentPlatformQwDataStat::getRootSourceId).collect(Collectors.toList());
|
|
|
+ List<String> existRootSourceIds = existList.stream().map(ContentPlatformQwDataStat::getRootSourceId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
Map<String, Long> rootSourceIdMap = qwPlanList.stream()
|
|
|
.collect(Collectors.toMap(ContentPlatformQwPlan::getRootSourceId, ContentPlatformQwPlan::getId));
|
|
|
List<Long> planIds = qwPlanList.stream().map(ContentPlatformQwPlan::getId).collect(Collectors.toList());
|
|
@@ -449,19 +487,27 @@ public class ContentPlatformDatastatJob {
|
|
|
dt = param;
|
|
|
}
|
|
|
Map<String, ContentPlatformQwDataStatTotal> saveMap = new HashMap<>();
|
|
|
- String outSql = String.format("SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv " +
|
|
|
- "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
+ String outSql = String.format(
|
|
|
+ "SELECT first_level.channel_shortname, first_level.first_uv, fission.split_uv, price.arpu " +
|
|
|
+ "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
"left join loghubods.out_channel_mid_split_total fission " +
|
|
|
"on first_level.channel_shortname = fission.channel_shortname and first_level.dt = fission.dt " +
|
|
|
"and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
- "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '投放渠道内去重' ;", dt);
|
|
|
+ "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
|
|
|
+ "on first_level.channel_shortname = price.channel_shortname and first_level.dt = price.dt " +
|
|
|
+ "and first_level.type = price.type and first_level.tag = price.tag " +
|
|
|
+ "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '投放渠道内去重' ;", dt);
|
|
|
List<Record> outDataList = OdpsUtil.getOdpsData(outSql);
|
|
|
+ List<ContentPlatformAccount> accountList = getAllAccount();
|
|
|
+ Map<String, ContentPlatformAccount> accountMap = accountList.stream()
|
|
|
+ .collect(Collectors.toMap(ContentPlatformAccount::getChannel, account -> account));
|
|
|
Long now = System.currentTimeMillis();
|
|
|
if (CollectionUtils.isNotEmpty(outDataList)) {
|
|
|
for (Record record : outDataList) {
|
|
|
String channel = (String) record.get(0);
|
|
|
int firstLevelCount = Integer.parseInt((String) record.get(1));
|
|
|
Integer fissionCount = parseInteger(record.get(2));
|
|
|
+ Double arpu = parseDouble(record.get(3));
|
|
|
if (firstLevelCount == 0) {
|
|
|
continue;
|
|
|
}
|
|
@@ -471,11 +517,32 @@ public class ContentPlatformDatastatJob {
|
|
|
if (item.getFirstLevelCount() == null) {
|
|
|
item.setFirstLevelCount(0);
|
|
|
}
|
|
|
-
|
|
|
- if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
|
|
|
- BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ ContentPlatformAccount account = accountMap.get(channel);
|
|
|
+ if (Objects.isNull(account)) {
|
|
|
+ account = new ContentPlatformAccount();
|
|
|
+ account.setPrice("{\n" +
|
|
|
+ "\"qiweihezuo_price_mode\": \"static\",\n" +
|
|
|
+ "\"qiweihezuo_dynamic_times\":3,\n" +
|
|
|
+ "\"qiweihezuo_static_price\":0.12,\n" +
|
|
|
+ "\"fuwuhaodaiyunying_price_mode\": \"dynamic\",\n" +
|
|
|
+ "\"fuwuhaodaiyunying_dynamic_times\":3,\n" +
|
|
|
+ "\"fuwuhaodaiyunying_static_price\":0.12,\n" +
|
|
|
+ "\"gongzhonghaozidonghuifu_price_mode\": \"static\",\n" +
|
|
|
+ "\"gongzhonghaozidonghuifu_dynamic_times\":3,\n" +
|
|
|
+ "\"gongzhonghaozidonghuifu_static_price\":0.12\n" +
|
|
|
+ "}");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
+ BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
+ BigDecimal rounded = fissionRate.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
item.setScore(rounded.doubleValue());
|
|
|
+ BigDecimal unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.QW);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ item.setUnitPrice(unitPrice.doubleValue());
|
|
|
+ BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ }
|
|
|
}
|
|
|
item.setFirstLevelCount(item.getFirstLevelCount() + firstLevelCount);
|
|
|
item.setCreateTimestamp(now);
|
|
@@ -529,7 +596,6 @@ public class ContentPlatformDatastatJob {
|
|
|
continue;
|
|
|
}
|
|
|
if (saveMap.containsKey(channel) && !out2Channels.contains(channel)) {
|
|
|
-
|
|
|
saveMap.remove(channel);
|
|
|
}
|
|
|
ContentPlatformQwDataStatReplyTotal item = saveMap.getOrDefault(channel, new ContentPlatformQwDataStatReplyTotal());
|
|
@@ -546,10 +612,12 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
List<ContentPlatformQwDataStatReplyTotal> saveList = new ArrayList<>(saveMap.values());
|
|
|
if (CollectionUtils.isNotEmpty(saveList)) {
|
|
|
- List<String> channels = saveList.stream().map(ContentPlatformQwDataStatReplyTotal::getChannel).distinct().collect(Collectors.toList());
|
|
|
+ List<String> channels = saveList.stream().map(ContentPlatformQwDataStatReplyTotal::getChannel).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
List<ContentPlatformQwDataStatReplyTotal> channelScoreList = dataStatMapperExt.getQwTotalDatastatReplyScoreList(dt, channels);
|
|
|
Map<String, Double> channelScoreMap = channelScoreList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformQwDataStatReplyTotal::getChannel, ContentPlatformQwDataStatReplyTotal::getScore, (a, b) -> a));
|
|
|
+ .collect(Collectors.toMap(ContentPlatformQwDataStatReplyTotal::getChannel,
|
|
|
+ ContentPlatformQwDataStatReplyTotal::getScore, (a, b) -> a));
|
|
|
for (ContentPlatformQwDataStatReplyTotal item : saveList) {
|
|
|
item.setScore(channelScoreMap.get(item.getChannel()));
|
|
|
}
|
|
@@ -566,12 +634,16 @@ public class ContentPlatformDatastatJob {
|
|
|
dt = param;
|
|
|
}
|
|
|
List<ContentPlatformQwDataStatSubChannel> saveList = new ArrayList<>();
|
|
|
- String outSql = String.format("SELECT first_level.channel_shortname, first_level.subchannel, first_level.first_uv, fission.split_uv " +
|
|
|
- "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
+ String outSql = String.format(
|
|
|
+ "SELECT first_level.channel_shortname, first_level.subchannel, first_level.first_uv, fission.split_uv, price.arpu " +
|
|
|
+ "FROM loghubods.out_channel_mid_first_total first_level " +
|
|
|
"left join loghubods.out_channel_mid_split_total fission " +
|
|
|
- "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel and first_level.dt = fission.dt " +
|
|
|
- "and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
- "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
|
|
|
+ "on first_level.channel_shortname = fission.channel_shortname and first_level.subchannel = fission.subchannel " +
|
|
|
+ "and first_level.dt = fission.dt and first_level.type = fission.type and first_level.tag = fission.tag " +
|
|
|
+ "left join loghubods.wecom_cooperation_dynamic_unit_price price " +
|
|
|
+ "on first_level.channel_shortname = price.channel_shortname and first_level.subchannel = price.subchannel " +
|
|
|
+ "and first_level.dt = price.dt and first_level.type = price.type and first_level.tag = price.tag " +
|
|
|
+ "WHERE first_level.dt = %s and first_level.type = '企微外部' and first_level.tag = '分投放渠道客户分账号去重' ;", dt);
|
|
|
List<Record> outDataList = OdpsUtil.getOdpsData(outSql);
|
|
|
List<ContentPlatformAccount> accountList = getAllAccount();
|
|
|
Map<String, ContentPlatformAccount> accountMap = accountList.stream()
|
|
@@ -587,6 +659,7 @@ public class ContentPlatformDatastatJob {
|
|
|
String subChannel = (String) record.get(1);
|
|
|
int firstLevelCount = Integer.parseInt((String) record.get(2));
|
|
|
Integer fissionCount = parseInteger(record.get(3));
|
|
|
+ Double arpu = parseDouble(record.get(4));
|
|
|
if (firstLevelCount == 0) {
|
|
|
continue;
|
|
|
}
|
|
@@ -597,23 +670,27 @@ public class ContentPlatformDatastatJob {
|
|
|
continue;
|
|
|
}
|
|
|
List<ContentPlatformQwPlan> qwPlans = qwPlanMap.getOrDefault(account.getId(), new ArrayList<>());
|
|
|
- List<String> subChannelList = qwPlans.stream().map(ContentPlatformQwPlan::getSubChannel).distinct().collect(Collectors.toList());
|
|
|
+ List<String> subChannelList = qwPlans.stream().map(ContentPlatformQwPlan::getSubChannel).distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(qwPlans) || !subChannelList.contains(subChannel)) {
|
|
|
noSubChannelRecordList.add(record);
|
|
|
continue;
|
|
|
}
|
|
|
item.setCreateAccountId(account.getId());
|
|
|
item.setSubChannel(subChannel);
|
|
|
- if (item.getFirstLevelCount() == null) {
|
|
|
- item.setFirstLevelCount(0);
|
|
|
- }
|
|
|
+ item.setFirstLevelCount(firstLevelCount);
|
|
|
|
|
|
- if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
|
|
|
- BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
+ BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
+ BigDecimal rounded = fissionRate.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
item.setScore(rounded.doubleValue());
|
|
|
+ BigDecimal unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.QW);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ item.setUnitPrice(unitPrice.doubleValue());
|
|
|
+ BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ }
|
|
|
}
|
|
|
- item.setFirstLevelCount(item.getFirstLevelCount() + firstLevelCount);
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
|
}
|
|
@@ -621,6 +698,7 @@ public class ContentPlatformDatastatJob {
|
|
|
String channel = (String) record.get(0);
|
|
|
int firstLevelCount = Integer.parseInt((String) record.get(2));
|
|
|
Integer fissionCount = parseInteger(record.get(3));
|
|
|
+ Double arpu = parseDouble(record.get(4));
|
|
|
ContentPlatformQwDataStatSubChannel item = new ContentPlatformQwDataStatSubChannel();
|
|
|
item.setDateStr(dt);
|
|
|
ContentPlatformAccount account = accountMap.get(channel);
|
|
@@ -629,15 +707,18 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
item.setCreateAccountId(account.getId());
|
|
|
item.setSubChannel("未知");
|
|
|
- if (item.getFirstLevelCount() == null) {
|
|
|
- item.setFirstLevelCount(0);
|
|
|
- }
|
|
|
- item.setFirstLevelCount(item.getFirstLevelCount() + firstLevelCount);
|
|
|
+ item.setFirstLevelCount(firstLevelCount);
|
|
|
|
|
|
- if (Objects.nonNull(fissionCount) && fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() * 10 / firstLevelCount);
|
|
|
- BigDecimal rounded = num.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
+ BigDecimal fissionRate = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
+ BigDecimal rounded = fissionRate.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
item.setScore(rounded.doubleValue());
|
|
|
+ BigDecimal unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.QW);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ item.setUnitPrice(unitPrice.doubleValue());
|
|
|
+ BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ }
|
|
|
}
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
@@ -655,13 +736,59 @@ public class ContentPlatformDatastatJob {
|
|
|
example.createCriteria().andSubChannelIsNotNull();
|
|
|
return qwPlanMapper.selectByExample(example);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private Integer parseInteger(Object value) {
|
|
|
try {
|
|
|
return Integer.parseInt((String) value);
|
|
|
} catch (NumberFormatException e) {
|
|
|
- return null;
|
|
|
+ return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private Double parseDouble(Object value) {
|
|
|
+ try {
|
|
|
+ return Double.parseDouble((String) value);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getUnitPriceMin(BussinessTypeEnum typeEnum) {
|
|
|
+ return unitPriceMinConfig.get(typeEnum.getVal());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getUnitPriceMax(BussinessTypeEnum typeEnum) {
|
|
|
+ return unitPriceMaxConfig.get(typeEnum.getVal());
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getUnitPrice(String price, BigDecimal fissionRate, Double arpu, BussinessTypeEnum typeEnum) {
|
|
|
+ JSONObject priceJSON;
|
|
|
+ try {
|
|
|
+ priceJSON = JSONObject.parseObject(price);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String priceModeKey = typeEnum.getPrefix() + "_price_mode";
|
|
|
+ String staticPriceKey = typeEnum.getPrefix() + "_static_price";
|
|
|
+ String dynamicTimesKey = typeEnum.getPrefix() + "_dynamic_times";
|
|
|
+ String priceMode = priceJSON.getString(priceModeKey);
|
|
|
+ Double staticPrice = priceJSON.getDouble(staticPriceKey);
|
|
|
+ Double dynamicTimes = priceJSON.getDouble(dynamicTimesKey);
|
|
|
+ if ("static".equals(priceMode)) {
|
|
|
+ if (Objects.isNull(staticPrice) || staticPrice == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return new BigDecimal(staticPrice);
|
|
|
+ } else if ("dynamic".equals(priceMode)) {
|
|
|
+ if (Objects.isNull(fissionRate) || Objects.isNull(arpu) || Objects.isNull(dynamicTimes) || dynamicTimes == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return fissionRate.multiply(new BigDecimal(arpu))
|
|
|
+ .multiply(BigDecimal.valueOf(dynamicTimes))
|
|
|
+ .setScale(2, RoundingMode.HALF_UP)
|
|
|
+ .min(BigDecimal.valueOf(getUnitPriceMax(typeEnum)))
|
|
|
+ .max(BigDecimal.valueOf(getUnitPriceMin(typeEnum)));
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|