소스 검색

素材报表

hcst_sunzhen 5 년 전
부모
커밋
e603824232

+ 37 - 4
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -753,9 +753,9 @@ public class DateUtils extends PropertyEditorSupport {
         return sdf.format(calendar.getTime());
     }
 
-    public static void main(String[] args) throws ParseException {
-        System.out.println(DateUtils.addDay( "2020-01-03",  7));
-    }
+    //public static void main(String[] args) throws ParseException {
+    //    System.out.println(DateUtils.addDay( "2020-01-03",  7));
+    //}
 
     public static Date addDay(Date date, int day) {
         Calendar calendar = Calendar.getInstance();
@@ -1174,7 +1174,40 @@ public class DateUtils extends PropertyEditorSupport {
 
         return resultMap;
     }
-}
 
+    /***
+     * 两日期之间相差天数
+     * @param dateStart
+     * @param dateEnd
+     * @return
+     */
+    public static long getDiscrepantDays(String dateStart, String dateEnd){
+        //设置转换的日期格式
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        //结束时间
+        Date startDate = null;
+        Date endDate = null;
+        try {
+            //开始时间
+            startDate = sdf.parse(dateStart);
+            endDate = sdf.parse(dateEnd);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+
+        //得到相差的天数 betweenDate
+        long betweenDate = (endDate.getTime() - startDate.getTime())/(60*60*24*1000);
+
+        //打印控制台相差的天数
+        System.out.println(betweenDate);
+        return betweenDate;
+    }
+
+    public static void main(String[] args) {
+        getDiscrepantDays("2020-01-01","2020-03-31");
+    }
+
+}
 
 

+ 103 - 8
module-report/src/main/java/cn/com/ctop/bytedance/controller/BytedanceReportController.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.bytedance.controller;
 
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
 import cn.com.ctop.bytedance.service.IBytedanceReportService;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
@@ -12,8 +13,11 @@ import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @Slf4j
 @RestController
@@ -136,19 +140,56 @@ public class BytedanceReportController {
 
         try {
             log.info("头条获取素材报表数据任务执行开始");
-            Long start = System.currentTimeMillis();
+            Long starttime = System.currentTimeMillis();
             List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
             if (null == tokens || tokens.size() <= 0) {
                 log.info("头条获取素材报表数据任务执行失败:未获取到可用的token");
                 return result;
             }
-            for (CtopOauthToken token : tokens) {
-                //if(token.getAccountId() == 1647352267707396L){
-                    bytedanceReportService.bytedanceMaterialReport(token,startDate,endDate);
-                //}
-            }
-            Long end = System.currentTimeMillis();
-            log.info("头条获取素材报表数据任务执行结束,执行耗时:{}秒", (end - start) / 1000);
+
+            //非异步
+            //for (CtopOauthToken token : tokens) {
+            //    //if(token.getAccountId() == 1647352267707396L){
+            //    bytedanceReportService.bytedanceMaterialReport(token,startDate,endDate);
+            //    //}
+            //}
+            ////}
+
+            //多线程
+            final ExecutorService executorService = Executors.newFixedThreadPool(8);
+            tokens.forEach(token -> {
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
+                            String start = null;
+                            String end = null;
+                            for(int i=0; i<=days; i++){
+                                start = DateUtils.addDay(startDate,i);
+                                end = start;
+                                //获取头条素材报表数据
+                                bytedanceReportService.bytedanceMaterialReport(token,start,end);
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        } finally {
+                        }
+                    }
+                });
+            });
+            ////
+
+
+
+
+
+
+
+
+
+            Long endtime = System.currentTimeMillis();
+            log.info("头条获取素材报表数据任务执行结束,执行耗时:{}秒", (endtime - starttime) / 1000);
         } catch (Exception e) {
             log.error("头条获取素材报表数据任务执行结失败");
             e.printStackTrace();
@@ -157,4 +198,58 @@ public class BytedanceReportController {
         return result;
     }
 
+    @GetMapping("/bytedance/bytedanceMaterialReporRetry")
+    public Result bytedanceMaterialReportRetry() {
+        log.info("头条获取素材报表失败数据任务重试开始");
+        Result result = new Result<>();
+        try {
+            List<BytedanceReportMaterialRetry> retryList = bytedanceReportService.getRetryList();
+            //for(BytedanceReportMaterialRetry retry:retryList){
+            //    CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(retry.getAccountId()));
+            //    log.info("头条素材报表当前accountId为:" + token.getAccountId());
+            //    bytedanceReportService.bytedanceMaterialReportRetry(token,retry.getStartDate(),retry.getEndDate());
+            //}
+
+
+                //
+                //多线程
+                final ExecutorService executorService = Executors.newFixedThreadPool(8);
+                retryList.forEach(retry -> {
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(retry.getAccountId()));
+                                log.info("头条素材报表当前accountId为:" + token.getAccountId());
+                                bytedanceReportService.bytedanceMaterialReportRetry(token,retry.getStartDate(),retry.getEndDate());
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            } finally {
+                            }
+                        }
+                    });
+                });
+                ////
+
+                //
+
+
+
+
+
+
+
+
+
+        } catch (Exception e) {
+            log.error("条获取素材报表失败数据任务重试失败");
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+
+        log.info("头条获取素材报表失败数据任务重试结束");
+        return result;
+    }
+
+
 }

