|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.ctop.toutiao.modules.report.utils;
|
|
|
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
@@ -9,7 +10,7 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
- * Created by JQ.bi on 2020.6.5
|
|
|
+ * Created by JQ.bi on 2020.6.5
|
|
|
*/
|
|
|
public class LinkUtils {
|
|
|
|
|
@@ -17,13 +18,15 @@ public class LinkUtils {
|
|
|
//数据对比,环比计算
|
|
|
public static List<JSONObject> getCompareDate(List<JSONObject> beforeData, List<JSONObject> AfterData, String standard) {
|
|
|
List<JSONObject> result = new ArrayList<>();
|
|
|
- beforeData.forEach(before -> {
|
|
|
+ for (int i = 0; i < beforeData.size(); i++) {
|
|
|
+ JSONObject before = beforeData.get(i);
|
|
|
String yesStat = String.valueOf(before.get(standard));
|
|
|
//修改点记率 乱码
|
|
|
- byte[] click = before.getBytes("clickRate");
|
|
|
- String clickRate = new String(click, Charset.forName("UTF-8"));
|
|
|
- before.put("clickRate",clickRate);
|
|
|
-
|
|
|
+ byte[] click = before.getBytes("clickRate");
|
|
|
+ if (!Check.isNull(click)) {
|
|
|
+ String clickRate = new String(click, Charset.forName("UTF-8"));
|
|
|
+ before.put("clickRate", clickRate);
|
|
|
+ }
|
|
|
AfterData.forEach(after -> {
|
|
|
if ((String.valueOf(after.get(standard))).equals(yesStat)) {
|
|
|
//消耗较昨日环比
|
|
@@ -32,26 +35,27 @@ public class LinkUtils {
|
|
|
after.put("showProportion", countLink(BigDecimal.valueOf(after.getLong("showNum")), BigDecimal.valueOf(before.getLong("showNum"))));
|
|
|
//点击量较昨日环比
|
|
|
after.put("photoClickProportion", countLink(BigDecimal.valueOf(after.getLong("click")), BigDecimal.valueOf(before.getLong("click"))));
|
|
|
- if(after.getLong("convertNum")!=null){
|
|
|
+ if (after.getLong("convertNum") != null) {
|
|
|
after.put("convertNumProportion", countLink(BigDecimal.valueOf(after.getLong("convertNum")), BigDecimal.valueOf(before.getLong("convertNum"))));
|
|
|
}
|
|
|
//修改点记率 乱码
|
|
|
- byte[] aftClick = after.getBytes("clickRate");
|
|
|
- String afterCli = new String(aftClick, Charset.forName("UTF-8"));
|
|
|
- after.put("clickRate",afterCli);
|
|
|
-
|
|
|
+ byte[] aftClick = after.getBytes("clickRate");
|
|
|
+ if (!Check.isNull(aftClick)) {
|
|
|
+ String afterCli = new String(aftClick, Charset.forName("UTF-8"));
|
|
|
+ after.put("clickRate", afterCli);
|
|
|
+ }
|
|
|
before.put("afterData", after);
|
|
|
}
|
|
|
});
|
|
|
result.add(before);
|
|
|
- });
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//环比计算
|
|
|
public static BigDecimal countLink(BigDecimal numA, BigDecimal numB) {
|
|
|
BigDecimal link = new BigDecimal(0);
|
|
|
- if (numB.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
+ if (numB.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
link = (numA.subtract(numB)).divide(numB, 4, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
return link;
|
|
@@ -60,7 +64,7 @@ public class LinkUtils {
|
|
|
public static void main(String[] args) {
|
|
|
BigDecimal a = BigDecimal.valueOf(5.2);
|
|
|
BigDecimal b = BigDecimal.valueOf(4.2);
|
|
|
- System.out.println(countLink(a,b));
|
|
|
+ System.out.println(countLink(a, b));
|
|
|
}
|
|
|
|
|
|
}
|