Bladeren bron

查询日消耗最大账户信息

zhaoxian 4 jaren geleden
bovenliggende
commit
1bc28dbb2a

+ 4 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/EtlKuaishouReportAccountHourlyController.java

@@ -115,6 +115,7 @@ public class EtlKuaishouReportAccountHourlyController {
         }
         return Result.error("查询失败");
     }
+
     /**
      * 获取当日花费最大的账户
      *
@@ -126,15 +127,16 @@ public class EtlKuaishouReportAccountHourlyController {
     @AutoLog(value = "获取当日花费最大的账户")
     @ApiOperation(value = "获取当日花费最大的账户", notes = "获取当日花费最大的账户")
     @GetMapping(value = "/getMaxChargeAccountId")
-    public Result<Object> getMaxChargeAccountId(Long accountId,String userId) {
+    public Result<Object> getMaxChargeAccountId(Long accountId) {
         try {
-            return etlKuaishouReportAccountHourlyService.getMaxChargeAccountId(accountId,userId);
+            return etlKuaishouReportAccountHourlyService.getMaxChargeAccountId(accountId);
         } catch (Exception e) {
             log.error("查询异常,", e.getMessage());
             e.printStackTrace();
         }
         return Result.error("查询失败");
     }
+
     /**
      * 获取时间趋势汇总投放数据
      *

+ 1 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/EtlKuaishouReportAccountDailyMapper.java

@@ -23,7 +23,6 @@ public interface EtlKuaishouReportAccountDailyMapper extends BaseMapper<EtlKuais
 
     List<JSONObject> getOnedayEtlReportList(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("accountId") Long accountId, @Param("value") String value, @Param("type") String type);
 
-    Long getMaxChargeAccountId(@Param("userId") String userId);
+    JSONObject getMaxChargeAccountId(@Param("userId") String userId);
 
-    Long getMaxCharge();
 }

+ 6 - 9
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouReportAccountDailyMapper.xml

@@ -252,18 +252,15 @@
     </select>
 
 
-    <select id="getMaxChargeAccountId" resultType="java.lang.Long">
-        SELECT t1.account_id
+    <select id="getMaxChargeAccountId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.account_id as 'accountId',
+        t1.auth_name as 'accountName'
         FROM ctop_user_allocation t1
-                 INNER JOIN ctop_kuaishou_report_hourly_account t2 ON t1.account_id = t2.account_id
+                 LEFT JOIN ctop_kuaishou_report_hourly_account t2 ON t1.account_id = t2.account_id
         where t2.stat_date = DATE_FORMAT(now(), '%Y-%m-%d')
+          <if test="userId!=null">
           AND t1.user_id = #{userId}
-        order by sum(charge) desc limit 1
-    </select>
-    <select id="getMaxCharge" resultType="java.lang.Long">
-          SELECT account_id
-        FROM  ctop_kuaishou_report_hourly_account
-        where stat_date = DATE_FORMAT(now(), '%Y-%m-%d')
+          </if>
         order by sum(charge) desc limit 1
     </select>
 </mapper>

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IEtlKuaishouReportAccountHourlyService.java

@@ -22,7 +22,7 @@ public interface IEtlKuaishouReportAccountHourlyService extends IService<EtlKuai
 
     Result<Object> getEtlReportList(JSONObject request);
 
-    Result<Object> getMaxChargeAccountId(Long accountId, String userId);
+    Result<Object> getMaxChargeAccountId(Long accountId);
 
     Result<Object> getMaxChargeAccountIdByUser(String userId);
 }

+ 18 - 19
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaishouReportAccountHourlyServiceImpl.java

@@ -136,30 +136,16 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
 
     @Override
     public Result<Object> getMaxChargeAccountIdByUser(String userId) {
-        Long accountId = etlDailyAccountMapper.getMaxChargeAccountId(userId);
-        if (Check.isNull(accountId)) {
-            accountId = etlDailyAccountMapper.getMaxCharge();
+        JSONObject obj = etlDailyAccountMapper.getMaxChargeAccountId(userId);
+        if (Check.isNull(obj)) {
+            obj = etlDailyAccountMapper.getMaxChargeAccountId(null);
         }
-        return Result.ok(accountId);
+        return Result.ok(obj.getLong("accountId"));
     }
 
     @Override
-    public Result<Object> getMaxChargeAccountId(Long accountId, String userId) {
-        if (Check.isNull(accountId)) {
-            accountId = etlDailyAccountMapper.getMaxChargeAccountId(userId);
-            if (Check.isNull(accountId)) {
-                accountId = etlDailyAccountMapper.getMaxCharge();
-            }
-        }
+    public Result<Object> getMaxChargeAccountId(Long accountId) {
         JSONObject obj = new JSONObject();
-        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
-        if (Check.isNull(oauthToken)) {
-            return Result.error("未获取到账户信息,accountId:" + accountId);
-        }
-        JSONObject fundJson = iKuaishouInterfaceService.fundGet(oauthToken);
-        if (!Check.isNull(fundJson)) {
-            obj.put("totalBalance", fundJson.getBigDecimal("balance")); // 余额
-        }
         UserAllocation userAllocation = allocationMapper.getUserAllocation(accountId);
         if (!Check.isNull(userAllocation)) {
             obj.put("accountName", userAllocation.getAuthName());
@@ -169,6 +155,19 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
         Integer counts = kuaiShouCreativeMapper.getRejectedCountsforAccountId(accountId);
         obj.put("rejectedCounts", counts);
         obj.put("accountId", accountId);
+        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+        if (Check.isNull(oauthToken)) {
+            Result result = new Result();
+            result.setResult(obj);
+            result.setSuccess(false);
+            result.setCode(500);
+            result.setMessage("未获取到账户信息");
+            return result;
+        }
+        JSONObject fundJson = iKuaishouInterfaceService.fundGet(oauthToken);
+        if (!Check.isNull(fundJson)) {
+            obj.put("totalBalance", fundJson.getBigDecimal("balance")); // 余额
+        }
         return Result.ok(obj);
     }
 }