+ 242 - 0
module-report/src/main/java/cn/com/ctop/bytedance/controller/BytedanceReportMaterialRetryController.java

@@ -0,0 +1,242 @@
+package cn.com.ctop.bytedance.controller;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.util.oConvertUtils;
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
+import cn.com.ctop.bytedance.service.IBytedanceReportMaterialRetryService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
+
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+import com.alibaba.fastjson.JSON;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+ /**
+ * 头条素材报表连接出错数据记录表
+ * @author jeecg-boot
+ * @date   2020-04-21
+ * @version V1.0
+ */
+@Slf4j
+@Api(tags="头条素材报表连接出错数据记录表")
+@RestController
+@RequestMapping("/bytedance/bytedanceReportMaterialRetry")
+public class BytedanceReportMaterialRetryController {
+	@Autowired
+	private IBytedanceReportMaterialRetryService bytedanceReportMaterialRetryService;
+
+	/**
+	  * 分页列表查询
+	 * @param bytedanceReportMaterialRetry
+	 * @param pageNo
+	 * @param pageSize
+	 * @param req
+	 * @return
+	 */
+	@AutoLog(value = "头条素材报表连接出错数据记录表-分页列表查询")
+	@ApiOperation(value="头条素材报表连接出错数据记录表-分页列表查询", notes="头条素材报表连接出错数据记录表-分页列表查询")
+	@GetMapping(value = "/list")
+	public Result<IPage<BytedanceReportMaterialRetry>> queryPageList(BytedanceReportMaterialRetry bytedanceReportMaterialRetry,
+																	 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+																	 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+																	 HttpServletRequest req) {
+		Result<IPage<BytedanceReportMaterialRetry>> result = new Result<IPage<BytedanceReportMaterialRetry>>();
+		QueryWrapper<BytedanceReportMaterialRetry> queryWrapper = QueryGenerator.initQueryWrapper(bytedanceReportMaterialRetry, req.getParameterMap());
+		Page<BytedanceReportMaterialRetry> page = new Page<BytedanceReportMaterialRetry>(pageNo, pageSize);
+		IPage<BytedanceReportMaterialRetry> pageList = bytedanceReportMaterialRetryService.page(page, queryWrapper);
+		result.setSuccess(true);
+		result.setResult(pageList);
+		return result;
+	}
+
+	/**
+	  *   添加
+	 * @param bytedanceReportMaterialRetry
+	 * @return
+	 */
+	@AutoLog(value = "头条素材报表连接出错数据记录表-添加")
+	@ApiOperation(value="头条素材报表连接出错数据记录表-添加", notes="头条素材报表连接出错数据记录表-添加")
+	@PostMapping(value = "/add")
+	public Result<BytedanceReportMaterialRetry> add(@RequestBody BytedanceReportMaterialRetry bytedanceReportMaterialRetry) {
+		Result<BytedanceReportMaterialRetry> result = new Result<BytedanceReportMaterialRetry>();
+		try {
+			bytedanceReportMaterialRetryService.save(bytedanceReportMaterialRetry);
+			result.success("添加成功!");
+		} catch (Exception e) {
+			log.error(e.getMessage(),e);
+			result.error500("操作失败");
+		}
+		return result;
+	}
+
+	/**
+	  *  编辑
+	 * @param bytedanceReportMaterialRetry
+	 * @return
+	 */
+	@AutoLog(value = "头条素材报表连接出错数据记录表-编辑")
+	@ApiOperation(value="头条素材报表连接出错数据记录表-编辑", notes="头条素材报表连接出错数据记录表-编辑")
+	@PutMapping(value = "/edit")
+	public Result<BytedanceReportMaterialRetry> edit(@RequestBody BytedanceReportMaterialRetry bytedanceReportMaterialRetry) {
+		Result<BytedanceReportMaterialRetry> result = new Result<BytedanceReportMaterialRetry>();
+		BytedanceReportMaterialRetry bytedanceReportMaterialRetryEntity = bytedanceReportMaterialRetryService.getById(bytedanceReportMaterialRetry.getId());
+		if(bytedanceReportMaterialRetryEntity==null) {
+			result.error500("未找到对应实体");
+		}else {
+			boolean ok = bytedanceReportMaterialRetryService.updateById(bytedanceReportMaterialRetry);
+			if(ok) {
+				result.success("修改成功!");
+			}
+		}
+
+		return result;
+	}
+
+	/**
+	  *   通过id删除
+	 * @param id
+	 * @return
+	 */
+	@AutoLog(value = "头条素材报表连接出错数据记录表-通过id删除")
+	@ApiOperation(value="头条素材报表连接出错数据记录表-通过id删除", notes="头条素材报表连接出错数据记录表-通过id删除")
+	@DeleteMapping(value = "/delete")
+	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
+		try {
+			bytedanceReportMaterialRetryService.removeById(id);
+		} catch (Exception e) {
+			log.error("删除失败",e.getMessage());
+			return Result.error("删除失败!");
+		}
+		return Result.ok("删除成功!");
+	}
+
+	/**
+	  *  批量删除
+	 * @param ids
+	 * @return
+	 */
+	@AutoLog(value = "头条素材报表连接出错数据记录表-批量删除")
+	@ApiOperation(value="头条素材报表连接出错数据记录表-批量删除", notes="头条素材报表连接出错数据记录表-批量删除")
+	@DeleteMapping(value = "/deleteBatch")
+	public Result<BytedanceReportMaterialRetry> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
+		Result<BytedanceReportMaterialRetry> result = new Result<BytedanceReportMaterialRetry>();
+		if(ids==null || "".equals(ids.trim())) {
+			result.error500("参数不识别!");
+		}else {
+			this.bytedanceReportMaterialRetryService.removeByIds(Arrays.asList(ids.split(",")));
+			result.success("删除成功!");
+		}
+		return result;
+	}
+
+	/**
+	  * 通过id查询
+	 * @param id
+	 * @return
+	 */
+	@AutoLog(value = "头条素材报表连接出错数据记录表-通过id查询")
+	@ApiOperation(value="头条素材报表连接出错数据记录表-通过id查询", notes="头条素材报表连接出错数据记录表-通过id查询")
+	@GetMapping(value = "/queryById")
+	public Result<BytedanceReportMaterialRetry> queryById(@RequestParam(name="id",required=true) String id) {
+		Result<BytedanceReportMaterialRetry> result = new Result<BytedanceReportMaterialRetry>();
+		BytedanceReportMaterialRetry bytedanceReportMaterialRetry = bytedanceReportMaterialRetryService.getById(id);
+		if(bytedanceReportMaterialRetry==null) {
+			result.error500("未找到对应实体");
+		}else {
+			result.setResult(bytedanceReportMaterialRetry);
+			result.setSuccess(true);
+		}
+		return result;
+	}
+
+  /**
+      * 导出excel
+   *
+   * @param request
+   * @param response
+   */
+  @RequestMapping(value = "/exportXls")
+  public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+      // Step.1 组装查询条件
+      QueryWrapper<BytedanceReportMaterialRetry> queryWrapper = null;
+      try {
+          String paramsStr = request.getParameter("paramsStr");
+          if (oConvertUtils.isNotEmpty(paramsStr)) {
+              String deString = URLDecoder.decode(paramsStr, "UTF-8");
+              BytedanceReportMaterialRetry bytedanceReportMaterialRetry = JSON.parseObject(deString, BytedanceReportMaterialRetry.class);
+              queryWrapper = QueryGenerator.initQueryWrapper(bytedanceReportMaterialRetry, request.getParameterMap());
+          }
+      } catch (UnsupportedEncodingException e) {
+          e.printStackTrace();
+      }
+
+      //Step.2 AutoPoi 导出Excel
+      ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+      List<BytedanceReportMaterialRetry> pageList = bytedanceReportMaterialRetryService.list(queryWrapper);
+      //导出文件名称
+      mv.addObject(NormalExcelConstants.FILE_NAME, "头条素材报表连接出错数据记录表列表");
+      mv.addObject(NormalExcelConstants.CLASS, BytedanceReportMaterialRetry.class);
+      mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("头条素材报表连接出错数据记录表列表数据", "导出人:Jeecg", "导出信息"));
+      mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+      return mv;
+  }
+
+  /**
+      * 通过excel导入数据
+   *
+   * @param request
+   * @param response
+   * @return
+   */
+  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+      Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+      for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+          MultipartFile file = entity.getValue();
+          ImportParams params = new ImportParams();
+          params.setTitleRows(2);
+          params.setHeadRows(1);
+          params.setNeedSave(true);
+          try {
+              List<BytedanceReportMaterialRetry> listbytedanceReportMaterialRetries = ExcelImportUtil.importExcel(file.getInputStream(), BytedanceReportMaterialRetry.class, params);
+              bytedanceReportMaterialRetryService.saveBatch(listbytedanceReportMaterialRetries);
+              return Result.ok("文件导入成功!数据行数:" + listbytedanceReportMaterialRetries.size());
+          } catch (Exception e) {
+              log.error(e.getMessage(),e);
+              return Result.error("文件导入失败:"+e.getMessage());
+          } finally {
+              try {
+                  file.getInputStream().close();
+              } catch (IOException e) {
+                  e.printStackTrace();
+              }
+          }
+      }
+      return Result.ok("文件导入失败!");
+  }
+
+}

