Browse Source

培训、报表接口代码优化、华南报表

hcst_sunzhen 5 năm trước cách đây
mục cha
commit
4939ddbe26

+ 29 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/EduLessonController.java

@@ -5,13 +5,19 @@ import cn.com.ctop.manage.modules.edu.service.IEduLessonService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Slf4j
 @Api(tags="在线培训")
@@ -92,4 +98,27 @@ public class EduLessonController {
         result.setSuccess(true);
         return result;
     }
+
+    @GetMapping(value = "/lesson/upload")
+    public Result<Map<String,String>> updaloadLesson(@RequestBody EduLesson eduLesson){
+        Result<Map<String,String>> result = new Result();
+        Map<String,String> resultMap = new HashMap<>();
+
+        if (StringUtils.isBlank(eduLesson.getMedia()) || StringUtils.isBlank(eduLesson.getTitle()) ||
+            StringUtils.isBlank(eduLesson.getTopic()) || StringUtils.isBlank(eduLesson.getIntro()) ||
+            StringUtils.isBlank(eduLesson.getOssFileUrl()) || StringUtils.isBlank(eduLesson.getFileType())
+        ){
+            result.error500("参数不可为空");
+            return result;
+        }
+        String lessonId = eduLessonService.uploadLesson(eduLesson);
+
+        resultMap.put("lessonId",lessonId);
+        result.setResult(resultMap);
+        result.setSuccess(true);
+
+        return result;
+    }
+
+
 }

+ 2 - 0
module-ctop/src/main/java/cn/com/ctop/manage/modules/edu/service/IEduLessonService.java

@@ -16,4 +16,6 @@ public interface IEduLessonService extends IService<EduLesson> {
     public void getKuaishouEduLesson(String url);
     public List<String> getTitleList(String media);
     public List<String> getTopicList(String media,String title);
+
+    String uploadLesson(EduLesson eduLesson);
 }

+ 19 - 4
module-ctop/src/main/java/cn/com/ctop/manage/modules/edu/service/impl/EduLessonServiceImpl.java

@@ -9,14 +9,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 在线培训
@@ -170,4 +169,20 @@ public class EduLessonServiceImpl extends ServiceImpl<EduLessonMapper, EduLesson
             e.printStackTrace();
         }
     }
+
+    //培训视频上传接口
+    @Override
+    public String uploadLesson(EduLesson eduLesson){
+        String uuid = UUID.randomUUID().toString().replaceAll("-","");
+        System.out.println();
+
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        eduLesson.setLessonId(uuid);
+        eduLesson.setCreator(sysUser.getRealname());
+
+        save(eduLesson);
+        return uuid;
+    }
+
+
 }

+ 157 - 165
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportServiceImpl.java

@@ -15,6 +15,7 @@ import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAccount;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
 import cn.com.ctop.kuaishou.modules.utils.DownloadUtils;
@@ -744,78 +745,83 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             }
         };
 
