소스 검색

Merge branch 'test' of http://39.106.184.70:3000/ctop/adsp-boot into test

# Conflicts:
#	jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
syh 5 년 전
부모
커밋
5b065ef25e
24개의 변경된 파일748개의 추가작업 그리고 243개의 파일을 삭제
  1. 21 6
      jeecg-boot-base-common/src/main/java/org/jeecg/common/system/vo/LoginUser.java
  2. 26 3
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java
  3. 46 19
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java
  4. 2 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java
  5. 28 9
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml
  6. 96 84
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysUserService.java
  7. 6 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java
  8. 2 2
      jeecg-boot-module-system/src/main/resources/application-prod.yml
  9. 59 21
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  10. 1 1
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialCutFrameServiceImpl.java
  11. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java
  12. 25 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java
  13. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroup.java
  14. 36 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/vo/ConvertVo.java
  15. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupMapper.xml
  16. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  17. 32 20
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java
  18. 49 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  19. 17 3
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceHomepageReportCtrl.java
  20. 7 4
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/BytedanceHomepageMapper.java
  21. 143 25
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceHomepageMapper.xml
  22. 4 3
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IBytedanceHomepageReportService.java
  23. 100 41
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceHomepageReportServiceImpl.java
  24. 26 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ReportServiceImpl.java

+ 21 - 6
jeecg-boot-base-common/src/main/java/org/jeecg/common/system/vo/LoginUser.java

@@ -1,14 +1,12 @@
 package org.jeecg.common.system.vo;
 
-import java.util.Date;
-
-import org.springframework.format.annotation.DateTimeFormat;
-
 import com.fasterxml.jackson.annotation.JsonFormat;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
 
 /**
  * <p>
@@ -73,11 +71,28 @@ public class LoginUser {
 	 * 状态(1:正常 2:冻结 )
 	 */
 	private Integer status;
-	
+
 	private String delFlag;
 	/**
      * 同步工作流引擎1同步0不同步
      */
     private String activitiSync;
 
+	@Override
+	public String toString() {
+		return "LoginUser{" +
+				"id='" + id + '\'' +
+				", username='" + username + '\'' +
+				", realname='" + realname + '\'' +
+				", orgCode='" + orgCode + '\'' +
+				", avatar='" + avatar + '\'' +
+				", birthday=" + birthday +
+				", sex=" + sex +
+				", email='" + email + '\'' +
+				", phone='" + phone + '\'' +
+				", status=" + status +
+				", delFlag='" + delFlag + '\'' +
+				", activitiSync='" + activitiSync + '\'' +
+				'}';
+	}
 }