+ 62 - 0
module-report/src/main/java/cn/com/ctop/bytedance/entity/BytedanceReportMaterialRetry.java

@@ -0,0 +1,62 @@
+package cn.com.ctop.bytedance.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+/**
+ * 头条素材报表连接出错数据记录表
+ * @author jeecg-boot
+ * @date   2020-04-21
+ * @version V1.0
+ */
+@Data
+@TableName("ctop_bytedance_report_material_retry")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="ctop_bytedance_report_material_retry对象", description="头条素材报表连接出错数据记录表")
+public class BytedanceReportMaterialRetry {
+
+	/**id*/
+	@TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+	private Integer id;
+	/**账户id*/
+	@Excel(name = "账户id", width = 15)
+    @ApiModelProperty(value = "账户id")
+	private Long accountId;
+	/**开始时间*/
+	@Excel(name = "开始时间", width = 15, format = "yyyy-MM-dd")
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern="yyyy-MM-dd")
+    @ApiModelProperty(value = "开始时间")
+	private String startDate;
+	/**结束时间*/
+	@Excel(name = "结束时间", width = 15, format = "yyyy-MM-dd")
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
+    @DateTimeFormat(pattern="yyyy-MM-dd")
+    @ApiModelProperty(value = "结束时间")
+	private String endDate;
+	/**状态 0同步失败 1同步成功*/
+	@Excel(name = "状态 0同步失败 1同步成功", width = 15)
+    @ApiModelProperty(value = "状态 0同步失败 1同步成功")
+	private Integer status;
+	/**createTime*/
+    @ApiModelProperty(value = "createTime")
+	private Date createTime;
+	/**updateTime*/
+    @ApiModelProperty(value = "updateTime")
+	private Date updateTime;
+    private Integer statusCode;
+}

