Quellcode durchsuchen

服务层逻辑修改

lth vor 1 Jahr
Ursprung
Commit
c1c0bb0052

+ 18 - 17
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/AdsOverallSummaryServiceImpl.java

@@ -53,7 +53,7 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
                 "SUM(x.today_amount) total_amount ,\n" +
                 "SUM(x.today_agent_count) total_agent_count ,\n" +
                 "SUM(x.today_game_count) total_game_count ,\n" +
-                "SUM(x.today_new_player_amount)/SUM(x.today_total_cost) total_roi \n" +
+                "IFNULL(SUM(x.today_new_player_amount)/SUM(x.today_total_cost),0) total_roi \n" +
                 "FROM ads_overall_summary x " + totalDataConString);
 
         //自定义回显对象 结果自动封装到给定的Entity对象中
@@ -82,7 +82,7 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
                 "SUM(x.yesterday_agent_count) yesterday_agent_count ,\n" +
                 "SUM(x.today_game_count) today_game_count ,\n" +
                 "SUM(x.yesterday_game_count) yesterday_game_count ,\n" +
-                "SUM(x.first_new_user_amount)/SUM(x.today_total_cost) first_roi \n" +
+                "IFNULL(SUM(x.first_new_user_amount)/SUM(x.today_total_cost),0) first_roi \n" +
                 "FROM ads_overall_summary x" + todayDataConString);
 
         //自定义回显对象 结果自动封装到给定的Entity对象中
@@ -91,10 +91,10 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
         //执行自定义sql语句
         dao.execute(todayDataSql);
         //得到一个包含有今日和昨日数据的AdsOverallSummaryVO对象
-        AdsOverallSummaryVO todayDataVO = todayDataSql.getObject(AdsOverallSummaryVO.class);
+        AdsOverallSummaryVO adsOverallSummaryVO = todayDataSql.getObject(AdsOverallSummaryVO.class);
 
         //拼接参数
-        copyNullProperties(totalDataVO, todayDataVO);
+        copyNullProperties(totalDataVO, adsOverallSummaryVO);
 
         //7日和30日Roi数据需要手动计算
         //7日内新用户累计充值
@@ -102,21 +102,16 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
         //7日内总消耗
         BigDecimal d7TotalCost = BigDecimal.valueOf(dao.func(AdsOverallSummary.class, "sum", "todayTotalCost", myCondition(param, false, 7)));
         //计算7日Roi
-        todayDataVO.setD7TotalRoi(d7NewPlayerAmount.divide(d7TotalCost, 4, RoundingMode.HALF_UP));
+        adsOverallSummaryVO.setD7TotalRoi(BigDecimal.ZERO.equals(d7TotalCost) ? BigDecimal.ZERO : d7NewPlayerAmount.divide(d7TotalCost, 4, RoundingMode.HALF_UP));
 
         //30日内新用户累计充值
         BigDecimal d30NewPlayerAmount = BigDecimal.valueOf(dao.func(AdsOverallSummary.class, "sum", "todayNewPlayerAmount", myCondition(param, false, 30)));
         //30日内总消耗
         BigDecimal d30TotalCost = BigDecimal.valueOf(dao.func(AdsOverallSummary.class, "sum", "todayTotalCost", myCondition(param, false, 30)));
         //计算30日Roi
-        todayDataVO.setD30TotalRoi(d30NewPlayerAmount.divide(d30TotalCost, 4, RoundingMode.HALF_UP));
+        adsOverallSummaryVO.setD30TotalRoi(BigDecimal.ZERO.equals(d30TotalCost) ? BigDecimal.ZERO : d30NewPlayerAmount.divide(d30TotalCost, 4, RoundingMode.HALF_UP));
 
-        //存在首日Roi为null的情况 消耗为0 但是有用户充值 无法计算 设置为 0
-        if (todayDataVO.getFirstRoi() == null) {
-            todayDataVO.setFirstRoi(BigDecimal.ZERO);
-        }
-
-        return todayDataVO;
+        return adsOverallSummaryVO;
     }
 
     @Override
@@ -133,7 +128,7 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
                 "SUM(x.today_amount) amount, " +
                 "SUM(x.today_buy_amount) buy_amount," +
                 "SUM(x.today_nature_amount) nature_amount, " +
-                "SUM(x.first_new_user_amount)/SUM(x.today_total_cost) first_roi," +
+                "IFNULL(SUM(x.first_new_user_amount)/SUM(x.today_total_cost),0) first_roi," +
                 "SUM(x.today_player_count) player_account " +
                 "from ads_overall_summary x " + lineConString);
 
@@ -176,6 +171,12 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
             cri.where().andEquals("accountId", param.getAccountId());
         }
 
+        /*
+        * 如果是组长 则需要排除掉 pitcher = -2 的所有数据
+        * cri.where().andNotEquals("pithcerId", -2);
+        * 如果是管理员账号 则不需要排除 pitcher = -2 的数据
+        * */
+
         //根据参数拼接条件
         switch (queryDays) {
             case 1:
@@ -216,8 +217,8 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
     /**
      * 所有为空值的属性都不copy
      *
-     * @param source
-     * @param target
+     * @param source 原数据
+     * @param target 目标数据
      */
     public static void copyNullProperties(Object source, Object target) {
         BeanUtils.copyProperties(source, target, getNullField(source));
@@ -226,8 +227,8 @@ public class AdsOverallSummaryServiceImpl implements IAdsOverallSummaryService {
     /**
      * 获取属性中为空的字段
      *
-     * @param target
-     * @return
+     * @param target 目标对象
+     * @return 不需要替换的字段数组
      */
     private static String[] getNullField(Object target) {
         BeanWrapper beanWrapper = new BeanWrapperImpl(target);