+ 26 - 3
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -20,7 +20,7 @@ import java.util.*;
  */
 public class DateUtils extends PropertyEditorSupport {
 
-    private static Logger logger= LoggerFactory.getLogger(DateUtils.class);
+    private static Logger logger = LoggerFactory.getLogger(DateUtils.class);
 
     /**
      * 以毫秒表示的时间
@@ -1227,7 +1227,7 @@ public class DateUtils extends PropertyEditorSupport {
             e.printStackTrace();
         }
         //得到相差的天数 betweenDate
-        return  (endDate.getTime() - startDate.getTime())/(60*60*24*1000);
+        return (endDate.getTime() - startDate.getTime()) / (60 * 60 * 24 * 1000);
     }
 
     /***
@@ -1313,8 +1313,31 @@ public class DateUtils extends PropertyEditorSupport {
         return calendar.getTime();
     }
 
+
+    public static List<Date> findDates(Date dBegin, Date dEnd) {
+        List<Date> lDate = new ArrayList<Date>();
+        lDate.add(dBegin);
+        Calendar calBegin = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calBegin.setTime(dBegin);
+        Calendar calEnd = Calendar.getInstance();
+        // 使用给定的 Date 设置此 Calendar 的时间
+        calEnd.setTime(dEnd);
+        // 测试此日期是否在指定日期之后
+        while (dEnd.after(calBegin.getTime())) {
+            // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
+            calBegin.add(Calendar.DAY_OF_MONTH, 1);
+            lDate.add(calBegin.getTime());
+        }
+        return lDate;
+    }
+
+
     public static void main(String[] args) throws ParseException {
-        System.out.println(calDiffMonth(DateUtils.parseDate("2019-04-01", "yyyy-MM-dd"), new Date()));
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String s = DateUtils.addDay(nowDate, -180);
+        System.err.println(nowDate);
+        System.err.println(s);
     }
 
 }

+ 46 - 19
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/SysUserController.java

@@ -25,10 +25,8 @@ import org.jeecg.common.util.RedisUtil;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.ctop.entity.ProjectMember;
 import org.jeecg.modules.ctop.service.IProjectMemberService;
-import org.jeecg.modules.system.entity.SysDepart;
-import org.jeecg.modules.system.entity.SysUser;
-import org.jeecg.modules.system.entity.SysUserDepart;
-import org.jeecg.modules.system.entity.SysUserRole;
+import org.jeecg.modules.system.entity.*;
+import org.jeecg.modules.system.mapper.UserCompanyMapper;
 import org.jeecg.modules.system.model.DepartIdModel;
 import org.jeecg.modules.system.model.SysUserDepartsVO;
 import org.jeecg.modules.system.service.*;
@@ -105,25 +103,28 @@ public class SysUserController {
         return result;
     }
 
+    @Autowired
+    private UserCompanyMapper userCompanyMapper;
 
     @RequestMapping(value = "/getAllUserListByCompany", method = RequestMethod.GET)
-    public Result<List<SysUserVo>> getAllUserListByCompany(String userId) {
+    public Result<List<SysUserVo>> getAllUserListByCompany() {
         Result<List<SysUserVo>> result = new Result<>();
         try {
-            /*List<SysUserVo> userList = new ArrayList<>();
-            String roleCode = materialReportMapper.getRoleCodeByUserId(userId);
-            if (!"admin".equals(roleCode)) {
-                QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
-                userCompanyQueryWrapper.eq("user_id", userId);
-                userCompanyQueryWrapper.orderByDesc("create_time");
-                userCompanyQueryWrapper.last("limit 1");
-                UserCompany userCompany = userCompanyMapper.selectOne(userCompanyQueryWrapper);
-                userList = sysUserService.getUserListByCompany(userCompany.getCompanyId());
-            } else {
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
+            userCompanyQueryWrapper.eq("user_id", user.getId());
+            userCompanyQueryWrapper.orderByDesc("create_time");
+            userCompanyQueryWrapper.last("limit 1");
+            UserCompany userCompany = userCompanyMapper.selectOne(userCompanyQueryWrapper);
+            String companyId = userCompany.getCompanyId();
+            List<SysUserVo> userList;
+            if ("4b10089775c040119e139087517aed88".equals(companyId) || "6608ed13c0dd42de93c790dbdf124234".equals(companyId) || "d57fecdcf7a94d009736d9c850731582".equals(companyId)) {
                 userList = sysUserService.getAllUser();
+            } else {
+                userList = sysUserService.getUserListByCompany(companyId);
             }
-*/
-            List<SysUserVo> userList = sysUserService.getAllUser();
+
+
             result.setSuccess(true);
             result.setResult(userList);
         } catch (Exception e) {
@@ -140,7 +141,19 @@ public class SysUserController {
     public Result<List<SysUserVo>> getAllList() {
         Result<List<SysUserVo>> result = new Result<>();
         try {
-            List<SysUserVo> userList = sysUserService.getAllUser();
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
+            userCompanyQueryWrapper.eq("user_id", user.getId());
+            userCompanyQueryWrapper.orderByDesc("create_time");
+            userCompanyQueryWrapper.last("limit 1");
+            UserCompany userCompany = userCompanyMapper.selectOne(userCompanyQueryWrapper);
+            String companyId = userCompany.getCompanyId();
+            List<SysUserVo> userList;
+            if ("4b10089775c040119e139087517aed88".equals(companyId) || "6608ed13c0dd42de93c790dbdf124234".equals(companyId) || "d57fecdcf7a94d009736d9c850731582".equals(companyId)) {
+                userList = sysUserService.getAllUser();
+            } else {
+                userList = sysUserService.getUserListByCompany(companyId);
+            }
             result.setSuccess(true);
             result.setResult(userList);
         } catch (Exception e) {
@@ -155,7 +168,21 @@ public class SysUserController {
     public Result<List<SysUserVo>> getSaleList() {
         Result<List<SysUserVo>> result = new Result<>();
         try {
-            List<SysUserVo> userList = sysUserService.getAllSales();
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            List<SysUserVo> userList;
+            QueryWrapper<UserCompany> userCompanyQueryWrapper = new QueryWrapper<>();
+            userCompanyQueryWrapper.eq("user_id", user.getId());
+            userCompanyQueryWrapper.orderByDesc("create_time");
+            userCompanyQueryWrapper.last("limit 1");
+            UserCompany userCompany = userCompanyMapper.selectOne(userCompanyQueryWrapper);
+            String companyId = userCompany.getCompanyId();
+            if ("4b10089775c040119e139087517aed88".equals(companyId) || "6608ed13c0dd42de93c790dbdf124234".equals(companyId) || "d57fecdcf7a94d009736d9c850731582".equals(companyId)) {
+                userList = sysUserService.getAllSales();
+            } else {
+                userList = sysUserService.getAllSalesByCompanyId(companyId);
+            }
+
+
             result.setSuccess(true);
             result.setResult(userList);
         } catch (Exception e) {

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysUserMapper.java

@@ -80,4 +80,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
     List<SysUserVo> getUserListByCompany(@Param("companyId") String companyId);
 
     List<SysUserVo> getAllSale();
+
+    List<SysUserVo> getAllSalesByCompanyId(@Param("companyId") String companyId);
 }

+ 28 - 9
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/SysUserMapper.xml

@@ -94,15 +94,34 @@ SELECT
     WHERE t1.company_id = #{companyId}
     </select>
     <select id="getAllSale" resultType="cn.com.ctop.common.module.vo.SysUserVo">
-        SELECT
-            t1.id userId,
-            t1.username userName,
-            t1.realname realName,
-            t3.role_name as  roleName
-        FROM sys_user t1
-        LEFT JOIN sys_user_role t2 on t1.id = t2.user_id
-        left join sys_role t3 on t3.id = t2.role_id
-        where t3.role_name like '销售%';
+       SELECT
+	t2.id userId,
+	t2.username userName,
+	t2.realname realName,
+   t4.role_name AS roleName
+    FROM
+	user_company t1
+    LEFT JOIN sys_user t2 ON t1.user_id = t2.id
+    LEFT JOIN sys_user_role t3 ON t2.id = t3.user_id
+    LEFT JOIN sys_role t4 ON t3.role_id = t4.id
+    WHERE
+	t4.role_name LIKE '%销售%';
+    </select>
+
+
+    <select id="getAllSalesByCompanyId" resultType="cn.com.ctop.common.module.vo.SysUserVo">
+       SELECT
+	t2.id userId,
+	t2.username userName,
+	t2.realname realName,
+    t4.role_name AS roleName
+  FROM
+	user_company t1
+    LEFT JOIN sys_user t2 ON t1.user_id = t2.id
+    LEFT JOIN sys_user_role t3 ON t2.id = t3.user_id
+    LEFT JOIN sys_role t4 ON t3.role_id = t4.id
+    WHERE t1.company_id = #{companyId}
+	and t4.role_name LIKE '%销售%';
     </select>
 
 

+ 96 - 84
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysUserService.java

@@ -22,115 +22,127 @@ import java.util.Set;
  */
 public interface ISysUserService extends IService<SysUser> {
 
-	public SysUser getUserByName(String username);
+    public SysUser getUserByName(String username);
+
+    /**
+     * 添加用户和用户角色关系
+     *
+     * @param user
+     * @param roles
+     */
+    public void addUserWithRole(SysUser user, String roles);
 
-	/**
-	 * 添加用户和用户角色关系
-	 * @param user
-	 * @param roles
-	 */
-	public void addUserWithRole(SysUser user,String roles);
 
+    /**
+     * 修改用户和用户角色关系
+     *
+     * @param user
+     * @param roles
+     */
+    public void editUserWithRole(SysUser user, String roles);
 
     /**
-	 * 修改用户和用户角色关系
-	 * @param user
-	 * @param roles
-	 */
-	public void editUserWithRole(SysUser user,String roles);
-
-	/**
-	 * 获取用户的授权角色
-	 * @param username
-	 * @return
-	 */
-	public List<String> getRole(String username);
+     * 获取用户的授权角色
+     *
+     * @param username
+     * @return
+     */
+    public List<String> getRole(String username);
 
     /**
-	  * 查询用户信息包括 部门信息
-	 * @param username
-	 * @return
-	 */
-	public SysUserCacheInfo getCacheUser(String username);
-
-	/**
-	 * 根据部门Id查询
-	 * @param
-	 * @return
-	 */
-	public IPage<SysUser> getUserByDepId(Page<SysUser> page, String departId, String username);
-
-	/**
-	 * 根据角色Id查询
-	 * @param
-	 * @return
-	 */
-	public IPage<SysUser> getUserByRoleId(Page<SysUser> page,String roleId, String username);
-
-	/**
-	 * 通过用户名获取用户角色集合
-	 *
-	 * @param username 用户名
-	 * @return 角色集合
-	 */
-	Set<String> getUserRolesSet(String username);
-
-	/**
-	 * 通过用户名获取用户权限集合
-	 *
-	 * @param username 用户名
-	 * @return 权限集合
-	 */
-	Set<String> getUserPermissionsSet(String username);
+     * 查询用户信息包括 部门信息
+     *
+     * @param username
+     * @return
+     */
+    public SysUserCacheInfo getCacheUser(String username);
 
     /**
-	 * 根据用户名设置部门ID
-	 * @param username
-	 * @param orgCode
-	 */
-	void updateUserDepart(String username,String orgCode);
+     * 根据部门Id查询
+     *
+     * @param
+     * @return
+     */
+    public IPage<SysUser> getUserByDepId(Page<SysUser> page, String departId, String username);
 
     /**
-	 * 根据手机号获取用户名和密码
-	 */
-	public SysUser getUserByPhone(String phone);
+     * 根据角色Id查询
+     *
+     * @param
+     * @return
+     */
+    public IPage<SysUser> getUserByRoleId(Page<SysUser> page, String roleId, String username);
 
+    /**
+     * 通过用户名获取用户角色集合
+     *
+     * @param username 用户名
+     * @return 角色集合
+     */
+    Set<String> getUserRolesSet(String username);
 
-	/**
-	 * 根据邮箱获取用户
-	 */
-	public SysUser getUserByEmail(String email);
+    /**
+     * 通过用户名获取用户权限集合
+     *
+     * @param username 用户名
+     * @return 权限集合
+     */
+    Set<String> getUserPermissionsSet(String username);
 
+    /**
+     * 根据用户名设置部门ID
+     *
+     * @param username
+     * @param orgCode
+     */
+    void updateUserDepart(String username, String orgCode);
 
-	/**
-	 * 添加用户和用户部门关系
-	 * @param user
-	 * @param selectedParts
-	 */
-	void addUserWithDepart(SysUser user, String selectedParts);
+    /**
+     * 根据手机号获取用户名和密码
+     */
+    public SysUser getUserByPhone(String phone);
 
-	/**
-	 * 编辑用户和用户部门关系
-	 * @param user
-	 * @param departs
-	 */
-	void editUserWithDepart(SysUser user, String departs);
 
     /**
-	   * 校验用户是否有效
-	 * @param sysUser
-	 * @return
-	 */
-	Result checkUserIsEffective(SysUser sysUser);
+     * 根据邮箱获取用户
+     */
+    public SysUser getUserByEmail(String email);
+
+
+    /**
+     * 添加用户和用户部门关系
+     *
+     * @param user
+     * @param selectedParts
+     */
+    void addUserWithDepart(SysUser user, String selectedParts);
+
+    /**
+     * 编辑用户和用户部门关系
+     *
+     * @param user
+     * @param departs
+     */
+    void editUserWithDepart(SysUser user, String departs);
+
+    /**
+     * 校验用户是否有效
+     *
+     * @param sysUser
+     * @return
+     */
+    Result checkUserIsEffective(SysUser sysUser);
 
     Map<String, Object> queryRoleCode(String userId);
 
     List<SysUserVo> getAllUser();
 
 
-	List<SysUserVo> getUserListByCompany(String companyId);
+    List<SysUserVo> getUserListByCompany(String companyId);
 
     List<SysUser> getUserListByRoleId(String roleId);
 
     List<SysUserVo> getAllSales();
+
+    List<SysUserVo> getAllSalesByCompanyId(String companyId);
 }

+ 6 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java

@@ -289,5 +289,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         return userMapper.getAllSale();
     }
 
+    @Override
+    public List<SysUserVo> getAllSalesByCompanyId(String companyId) {
+        return userMapper.getAllSalesByCompanyId(companyId);
+
+    }
+
 
 }

+ 2 - 2
jeecg-boot-module-system/src/main/resources/application-prod.yml

@@ -33,8 +33,8 @@ spring:
             enable: true
             required: true
   ## quartz定时任务,采用数据库方式
-#  quartz:
-#    job-store-type: jdbc
+  quartz:
+    job-store-type: jdbc
   #json 时间戳统一转换
   jackson:
     date-format:   yyyy-MM-dd HH:mm:ss

+ 59 - 21
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -1,14 +1,19 @@
 package org.jeecg;
 
 import cn.com.ctop.common.module.entity.BindAccountLogin;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.IBindAccountLoginService;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.crawler.modules.oceanengine.service.IOceanEngineService;
 import cn.com.ctop.crawler.modules.pangolin.entity.PangolinApp;
 import cn.com.ctop.crawler.modules.pangolin.service.PangolinAppService;
 import cn.com.ctop.crawler.modules.pangolin.service.PangolinCrawlerService;
 import cn.com.ctop.crawler.modules.pangolin.service.PangolinLoginService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
+import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
@@ -18,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -30,10 +37,38 @@ import java.util.concurrent.Executors;
 public class SampleTest {
     @Autowired
     private IOceanEngineService oceanEngineService;
+    @Autowired
+    private IKuaishouInterfaceService interfaceService;
+    @Autowired
+    private IBytedanceReportService bytedanceReportService;
+    @Autowired
+    private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
     @Test
-    public void testOceanEngineJob(){
-        String account="3248395570@qq.com";
-        String password = "Ydxq-704127411";
+    public void testOceanEngineJob() {
+        try {
+            CtopOauthToken byId = oauthTokenService.getById(303094936123368L);
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            String endDate = DateUtils.addDay(nowDate, -180);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date start = simpleDateFormat.parse(nowDate);
+            Date end = simpleDateFormat.parse(endDate);
+            List<Date> dates = DateUtils.findDates(end,start);
+            for (int i = 0; i < dates.size(); i++) {
+                String formatDate = simpleDateFormat.format(dates.get(i));
+                int code = bytedanceReportService.bytedanceMaterialReport(byId, formatDate, formatDate);
+                //如果成功的话跑视频清洗数据方法,失败会进入重试库,重试成功后再清洗数据
+                if (code == 200 || code == 1) {
+                    byteDanceVideoReportDailyService.videoInfoListByAccountId(formatDate, formatDate, byId.getAccountId());
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        String account = "3248395570@qq.com";
+       /* String password = "Ydxq-704127411";
         oceanEngineService.login(account,password);
         oceanEngineService.douyinHotHandler(1,1);
         oceanEngineService.effectCaseHandler(1);
@@ -42,45 +77,48 @@ public class SampleTest {
         oceanEngineService.hotMaterialHandler(1,1,"西瓜");
         oceanEngineService.hotMaterialHandler(1,3,"火山");
         oceanEngineService.hotMaterialHandler(1,9,"穿山甲");
-        log.info("巨量创意抓取完成");
+        log.info("巨量创意抓取完成");*/
     }
 
     @Autowired
     private IBindAccountLoginService bindAccountLoginService;
     @Autowired
     private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
+
     @Test
-    public void kuaishouLogin(){
-        Long start =System.currentTimeMillis();
-        List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY,1);
-        if(list!=null&&!list.isEmpty()){
-            for (BindAccountLogin login:list) {
-                if(null==login.getCookie()||"".equals(login.getCookie().trim())){
+    public void kuaishouLogin() {
+        Long start = System.currentTimeMillis();
+        List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
+        if (list != null && !list.isEmpty()) {
+            for (BindAccountLogin login : list) {
+                if (null == login.getCookie() || "".equals(login.getCookie().trim())) {
                     kuaishouWebInterfaceService.getkuaishouWebLoginCookie(login);
                 }
             }
         }
         Long end = System.currentTimeMillis();
-        log.info("总用时:{}毫秒",end-start);
+        log.info("总用时:{}毫秒", end - start);
     }
+
     static ExecutorService executorService = null;
     static CountDownLatch countDownLatch = null;
+
     @Test
-    public void kuaishouCommentDelete(){
-        Long start =System.currentTimeMillis();
-        List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY,1);
-        if(list!=null&&!list.isEmpty()){
+    public void kuaishouCommentDelete() {
+        Long start = System.currentTimeMillis();
+        List<BindAccountLogin> list = bindAccountLoginService.getListByParams(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_PY, 1);
+        if (list != null && !list.isEmpty()) {
             executorService = Executors.newFixedThreadPool(10);
             countDownLatch = new CountDownLatch(list.size());
             list.forEach(login -> {
-                executorService.submit(()->{
+                executorService.submit(() -> {
                     try {
-                        if(null!=login.getCookie()&&!"".equals(login.getCookie().trim())){
-                            kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(),login);
+                        if (null != login.getCookie() && !"".equals(login.getCookie().trim())) {
+                            kuaishouWebInterfaceService.deleteAllComment(new HashMap<>(), login);
                         }
-                    }catch (Exception e){
+                    } catch (Exception e) {
 
-                    }finally {
+                    } finally {
                         countDownLatch.countDown();
                     }
                 });
@@ -92,7 +130,7 @@ public class SampleTest {
             e.printStackTrace();
         }
         Long end = System.currentTimeMillis();
-        log.info("总用时:{}毫秒",end-start);
+        log.info("总用时:{}毫秒", end - start);
     }
     @Autowired
     private PangolinLoginService pangolinLoginService;

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialCutFrameServiceImpl.java

@@ -118,7 +118,7 @@ public class MaterialCutFrameServiceImpl extends ServiceImpl<MaterialCutFrameMap
             // SnapshotConfig->Time
             //   Integer time = ((secondDuration.intValue() - 2) / 14) + 1; // 时长 / 14 == 间隔时间
 
-            double num = (double) secondDuration / 13;
+            double num = (double) (secondDuration - 2) / 15;
             long rint = Math.round(num);
             log.info("相隔时间数:{}", rint);
             snapshotConfig.put("Time", 2000);

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -109,6 +109,11 @@ public class KuaishouInterfaceConstant {
      */
     public static final String APP_SEARCH = "/rest/openapi/v1/tool/app/search";
 
+    /**
+     * 获取可选的应用定向
+     */
+    public static final String CONVERT_LIST = "/rest/openapi/v1/tool/convert/list";
+
 
     /**
      * 获取定向标签

+ 25 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.utils.BigDecimalUtil;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.RandomUtil;
 import cn.com.ctop.kuaishou.modules.batch.entity.*;
+import cn.com.ctop.kuaishou.modules.batch.entity.vo.ConvertVo;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.SpendVo;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
@@ -1811,4 +1812,28 @@ public class BatchController {
     }
 
 
+    @GetMapping(value = "/getConvertList")
+    public Result<List<ConvertVo>> getConvertList(Long accountId, Integer type) {
+        Result result = new Result<>();
+        try {
+            if (Check.isNull(accountId) || Check.isNull(type)) {
+                throw new Exception("必填参数不能为空");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+            List<ConvertVo> convertList = iKuaishouInterfaceService.getConvertList(accountId, oauthToken.getAccessToken(), type);
+            result.setResult(convertList);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
 }

+ 1 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroup.java

@@ -159,6 +159,7 @@ public class KuaiShouGroup {
 
 
     private Long convertId; // 转化目标
+    private Integer useAppMarket; // 转化目标
     private String groupCreateTime;
     private String groupUpdateTime;
 

+ 36 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/vo/ConvertVo.java

@@ -0,0 +1,36 @@
+package cn.com.ctop.kuaishou.modules.batch.entity.vo;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.sql.Date;
+
+@Data
+public class ConvertVo implements Serializable {
+    @JsonProperty("app_name")
+    private String appName;
+    @JsonProperty("convert_target")
+    private Integer convertTarget;
+    @JsonProperty("convert_name")
+    private String convertName;
+    @JsonProperty("deep_conversion_count")
+    private Long deepConversionCount;
+    @JsonProperty("deep_conversion_type")
+    private Integer deepConversionType;
+    @JsonProperty("type")
+    private Integer type;
+    @JsonProperty("app_id")
+    private Long appId;
+    @JsonProperty("convert_id")
+    private Long convertId;
+    @JsonProperty("convert_count")
+    private Long convertCount;
+    @JsonProperty("click_url")
+    private String clickUrl;
+    @JsonProperty("create_time")
+    private String createTime;
+    @JsonProperty("update_time")
+    private String updateTime;
+
+}

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupMapper.xml

@@ -31,6 +31,7 @@
         app_id,
         app_icon_url,
         convert_id,
+        use_app_market,
         group_create_time,
         group_update_time,
         create_time,
@@ -66,6 +67,7 @@
             #{getGroup.appId},
             #{getGroup.appIconUrl},
             #{getGroup.convertId},
+            #{getGroup.useAppMarket},
             #{getGroup.groupCreateTime},
             #{getGroup.groupUpdateTime},
             #{getGroup.createTime},

+ 14 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.kuaishou.modules.batch.entity.vo.ConvertVo;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
 import cn.com.ctop.kuaishou.modules.report.entity.*;
@@ -10,6 +11,7 @@ import com.alibaba.fastjson.JSONObject;
 
 import java.text.ParseException;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -480,6 +482,18 @@ public interface IKuaishouInterfaceService {
      */
 
     void getAsyncCreativeList(Long accountId, String accessToken, Long campaignId);
+
+
+    /**
+     * 获取转化目标
+     *
+     * @param accountId
+     * @param accessToken
+     * @param type
+     * @return
+     */
+    List<ConvertVo> getConvertList(Long accountId, String accessToken, Integer type);
+
 }
 
 

+ 32 - 20
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -58,6 +58,18 @@ public class BatchServiceImpl implements IBatchService {
     private KuaiShouGroupMapper groupMapper;
     @Autowired
     private KuaiShouCreativeMapper creativeMapper;
+    @Autowired
+    private KuaiShouGroupMapper kuaiShouGroupMapper;
+    @Autowired
+    private KuaiShouGroupTargetMapper targetMapper;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private IKuaiShouImageGetService imageGetService;
+    @Autowired
+    private RestTemplate rest;
 
 
     /**
@@ -133,8 +145,7 @@ public class BatchServiceImpl implements IBatchService {
      * @param unitName
      * @return
      */
-    @Autowired
-    private KuaiShouGroupMapper kuaiShouGroupMapper;
+
 
     @Override
     public Boolean checkUnitName(Long campaignId, String unitName) {
@@ -157,11 +168,6 @@ public class BatchServiceImpl implements IBatchService {
      * @param requestJson
      * @return
      */
-    @Autowired
-    private ICtopOauthTokenService oauthTokenService;
-    @Autowired
-    private IKuaishouInterfaceService kuaishouInterfaceService;
-
     @Override
     public JSONObject createUnit(JSONObject requestJson) throws Exception {
         Long accountId = requestJson.getLong("accountId");
@@ -197,6 +203,16 @@ public class BatchServiceImpl implements IBatchService {
             unitJson.put("unit_type", requestJson.getInteger("unitType"));
         }
 
+        // 转化目标id
+        if (!Check.isNull(requestJson.getInteger("convertId"))) {
+            unitJson.put("convert_id", requestJson.getInteger("convertId"));
+        }
+
+        // 优先从系统应用商店下载
+        if (!Check.isNull(requestJson.getInteger("useAppMarket"))) {
+            unitJson.put("use_app_market", requestJson.getInteger("useAppMarket"));
+        }
+
         //投放开始时间
         if (!Check.isNull(requestJson.getString("beginTime"))) {
             String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
@@ -447,9 +463,6 @@ public class BatchServiceImpl implements IBatchService {
      * @throws Exception
      */
 
-    @Autowired
-    private KuaiShouGroupTargetMapper targetMapper;
-
 
     @Override
     public JSONObject copyUnit(KuaiShouGroup group, Long copyToCampaignId) {
@@ -489,6 +502,15 @@ public class BatchServiceImpl implements IBatchService {
                     }
 
                 }
+
+                // 优先从系统应用商店下载
+                if (!Check.isNull(group.getUseAppMarket())) {
+                    unitJson.put("use_app_market", group.getUseAppMarket());
+                }
+                // 转化目标id
+                if (!Check.isNull(group.getConvertId())) {
+                    unitJson.put("convert_id", group.getConvertId());
+                }
                 // 投放结束时间
                 if (!Check.isNull(group.getEndTime())) {
                     unitJson.put("end_time", group.getEndTime());
@@ -807,10 +829,6 @@ public class BatchServiceImpl implements IBatchService {
      * @param requestJson
      * @return
      */
-    @Autowired
-    private IKuaiShouImageGetService imageGetService;
-
-
     @Override
     public JSONObject createCreative(JSONObject requestJson) throws Exception {
         if (Check.isNull(requestJson)) {
@@ -1167,9 +1185,6 @@ public class BatchServiceImpl implements IBatchService {
      * @param requestJson
      * @return
      */
-    @Autowired
-    private IKuaiShouImageGetService iKuaiShouImageGetService;
-
     @Override
     public JSONObject updateCreative(JSONObject requestJson) throws Exception {
         if (Check.isNull(requestJson)) {
@@ -1249,9 +1264,6 @@ public class BatchServiceImpl implements IBatchService {
     }
 
 
-    @Autowired
-    private RestTemplate rest;
-
     private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
         try {
             MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();

+ 49 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -8,6 +8,7 @@ import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.*;
 import cn.com.ctop.kuaishou.modules.batch.entity.*;
+import cn.com.ctop.kuaishou.modules.batch.entity.vo.ConvertVo;
 import cn.com.ctop.kuaishou.modules.batch.mapper.*;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
@@ -16,7 +17,6 @@ import cn.com.ctop.kuaishou.modules.report.entity.*;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCampaignMapper;
 import cn.com.ctop.kuaishou.modules.report.service.*;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -1178,7 +1178,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         }
         JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
         if (Check.isNull(details)) {
-
             return;
         }
         addGroup(token.getAccountId(), details);
@@ -1281,6 +1280,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     group.setGroupCreateTime(detail.getString("create_time"));
                     group.setGroupUpdateTime(detail.getString("update_time"));
                     group.setConvertId(detail.getLong("convert_id"));
+                    group.setUseAppMarket(detail.getInteger("use_app_market"));
                     group.setCreateTime(new Date());
                     group.setUpdateTime(new Date());
                     groups.add(group);
@@ -3163,5 +3163,52 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     }
 
+    /**
+     * 获取转化目标
+     *
+     * @param accountId
+     * @param accessToken
+     * @param type
+     * @return
+     */
+    @Override
+    public List<ConvertVo> getConvertList(Long accountId, String accessToken, Integer type) {
+        List<ConvertVo> convertVoList = new ArrayList<>();
+        try {
+
+            log.info("获取转化目标:accountId:{}", accountId);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CONVERT_LIST;
+            Map<String, String> headers = new HashMap<>();
+            headers.put("Access-Token", accessToken);
+            headers.put("Content-Type", "application/json");
+            JSONObject requestJson = new JSONObject();
+            requestJson.put("advertiser_id", accountId);
+            requestJson.put("type", type);
+
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                JSONObject data = resultJson.getJSONObject("data");
+                if (!Check.isNull(data)) {
+                    JSONArray details = data.getJSONArray("details");
+                    if (!Check.isNull(details)) {
+                        for (int i = 0; i < details.size(); i++) {
+                            ConvertVo convertVo = JsonUtil.jsonToObj(details.getJSONObject(i), ConvertVo.class);
+                            convertVoList.add(convertVo);
+                        }
+
+                    }
+
+                }
+
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return convertVoList;
+    }
+
 
 }

+ 17 - 3
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceHomepageReportCtrl.java

@@ -39,14 +39,14 @@ public class BytedanceHomepageReportCtrl {
     }
 
     @PostMapping("/report/chart")
-    public Result<List<JSONObject>> getChartReport(@RequestBody JSONObject requestBody) {
-        Result<List<JSONObject>> result = new Result<>();
+    public Result<Map<String,List<JSONObject>>> getChartReport(@RequestBody JSONObject requestBody) {
+        Result<Map<String,List<JSONObject>>> result = new Result<>();
         if(requestBody.isEmpty()){
             log.error("request body is empty");
             result.setSuccess(false);
         }
         try {
-            List<JSONObject> chartReport=bytedanceHomepageReportService.getChartByDate(requestBody);
+            Map<String,List<JSONObject>> chartReport=bytedanceHomepageReportService.getChartByDate(requestBody);
             result.setResult(chartReport);
             result.setSuccess(true);
         } catch (Exception e) {
@@ -55,6 +55,20 @@ public class BytedanceHomepageReportCtrl {
         }
 
         return result;
+    }
+    @PostMapping("/report/compare")
+    public Result<Map<String,JSONObject>> getCompareReport(@RequestBody JSONObject requestBody) {
+        Result<Map<String,JSONObject>> result = new Result<>();
+        try {
+            Map<String,JSONObject> chartReport=bytedanceHomepageReportService.getCompareByDate(requestBody);
+            result.setResult(chartReport);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(),e);
+            result.setSuccess(false);
+        }
 
+        return result;
     }
+
 }

+ 7 - 4
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/BytedanceHomepageMapper.java

@@ -13,22 +13,25 @@ public interface BytedanceHomepageMapper {
     //今日汇总数据
     JSONObject queryTodaySumReportBy(@Param("statDate") String statDate);
 
+    //根据小时区间查询今日汇总数据
+    List<JSONObject> queryTodaySumByHour(@Param("hour") int hour);
+
     //今日明细数据
     List<JSONObject> queryTodayDetailReportBy(@Param("statDate") String statDate);
 
     //根据开始、结束时间 查询汇总数据
-    JSONObject querySumByStartEndDate(@Param("startDate") String anotherDay, @Param("endDate") String endDate);
+    JSONObject querySumByStartEndDate(@Param("endDate") String endDate, @Param("startDate") String startDate);
 
     //根据开始、结束时间 查询明细数据
-     List<JSONObject> queryDetailByStartEndDate(@Param("startDate") String anotherDay, @Param("endDate") String endDate);
+    List<JSONObject> queryDetailByStartEndDate(@Param("endDate") String endDate, @Param("startDate") String startDate);
 
     //按月分组查询明细数据
-    List<JSONObject> queryDetailGroupMonthByDate(@Param("startDate") String anotherDay, @Param("endDate") String endDate);
+    List<JSONObject> queryDetailGroupMonthByDate(@Param("endDate") String endDate, @Param("startDate") String startDate);
 
     //查询固定月的明细数据
     List<JSONObject> queryDetailGroupDayByMonth(@Param("month") String month);
 
     //项目消耗排行榜
-    List<JSONObject> queryTopCost(@Param("startDate") String anotherDay, @Param("endDate") String endDate, @Param("rank") int rank);
+    List<JSONObject> queryTopCost(@Param("endDate") String endDate, @Param("startDate") String startDate, @Param("rank") int rank);
 
 }

+ 143 - 25
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceHomepageMapper.xml

@@ -7,7 +7,7 @@
        SELECT
 	     ROUND(sum(cost),2) cost,
 	     sum(show_num) showNum,
-	     sum(stat_datetime) click,
+	     sum(click) click,
 	     max(stat_hour) maxHour
        FROM
 	      ctop_bytedance_report_advertiser_hourly
@@ -15,22 +15,59 @@
 	      stat_datetime = #{statDate}
       </select>
 
+    <select id="queryTodaySumByHour" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            ROUND(sum(cost),2) cost,
+            sum(show_num) showNum,
+            sum(click) click
+        FROM
+            ctop_bytedance_report_advertiser_hourly
+        WHERE
+            stat_hour &lt;= #{hour}
+    </select>
 
     <select id="queryTodayDetailReportBy" resultType="com.alibaba.fastjson.JSONObject">
-       SELECT
-         stat_datetime statDate,
-         stat_hour statHour,
-	     ROUND(sum(cost),2) cost,
-	     sum(show_num) showNum,
-	     sum(click) click
-	   FROM
-	      ctop_bytedance_report_advertiser_hourly
-       WHERE
-	      stat_datetime = #{statDate}
-       GROUP BY
-	      stat_hour
-       ORDER BY
-	      stat_hour ASC
+        SELECT
+            stat_datetime statDate,
+            stat_hour statHour,
+            ROUND(sum(cost), 2) cost,
+            sum(show_num) showNum,
+            sum(click) click,
+            CASE
+                WHEN (click / show_num) IS NULL THEN
+                    0
+                ELSE
+                    CONCAT(
+                            ROUND(
+                                    (click / show_num) * 100,
+                                    2
+                                ),
+                            '%'
+                        )
+                END AS 'clickRate',
+            CASE
+                WHEN (cost / show_num) IS NULL THEN
+                    0
+                ELSE
+                    ROUND(
+                            (cost / show_num) * 1000,
+                            2
+                        )
+                END AS 'cpm',
+            CASE
+                WHEN (click / cost) IS NULL THEN
+                    0
+                ELSE
+                    ROUND((cost / click), 2)
+                END AS 'cp'
+        FROM
+            ctop_bytedance_report_advertiser_hourly
+        WHERE
+            stat_datetime = #{statDate}
+        GROUP BY
+            stat_hour
+        ORDER BY
+            stat_hour ASC
 
     </select>
 
@@ -49,9 +86,36 @@
 
     <select id="queryDetailByStartEndDate" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
-         ROUND(sum(cost), 2) cost,
-         sum(show_num) showNum,
-         sum(click) click,
+           ROUND(sum(cost), 2) cost,
+           sum(show_num) showNum,
+           sum(click) click,
+           CASE
+               WHEN (sum(click) / sum(show_num)) IS NULL THEN
+                   0
+               ELSE
+                   CONCAT(
+                           ROUND(
+                                   (sum(click) / sum(show_num)) * 100,
+                                   2
+                               ),
+                           '%'
+                       )
+               END AS 'clickRate',
+           CASE
+               WHEN (sum(cost) / sum(show_num)) IS NULL THEN
+                   0
+               ELSE
+                   ROUND(
+                           (sum(cost) / sum(show_num)) * 1000,
+                           2
+                       )
+               END AS 'cpm',
+           CASE
+               WHEN (sum(click) / sum(cost)) IS NULL THEN
+                   0
+               ELSE
+                   ROUND((sum(cost) / sum(click)), 2)
+               END AS 'cp',
          DATE_FORMAT(stat_datetime,'%Y-%m-%d') statDate
        FROM
          ctop_bytedance_report_advertiser_daily
@@ -64,9 +128,36 @@
 
     <select id="queryDetailGroupMonthByDate" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
-         ROUND(sum(cost), 2) cost,
-         sum(show_num) showNum,
-         sum(click) click,
+           ROUND(sum(cost), 2) cost,
+           sum(show_num) showNum,
+           sum(click) click,
+           CASE
+               WHEN (sum(click) / sum(show_num)) IS NULL THEN
+                   0
+               ELSE
+                   CONCAT(
+                           ROUND(
+                                   (sum(click) / sum(show_num)) * 100,
+                                   2
+                               ),
+                           '%'
+                       )
+               END AS 'clickRate',
+           CASE
+               WHEN (sum(cost) / sum(show_num)) IS NULL THEN
+                   0
+               ELSE
+                   ROUND(
+                           (sum(cost) / sum(show_num)) * 1000,
+                           2
+                       )
+               END AS 'cpm',
+           CASE
+               WHEN (sum(click) / sum(cost)) IS NULL THEN
+                   0
+               ELSE
+                   ROUND((sum(cost) / sum(click)), 2)
+               END AS 'cp',
          DATE_FORMAT(stat_datetime,'%Y-%m') statDate
        FROM
          ctop_bytedance_report_advertiser_daily
@@ -79,10 +170,37 @@
     </select>
 
     <select id="queryDetailGroupDayByMonth" resultType="com.alibaba.fastjson.JSONObject">
-       SELECT
-         ROUND(sum(cost), 2) cost,
-         sum(show_num) showNum,
-         sum(click) click,
+        SELECT
+            ROUND(sum(cost), 2) cost,
+            sum(show_num) showNum,
+            sum(click) click,
+            CASE
+                WHEN (sum(click) / sum(show_num)) IS NULL THEN
+                    0
+                ELSE
+                    CONCAT(
+                            ROUND(
+                                    (sum(click) / sum(show_num)) * 100,
+                                    2
+                                ),
+                            '%'
+                        )
+                END AS 'clickRate',
+            CASE
+                WHEN (sum(cost) / sum(show_num)) IS NULL THEN
+                    0
+                ELSE
+                    ROUND(
+                            (sum(cost) / sum(show_num)) * 1000,
+                            2
+                        )
+                END AS 'cpm',
+            CASE
+                WHEN (sum(click) / sum(cost)) IS NULL THEN
+                    0
+                ELSE
+                    ROUND((sum(cost) / sum(click)), 2)
+                END AS 'cp',
          DATE_FORMAT(stat_datetime,'%Y-%m-%d') statDate,
          SUBSTR(DATE_FORMAT(stat_datetime,'%Y-%m-%d') FROM 9 FOR 2) day
        FROM

+ 4 - 3
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IBytedanceHomepageReportService.java

@@ -7,9 +7,10 @@ import java.util.Map;
 
 public interface IBytedanceHomepageReportService {
 
-    Map<String,JSONObject> getWeekReport(JSONObject json);
+    Map<String,JSONObject> getWeekReport(JSONObject requestBody);
 
-    List<JSONObject> getChartByDate(JSONObject json);
+    Map<String,List<JSONObject>> getChartByDate(JSONObject requestBody);
+
+    Map<String,JSONObject> getCompareByDate(JSONObject requestBody);
 
-    JSONObject getTopCostByDate(JSONObject json);
 }

+ 100 - 41
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceHomepageReportServiceImpl.java

@@ -44,23 +44,29 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
         top.put("top7", costTop);
         //周明细环比数据拼接
         JSONObject costWeekData = new JSONObject();
+        JSONObject costWeekLink = new JSONObject();
         JSONObject clickWeekData = new JSONObject();
+        JSONObject clickWeekLink = new JSONObject();
         JSONObject showNumWeekData = new JSONObject();
+        JSONObject showNumWeekLink = new JSONObject();
         weekDetailData.forEach(day -> {
             costWeekData.put((String) day.get("statDate"), day.get("cost"));
             clickWeekData.put((String) day.get("statDate"), day.get("click"));
             showNumWeekData.put((String) day.get("statDate"), day.get("showNum"));
         });
-        costWeekData.put("weekCostSum", weekSumData.get("cost"));
-        costWeekData.put("weekCostSumLink", countLink(weekSumData.getBigDecimal("cost"), weekBeforeSumData.getBigDecimal("cost")));
-        clickWeekData.put("weekClickSum", weekSumData.get("click"));
-        clickWeekData.put("weekClickSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("click")), BigDecimal.valueOf(weekBeforeSumData.getLong("click"))));
-        showNumWeekData.put("weekCostSum", weekSumData.get("showNum"));
-        showNumWeekData.put("weekShowNumSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("showNum")), BigDecimal.valueOf(weekBeforeSumData.getLong("showNum"))));
+        costWeekLink.put("weekCostSum", weekSumData.get("cost"));
+        costWeekLink.put("weekCostSumLink", countLink(weekSumData.getBigDecimal("cost"), weekBeforeSumData.getBigDecimal("cost")));
+        clickWeekLink.put("weekClickSum", weekSumData.get("click"));
+        clickWeekLink.put("weekClickSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("click")), BigDecimal.valueOf(weekBeforeSumData.getLong("click"))));
+        showNumWeekLink.put("weekShowNumSum", weekSumData.get("showNum"));
+        showNumWeekLink.put("weekShowNumSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("showNum")), BigDecimal.valueOf(weekBeforeSumData.getLong("showNum"))));
 
         result.put("costWeek", costWeekData);
+        result.put("costWeekLink", costWeekLink);
         result.put("clickWeek", clickWeekData);
+        result.put("clickWeekLink", clickWeekLink);
         result.put("showNumWeek", showNumWeekData);
+        result.put("showNumWeekLink", showNumWeekLink);
         result.put("top", top);
 
         return result;
@@ -70,12 +76,14 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
      * timeType :1,2,3,4,5,6,7,8,9  前端约束入参类型
      */
     @Override
-    public List<JSONObject> getChartByDate(JSONObject requestBody) {
+    public Map<String,List<JSONObject>> getChartByDate(JSONObject requestBody) {
         int timeType = requestBody.getInteger("type");
-        List<JSONObject> resultBody = new ArrayList<>();
+        Map<String,List<JSONObject>> resultBody=new HashMap<>();
         if (requestBody.isEmpty()) {
             return resultBody;
         }
+        List<JSONObject> resultChart = new ArrayList<>();
+        List<JSONObject> resultList = new ArrayList<>();
         //当天日期
         String nowDate = DateUtils.getNowDate(SystemDateConstant.yyyy_MM_dd);
         //startTime 为取什么时间段数据的开始时间,默认昨天
@@ -83,69 +91,128 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
         switch (timeType) {
             //今天
             case 1:
-                resultBody = getCompareGroupByHour(nowDate, anotherDay);
+                resultChart = getCompareGroupByHour(nowDate, anotherDay);
+                resultList = getFormDetailByDate(nowDate,nowDate,"hour");
                 break;
             //昨天
             case 2:
-                resultBody = bytedanceHomepageMapper.queryTodayDetailReportBy(anotherDay);
+                resultChart = getCompareGroupByHour(anotherDay, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -1));
+                resultList = getFormDetailByDate(anotherDay,anotherDay,"hour");
                 break;
             //近一周
             case 3:
-                resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
+                resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
                         DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -6));
+                resultList = getFormDetailByDate(nowDate, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -6),"day");
                 break;
             //近半个月(15天)
             case 4:
-                resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
+                resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
                         DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -14));
+                resultList = getFormDetailByDate(nowDate, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -14),"day");
                 break;
             //近一个月
             case 5:
-                resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
+                resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
                         DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -1));
+                resultList = getFormDetailByDate(nowDate, DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -1),"day");
                 break;
             //近三个月
             case 6:
-                resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
+                resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
                         DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -3));
+                resultList = getFormDetailByDate(nowDate, DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -3),"day");
                 break;
             //近半年
             case 7:
-                resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
+                resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
                         DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -6));
+                resultList = getFormDetailByDate(nowDate, DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -6),"day");
                 break;
-            //全部数据
+            //近一年
             case 8:
-                resultBody = bytedanceHomepageMapper.queryDetailGroupMonthByDate(SystemDateConstant.BEGIN_TIME, nowDate);
+                resultChart = bytedanceHomepageMapper.queryDetailGroupMonthByDate( nowDate, SystemDateConstant.BEGIN_TIME);
+                resultList = getFormDetailByDate(nowDate, SystemDateConstant.BEGIN_TIME,"day");
                 break;
             //自定义起始时间
             case 9:
-                resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(requestBody.getString("startDate"), requestBody.getString("endDate"));
-                break;
-            //对比
-            case 10:
-                resultBody = getChartByType_10(requestBody.getString("sign"), requestBody.getString("smallDate"), requestBody.getString("bigDate"));
+                resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(requestBody.getString("endDate"), requestBody.getString("startDate"));
+                resultList = getFormDetailByDate(requestBody.getString("endDate"), requestBody.getString("startDate"),"day");
                 break;
             default:
         }
+        resultBody.put("chart",resultChart);
+        resultBody.put("list",resultList);
         return resultBody;
     }
 
     @Override
-    public JSONObject getTopCostByDate(JSONObject requestBody) {
-        return null;
+    public Map<String, JSONObject> getCompareByDate(JSONObject requestBody) {
+        Map<String,JSONObject> resultBody=new HashMap<>();
+        if (requestBody.isEmpty()) {
+            return resultBody;
+        }
+        String sign= requestBody.getString("sign");
+        String smallDate= requestBody.getString("smallDate");
+        String bigDate= requestBody.getString("bigDate");
+        resultBody.put("chart",this.getCompareChart(sign,smallDate,bigDate));
+        resultBody.put("list",this.getCompareList(sign,smallDate,bigDate));
+
+        return resultBody;
+    }
+
+
+    //表格数据查询
+    private List<JSONObject> getFormDetailByDate(String endDate, String startDate, String group){
+        List<JSONObject> result =null;
+        if("day".equals(group)){
+            result= bytedanceHomepageMapper.queryDetailByStartEndDate(endDate,startDate);
+        }else {
+            result= bytedanceHomepageMapper.queryTodayDetailReportBy(endDate);
+        }
+        return getListLink(result);
     }
 
     //自定义日期对比(日对比,月对比)
-    private List<JSONObject> getChartByType_10(String sign, String smallDate, String bigDate) {
-        List<JSONObject> result = new ArrayList<>();
+    private JSONObject getCompareChart(String sign, String smallDate, String bigDate) {
+        JSONObject result = new JSONObject();
         if (!sign.isEmpty() && sign.equals("month")) {
-            result = this.getCompareGroupByDay(smallDate, bigDate);
+            result.put("compare",this.getCompareGroupByDay(smallDate, bigDate));
         } else if (!sign.isEmpty() && sign.equals("day")) {
-            result = this.getCompareGroupByHour(bigDate, smallDate);
+            result.put("compare",this.getCompareGroupByHour(bigDate, smallDate));
+        }
+        return result;
+    }
+    private JSONObject getCompareList(String sign, String smallDate, String bigDate){
+        JSONObject result = new JSONObject();
+        if (!sign.isEmpty() && sign.equals("month")) {
+            result.put("smallDate",getListLink(bytedanceHomepageMapper.queryDetailGroupDayByMonth(smallDate)));
+            result.put("bigDate",getListLink(bytedanceHomepageMapper.queryDetailGroupDayByMonth(bigDate)));
+        } else if (!sign.isEmpty() && sign.equals("day")) {
+            result.put("smallDate",getListLink(bytedanceHomepageMapper.queryTodayDetailReportBy(smallDate)));
+            result.put("bigDate",getListLink(bytedanceHomepageMapper.queryTodayDetailReportBy(bigDate)));
         }
         return result;
     }
+    //List环比计算
+    private List<JSONObject> getListLink(List<JSONObject> result){
+        if(result.size()>1){
+            for(int i=1;i<result.size();i++){
+                if(i==1){result.get(i).put("costProportion",BigDecimal.ZERO);}
+                result.get(i).put("costProportion",countLink((BigDecimal) result.get(i).get("cost"),(BigDecimal) result.get(i-1).get("cost")));
+            }
+        }
+        return result;
+    }
+    /*private JSONObject getCompareSum(String sign, String smallDate, String bigDate){
+        JSONObject result = new JSONObject();
+        if (!sign.isEmpty() && sign.equals("month")) {
+            bytedanceHomepageMapper.querySumByStartEndDate()
+        } else if (!sign.isEmpty() && sign.equals("day")) {
+            result = this.getCompareGroupByHour(bigDate, smallDate);
+        }
+        return result;
+    }*/
 
     //两个月份的数据对比
     private List<JSONObject> getCompareGroupByDay(String smallDate, String bigDate) {
@@ -153,15 +220,8 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
         List<JSONObject> afterDetail = bytedanceHomepageMapper.queryDetailGroupDayByMonth(bigDate);
         //小月份数据
         List<JSONObject> beforeDetail = bytedanceHomepageMapper.queryDetailGroupDayByMonth(smallDate);
-        List<JSONObject> beforeData;List<JSONObject> afterData;
-        if (afterDetail.size() >= beforeDetail.size()) {
-            beforeData = afterDetail;
-            afterData = beforeData;
-        } else {
-            beforeData = beforeDetail;
-            afterData = afterDetail;
-        }
-        return this.getCompareDate(beforeData,afterData,"day");
+
+        return this.getCompareDate(beforeDetail,afterDetail,"day");
     }
 
     //今天昨天数据对比
@@ -175,9 +235,9 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
     private List<JSONObject> getCompareDate(List<JSONObject> beforeData, List<JSONObject> AfterData, String standard) {
         List<JSONObject> result = new ArrayList<>();
         beforeData.forEach(before -> {
-            String yesStatHour = String.valueOf(before.get(standard));
+            String yesStat = String.valueOf(before.get(standard));
             AfterData.forEach(after -> {
-                if ((String.valueOf(after.get(standard))).equals(yesStatHour)) {
+                if ((String.valueOf(after.get(standard))).equals(yesStat)) {
                     //消耗较昨日环比
                     after.put("costProportion", countLink(after.getBigDecimal("cost"), before.getBigDecimal("cost")));
                     //展示量较昨日环比
@@ -201,5 +261,4 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
         return link;
     }
 
-}
-
+}

+ 26 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/ReportServiceImpl.java

@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -247,6 +248,11 @@ public class ReportServiceImpl implements IReportService {
 
     @Autowired
     private BytedanceReportMaterialDailyMapper materialDailyMapper;
+    @Autowired
+    private IBytedanceReportService bytedanceReportService;
+    @Autowired
+    private IByteDanceVideoReportDailyService byteDanceVideoReportDailyService;
+
     @Override
     public void loadBytedanceHistoryData(CtopOauthToken token) {
         for (int i = 1; i < 180; i++) {
@@ -255,6 +261,26 @@ public class ReportServiceImpl implements IReportService {
             this.getAdvertiserPlanReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
             this.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
         }
+
+        try {
+            log.info("获取历史素材报表:accountId:{}", token.getAccountId());
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            String endDate = DateUtils.addDay(nowDate, -180);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date end = simpleDateFormat.parse(nowDate);
+            Date start = simpleDateFormat.parse(endDate);
+            List<Date> dates = DateUtils.findDates(start, end);
+            for (int i = 0; i < dates.size(); i++) {
+                String formatDate = simpleDateFormat.format(dates.get(i));
+                int code = bytedanceReportService.bytedanceMaterialReport(token, formatDate, formatDate);
+                //如果成功的话跑视频清洗数据方法,失败会进入重试库,重试成功后再清洗数据
+                if (code == 200 || code == 1) {
+                    byteDanceVideoReportDailyService.videoInfoListByAccountId(formatDate, formatDate, token.getAccountId());
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     private ByteDanceAdvertiserReportDTO getReportDTO(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl) {