+ 7 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/BytedanceReportMaterialDailyMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.bytedance.mapper;
 
 import java.util.List;
 
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
 import org.apache.ibatis.annotations.Param;
 import cn.com.ctop.bytedance.entity.BytedanceReportMaterialDaily;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -15,4 +16,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 public interface BytedanceReportMaterialDailyMapper extends BaseMapper<BytedanceReportMaterialDaily> {
 
     void replaceIntoBatch(@Param("infos") List<BytedanceReportMaterialDaily> infos);
+
+    void replaceMaterialRetry(@Param("retry")BytedanceReportMaterialRetry retry);
+
+    List<BytedanceReportMaterialRetry> getRetryList();
+
+    void updateRetry(@Param("retry")BytedanceReportMaterialRetry retry);
 }

+ 14 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/BytedanceReportMaterialRetryMapper.java

@@ -0,0 +1,14 @@
+package cn.com.ctop.bytedance.mapper;
+
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 头条素材报表连接出错数据记录表
+ * @author: jeecg-boot
+ * @date:   2020-04-21
+ * @cersion: V1.0
+ */
+public interface BytedanceReportMaterialRetryMapper extends BaseMapper<BytedanceReportMaterialRetry> {
+
+}

+ 41 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/BytedanceReportMaterialDailyMapper.xml