-        // 构造请求
-        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
-            @Override
-            public String getMethod() {
-                return "POST";
-            }
-        };
-
-        httpEntity.setHeader("Access-Token", access_token);
-
-        CloseableHttpResponse response = null;
-        CloseableHttpClient client = null;
-
-        try {
-            client = HttpClientBuilder.create().build();
-            httpEntity.setURI(URI.create(open_api_domain + path));
-            httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
-
-            response = client.execute(httpEntity);
-            if (response != null && response.getStatusLine().getStatusCode() == 200) {
-                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-                StringBuffer result = new StringBuffer();
-                String line = "";
-                while ((line = bufferedReader.readLine()) != null) {
-                    result.append(line);
-                }
-                bufferedReader.close();
-
-                JSONObject  json = JSONObject.parseObject(result.toString());
-                String jsonString = JSON.toJSONString(json);
-
-                if(!Check.isNull(json)){
-                    Integer code = json.getInteger("code");
-                    if(code != 0){
-                        log.info("返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ",message:"+ json.getString("message"));
-                        return;
-                    }
-                    JSONObject dataJson = json.getJSONObject("data");
-
-                    //解析数据并入库
-                    BytedanceDailyReportTask task = new BytedanceDailyReportTask();
-                    task.setAccountId(accountId);
-                    task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
-                    task.setTaskId(dataJson.getLong("task_id") ==  null ? null : dataJson.getLong("task_id") );
-                    task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
-                    task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
-                    task.setJson(jsonString);
-                    task.setTaskStatus(dataJson.getString("task_status"));
-                    task.setTaskType(dataJson.getString("task_type"));
-                    task.setType(type);
-                    task.setIsDownload(0);
-                    task.setStatus(1); //状态1正常 0废弃
-                    bytedanceDailyReportTaskMapper.insert(task);
-                }
-
-            }else{
-                log.error("请求有误:" + response );
-            }
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            try {
-                if (response != null) {
-                    response.close();
-                }
-                client.close();
-            } catch (IOException e) {
-                e.printStackTrace();
+        JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
+        if(json == null){
+            log.error("请求有误:" + JSONObject.toJSONString(data));
+        }
+        //
+        //// 构造请求
+        //HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+        //    @Override
+        //    public String getMethod() {
+        //        return "POST";
+        //    }
+        //};
+        //
+        //httpEntity.setHeader("Access-Token", access_token);
+        //
+        //CloseableHttpResponse response = null;
+        //CloseableHttpClient client = null;
+
+        //try {
+        //    client = HttpClientBuilder.create().build();
+        //    httpEntity.setURI(URI.create(open_api_domain + path));
+        //    httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
+        //
+        //    response = client.execute(httpEntity);
+        //    if (response != null && response.getStatusLine().getStatusCode() == 200) {
+        //        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+        //        StringBuffer result = new StringBuffer();
+        //        String line = "";
+        //        while ((line = bufferedReader.readLine()) != null) {
+        //            result.append(line);
+        //        }
+        //        bufferedReader.close();
+
+                //JSONObject  json = JSONObject.parseObject(result.toString());
+        String jsonString = JSON.toJSONString(json);
+
+        if(!Check.isNull(json)){
+            Integer code = json.getInteger("code");
+            if(code != 0){
+                log.info("返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ",message:"+ json.getString("message"));
+                return;
             }
+            JSONObject dataJson = json.getJSONObject("data");
+
+            //解析数据并入库
+            BytedanceDailyReportTask task = new BytedanceDailyReportTask();
+            task.setAccountId(accountId);
+            task.setTaskCreateTime(dataJson.getDate("create_time") == null ? null : dataJson.getDate("create_time"));
+            task.setTaskId(dataJson.getLong("task_id") ==  null ? null : dataJson.getLong("task_id") );
+            task.setTaskName(dataJson.getString("task_name") == null ? null : dataJson.getString("task_name"));
+            task.setTaskParams(JSON.toJSONString(dataJson.getJSONObject("task_params")));
+            task.setJson(jsonString);
+            task.setTaskStatus(dataJson.getString("task_status"));
+            task.setTaskType(dataJson.getString("task_type"));
+            task.setType(type);
+            task.setIsDownload(0);
+            task.setStatus(1); //状态1正常 0废弃
+            bytedanceDailyReportTaskMapper.insert(task);
         }
+        //
+        //    }else{
+        //        log.error("请求有误:" + response );
+        //    }
+        //} catch (ClientProtocolException e) {
+        //    e.printStackTrace();
+        //} catch (IOException e) {
+        //    e.printStackTrace();
+        //} finally {
+        //    try {
+        //        if (response != null) {
+        //            response.close();
+        //        }
+        //        client.close();
+        //    } catch (IOException e) {
+        //        e.printStackTrace();
+        //    }
+        //}
     }
 
     //获取任务列表
@@ -855,36 +861,42 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                         }
                     };
 
-                    // 构造请求
-                    HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
-                        @Override
-                        public String getMethod() {
-                            return "GET";
-                        }
-                    };
-
-                    httpEntity.setHeader("Access-Token",access_token);
+                    JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
+                    if(json == null){
+                        log.error("请求有误:" + JSONObject.toJSONString(data));
+                    }
 
