|
@@ -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;
|
|
@@ -14,7 +17,6 @@ import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
@@ -54,11 +56,11 @@ public class ContentPlatformDatastatJob {
|
|
|
@Autowired
|
|
|
private ContentPlatformPlanService planService;
|
|
|
|
|
|
- @Value("${unit.price.min:0.1}")
|
|
|
- private Double unitPriceMin;
|
|
|
+ @ApolloJsonValue("${unit.price.min:{\"gzh_autoReply\":0.1,\"fwh_push\":0.1,\"qw\":0.15}}")
|
|
|
+ private Map<String, Double> unitPriceMinConfig;
|
|
|
|
|
|
- @Value("${unit.price.max:0.2}")
|
|
|
- private Double unitPriceMax;
|
|
|
+ @ApolloJsonValue("${unit.price.max:{\"gzh_autoReply\":0.2,\"fwh_push\":0.2,\"qw\":0.3}}")
|
|
|
+ private Map<String, Double> unitPriceMaxConfig;
|
|
|
|
|
|
|
|
|
@XxlJob("syncContentPlatformGzhDatastatJob")
|
|
@@ -97,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)) {
|
|
@@ -163,7 +165,7 @@ 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);
|
|
@@ -184,15 +186,15 @@ public class ContentPlatformDatastatJob {
|
|
|
item.setFansIncreaseCount(fansIncreaseCount);
|
|
|
|
|
|
if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
- BigDecimal rounded = num.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ 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 = num.multiply(new BigDecimal(arpu)).multiply(BigDecimal.valueOf(account.getPrice()))
|
|
|
- .setScale(2, RoundingMode.HALF_UP)
|
|
|
- .min(BigDecimal.valueOf(unitPriceMax)).max(BigDecimal.valueOf(unitPriceMin));
|
|
|
- item.setUnitPrice(unitPrice.doubleValue());
|
|
|
- BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount));
|
|
|
- item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ Double unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.GZH_AUTO_REPLY);
|
|
|
+ item.setUnitPrice(unitPrice);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ Double settlementAmount = unitPrice * firstLevelCount;
|
|
|
+ item.setSettlementAmount(settlementAmount);
|
|
|
+ }
|
|
|
}
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
@@ -241,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)) {
|
|
@@ -307,7 +309,7 @@ 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);
|
|
@@ -328,15 +330,15 @@ public class ContentPlatformDatastatJob {
|
|
|
item.setFansIncreaseCount(fansIncreaseCount);
|
|
|
|
|
|
if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
- BigDecimal rounded = num.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ 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 = num.multiply(new BigDecimal(arpu)).multiply(BigDecimal.valueOf(account.getPrice()))
|
|
|
- .setScale(2, RoundingMode.HALF_UP)
|
|
|
- .min(BigDecimal.valueOf(unitPriceMax)).max(BigDecimal.valueOf(unitPriceMin));
|
|
|
- item.setUnitPrice(unitPrice.doubleValue());
|
|
|
- BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount));
|
|
|
- item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ Double unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.FWH_PUSH);
|
|
|
+ item.setUnitPrice(unitPrice);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ Double settlementAmount = unitPrice * firstLevelCount;
|
|
|
+ item.setSettlementAmount(settlementAmount);
|
|
|
+ }
|
|
|
}
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
@@ -518,19 +520,29 @@ public class ContentPlatformDatastatJob {
|
|
|
ContentPlatformAccount account = accountMap.get(channel);
|
|
|
if (Objects.isNull(account)) {
|
|
|
account = new ContentPlatformAccount();
|
|
|
- account.setPrice(1d);
|
|
|
+ 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 num = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
- BigDecimal rounded = num.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ 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 = num.multiply(new BigDecimal(arpu)).multiply(BigDecimal.valueOf(account.getPrice()))
|
|
|
- .setScale(2, RoundingMode.HALF_UP)
|
|
|
- .min(BigDecimal.valueOf(unitPriceMax)).max(BigDecimal.valueOf(unitPriceMin));
|
|
|
- item.setUnitPrice(unitPrice.doubleValue());
|
|
|
- BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount));
|
|
|
- item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ Double unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.QW);
|
|
|
+ item.setUnitPrice(unitPrice);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ Double settlementAmount = unitPrice * firstLevelCount;
|
|
|
+ item.setSettlementAmount(settlementAmount);
|
|
|
+ }
|
|
|
}
|
|
|
item.setFirstLevelCount(item.getFirstLevelCount() + firstLevelCount);
|
|
|
item.setCreateTimestamp(now);
|
|
@@ -669,15 +681,15 @@ public class ContentPlatformDatastatJob {
|
|
|
item.setFirstLevelCount(firstLevelCount);
|
|
|
|
|
|
if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
- BigDecimal rounded = num.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ 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 = num.multiply(new BigDecimal(arpu)).multiply(BigDecimal.valueOf(account.getPrice()))
|
|
|
- .setScale(2, RoundingMode.HALF_UP)
|
|
|
- .min(BigDecimal.valueOf(unitPriceMax)).max(BigDecimal.valueOf(unitPriceMin));
|
|
|
- item.setUnitPrice(unitPrice.doubleValue());
|
|
|
- BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount));
|
|
|
- item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ Double unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.QW);
|
|
|
+ item.setUnitPrice(unitPrice);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ Double settlementAmount = unitPrice * firstLevelCount;
|
|
|
+ item.setSettlementAmount(settlementAmount);
|
|
|
+ }
|
|
|
}
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
@@ -698,15 +710,15 @@ public class ContentPlatformDatastatJob {
|
|
|
item.setFirstLevelCount(firstLevelCount);
|
|
|
|
|
|
if (fissionCount > 0 && firstLevelCount > 0) {
|
|
|
- BigDecimal num = BigDecimal.valueOf(fissionCount.doubleValue() / firstLevelCount);
|
|
|
- BigDecimal rounded = num.multiply(new BigDecimal(10)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ 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 = num.multiply(new BigDecimal(arpu)).multiply(BigDecimal.valueOf(account.getPrice()))
|
|
|
- .setScale(2, RoundingMode.HALF_UP)
|
|
|
- .min(BigDecimal.valueOf(unitPriceMax)).max(BigDecimal.valueOf(unitPriceMin));
|
|
|
- item.setUnitPrice(unitPrice.doubleValue());
|
|
|
- BigDecimal settlementAmount = unitPrice.multiply(new BigDecimal(firstLevelCount));
|
|
|
- item.setSettlementAmount(settlementAmount.doubleValue());
|
|
|
+ Double unitPrice = getUnitPrice(account.getPrice(), fissionRate, arpu, BussinessTypeEnum.QW);
|
|
|
+ item.setUnitPrice(unitPrice);
|
|
|
+ if (Objects.nonNull(unitPrice)) {
|
|
|
+ Double settlementAmount = unitPrice * firstLevelCount;
|
|
|
+ item.setSettlementAmount(settlementAmount);
|
|
|
+ }
|
|
|
}
|
|
|
item.setCreateTimestamp(now);
|
|
|
saveList.add(item);
|
|
@@ -741,4 +753,43 @@ public class ContentPlatformDatastatJob {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private Double getUnitPriceMin(BussinessTypeEnum typeEnum) {
|
|
|
+ return unitPriceMinConfig.get(typeEnum.getVal());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getUnitPriceMax(BussinessTypeEnum typeEnum) {
|
|
|
+ return unitPriceMaxConfig.get(typeEnum.getVal());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double 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 staticPrice;
|
|
|
+ } else if ("dynamic".equals(priceMode)) {
|
|
|
+ if (Objects.isNull(fissionRate) || Objects.isNull(arpu) || Objects.isNull(dynamicTimes) || dynamicTimes == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ BigDecimal unitPrice = 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 unitPrice.doubleValue();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|