@@ -205,4 +205,45 @@
         </foreach>
     </insert>
 
+    <insert id="replaceMaterialRetry">
+        REPLACE INTO ctop_bytedance_report_material_retry
+        (
+            account_id,
+            start_date,
+            end_date,
+            status,
+            status_code
+        )
+        VALUES
+        (
+            #{retry.accountId},
+            #{retry.startDate},
+            #{retry.endDate},
+            #{retry.status},
+            #{retry.statusCode}
+        )
+
+    </insert>
+
+    <select id="getRetryList" resultType="cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry">
+            select
+            account_id,
+            start_date,
+            end_date,
+            status
+        from
+        ctop_bytedance_report_material_retry
+        where status = 0
+    </select>
+
+    <update id="updateRetry">
+        update
+        ctop_bytedance_report_material_retry
+        set
+        status = 1
+        where
+        account_id = #{retry.accountId}
+        and start_date = #{retry.startDate}
+        and end_date = #{retry.endDate}
+    </update>
 </mapper>

+ 5 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/BytedanceReportMaterialRetryMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.bytedance.mapper.BytedanceReportMaterialRetryMapper">
+
+</mapper>

+ 14 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/IBytedanceReportMaterialRetryService.java

@@ -0,0 +1,14 @@
+package cn.com.ctop.bytedance.service;
+
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 头条素材报表连接出错数据记录表
+ * @author jeecg-boot
+ * @date   2020-04-21
+ * @version V1.0
+ */
+public interface IBytedanceReportMaterialRetryService extends IService<BytedanceReportMaterialRetry> {
+
+}

+ 5 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/IBytedanceReportService.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.bytedance.service;
 
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import com.alibaba.fastjson.JSONObject;
 
