Browse Source

fix on 2020.11.30

jiequan.bi 4 years ago
parent
commit
b43ee56f76

+ 21 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaiShouAccountReportServiceImpl.java

@@ -96,12 +96,22 @@ public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportS
         List<JSONObject> result;
         String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.dicMapKs);
         if (startDate.equals(endDate)) {
-            result = kuaiShouAccountReportMapper.queryTodaySumByHourGroupAccount(filedAll, startDate, hour, accounts, target, order);
-            JSONObject afterSum = kuaiShouAccountReportMapper.querySumByHour(filedAll, startDate, hour, accounts);
-            JSONObject beforeSum = kuaiShouAccountReportMapper.querySumByHour(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), hour, accounts);
-            result.add(afterSum);
-            result.add(beforeSum);
-            result.add(countTotal(afterSum, beforeSum));
+            if(startDate.equals(DateUtils.date2Str())) {
+                result = kuaiShouAccountReportMapper.queryTodaySumByHourGroupAccount(filedAll, startDate, hour, accounts, target, order);
+                JSONObject afterSum = kuaiShouAccountReportMapper.querySumByHour(filedAll, startDate, hour, accounts);
+                JSONObject beforeSum = kuaiShouAccountReportMapper.querySumByHour(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), hour, accounts);
+                result.add(afterSum);
+                result.add(beforeSum);
+                result.add(countTotal(afterSum, beforeSum));
+            }
+            else {
+                result = kuaiShouAccountReportMapper.querySumByDateGroupAccount(filedAll, endDate, startDate, accounts, target, order);
+                JSONObject afterSum = kuaiShouAccountReportMapper.queryAllSumByStartEndDate(filedAll, endDate, startDate, accounts);
+                JSONObject beforeSum = kuaiShouAccountReportMapper.queryAllSumByStartEndDate(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, endDate, -1), DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), accounts);
+                result.add(afterSum);
+                result.add(beforeSum);
+                result.add(countTotal(afterSum, beforeSum));
+            }
         } else {
             if(accounts.size()>1){
                 result = kuaiShouAccountReportMapper.querySumByDateGroupAccount(filedAll, endDate, startDate, accounts, target, order);
@@ -117,7 +127,11 @@ public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportS
     public List<JSONObject> getExcelDataBy(String filed, String mediaId, JSONArray accounts, String startDate, String endDate, int hour, String target, String order) {
         List<JSONObject> result;
         if (startDate.equals(endDate)) {
-            result = kuaiShouAccountReportMapper.queryTodaySumByHourGroupAccount(filed, startDate, hour, accounts, target, order);
+            if(startDate.equals(DateUtils.date2Str())) {
+                result = kuaiShouAccountReportMapper.queryTodaySumByHourGroupAccount(filed, startDate, hour, accounts, target, order);
+            }else {
+                result = kuaiShouAccountReportMapper.querySumByDateGroupAccount(filed, endDate, startDate, accounts, target, order);
+            }
         } else {
             result = kuaiShouAccountReportMapper.querySumByDateGroupAccount(filed, endDate, startDate, accounts, target, order);
         }

+ 48 - 44
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAccountReportCtrl.java

@@ -39,6 +39,7 @@ public class BytedanceAccountReportCtrl {
 
     /**
      * 查询素材报表chart数据
+     *
      * @param requestBody
      * @return
      */
@@ -49,31 +50,33 @@ public class BytedanceAccountReportCtrl {
         if (requestBody.isEmpty()) {
             log.error("request body is empty");
             resultBody.setSuccess(false);
-        }
-        String mediaId = requestBody.getString("mediaId");
-        BigDecimal discount = requestBody.getBigDecimal("discount");
-        JSONArray accounts = requestBody.getJSONArray("accountIds");
-        if(accounts.isEmpty()){
-         return resultBody;
-        }
-        String startDate = requestBody.getString("startDate");
-        String endDate = requestBody.getString("endDate");
-        try {
-            Map<String, Object> sumData = bytedanceAccountReportService.getSumDataBy(mediaId, discount, accounts, startDate, endDate);
-            List<JSONObject> chartData = bytedanceAccountReportService.getChartDataBy(mediaId, discount, accounts, startDate, endDate);
-            result.put("sumData",sumData);
-            result.put("chartData",chartData);
-            resultBody.setResult(result);
-            resultBody.setSuccess(true);
-        } catch (Exception e) {
-            log.error(e.getMessage(), e);
-            resultBody.setSuccess(false);
+        } else {
+            String mediaId = requestBody.getString("mediaId");
+            BigDecimal discount = requestBody.getBigDecimal("discount");
+            JSONArray accounts = requestBody.getJSONArray("accountIds");
+            if (accounts.isEmpty()) {
+                return resultBody;
+            }
+            String startDate = requestBody.getString("startDate");
+            String endDate = requestBody.getString("endDate");
+            try {
+                Map<String, Object> sumData = bytedanceAccountReportService.getSumDataBy(mediaId, discount, accounts, startDate, endDate);
+                List<JSONObject> chartData = bytedanceAccountReportService.getChartDataBy(mediaId, discount, accounts, startDate, endDate);
+                result.put("sumData", sumData);
+                result.put("chartData", chartData);
+                resultBody.setResult(result);
+                resultBody.setSuccess(true);
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                resultBody.setSuccess(false);
+            }
         }
         return resultBody;
     }
 
     /**
      * 查询素材报表表格数据
+     *
      * @param requestBody
      * @return
      */
@@ -87,16 +90,16 @@ public class BytedanceAccountReportCtrl {
         String mediaId = requestBody.getString("mediaId");
         BigDecimal discount = requestBody.getBigDecimal("discount");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
-        if(accounts.isEmpty()){
+        if (accounts.isEmpty()) {
             return result;
         }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
-        int hour= requestBody.getInteger("hour");
-        String target= requestBody.getString("target");
-        String order= requestBody.getString("order");
+        int hour = requestBody.getInteger("hour");
+        String target = requestBody.getString("target");
+        String order = requestBody.getString("order");
         try {
-            List<JSONObject> listData= bytedanceAccountReportService.getListDataBy(mediaId,discount,accounts,startDate,endDate,hour,target,order);
+            List<JSONObject> listData = bytedanceAccountReportService.getListDataBy(mediaId, discount, accounts, startDate, endDate, hour, target, order);
             result.setResult(listData);
             result.setSuccess(true);
         } catch (Exception e) {
@@ -107,7 +110,8 @@ public class BytedanceAccountReportCtrl {
     }
 
     /**
-     *  导出数据
+     * 导出数据
+     *
      * @param requestBody
      * @param request
      * @param response
@@ -116,41 +120,41 @@ public class BytedanceAccountReportCtrl {
     public void getExcelReport(@RequestBody JSONObject requestBody,
                                HttpServletRequest request,
                                HttpServletResponse response) {
-        JSONArray columns=requestBody.getJSONArray("columns");
-        if(columns.isEmpty()){
+        JSONArray columns = requestBody.getJSONArray("columns");
+        if (columns.isEmpty()) {
             log.error("请选择需要导出的字段");
         }
-        String filed= JsonResourceUtil.joinFiled(AccountReportConstants.dicMapBy,columns);
-        List<String> titles= new ArrayList<>();
+        String filed = JsonResourceUtil.joinFiled(AccountReportConstants.dicMapBy, columns);
+        List<String> titles = new ArrayList<>();
         titles.add("账户Id");
         titles.add("账户名称");
-        titles.addAll(JsonResourceUtil.joinTitle(AccountReportConstants.dicMapBy,columns));
+        titles.addAll(JsonResourceUtil.joinTitle(AccountReportConstants.dicMapBy, columns));
         //此处增加两个元素是为了保证数据有序
-        columns.add(0,"accountId");
-        columns.add(1,"authName");
+        columns.add(0, "accountId");
+        columns.add(1, "authName");
         String mediaId = requestBody.getString("mediaId");
         JSONArray accounts = requestBody.getJSONArray("accountIds");
-        if(accounts.isEmpty()){
+        if (accounts.isEmpty()) {
             return;
         }
         String startDate = requestBody.getString("startDate");
         String endDate = requestBody.getString("endDate");
-        String target= requestBody.getString("target");
-        String order= requestBody.getString("order");
-        int hour= requestBody.getInteger("hour");
-        List<JSONObject> excelData= bytedanceAccountReportService.getExcelDataBy(filed,mediaId,accounts,startDate,endDate,hour,target,order);
-        if(excelData.isEmpty()){
+        String target = requestBody.getString("target");
+        String order = requestBody.getString("order");
+        int hour = requestBody.getInteger("hour");
+        List<JSONObject> excelData = bytedanceAccountReportService.getExcelDataBy(filed, mediaId, accounts, startDate, endDate, hour, target, order);
+        if (excelData.isEmpty()) {
             return;
         }
-        List<List<Object>> excelList= new ArrayList<>();
-        excelData.forEach(data->{
-            List<Object> temp= new ArrayList<>();
-            columns.forEach(k->{
+        List<List<Object>> excelList = new ArrayList<>();
+        excelData.forEach(data -> {
+            List<Object> temp = new ArrayList<>();
+            columns.forEach(k -> {
                 temp.add(data.get(k.toString()));
             });
             excelList.add(temp);
         });
-        try{
+        try {
             String[] headers = titles.toArray(new String[titles.size()]);
             OutputStream os = response.getOutputStream();
             ExportExcelUtils eeu = new ExportExcelUtils();
@@ -160,7 +164,7 @@ public class BytedanceAccountReportCtrl {
             workbook.write(os);
             os.flush();
             os.close();
-        }catch (IOException e){
+        } catch (IOException e) {
             log.error(e.getMessage());
         }
     }

+ 22 - 7
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceAccountReportServiceImpl.java

@@ -103,12 +103,22 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
         List<JSONObject> result;
         String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.dicMapBy);
         if (startDate.equals(endDate)) {
-            result = bytedanceAccountReportMapper.queryTodaySumByHourGroupAccount(filedAll, startDate, hour, accounts, target, order);
-            JSONObject afterSum = bytedanceAccountReportMapper.querySumByHour(filedAll, startDate, hour, accounts);
-            JSONObject beforeSum = bytedanceAccountReportMapper.querySumByHour(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), hour, accounts);
-            result.add(afterSum);
-            result.add(beforeSum);
-            result.add(countTotal(afterSum, beforeSum));
+            //由于时报数据不准,修改逻辑除当日数据外全部请求日报数据
+            if(startDate.equals(DateUtils.date2Str())){
+                result = bytedanceAccountReportMapper.queryTodaySumByHourGroupAccount(filedAll, startDate, hour, accounts, target, order);
+                JSONObject afterSum = bytedanceAccountReportMapper.querySumByHour(filedAll, startDate, hour, accounts);
+                JSONObject beforeSum = bytedanceAccountReportMapper.querySumByHour(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), hour, accounts);
+                result.add(afterSum);
+                result.add(beforeSum);
+                result.add(countTotal(afterSum, beforeSum));
+            }else {
+                result= bytedanceAccountReportMapper.querySumByDateGroupAccount(filedAll, endDate, startDate, accounts, target, order);
+                JSONObject afterSum = bytedanceAccountReportMapper.queryAllSumByStartEndDate(filedAll, endDate, startDate, accounts);
+                JSONObject beforeSum = bytedanceAccountReportMapper.queryAllSumByStartEndDate(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, endDate, -1), DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), accounts);
+                result.add(afterSum);
+                result.add(beforeSum);
+                result.add(countTotal(afterSum, beforeSum));
+            }
         } else {
             if (accounts.size() > 1) {
                 result = bytedanceAccountReportMapper.querySumByDateGroupAccount(filedAll, endDate, startDate, accounts, target, order);
@@ -124,7 +134,12 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
     public List<JSONObject> getExcelDataBy(String filed, String mediaId, JSONArray accounts, String startDate, String endDate, int hour, String target, String order) {
         List<JSONObject> result;
         if (startDate.equals(endDate)) {
-            result = bytedanceAccountReportMapper.queryTodaySumByHourGroupAccount(filed, startDate, hour, accounts, target, order);
+            //由于时报数据不准,修改逻辑除当日数据外全部请求日报数据
+            if(startDate.equals(DateUtils.date2Str())){
+                result = bytedanceAccountReportMapper.queryTodaySumByHourGroupAccount(filed, startDate, hour, accounts, target, order);
+            }else {
+                result= bytedanceAccountReportMapper.querySumByDateGroupAccount(filed, startDate, endDate, accounts, target, order);
+            }
         } else {
             result = bytedanceAccountReportMapper.querySumByDateGroupAccount(filed, endDate, startDate, accounts, target, order);
         }