-                    CloseableHttpResponse response = null;
-                    CloseableHttpClient client = null;
+                    //
+                    //// 构造请求
+                    //HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+                    //    @Override
+                    //    public String getMethod() {
+                    //        return "GET";
+                    //    }
+                    //};
+                    //
+                    //httpEntity.setHeader("Access-Token",access_token);
+                    //
+                    //CloseableHttpResponse response = null;
+                    //CloseableHttpClient client = null;
 
                     try {
-                        client = HttpClientBuilder.create().build();
-                        httpEntity.setURI(URI.create(open_api_domain + path));
-                        httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
-
-                        response = client.execute(httpEntity);
-                        log.info("response为:" +  response);
-                        if (response != null && response.getStatusLine().getStatusCode() == 200) {
-                            BufferedReader bufferedReader  = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-                            StringBuffer result = new StringBuffer();
-                            String line = "";
-                            while((line = bufferedReader.readLine()) != null) {
-                                result.append(line);
-                            }
-                            bufferedReader.close();
-
-                            JSONObject  json = JSONObject.parseObject(result.toString());
+                        //client = HttpClientBuilder.create().build();
+                        //httpEntity.setURI(URI.create(open_api_domain + path));
+                        //httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
+                        //
+                        //response = client.execute(httpEntity);
+                        //log.info("response为:" +  response);
+                        //if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                        //    BufferedReader bufferedReader  = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                        //    StringBuffer result = new StringBuffer();
+                        //    String line = "";
+                        //    while((line = bufferedReader.readLine()) != null) {
+                        //        result.append(line);
+                        //    }
+                        //    bufferedReader.close();
+
+                         //   JSONObject  json = JSONObject.parseObject(result.toString());
                             String jsonString = JSON.toJSONString(json);
                             log.info("返回json为" + jsonString);
 
@@ -916,25 +928,12 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                                     }
                                 }
 
-                        }else{
-                            log.error("请求有误:" + response);
-                        }
+                        //}else{
+                        //    log.error("请求有误:" + response);
+                        //}
 
-                    } catch (ClientProtocolException e) {
-                        e.printStackTrace();
-                    } catch (IOException e) {
-                        e.printStackTrace();
-                    } catch (Exception e) {
+                    }  catch (Exception e) {
                         e.printStackTrace();
-                    }finally {
-                        try {
-                            if (response != null) {
-                                response.close();
-                            }
-                            client.close();
-                        } catch (IOException e) {
-                            e.printStackTrace();
-                        }
                     }
 
                 }
@@ -1039,26 +1038,31 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             }
         };
 
-        // 构造请求
-        HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
-            @Override
-            public String getMethod() {
-                return "GET";
-            }
-        };
-
-        httpEntity.setHeader("Access-Token",access_token);
-
-        CloseableHttpResponse response = null;
-        CloseableHttpClient client = null;
-
+        JSONObject json = HttpUtils.bytedancePostRequest(access_token, open_api_domain + path, JSONObject.parseObject(JSONObject.toJSONString(data)));
+        if(json == null){
+            log.error("请求有误:" + JSONObject.toJSONString(data));
+        }
+        //
+        //// 构造请求
+        //HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
+        //    @Override
+        //    public String getMethod() {
+        //        return "GET";
+        //    }
+        //};
+        //
+        //httpEntity.setHeader("Access-Token",access_token);
+        //
+        //CloseableHttpResponse response = null;
+        //CloseableHttpClient client = null;
+        //
         int returnCode = 200;
         try {
             //Long connectStartTime = System.currentTimeMillis();
 
-            client = HttpClientBuilder.create().build();
-            httpEntity.setURI(URI.create(open_api_domain + path));
-            httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
+            //client = HttpClientBuilder.create().build();
+            //httpEntity.setURI(URI.create(open_api_domain + path));
+            //httpEntity.setEntity(new StringEntity(JSONObject.toJSONString(data), ContentType.APPLICATION_JSON));
 
             //RequestConfig requestConfig = RequestConfig.custom()
             //        .setConnectTimeout(60000).setConnectionRequestTimeout(60000)
@@ -1066,28 +1070,28 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
             //httpEntity.setConfig(requestConfig);
 
-            response = client.execute(httpEntity);
+            //response = client.execute(httpEntity);
             //Long connectEndTime = System.currentTimeMillis();
             //log.info("头条获取素材报表数据任务获取服务器数据结束,执行耗时:{}秒", (connectEndTime - connectStartTime) / 1000);
             //System.out.println(response);
-            if (response != null && response.getStatusLine().getStatusCode() == 200) {
-                BufferedReader bufferedReader  = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-                StringBuffer result = new StringBuffer();
-                String line = "";
-                while((line = bufferedReader.readLine()) != null) {
-                    result.append(line);
-                }
-                bufferedReader.close();
-
-                JSONObject  json = JSONObject.parseObject(result.toString());
-                String jsonString = JSON.toJSONString(json);
+            //if (response != null && response.getStatusLine().getStatusCode() == 200) {
+                //BufferedReader bufferedReader  = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
+                //StringBuffer result = new StringBuffer();
+                //String line = "";
+                //while((line = bufferedReader.readLine()) != null) {
+                //    result.append(line);
+                //}
+                //bufferedReader.close();
+                //
+                //JSONObject  json = JSONObject.parseObject(result.toString());
+                //String jsonString = JSON.toJSONString(json);
                 //log.info("返回值为:" + jsonString);
 
                 if(!Check.isNull(json)){
                     Integer code = json.getInteger("code");
                     if(code != 0){
-                        log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + jsonString);
-                        returnCode = -1;
+                        log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + JSONObject.toJSONString(data));
+                        //returnCode = -1;
                         return -1;
                     }
 
@@ -1102,7 +1106,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     JSONArray jsonArrayay = jsonData.getJSONArray("list");
                     if(jsonArrayay.size() == 0){
                         log.info("accountId:" + accountId + ";没有数据。总页数为:" +  totalPage + "当前页数为:" + currentPage);
-                        returnCode = 1;
+                        //returnCode = 1;
                         return 1;
                     }
 
@@ -1227,30 +1231,18 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                         bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
                     }
                 }else{
-                    returnCode = -1;
-                    log.error("服务器返回为空,json:"+jsonString);
+                    //returnCode = -1;
+                    log.error("服务器返回为空,json:"+JSONObject.toJSONString(data));
                     return -1;
                 }