@@ -41,4 +42,8 @@ public interface IBytedanceReportService {
     void bytedanceAsyncTaskGet();
 
     void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate);
+
+    void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate);
+
+    List<BytedanceReportMaterialRetry> getRetryList();
 }

+ 19 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportMaterialRetryServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.bytedance.service.impl;
+
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
+import cn.com.ctop.bytedance.mapper.BytedanceReportMaterialRetryMapper;
+import cn.com.ctop.bytedance.service.IBytedanceReportMaterialRetryService;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * 头条素材报表连接出错数据记录表
+ * @author jeecg-boot
+ * @date   2020-04-21
+ * @version V1.0
+ */
+@Service
+public class BytedanceReportMaterialRetryServiceImpl extends ServiceImpl<BytedanceReportMaterialRetryMapper, BytedanceReportMaterialRetry> implements IBytedanceReportMaterialRetryService {
+
+}

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

@@ -3,6 +3,7 @@ package cn.com.ctop.bytedance.service.impl;
 import cn.com.ctop.bytedance.entity.BytedanceAdvertiserDailyReport;
 import cn.com.ctop.bytedance.entity.BytedanceDailyReportTask;
 import cn.com.ctop.bytedance.entity.BytedanceReportMaterialDaily;
+import cn.com.ctop.bytedance.entity.BytedanceReportMaterialRetry;
 import cn.com.ctop.bytedance.mapper.BytedanceAdvertiserDailyReportMapper;
 import cn.com.ctop.bytedance.mapper.BytedanceDailyReportTaskMapper;
 import cn.com.ctop.bytedance.mapper.BytedanceReportMapper;
@@ -972,16 +973,47 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
     /////////////////////////////////////////////////////////\
     //素材报表
+    public void bytedanceMaterialReportRetry(CtopOauthToken token, String startDate, String endDate){
+        //CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
+        Long accountId = token.getAccountId();
+        log.info("头条素材报表当前accountId为:" + accountId);
+        Integer page = 1;
+        Integer pageSize = 100;
+        int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
+
+        BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
+        retry.setAccountId(accountId);
+        retry.setStartDate(startDate);
+        retry.setEndDate(endDate);
+        retry.setStatusCode(code);
+        if (code != 200 && code != 1){
+            retry.setStatus(0);
+            bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
+        }else{
+            retry.setStatus(1);
+            bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
+        }
+    }
+
     public void bytedanceMaterialReport(CtopOauthToken token, String startDate, String endDate){
         //CtopOauthToken token = ctopOauthTokenService.getTokenByAccountId(accountId);
         Long accountId = token.getAccountId();
         log.info("头条素材报表当前accountId为:" + accountId);
         Integer page = 1;
-        Integer pageSize = 500;
-        bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
+        Integer pageSize = 100;
+        int code = bytedanceMaterialReportByPage(page, pageSize, token, accountId, startDate, endDate);
+        if (code != 200 && code != 1){
+            BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
+            retry.setAccountId(accountId);
+            retry.setStatus(0);
+            retry.setStartDate(startDate);
+            retry.setEndDate(endDate);
+            retry.setStatusCode(code);
+            bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
+        }
     }
 
-    private void bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate){
+    private int bytedanceMaterialReportByPage(Integer page, Integer pageSize, CtopOauthToken token, Long accountId, String startDate, String endDate){
         //log.info("当前页数:"+ page);
         String access_token = token.getAccessToken();
 
@@ -1020,7 +1052,10 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
         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));
@@ -1032,6 +1067,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             //httpEntity.setConfig(requestConfig);
 
             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()));
@@ -1050,7 +1087,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     Integer code = json.getInteger("code");
                     if(code != 0){
                         log.info("获取任务列表返回信息错误,错误码为:" + code + ",头条accountId:" + accountId + ";返回json为:" + jsonString);
-                        return;
+                        returnCode = -1;
+                        return -1;
                     }
 
                     JSONObject jsonData = json.getJSONObject("data");
@@ -1064,8 +1102,10 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     JSONArray jsonArrayay = jsonData.getJSONArray("list");
                     if(jsonArrayay.size() == 0){
                         log.info("accountId:" + accountId + ";没有数据。总页数为:" +  totalPage + "当前页数为:" + currentPage);
-                        return;
+                        returnCode = 1;
+                        return 1;
                     }
+
                     List<BytedanceReportMaterialDaily> bytedanceReportMaterialDailyList = new ArrayList<>();
                     for (int i = 0; i < jsonArrayay.size(); i++) {
                         BytedanceReportMaterialDaily daily = new BytedanceReportMaterialDaily();
@@ -1175,22 +1215,41 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                             //bytedanceReportMaterialDailyMapper.insert(daily);
                         }
                     }
-
+                    //Long insertStartTime = System.currentTimeMillis();
                     bytedanceReportMaterialDailyMapper.replaceIntoBatch(bytedanceReportMaterialDailyList);
+                    //Long insertEndTime = System.currentTimeMillis();
+                    //log.info("头条获取素材报表插入数据结束,执行耗时:{}秒", (insertEndTime - insertStartTime) / 1000);
                     if(currentPage >= totalPage){
-                        log.info("accountId:" + accountId + "数据同步完成");
-                        return;
+                        log.info("accountId:" + accountId + "数据同步完成,开始时间:" + startDate + ",结束时间:"+ endDate);
+                        //returnCode = 1;
+                        return 1;
                     }else{
                         bytedanceMaterialReportByPage(page + 1, pageSize, token, accountId, startDate, endDate);
                     }
+                }else{
+                    returnCode = -1;
+                    log.error("服务器返回为空,json:"+jsonString);
+                    return -1;
                 }
             }else{
+                //BytedanceReportMaterialRetry retry = new BytedanceReportMaterialRetry();
+                //retry.setAccountId(accountId);
+                //retry.setStatus(0);
+                //retry.setStartDate(startDate);
+                //retry.setEndDate(endDate);
+                //bytedanceReportMaterialDailyMapper.replaceMaterialRetry(retry);
+
                 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) {
             e.printStackTrace();
+            returnCode = -2;
         } finally {
             try {
                 if (response != null) {
@@ -1201,6 +1260,11 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                 e.printStackTrace();
             }
         }
+        return returnCode;
+    }
+
+    public List<BytedanceReportMaterialRetry> getRetryList(){
+        return bytedanceReportMaterialDailyMapper.getRetryList();
     }
 
 }

+ 7 - 3
performance-appraisal/src/main/java/cn/com/ctop/performanceappraisal/controller/PerformanceOptimizerController.java

@@ -282,7 +282,7 @@ public class PerformanceOptimizerController {
     /**
      * 获取项目经理相关数据
      *
-     * @param req
+     * @param
      * @param mediaType
      * @return
      */
@@ -303,8 +303,12 @@ public class PerformanceOptimizerController {
                                                            @RequestParam(name = "quarter") Integer quarter) {
 
         Map<String,String> map = DateUtils.quarterStartEndDate(year, quarter);
-        performanceOptimizerService.toutiaoYunyingQuarterPerformance(year, quarter, map.get("startDate"), map.get("endDate"));
-        performanceOptimizerService.kuaishouYunyingQuarterPerformance(year, quarter, map.get("startDate"), map.get("endDate"));
+        //performanceOptimizerService.toutiaoYunyingQuarterPerformance(year, quarter, map.get("startDate"), map.get("endDate"));
+        //performanceOptimizerService.kuaishouYunyingQuarterPerformance(year, quarter, map.get("startDate"), map.get("endDate"));
+
+        performanceOptimizerService.toutiaoYunyingQuarterPerformance(year, quarter, "2020-01-01", "2020-03-31");
+        performanceOptimizerService.kuaishouYunyingQuarterPerformance(year, quarter, "2020-01-01", "2020-03-31");
+
     }
 
     /**