-            }else{
-                log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" +response);
-                returnCode = 0;  //504等状态0;-2连接服务器报错 ;-1对方服务器返回值为空;200正常;1没有数据(也属于正常)
-                return 0;
-            }
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
-            returnCode = -2;
-        } catch (IOException e) {
+         //   }else{
+         //       log.error("头条素材报表请求有误:accountId:" + accountId + ",开始时间:" + startDate + "结束时间:" + endDate + "错误返回:" +response);
+         //       returnCode = 0;  //504等状态0;-2连接服务器报错 ;-1对方服务器返回值为空;200正常;1没有数据(也属于正常)
+         //       return 0;
+         //   }
+        } catch (Exception e) {
             e.printStackTrace();
             returnCode = -2;
-        } finally {
-            try {
-                if (response != null) {
-                    response.close();
-                }
-                client.close();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
         }
         return returnCode;
     }

+ 1 - 1
performance-appraisal/src/main/java/cn/com/ctop/huananvideoreport/controller/HuananVideoReportController.java

@@ -250,7 +250,7 @@ public class HuananVideoReportController {
 	 @PostMapping(value = "/getHuananMaterialInfo")
 	 public Result getHuananMaterialInfo(HttpServletRequest req) throws ParseException {
 		 Result<List<UserDto2>> result = new Result<List<UserDto2>>();
-		 huananVideoReportService.getHuananMaterialInfo("2020-04-01", "2020-04-29");
+		 huananVideoReportService.getHuananMaterialInfo("2020-05-01", "2020-05-07");
 		 result.setSuccess(true);
 		 return result;
 	 }

+ 29 - 0
performance-appraisal/src/main/java/cn/com/ctop/huananvideoreport/mapper/xml/HuananVideoReportMapper.xml

@@ -53,5 +53,34 @@
         where a.material_id = #{materialId}
     </select>
 
+    <select id="getHuananVideoInfo" resultType="cn.com.ctop.huananvideoreport.entity.HuananVideoReport">
+        select
+        a.material_id as materialId,
+--         a.account_id as accountId,
+--         b.auth_name as authName,
+        b.project_id as projectId,
+        b.project_name as projectName,
+        b.advertiser_id as advertiserId,
+        b.advertiser_name as advertiserName,
+        a.stat_datetime as statDatetime,
+        sum(a.cost) as cost,
+        d.signature as signature,
+        d.video_url as video_url,
+        e.url as url,
+        e.material_name as materialName,
+        1 as appType
+        from ctop_bytedance_report_material_daily a
+        left join ctop_user_allocation b on a.account_id = b.account_id
+        left join user_company c on b.user_id = c.user_id
+        left join ctop_bytedance_video_info d on a.material_id = d.material_id
+        left join (select code,url,material_name from ctop_material_info group by code) e on d.signature = e.code
+        where c.company_id = '6608ed13c0dd42de93c790dbdf124234'
+        and a.image_mode in ('CREATIVE_IMAGE_MODE_VIDEO',
+        'CREATIVE_IMAGE_MODE_VIDEO_VERTICAL')
+        and date_format(stat_datetime,'%Y-%m-%d') &gt;= #{startDate}
+        and date_format(stat_datetime,'%Y-%m-%d') &lt;= #{endDate}
+        group by `statDatetime`,`signature`
+        order by `statDatetime`,`projectId`,`materialId`
+    </select>
 
 </mapper>