Jelajahi Sumber

Merge branch 'master' into test

yumeng 5 tahun lalu
induk
melakukan
eddbc47cab
31 mengubah file dengan 830 tambahan dan 337 penghapusan
  1. 12 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialInfoController.java
  2. 5 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialUploadController.java
  3. 1 7
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java
  4. 2 2
      jeecg-boot-module-system/src/main/resources/application-dev.yml
  5. 14 14
      jeecg-boot-module-system/src/main/resources/application-prod.yml
  6. 4 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/MaterialImageInfoMapper.java
  7. 2 2
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/BindAccountLoginMapper.xml
  8. 11 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MaterialImageInfoMapper.xml
  9. 1 1
      module-common/src/main/java/cn/com/ctop/common/module/service/IFileInfoService.java
  10. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialImageInfoService.java
  11. 9 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java
  12. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/service/ISendMessageService.java
  13. 23 14
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/FileInfoServiceImpl.java
  14. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialImageInfoServiceImpl.java
  15. 57 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java
  16. 26 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/SendMessageServiceImpl.java
  17. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java
  18. 1 1
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/IMaterialUploadService.java
  19. 54 55
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadImageServiceImpl.java
  20. 23 11
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java
  21. 132 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java
  22. 3 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IBatchService.java
  23. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouGroupService.java
  24. 8 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  25. 21 23
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java
  26. 260 3
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java
  27. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java
  28. 33 116
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  29. 54 45
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/AccountReportMapper.xml
  30. 7 33
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/DailyReportMapper.xml
  31. 48 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/AccountReportServiceImpl.java

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

@@ -324,6 +324,10 @@ public class MaterialInfoController {
      */
     @Autowired
     private IProjectService projectService;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private ISendMessageService sendMessageService;
 
     @AutoLog(value = "素材信息-编辑")
     @ApiOperation(value = "素材信息-编辑", notes = "素材信息-编辑")
@@ -390,6 +394,14 @@ public class MaterialInfoController {
             if (ok) {
                 result.success("修改成功!");
             }
+
+            Integer status = materialInfo.getStatus();
+            // 如果状态为2 审核拒绝 给上传人发送消息
+            if (status == 2) {
+                Project project = projectService.getById(materialInfoEntity.getProjectId());
+                String text = messageTemplate.getMaterialRejectTemplate(project.getProjectName(), materialInfoEntity.getMaterialName(), materialInfo.getRefuseReason());
+                sendMessageService.sendMessage(materialInfoEntity.getUserId(), text);
+            }
         }
 
         return result;

+ 5 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialUploadController.java

@@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -44,8 +46,10 @@ public class MaterialUploadController {
             if (Check.isNull(materialArray) || Check.isNull(accountArray)) {
                 throw new Exception("请选择账号或素材");
             }
+            LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
 
-            new Thread(() -> materialUploadService.uploadAccount(mediaId, materialArray, accountArray)).start();
+
+            new Thread(() -> materialUploadService.uploadAccount(mediaId, materialArray, accountArray, sysUser.getId())).start();
             returnMap.put("success", true);
             returnMap.put("message", "开始上传文件");
             returnMap.put("code", 0);

+ 1 - 7
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java

@@ -149,11 +149,6 @@ public class UserAllocationController {
             QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("project_id", projectId);
 
-           /* if (!Check.isNull(project)) {
-            Project project = projectService.getById(projectId);
-                queryWrapper.eq("media_id", project.getMediaId());
-            }*/
-
             String roleCode = sysRoleService.getRoleCodeByUserId(userId);
             if (!CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode) && !"kuaishouOperationManager".equals(roleCode) && !"designTeamLeader".equals(roleCode) && !"touTiaoOperationManager".equals(roleCode)) {
                 queryWrapper.eq("user_id", userId);
@@ -182,10 +177,9 @@ public class UserAllocationController {
     public Result<List<UserAllocation>> getAccountListByProjectId(Long projectId) {
         Result<List<UserAllocation>> result = new Result<>();
         try {
-
             QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("project_id", projectId);
-
+            queryWrapper.eq("account_status", 0);
            /* if (!Check.isNull(project)) {
                  Project project = projectService.getById(projectId);
                  queryWrapper.eq("media_id", project.getMediaId());

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

@@ -129,8 +129,8 @@ mybatis-plus:
       # 默认数据库表下划线命名
       table-underline: true
     configuration:
-      # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
-      #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
+    #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 #jeecg专用配置
 jeecg:
   ffmpeg:

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

@@ -1,5 +1,5 @@
 server:
-  port: 8080
+  port: 8804
   ip: 39.97.120.42
   servlet:
     context-path: /jeecg-boot
@@ -97,7 +97,7 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://39.97.120.42:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+          url: jdbc:mysql://127.0.0.1:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
           username: hcst
           password: test@20190531
           driver-class-name: com.mysql.jdbc.Driver
@@ -110,7 +110,7 @@ spring:
   #redis 配置
   redis:
     database: 0
-    host: 127.0.0.1
+    host: 172.30.0.17
     lettuce:
       pool:
         max-active: 8   #最大连接数据库连接数,设 0 为没有限制
@@ -139,16 +139,16 @@ jeecg:
     bin: ffmpeg
   path:
     #文件上传根目录 设置
-    upload: /mnt/upload
+    upload: /data/upload
     #webapp文件路径
-    webapp: /mnt/webapp
-    video-upload: /mnt/upload/video/
-    image-upload: /mnt/upload/image/
+    webapp: /data/webapp
+    video-upload: /data/upload/video/
+    image-upload: /data/upload/image/
     chrome-driver: /usr/bin/chromedriver
-    csv-upload: /mnt/upload/csv/
-    bak-database-file: /mnt/data/bak/
-    report-history: /mnt/upload/report/history/
-    report-daily: /mnt/upload/report/daily/
+    csv-upload: /data/upload/csv/
+    bak-database-file: /data/data/bak/
+    report-history: /data/upload/report/history/
+    report-daily: /data/upload/report/daily/
 kuaishou:
   group-control:
     path: http://39.106.184.70
@@ -159,10 +159,10 @@ logging:
   config: classpath:logback-prod.xml
 chrome:
   script:
-    clean: sh /mnt/webapp/cleanProcess.sh
+    clean: sh /data/webapp/cleanProcess.sh
 
 oss:
   replace:
-    replace-value: oss-cn-beijing-internal
+    replace-value: oss-cn-beijing
     replace-old-value: oss-cn-beijing
-    download: /mnt/file/video/
+    download: /data/file/video/

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/MaterialImageInfoMapper.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.MaterialImageInfo;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -16,4 +18,6 @@ public interface MaterialImageInfoMapper extends BaseMapper<MaterialImageInfo> {
     void insertSelective(MaterialImageInfo materialImageInfo);
 
     List<String> getCodeList();
+
+    List<JSONObject> getUrlList(@Param("videoId") String videoId);
 }

+ 2 - 2
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/BindAccountLoginMapper.xml

@@ -11,10 +11,10 @@
             left join ctop_project project on login.project_id = project.id
         where 1=1
         <if test="userId!=null">
-            and user_id = #{userId}
+            and login.user_id = #{userId}
         </if>
         <if test="loginType!=null">
-            and login_type = #{loginType}
+            and login.login_type = #{loginType}
         </if>
         group by project_id
     </select>

+ 11 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/MaterialImageInfoMapper.xml

@@ -120,4 +120,15 @@
      SELECT DISTINCT(code)  from  ctop_material_image_info
     </select>
 
+    <select id="getUrlList" resultType="com.alibaba.fastjson.JSONObject">
+
+        SELECT t.url as 'imageUrl',t.`code` as 'signature'  from (
+        SELECT url,`code` from ctop_material_image_info
+        WHERE video_id = #{videoId}
+        UNION ALL
+        SELECT url,signature  from ctop_material_cut_frame WHERE video_signature = #{videoId}
+        ) t
+
+    </select>
+
 </mapper>

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

@@ -16,7 +16,7 @@ import java.util.Map;
  */
 public interface IFileInfoService extends IService<FileInfo> {
 
-    void uploadVideoToBytedance(String accountId, String videoUrl);
+    void uploadVideoToBytedance(String accountId, String videoUrl, String userId,String materialName);
 
     Map<String, Object> uploadImageToBytedance(String accountId, String imageFileId);
 

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialImageInfoService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.service;
 
 import cn.com.ctop.common.module.entity.MaterialImageInfo;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -26,4 +27,5 @@ public interface IMaterialImageInfoService extends IService<MaterialImageInfo> {
 
     List<String> getCodeList();
 
+    List<JSONObject> getUrlList(String videoId);
 }

+ 9 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java

@@ -0,0 +1,9 @@
+package cn.com.ctop.common.module.service;
+
+public interface IMessageTemplate {
+
+    String getMaterialSyncTemplate(String projectName, Long accountId, String accountName, String materialName, String reason);
+
+
+    String getMaterialRejectTemplate(String projectName, String materialName, String refuseReason);
+}

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/ISendMessageService.java

@@ -0,0 +1,5 @@
+package cn.com.ctop.common.module.service;
+
+public interface ISendMessageService {
+    void sendMessage(String id, String text);
+}

+ 23 - 14
module-common/src/main/java/cn/com/ctop/common/module/service/impl/FileInfoServiceImpl.java

@@ -2,10 +2,11 @@ package cn.com.ctop.common.module.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.FileInfo;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.FileInfoMapper;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
-import cn.com.ctop.common.module.service.IFileInfoService;
+import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.BytedanceInterfaceConstant;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import com.alibaba.fastjson.JSONArray;
@@ -53,14 +54,31 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
     FileInfoMapper fileInfoMapper;
     @Resource
     private ICtopOauthTokenService ctopOauthTokenService;
+    @Autowired
+    private IUserAllocationService userAllocationService;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private ISendMessageService sendMessageService;
 
     @Override
-    public void uploadVideoToBytedance(String accountId, String videoUrl) {
+    public void uploadVideoToBytedance(String accountId, String videoUrl, String userId, String materialName) {
         try {
             CtopOauthToken token = ctopOauthTokenService.getOauthTokenByAccountId(accountId);
-            uploadAdvideo(token, videoUrl, token.getAccountId() + "");
             JSONObject jsonObject = videoUpload(token, videoUrl);
-            log.info("头条上传素材返回信息:{},accountId:{}", jsonObject, accountId);
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 0) {
+                    log.info("头条上传素材成功,返回信息:{},accountId:{}", jsonObject, accountId);
+                } else {
+                    UserAllocation allocation = userAllocationService.getByAccountId(Long.valueOf(accountId));
+                    String message = messageTemplate.getMaterialSyncTemplate(allocation.getProjectName(), Long.valueOf(accountId), allocation.getAuthName(), materialName, jsonObject.getString("message"));
+                    sendMessageService.sendMessage(userId, message);
+                }
+
+            }
+
+
         } catch (Exception e) {
             log.error("头条上传视频文件失败,accountId:{}", accountId);
             log.error(e.getMessage(), e);
@@ -207,15 +225,6 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
         }
     }
 
-    public void uploadAdvideo(CtopOauthToken token, String videoUrl, String advertiserId) {
-        //1:下载文件到本地
-
-
-        //文件上传
-        // JSONObject bytedanceObject = videoUpload(token, advertiserId, videoPath);
-        // log.info("头条上传返回信息:{},accountId:{}", bytedanceObject, advertiserId);
-
-    }
 
     private JSONObject videoUpload(CtopOauthToken token, String videoPath) {
         CloseableHttpResponse response = null;

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialImageInfoServiceImpl.java

@@ -128,4 +128,9 @@ public class MaterialImageInfoServiceImpl extends ServiceImpl<MaterialImageInfoM
         return materialImageInfoMapper.getCodeList();
     }
 
+    @Override
+    public List<JSONObject> getUrlList(String videoId) {
+        return materialImageInfoMapper.getUrlList(videoId);
+    }
+
 }

+ 57 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java

@@ -0,0 +1,57 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.service.IMessageTemplate;
+import cn.com.ctop.common.module.utils.Check;
+import org.springframework.stereotype.Service;
+
+@Service
+public class MessageTemplateImpl implements IMessageTemplate {
+
+
+    /**
+     * 同步素材失败
+     *
+     * @param projectName
+     * @param accountId
+     * @param accountName
+     * @param materialName
+     * @param reason
+     * @return
+     */
+    @Override
+    public String getMaterialSyncTemplate(String projectName, Long accountId, String accountName, String materialName, String reason) {
+        StringBuilder text = new StringBuilder();
+        text.append("素材同步失败").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("下的账户:").append(accountId + ",").append("<br/>")
+                .append("授权名称为:" + accountName).append("<br/>")
+                .append("同步素材失败。").append("<br/>")
+                .append("素材名称为:").append(materialName).append("<br/>")
+                .append("失败原因:").append(reason);
+        return text.toString();
+    }
+
+
+    /**
+     * 素材库素材驳回
+     *
+     * @param projectName
+     * @param materialName
+     * @param refuseReason
+     * @return
+     */
+    @Override
+    public String getMaterialRejectTemplate(String projectName, String materialName, String refuseReason) {
+        StringBuilder text = new StringBuilder();
+        text.append("素材驳回通知").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("素材名称为:").append(materialName).append("<br/>")
+                .append("已被驳回。").append("<br/>");
+        if (!Check.isNull(refuseReason)) {
+            text.append("驳回原因为:").append(refuseReason).append("</br>");
+
+        }
+        text.append("请您联系相关同学及时调整");
+        return text.toString();
+    }
+}

+ 26 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/SendMessageServiceImpl.java

@@ -0,0 +1,26 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.mapper.MailLogMapper;
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.CorpWexinUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class SendMessageServiceImpl implements ISendMessageService {
+    @Autowired
+    private MailLogMapper mailLogMapper;
+
+    @Override
+    public void sendMessage(String userId, String text) {
+        String weChatId = mailLogMapper.getWChatIdByUserId(userId);
+        if (!Check.isNull(weChatId)) {
+            CorpWexinUtils.sendMessageByWeChatId(weChatId, text);
+            log.info("消息发送成功,userId:{}", userId);
+        }
+    }
+
+}

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

@@ -114,6 +114,11 @@ public class KuaishouInterfaceConstant {
      */
     public static final String CONVERT_LIST = "/rest/openapi/v1/tool/convert/list";
 
+    /**
+     * 获取可选的动态词包
+     */
+    public static final String CREATIVE_WORD = "/rest/openapi/v1/tool/creative_word/list";
+
 
     /**
      * 获取定向标签

+ 1 - 1
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/IMaterialUploadService.java

@@ -11,5 +11,5 @@ public interface IMaterialUploadService {
      * @param materialArray
      * @param accountArray
      */
-    void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray);
+    void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray,String userId);
 }

+ 54 - 55
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadImageServiceImpl.java

@@ -1,22 +1,20 @@
 package cn.com.ctop.manage.modules.material.service.impl;
 
-import cn.com.ctop.common.module.entity.MaterialImageInfo;
 import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.service.IMaterialImageInfoService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
-import cn.com.ctop.common.module.utils.LoadFileUtil;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
 import cn.com.ctop.manage.modules.material.service.IMaterialUploadImageService;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.ParseException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.io.FileSystemResource;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
@@ -26,7 +24,6 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
-import java.io.File;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -36,7 +33,7 @@ import java.util.concurrent.Executors;
 @Slf4j
 @Service
 public class MaterialUploadImageServiceImpl implements IMaterialUploadImageService {
-    static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    static ExecutorService executorService = Executors.newFixedThreadPool(8);
     @Value("${oss.replace.replace-value}")
     private String replaceValue;
     @Value("${oss.replace.replace-old-value}")
@@ -55,63 +52,65 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
     @Override
     public void uploadImage(String videoId, Long accountId, String accessToken) {
         try {
-            QueryWrapper<MaterialImageInfo> imageInfoQueryWrapper = new QueryWrapper<>();
-            imageInfoQueryWrapper.eq("video_id", videoId);
-            imageInfoQueryWrapper.eq("status", 0);
-            List<MaterialImageInfo> imageList = materialImageInfoService.list(imageInfoQueryWrapper);
+            List<JSONObject> imageList = materialImageInfoService.getUrlList(videoId);
             if (!Check.isNull(imageList)) {
-                for (MaterialImageInfo imageInfo : imageList) {
-                    QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
-                    imageQueryWrapper.eq("account_id", accountId);
-                    imageQueryWrapper.eq("signature", imageInfo.getCode());
-                    List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
-                    if (!Check.isNull(imageGetList)) {
-                        log.info("此封面已上传");
+                for (int i = 0; i < imageList.size(); i++) {
+                    JSONObject imageInfo = imageList.get(i);
+                    if (Check.isNull(imageInfo)) {
                         continue;
                     }
-                    String url = String.valueOf(imageInfo.getUrl());
-                    String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
-                    FileSystemResource resource = new FileSystemResource(new File(localUrl));
-                    Map<String, String> headerMap = new HashMap<>();
-                    JSONObject requestJson = new JSONObject();
-                    requestJson.put("advertiser_id", accountId);
-                    headerMap.put("Access-Token", accessToken);
-                    headerMap.put("Content-Type", "multipart/form-data");
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
+                            imageQueryWrapper.eq("account_id", accountId);
+                            imageQueryWrapper.eq("signature", imageInfo.getString("signature"));
+                            List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
+                            if (Check.isNull(imageGetList)) {
+                                Map<String, String> headerMap = new HashMap<>();
+                                JSONObject requestJson = new JSONObject();
+                                requestJson.put("advertiser_id", accountId);
+                                headerMap.put("Access-Token", accessToken);
+                                headerMap.put("Content-Type", "multipart/form-data");
 
-                    requestJson.put("file", resource);
-                    requestJson.put("signature", imageInfo.getCode());
-                    requestJson.put("type", "2");
-                    requestJson.put("upload_type", "1");
-                    String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
-                    String result = exceptInfoForRestTemplate(requestUrl, requestJson, headerMap);
-                    JSONObject resultJson = JSONObject.parseObject(result);
-                    if (!Check.isNull(resultJson)) {
-                        if (resultJson.getInteger("code") == 0) {
-                            JSONObject dataJson = resultJson.getJSONObject("data");
-                            if (!Check.isNull(dataJson)) {
-                                String signature = dataJson.getString("signature");
-                                String image_token = dataJson.getString("image_token");
-                                KuaiShouImageGet imageGet = new KuaiShouImageGet();
-                                imageGet.setId(accountId + image_token);
-                                imageGet.setAccountId(accountId);
-                                imageGet.setUrl(dataJson.getString("url"));
-                                imageGet.setWidth(dataJson.getInteger("width"));
-                                imageGet.setHeight(dataJson.getInteger("height"));
-                                imageGet.setSize(dataJson.getInteger("size"));
-                                imageGet.setFormat(dataJson.getString("format"));
-                                Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
-                                if (!Check.isNull(type)) {
-                                    imageGet.setMaterialType(type);
+                                requestJson.put("url", imageInfo.getString("imageUrl"));
+                                requestJson.put("signature", imageInfo.getString("signature"));
+                                requestJson.put("type", "2");
+                                requestJson.put("upload_type", "2");
+                                String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
+                                String result = exceptInfoForRestTemplate(requestUrl, requestJson, headerMap);
+                                JSONObject resultJson = JSONObject.parseObject(result);
+                                if (!Check.isNull(resultJson)) {
+                                    if (resultJson.getInteger("code") == 0) {
+                                        JSONObject dataJson = resultJson.getJSONObject("data");
+                                        if (!Check.isNull(dataJson)) {
+                                            String signature = dataJson.getString("signature");
+                                            String image_token = dataJson.getString("image_token");
+                                            KuaiShouImageGet imageGet = new KuaiShouImageGet();
+                                            imageGet.setId(accountId + image_token);
+                                            imageGet.setAccountId(accountId);
+                                            imageGet.setUrl(dataJson.getString("url"));
+                                            imageGet.setWidth(dataJson.getInteger("width"));
+                                            imageGet.setHeight(dataJson.getInteger("height"));
+                                            imageGet.setSize(dataJson.getInteger("size"));
+                                            imageGet.setFormat(dataJson.getString("format"));
+                                            Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
+                                            if (!Check.isNull(type)) {
+                                                imageGet.setMaterialType(type);
+                                            }
+                                            imageGet.setSignature(signature);
+                                            imageGet.setImageToken(image_token);
+                                            imageGetService.saveOrUpdate(imageGet);
+                                        }
+                                        log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getString("signature"), resultJson);
+                                    } else {
+                                        log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+                                    }
                                 }
-                                imageGet.setSignature(signature);
-                                imageGet.setImageToken(image_token);
-                                imageGetService.saveOrUpdate(imageGet);
                             }
-                            log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getCode(), resultJson);
-                        } else {
-                            log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+
                         }
-                    }
+                    });
                 }
             }
         } catch (Exception e) {

+ 23 - 11
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java

@@ -3,12 +3,12 @@ package cn.com.ctop.manage.modules.material.service.impl;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.MaterialInfo;
 import cn.com.ctop.common.module.entity.MaterialParameter;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
 import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
-import cn.com.ctop.common.module.service.IFileInfoService;
-import cn.com.ctop.common.module.service.IMaterialParameterService;
+import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.LoadFileUtil;
@@ -67,6 +67,12 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     private IKuaiShouVideoGetService kuaiShouVideoGetService;
     @Autowired
     private IMaterialUploadImageService materialUploadImageService;
+    @Autowired
+    private ISendMessageService sendMessageService;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private IUserAllocationService userAllocationService;
 
 
     /**
@@ -78,12 +84,12 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
      */
 
     @Override
-    public void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+    public void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray, String userId) {
         try {
             if ("2".equals(mediaId)) {
-                this.kuaiShouUpload(mediaId, materialArray, accountArray);
+                this.kuaiShouUpload(mediaId, materialArray, accountArray, userId);
             } else if ("1".equals(mediaId)) {
-                this.touTiaoUpload(mediaId, materialArray, accountArray);
+                this.touTiaoUpload(mediaId, materialArray, accountArray, userId);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -93,7 +99,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     }
 
 
-    private void touTiaoUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+    private void touTiaoUpload(String mediaId, JSONArray materialArray, JSONArray accountArray, String userId) {
         for (int j = 0; j < materialArray.size(); j++) {
             String materialId = materialArray.getString(j);
             MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
@@ -110,12 +116,12 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                         continue;
                     }
                     touTiaoExecutorService.submit(new Runnable() {
-                                @Override
-                                public void run() {
+                        @Override
+                        public void run() {
                             try {
                                 log.info("头条文件多线程上传:{},accountId:{}", Thread.currentThread().getName(), accountId);
                                 if ("VIDEO".equals(materialInfo.getType())) {
-                                    fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), localUrl);
+                                    fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), localUrl, userId, materialInfo.getMaterialName());
 
                                 } else if ("IMAGE".equals(materialInfo.getType())) {
                                     fileInfoService.uploadImageToBytedance(String.valueOf(accountId), localUrl);
@@ -138,7 +144,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     }
 
 
-    private void kuaiShouUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
+    private void kuaiShouUpload(String mediaId, JSONArray materialArray, JSONArray accountArray, String userId) {
         for (int j = 0; j < materialArray.size(); j++) {
             String materialId = materialArray.getString(j);
             MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
@@ -216,12 +222,16 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                                             videoGet.setPhotoId(photoId);
                                             videoGet.setSignature(signature);
                                             kuaiShouVideoGetService.saveOrUpdate(videoGet);
-                                            materialUploadImageService.uploadImage(videoGet.getId(), accountId, ctopOauthToken.getAccessToken());
+                                            materialUploadImageService.uploadImage(videoGet.getSignature(), accountId, ctopOauthToken.getAccessToken());
 
                                         }
                                         log.info("快手素材同步完成,accountId:{},code:{},返回信息:{}", accountId, materialInfo.getCode(), resultJson);
                                     } else {
                                         log.error("快手同步素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+                                        //  发送消息到上传人
+                                        UserAllocation allocation = userAllocationService.getByAccountId(accountId);
+                                        String message = messageTemplate.getMaterialSyncTemplate(allocation.getProjectName(), accountId, allocation.getAuthName(), materialInfo.getMaterialName(), resultJson.getString("message"));
+                                        sendMessageService.sendMessage(userId, message);
                                     }
                                 }
 
@@ -271,4 +281,6 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
         }
         return null;
     }
+
+
 }

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

@@ -147,6 +147,16 @@ public class BatchController {
             };
             thread3.start();
 
+            Thread thread4 = new Thread() {
+                @Override
+                public void run() {
+                    kuaiShouGroupService.getGroupList(oauthToken.getAccessToken(), oauthToken.getAccountId());
+
+                }
+            };
+            thread4.start();
+
+
         } catch (Exception e) {
             e.printStackTrace();
             result.setSuccess(false);
@@ -1062,13 +1072,13 @@ public class BatchController {
     public Result<IPage<KuaiShouVideoGet>> getVideoList(KuaiShouVideoGet kuaiShouVideoGet, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                         @RequestParam(name = "startDate", defaultValue = "2010-01-01") String startDate,
-                                                        @RequestParam(name = "endDate", defaultValue = "2100-01-01") String endDate,HttpServletRequest req) {
+                                                        @RequestParam(name = "endDate", defaultValue = "2100-01-01") String endDate, HttpServletRequest req) {
         Result<IPage<KuaiShouVideoGet>> result = new Result<>();
         try {
             QueryWrapper<KuaiShouVideoGet> queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouVideoGet, req.getParameterMap());
             startDate = startDate + " 00:00:00";
             endDate = endDate + " 23:59:59";
-            queryWrapper.between("create_time",startDate,endDate);
+            queryWrapper.between("create_time", startDate, endDate);
             queryWrapper.orderByDesc("create_time");
             Page<KuaiShouVideoGet> page = new Page<>(pageNo, pageSize);
             IPage<KuaiShouVideoGet> pageList = kuaiShouVideoGetService.page(page, queryWrapper);
@@ -1390,7 +1400,13 @@ public class BatchController {
             if (Check.isNull(requestJson)) {
                 throw new Exception("入参为空");
             }
-            JSONObject unitJson = batchService.updateUnit(requestJson);
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+            JSONObject unitJson = batchService.updateUnit(requestJson, oauthToken);
             result.setSuccess(true);
             result.setResult(unitJson);
         } catch (Exception e) {
@@ -1420,12 +1436,18 @@ public class BatchController {
             if (Check.isNull(unitIds)) {
                 throw new Exception("请选择需要修改的广告组");
             }
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
             JSONObject returnJson = new JSONObject();
             JSONArray failArr = new JSONArray();
             for (int i = 0; i < unitIds.size(); i++) {
                 Long unitId = unitIds.getLong(i);
                 requestJson.put("unitId", unitId);
-                JSONObject unitJson = batchService.updateUnit(requestJson);
+                JSONObject unitJson = batchService.updateUnit(requestJson, oauthToken);
                 if (!Check.isNull(unitJson)) {
                     Integer code = unitJson.getInteger("code");
                     if (code != 0) {
@@ -1466,7 +1488,18 @@ public class BatchController {
             if (Check.isNull(requestJson)) {
                 throw new Exception("入参为空");
             }
-            JSONObject creativeJson = batchService.updateCreative(requestJson);
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入需创建账号");
+            }
+
+
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+            JSONObject creativeJson = batchService.updateCreative(requestJson, oauthToken);
             result.setSuccess(true);
             result.setResult(creativeJson);
         } catch (Exception e) {
@@ -1863,4 +1896,98 @@ public class BatchController {
     }
 
 
+    /**
+     * 批量修改广告创意
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/batchUpdateCreative")
+    public Result<JSONObject> batchUpdateCreative(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参为空");
+            }
+
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请输入需创建账号");
+            }
+
+
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+
+            JSONArray creativeIds = requestJson.getJSONArray("creativeIds");
+            if (Check.isNull(creativeIds)) {
+                throw new Exception("请选择需要修改的广告创意");
+            }
+            JSONObject creativeJson = requestJson.getJSONObject("creativeJson");
+            JSONObject returnJson = new JSONObject();
+            JSONArray failArr = new JSONArray();
+            for (int i = 0; i < creativeIds.size(); i++) {
+                Long creativeId = creativeIds.getLong(i);
+                creativeJson.put("creativeId", creativeId);
+                JSONObject unitJson = batchService.updateCreative(creativeJson, oauthToken);
+                if (!Check.isNull(unitJson)) {
+                    Integer code = unitJson.getInteger("code");
+                    if (code != 0) {
+                        JSONObject failJson = new JSONObject();
+                        failJson.put("message", unitJson.get("message"));
+                        KuaiShouCreative creative = batchService.getCreativeInfo(requestJson.getLong("accountId"), creativeId);
+                        if (!Check.isNull(creative)) {
+                            failJson.put("creativeName", creative.getCreativeName());
+                        }
+                        failArr.add(failJson);
+                    }
+                }
+            }
+            returnJson.put("totalCount", creativeIds.size());
+            returnJson.put("failCount", failArr.size());
+            returnJson.put("failInfo", failArr);
+
+            result.setSuccess(true);
+            result.setResult(returnJson);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
+     * 获取可选的动态词包
+     *
+     * @param accountId
+     * @return
+     */
+    @GetMapping(value = "/creativeWord")
+    public Result<JSONArray> creativeWord(Long accountId) {
+        Result<JSONArray> result = new Result<>();
+        try {
+            if (Check.isNull(accountId)) {
+                throw new Exception("入参为空");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONArray creativeWordArr = iKuaishouInterfaceService.getCreativeWord(accountId, oauthToken.getAccessToken());
+            result.setResult(creativeWordArr);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
 }

+ 3 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IBatchService.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
@@ -109,7 +110,7 @@ public interface IBatchService {
      * @param requestJson
      * @return
      */
-    JSONObject updateUnit(JSONObject requestJson) throws Exception;
+    JSONObject updateUnit(JSONObject requestJson,CtopOauthToken token) throws Exception;
 
     /**
      * 修改广告创意
@@ -117,7 +118,7 @@ public interface IBatchService {
      * @param requestJson
      * @return
      */
-    JSONObject updateCreative(JSONObject requestJson) throws Exception;
+    JSONObject updateCreative(JSONObject requestJson, CtopOauthToken token) throws Exception;
 
 
     /**

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

@@ -11,4 +11,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaiShouGroupService extends IService<KuaiShouGroup> {
 
+    void getGroupList(String accessToken, Long accountId);
 }

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

@@ -494,6 +494,14 @@ public interface IKuaishouInterfaceService {
      */
     List<ConvertVo> getConvertList(Long accountId, String accessToken, Integer type);
 
+    /**
+     * 获取可选的动态词包
+     *
+     * @param accountId
+     * @param accessToken
+     * @return
+     */
+    JSONArray getCreativeWord(Long accountId, String accessToken);
 }
 
 

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

@@ -467,10 +467,7 @@ public class BatchServiceImpl implements IBatchService {
     @Override
     public JSONObject copyUnit(KuaiShouGroup group, Long copyToCampaignId) {
         JSONObject returnJson = new JSONObject();
-
         try {
-
-
             CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(group.getAccountId());
             if (Check.isNull(oauthToken)) {
                 throw new Exception("未获取到token信息");
@@ -784,6 +781,20 @@ public class BatchServiceImpl implements IBatchService {
                 creativeJson.put("photo_id", photo_id);
                 creativeJson.put("click_track_url", click_track_url);
 
+                //封面广告语标题
+                if (!Check.isNull(creative.getStickerTitle())) {
+                    creativeJson.put("sticker_title", creative.getStickerTitle());
+                }
+                // 贴纸样式类型
+                if (!Check.isNull(creative.getOverlayType())) {
+                    creativeJson.put("overlay_type", creative.getOverlayType());
+                }
+                // 安卓下载中间页
+                /*if (!Check.isNull(creative.getSiteId())) {
+                    creativeJson.put("site_id", creative.getSiteId());
+                }*/
+
+
                 Map<String, Object> returnCreativeMap = kuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), accountId, creativeJson);
                 if (!Check.isNullMap(returnCreativeMap)) {
                     Integer code = (Integer) returnCreativeMap.get("code");
@@ -990,15 +1001,10 @@ public class BatchServiceImpl implements IBatchService {
      * @return
      */
     @Override
-    public JSONObject updateUnit(JSONObject requestJson) throws Exception {
+    public JSONObject updateUnit(JSONObject requestJson, CtopOauthToken token) throws Exception {
 
-        Long accountId = requestJson.getLong("accountId");
-        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
-        if (Check.isNull(oauthToken)) {
-            throw new Exception("未获取到账户信息");
-        }
         JSONObject unitJson = new JSONObject();
-        unitJson.put("advertiser_id", accountId);
+        unitJson.put("advertiser_id", token.getAccountId());
 
         Long unitId = requestJson.getLong("unitId");
         if (Check.isNull(unitId)) {
@@ -1175,7 +1181,7 @@ public class BatchServiceImpl implements IBatchService {
 
         unitJson.put("target", targetJson);
 
-        JSONObject returnJson = updateService.updateUnit(oauthToken.getAccessToken(), unitJson);
+        JSONObject returnJson = updateService.updateUnit(token.getAccessToken(), unitJson);
         return returnJson;
     }
 
@@ -1186,22 +1192,14 @@ public class BatchServiceImpl implements IBatchService {
      * @return
      */
     @Override
-    public JSONObject updateCreative(JSONObject requestJson) throws Exception {
+    public JSONObject updateCreative(JSONObject requestJson, CtopOauthToken token) throws Exception {
         if (Check.isNull(requestJson)) {
             throw new Exception("入参为空");
         }
 
-        Long accountId = requestJson.getLong("accountId");
-        if (Check.isNull(accountId)) {
-            throw new Exception("请输入需创建账号");
-        }
-        JSONObject creativeJson = new JSONObject();
-        creativeJson.put("advertiser_id", accountId);
 
-        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
-        if (Check.isNull(oauthToken)) {
-            throw new Exception("未获取到账户信息");
-        }
+        JSONObject creativeJson = new JSONObject();
+        creativeJson.put("advertiser_id", token.getAccountId());
 
         Long creativeId = requestJson.getLong("creativeId");
         if (Check.isNull(creativeId)) {
@@ -1258,7 +1256,7 @@ public class BatchServiceImpl implements IBatchService {
         if (!Check.isNull(requestJson.get("impressionUrl"))) {
             creativeJson.put("impression_url", requestJson.get("impressionUrl"));
         }
-        JSONObject returnJson = updateService.updateCreative(oauthToken.getAccessToken(), creativeJson);
+        JSONObject returnJson = updateService.updateCreative(token.getAccessToken(), creativeJson);
 
         return returnJson;
     }

+ 260 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java

@@ -1,12 +1,27 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.kuaishou.modules.batch.entity.*;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouAppInfoMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupTargetMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouScheduleMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
-
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * @Description: 广告组信息
@@ -14,7 +29,249 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  * @Date: 2019-07-23
  * @Version: V1.0
  */
+
+@Slf4j
 @Service
 public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, KuaiShouGroup> implements IKuaiShouGroupService {
+    @Autowired
+    private IKuaiShouCampaignService kuaiShouCampaignService;
+    @Autowired
+    private KuaiShouGroupMapper groupMapper;
+    @Autowired
+    private KuaiShouAppInfoMapper appInfoMapper;
+    @Autowired
+    private KuaiShouScheduleMapper shouScheduleMapper;
+    @Autowired
+    private KuaiShouGroupTargetMapper groupTargetMapper;
+    private static ExecutorService executorService = Executors.newFixedThreadPool(10);
+
+
+    /**
+     * 获取广告组
+     *
+     * @param accessToken
+     * @param accountId
+     */
+    @Override
+    public void getGroupList(String accessToken, Long accountId) {
+
+        QueryWrapper<KuaiShouCampaign> campaignQueryWrapper = new QueryWrapper<>();
+        campaignQueryWrapper.eq("account_id", accountId);
+        campaignQueryWrapper.eq("status", 4);
+        campaignQueryWrapper.eq("put_status", 1);
+        campaignQueryWrapper.orderByDesc("put_create_time");
+        List<KuaiShouCampaign> list = kuaiShouCampaignService.list(campaignQueryWrapper);
+        if (Check.isNull(list)) {
+            return;
+        }
+        for (KuaiShouCampaign campaign : list) {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    getGroupListByPage(accessToken, accountId, campaign.getCampaignId(), 1);
+                }
+            });
+        }
+
+
+    }
+
+
+    private void getGroupListByPage(String accessToken, Long accountId, Long campaignId, int page) {
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", accountId);
+        param.put("campaign_id", campaignId);
+        param.put("page_size", 200);
+        param.put("page", page);
+
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (Check.isNull(resultJson)) {
+            log.error("获取广告组接口异常,advertiserId:{}", accountId);
+            return;
+        }
+        Integer code = resultJson.getInteger("code");
+        if (null == code || code != 0) {
+            log.error("获取广告组返回结果异常,advertiserId:{},异常信息:{}", accountId, resultJson);
+            return;
+        }
+        JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+        if (Check.isNull(details)) {
+            return;
+        }
+        addGroupV2(accountId, details);
+        getGroupListByPage(accessToken, accountId, campaignId, page + 1);
+    }
+
+
+    private void addGroupV2(Long advertiserId, JSONArray details) {
+        if (!Check.isNull(details)) {
+            List<KuaiShouGroup> groups = new ArrayList<>();
+            List<KuaiShouAppInfo> appInfos = new ArrayList<>();
+            List<KuaiShouSchedule> schedules = new ArrayList<>();
+            List<KuaiShouGroupTarget> targets = new ArrayList<>();
+            for (int i = 0; i < details.size(); i++) {
+                JSONObject detail = JSONObject.parseObject(details.get(i).toString());
+                if (!Check.isNull(detail)) {
+                    KuaiShouGroup group = new KuaiShouGroup();
+                    Long unitId = detail.getLong("unit_id");
+                    group.setId("" + advertiserId + unitId);
+                    group.setAccountId(advertiserId);
+                    group.setCampaignId(detail.getLong("campaign_id"));
+                    group.setUnitId(unitId);
+                    group.setUnitName(detail.getString("unit_name"));
+                    group.setStatus(detail.getInteger("status"));
+                    group.setPutStatus(detail.getInteger("put_status"));
+                    group.setCreateChannel(detail.getInteger("create_channel"));
+                    group.setReviewDetail(detail.getString("review_detail"));
+                    group.setBidType(detail.getInteger("bid_type"));
+                    group.setBid(detail.getLong("bid"));
+                    group.setCpaBid(detail.getLong("cpa_bid"));
+                    group.setOcpxActionType(detail.getInteger("ocpx_action_type"));
+                    group.setDeepConversionType(detail.getInteger("deep_conversion_type"));
+                    group.setDeepConversionBid(detail.getLong("deep_conversion_bid"));
+                    group.setDayBudget(detail.getLong("day_budget"));
+                    group.setSpeed(detail.getInteger("speed"));
+                    group.setBeginTime(detail.getString("begin_time"));
+                    group.setEndTime(detail.getString("end_time"));
+                    group.setScheduleTime(detail.getString("schedule_time"));
+                    group.setSceneId(detail.getJSONArray("scene_id") + "");
+                    group.setShowMode(detail.getInteger("show_mode"));
+                    group.setUnitType(detail.getInteger("unit_type"));
+                    group.setUrlType(detail.getInteger("url_type"));
+                    group.setUrl(detail.getString("url"));
+                    group.setAppId(detail.getLong("app_id"));
+                    group.setAppIconUrl(detail.getString("app_icon_url"));
+                    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);
+                    // 添加应用信息
+
+                    JSONObject diverseJson = detail.getJSONObject("diverse_data");
+                    if (!Check.isNull(diverseJson)) {
+                        KuaiShouAppInfo appInfo = new KuaiShouAppInfo();
+                        appInfo.setAccountId(advertiserId);
+                        appInfo.setAppName(diverseJson.getString("app_name"));
+                        appInfo.setAppPackageName(diverseJson.getString("app_package_name"));
+                        appInfo.setDeviceOsType(diverseJson.getInteger("device_os_type"));
+                        appInfo.setUnitId(unitId);
+                        appInfo.setCreateTime(new Date());
+                        appInfo.setUpdateTime(new Date());
+                        appInfos.add(appInfo);
+                    }
+                    //时间段信息
+                    JSONObject scheduleJson = detail.getJSONObject("schedule");
+                    if (!Check.isNull(scheduleJson)) {
+                        KuaiShouSchedule schedule = new KuaiShouSchedule();
+                        schedule.setUnitId(unitId);
+                        schedule.setAccountId(advertiserId);
+                        schedule.setMon(scheduleJson.getJSONArray("mon").toJSONString());
+                        schedule.setTues(scheduleJson.getJSONArray("tues").toJSONString());
+                        schedule.setWed(scheduleJson.getJSONArray("wed").toJSONString());
+                        schedule.setThur(scheduleJson.getJSONArray("thur").toJSONString());
+                        schedule.setFri(scheduleJson.getJSONArray("fri").toJSONString());
+                        schedule.setSat(scheduleJson.getJSONArray("sat").toJSONString());
+                        schedule.setSun(scheduleJson.getJSONArray("sun").toJSONString());
+                        schedule.setCreateTime(new Date());
+                        schedule.setUpdateTime(new Date());
+                        schedules.add(schedule);
+                    }
+
+                    JSONObject targetJson = detail.getJSONObject("target");
+                    if (!Check.isNull(targetJson)) {
+                        KuaiShouGroupTarget groupTarget = new KuaiShouGroupTarget();
+                        groupTarget.setAccountId(advertiserId);
+                        groupTarget.setUnitId(unitId);
+
+                        if (!Check.isNull(targetJson.getJSONArray("region"))) {
+                            groupTarget.setRegion(targetJson.getJSONArray("region").toJSONString());
+                        }
+
+                        JSONObject age = targetJson.getJSONObject("age");
+                        if (!Check.isNull(age)) {
+                            groupTarget.setAgeMin(age.getInteger("min"));
+                            groupTarget.setAgeMax(age.getInteger("max"));
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("ages_range"))) {
+                            groupTarget.setAgesRange(targetJson.getJSONArray("ages_range").toJSONString());
+                        }
+
+                        groupTarget.setGender(targetJson.getInteger("gender"));
+                        groupTarget.setPlatformOs(targetJson.getInteger("platform_os"));
+                        groupTarget.setAndroidOsv(targetJson.getInteger("android_osv"));
+                        groupTarget.setIosOsv(targetJson.getInteger("ios_osv"));
+                        groupTarget.setNetwork(targetJson.getInteger("network"));
+                        if (!Check.isNull(targetJson.getJSONArray("device_brand"))) {
+                            groupTarget.setDeviceBrand(targetJson.getJSONArray("device_brand").toJSONString());
+                        }
+
+                        if (!Check.isNull(targetJson.getJSONArray("device_price"))) {
+                            groupTarget.setDevicePrice(targetJson.getJSONArray("device_price").toJSONString());
+                        }
+
+                        groupTarget.setBusinessInterestType(targetJson.getInteger("business_interest_type"));
+                        if (!Check.isNull(targetJson.getJSONArray("business_interest"))) {
+                            groupTarget.setBusinessInterest(targetJson.getJSONArray("business_interest").toJSONString());
+                        }
+
+                        if (!Check.isNull(targetJson.getJSONArray("fans_star"))) {
+                            groupTarget.setFansStar(targetJson.getJSONArray("fans_star").toJSONString());
+                        }
+
+                        if (!Check.isNull(targetJson.getJSONArray("interest_video"))) {
+                            groupTarget.setInterestVideo(targetJson.getJSONArray("interest_video").toJSONString());
+                        }
+
+                        if (!Check.isNull(targetJson.getJSONArray("app_interest"))) {
+                            groupTarget.setAppInterest(targetJson.getJSONArray("app_interest").toJSONString());
+                        }
+
+                        if (!Check.isNull(targetJson.getJSONArray("app_ids"))) {
+                            groupTarget.setAppIds(targetJson.getJSONArray("app_ids").toJSONString());
+                        }
+
+                        if (!Check.isNull(targetJson.getJSONArray("population"))) {
+                            groupTarget.setPopulation(targetJson.getJSONArray("population").toJSONString());
+                        }
+
+                        if (!Check.isNull(targetJson.getJSONArray("exclude_population"))) {
+                            groupTarget.setExcludePopulation(targetJson.getJSONArray("exclude_population").toJSONString());
+                        }
+
+                        JSONObject intelliExtend = targetJson.getJSONObject("intelli_extend");
+                        if (!Check.isNull(intelliExtend)) {
+                            groupTarget.setIsOpen(intelliExtend.getInteger("is_open"));
+                            groupTarget.setNoAgeBreak(intelliExtend.getInteger("no_age_break"));
+                            groupTarget.setNoGenderBreak(intelliExtend.getInteger("no_gender_break"));
+                            groupTarget.setNoAreaBreak(intelliExtend.getInteger("no_area_break"));
+
+                        }
+                        targets.add(groupTarget);
+                    }
+                }
+            }
+            if (!Check.isNull(groups)) {
+                groupMapper.replaceBatch(groups);
+            }
+            if (!Check.isNull(schedules)) {
+                shouScheduleMapper.replaceBatch(schedules);
+            }
+            if (!Check.isNull(appInfos)) {
+                appInfoMapper.replaceBatch(appInfos);
+            }
+            if (!Check.isNull(targets)) {
+                groupTargetMapper.replaceBatch(targets);
+            }
+        }
+    }
 
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java

@@ -643,7 +643,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     if (!Check.isNull(data)) {
 
                         try {
-                            Thread.sleep(500);
+                            Thread.sleep(200);
                             interfaceService.getCreativeByCreativeId(accessToken, creativeJson.getLong("advertiser_id"), data.getLong("creative_id"));
                         } catch (InterruptedException e) {
                             e.printStackTrace();

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

@@ -1244,9 +1244,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private void addGroup(Long advertiserId, JSONArray details) {
         if (!Check.isNull(details)) {
             List<KuaiShouGroup> groups = new ArrayList<>();
-            List<KuaiShouAppInfo> appInfos = new ArrayList<>();
-            List<KuaiShouSchedule> schedules = new ArrayList<>();
-            List<KuaiShouGroupTarget> targets = new ArrayList<>();
             for (int i = 0; i < details.size(); i++) {
                 JSONObject detail = JSONObject.parseObject(details.get(i).toString());
                 if (!Check.isNull(detail)) {
@@ -1287,125 +1284,21 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     group.setUpdateTime(new Date());
                     groups.add(group);
                     // 添加应用信息
-
-                    JSONObject diverseJson = detail.getJSONObject("diverse_data");
-                    if (!Check.isNull(diverseJson)) {
-                        KuaiShouAppInfo appInfo = new KuaiShouAppInfo();
-                        appInfo.setAccountId(advertiserId);
-                        appInfo.setAppName(diverseJson.getString("app_name"));
-                        appInfo.setAppPackageName(diverseJson.getString("app_package_name"));
-                        appInfo.setDeviceOsType(diverseJson.getInteger("device_os_type"));
-                        appInfo.setUnitId(unitId);
-                        appInfo.setCreateTime(new Date());
-                        appInfo.setUpdateTime(new Date());
-                        appInfos.add(appInfo);
-                    }
-                    //时间段信息
-                    JSONObject scheduleJson = detail.getJSONObject("schedule");
-                    if (!Check.isNull(scheduleJson)) {
-                        KuaiShouSchedule schedule = new KuaiShouSchedule();
-                        schedule.setUnitId(unitId);
-                        schedule.setAccountId(advertiserId);
-                        schedule.setMon(scheduleJson.getJSONArray("mon").toJSONString());
-                        schedule.setTues(scheduleJson.getJSONArray("tues").toJSONString());
-                        schedule.setWed(scheduleJson.getJSONArray("wed").toJSONString());
-                        schedule.setThur(scheduleJson.getJSONArray("thur").toJSONString());
-                        schedule.setFri(scheduleJson.getJSONArray("fri").toJSONString());
-                        schedule.setSat(scheduleJson.getJSONArray("sat").toJSONString());
-                        schedule.setSun(scheduleJson.getJSONArray("sun").toJSONString());
-                        schedule.setCreateTime(new Date());
-                        schedule.setUpdateTime(new Date());
-                        schedules.add(schedule);
-                    }
-
-                    JSONObject targetJson = detail.getJSONObject("target");
-                    if (!Check.isNull(targetJson)) {
-                        KuaiShouGroupTarget groupTarget = new KuaiShouGroupTarget();
-                        groupTarget.setAccountId(advertiserId);
-                        groupTarget.setUnitId(unitId);
-
-                        if (!Check.isNull(targetJson.getJSONArray("region"))) {
-                            groupTarget.setRegion(targetJson.getJSONArray("region").toJSONString());
-                        }
-
-                        JSONObject age = targetJson.getJSONObject("age");
-                        if (!Check.isNull(age)) {
-                            groupTarget.setAgeMin(age.getInteger("min"));
-                            groupTarget.setAgeMax(age.getInteger("max"));
-                        }
-                        if (!Check.isNull(targetJson.getJSONArray("ages_range"))) {
-                            groupTarget.setAgesRange(targetJson.getJSONArray("ages_range").toJSONString());
-                        }
-
-                        groupTarget.setGender(targetJson.getInteger("gender"));
-                        groupTarget.setPlatformOs(targetJson.getInteger("platform_os"));
-                        groupTarget.setAndroidOsv(targetJson.getInteger("android_osv"));
-                        groupTarget.setIosOsv(targetJson.getInteger("ios_osv"));
-                        groupTarget.setNetwork(targetJson.getInteger("network"));
-                        if (!Check.isNull(targetJson.getJSONArray("device_brand"))) {
-                            groupTarget.setDeviceBrand(targetJson.getJSONArray("device_brand").toJSONString());
-                        }
-
-                        if (!Check.isNull(targetJson.getJSONArray("device_price"))) {
-                            groupTarget.setDevicePrice(targetJson.getJSONArray("device_price").toJSONString());
-                        }
-
-                        groupTarget.setBusinessInterestType(targetJson.getInteger("business_interest_type"));
-                        if (!Check.isNull(targetJson.getJSONArray("business_interest"))) {
-                            groupTarget.setBusinessInterest(targetJson.getJSONArray("business_interest").toJSONString());
-                        }
-
-                        if (!Check.isNull(targetJson.getJSONArray("fans_star"))) {
-                            groupTarget.setFansStar(targetJson.getJSONArray("fans_star").toJSONString());
-                        }
-
-                        if (!Check.isNull(targetJson.getJSONArray("interest_video"))) {
-                            groupTarget.setInterestVideo(targetJson.getJSONArray("interest_video").toJSONString());
-                        }
-
-                        if (!Check.isNull(targetJson.getJSONArray("app_interest"))) {
-                            groupTarget.setAppInterest(targetJson.getJSONArray("app_interest").toJSONString());
-                        }
-
-                        if (!Check.isNull(targetJson.getJSONArray("app_ids"))) {
-                            groupTarget.setAppIds(targetJson.getJSONArray("app_ids").toJSONString());
-                        }
-
-                        if (!Check.isNull(targetJson.getJSONArray("population"))) {
-                            groupTarget.setPopulation(targetJson.getJSONArray("population").toJSONString());
-                        }
-
-                        if (!Check.isNull(targetJson.getJSONArray("exclude_population"))) {
-                            groupTarget.setExcludePopulation(targetJson.getJSONArray("exclude_population").toJSONString());
-                        }
-
-                        JSONObject intelliExtend = targetJson.getJSONObject("intelli_extend");
-                        if (!Check.isNull(intelliExtend)) {
-                            groupTarget.setIsOpen(intelliExtend.getInteger("is_open"));
-                            groupTarget.setNoAgeBreak(intelliExtend.getInteger("no_age_break"));
-                            groupTarget.setNoGenderBreak(intelliExtend.getInteger("no_gender_break"));
-                            groupTarget.setNoAreaBreak(intelliExtend.getInteger("no_area_break"));
-
-                        }
-                        targets.add(groupTarget);
-                    }
                 }
             }
             if (!Check.isNull(groups)) {
-                groupMapper.replaceBatch(groups);
-            }
-            if (!Check.isNull(schedules)) {
-                shouScheduleMapper.replaceBatch(schedules);
-            }
-            if (!Check.isNull(appInfos)) {
-                appInfoMapper.replaceBatch(appInfos);
-            }
-            if (!Check.isNull(targets)) {
-                groupTargetMapper.replaceBatch(targets);
+                try {
+                    Thread.sleep(200L);
+                    groupMapper.replaceBatch(groups);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+
             }
         }
     }
 
+
     @Override
     public void getCreativeList(CtopOauthToken token, Date startDate, Date endDate) {
         getCreativeListByPage(token.getAccessToken(), token.getAccountId(), startDate, endDate, 1);
@@ -3040,7 +2933,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     }
 
-    private static ExecutorService executorService = Executors.newFixedThreadPool(5);
+    private static ExecutorService executorService = Executors.newFixedThreadPool(10);
 
     @Override
     public void getAsyncCreativeList(Long accountId, String accessToken, Long campaignId) {
@@ -3211,4 +3104,28 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         return convertVoList;
     }
 
+    @Override
+    public JSONArray getCreativeWord(Long accountId, String accessToken) {
+
+        try {
+            log.info("获取动态词包:accountId:{}", accountId);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_WORD;
+            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);
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                return resultJson.getJSONArray("data");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
 }

+ 54 - 45
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/AccountReportMapper.xml

@@ -21,6 +21,22 @@
         ((sum(charge) / sum(activation)) / #{discount}) afterActivationPrice, -- 激活单价
         sum(event_register) eventRegister, -- 注册数
 
+        sum(form_count + activation) conversionNum, -- 转化数
+
+        (case
+        when sum(activation +form_count) != 0
+        then (sum(charge) / sum(activation +form_count))
+        else 0
+        end
+        ) conversionPrice, -- 转化单价
+
+        (case
+        when sum(activation +form_count) != 0
+        then (sum(charge) / sum(activation +form_count)) / #{discount}
+        else 0
+        end
+        ) afterConversionPrice, -- 折后转化单价
+
         (case
         when sum(event_register) != 0
         then (sum(charge) / sum(event_register))
@@ -57,13 +73,13 @@
         ((sum(charge) / sum(activation)) / #{discount}) afterActivationPrice, -- 激活单价
         account_id accountId,
         (select auth_name from ctop_user_allocation where account_id = accountId limit 1) accountName,
-        sum(event_next_day_stay) eventNextDayStay,  -- 次留数
+        sum(event_next_day_stay) eventNextDayStay, -- 次留数
         (case
         when sum(activation) != 0
         then (sum(event_next_day_stay)/sum(activation))
         else 0
         end
-        ) eventNextDayStayRatio  -- 次留率=次留数/激活数
+        ) eventNextDayStayRatio -- 次留率=次留数/激活数
         from
         ctop_kuaishou_report_daily_account
         where account_id in
@@ -92,6 +108,8 @@
         (sum(charge) / sum(activation)) activationPrice, -- 激活单价
         ((sum(charge) / sum(activation)) / #{discount}) afterActivationPrice, -- 激活单价
         sum(event_register) eventRegister, -- 注册数
+        sum(form_count + activation) conversionNum, -- 转化数
+        (sum(charge) / sum(activation +form_count )) conversionPrice, -- 转化单价
         (case
         when sum(event_register) != 0
         then (sum(charge) / sum(event_register))
@@ -100,13 +118,13 @@
         ) eventRegisterCost, -- 注册成本
         account_id accountId,
         (select auth_name from ctop_user_allocation where account_id = accountId limit 1) accountName,
-        sum(event_next_day_stay) eventNextDayStay,  -- 次留数
+        sum(event_next_day_stay) eventNextDayStay, -- 次留数
         (case
         when sum(activation) != 0
         then (sum(event_next_day_stay)/sum(activation))
         else 0
         end
-        ) eventNextDayStayRatio  -- 次留率=次留数/激活数
+        ) eventNextDayStayRatio -- 次留率=次留数/激活数
         from
         ctop_kuaishou_report_daily_account
         where stat_date &lt;= #{startDate}
@@ -135,6 +153,15 @@
         sum(activation) activationCount, -- 激活数
         (sum(charge) / sum(activation)) activationPrice, -- 激活单价
         sum(event_register) eventRegister, -- 注册数
+        sum(form_count + activation) conversionNum, -- 转化数
+
+        (
+        case when sum(activation +form_count ) != 0
+        then (sum(charge) / sum(activation +form_count))
+        else 0
+        end
+        )conversionPrice, -- 转化单价
+
 
         (case
         when sum(event_register) != 0
@@ -173,6 +200,14 @@
         sum(activation) activationCount, -- 激活数
         (sum(charge) / sum(activation)) activationPrice, -- 激活单价
         sum(event_register) eventRegister, -- 注册数
+        sum(form_count + activation) conversionNum, -- 转化数
+        (
+        case when sum(activation +form_count ) != 0
+        then (sum(charge) / sum(activation +form_count))
+        else 0
+        end
+        )conversionPrice, -- 转化单价
+
         (case
         when sum(event_register) != 0
         then (sum(charge) / sum(event_register))
@@ -181,13 +216,13 @@
         ) eventRegisterCost, -- 注册成本
         account_id accountId,
         (select auth_name from ctop_user_allocation where account_id = accountId limit 1) accountName,
-        sum(event_next_day_stay) eventNextDayStay,  -- 次留数
+        sum(event_next_day_stay) eventNextDayStay, -- 次留数
         (case
         when sum(activation) != 0
         then ( sum(event_next_day_stay) / sum(activation) )
         else 0
         end
-        ) eventNextDayStayRatio  -- 次留率=次留数/激活数
+        ) eventNextDayStayRatio -- 次留率=次留数/激活数
         from
         ctop_kuaishou_report_daily_account
         where stat_date = #{statDate}
@@ -416,30 +451,17 @@
         sum(bclick) bClick,-- 行为数
         (
         CASE
-        WHEN sum(form_count) != 0 THEN
-        sum(form_count)
-        WHEN sum(activation) != 0 THEN
-        sum(activation)
-        ELSE
-        0
-        END
-        ) conversions, -- 转化数
-        (
-        CASE
-        WHEN sum(form_count) != 0 THEN
-        sum(charge) / sum(form_count)
-        WHEN sum(activation) != 0 THEN
-        sum(charge) / sum(activation)
+        WHEN sum(form_count + activation) != 0 THEN
+        sum(charge) / sum(form_count + activation)
         ELSE
         0
         END
         ) conversionPrice, -- 转化单价
+        sum(form_count + activation) conversions, -- 转化数
         (
         CASE
-        WHEN sum(form_count) != 0 THEN
-        (sum(charge) / sum(form_count)) / #{discount}
-        WHEN sum(activation) != 0 THEN
-        (sum(charge) / sum(activation)) / #{discount}
+        WHEN sum(form_count + activation) != 0 THEN
+        (sum(charge) / sum(form_count + activation)) / #{discount}
         ELSE
         0
         END
@@ -451,13 +473,13 @@
         else 0
         end
         ) eventRegisterCost, -- 注册成本
-        sum(event_next_day_stay) eventNextDayStay,  -- 次留数
+        sum(event_next_day_stay) eventNextDayStay, -- 次留数
         (case
         when sum(activation) != 0
         then (sum(event_next_day_stay)/sum(activation))
         else 0
         end
-        ) eventNextDayStayRatio  -- 次留率=次留数/激活数
+        ) eventNextDayStayRatio -- 次留率=次留数/激活数
 
         from
         ctop_kuaishou_report_daily_account
@@ -520,34 +542,21 @@
         else 0
         end
         ) cpm,
-
+        sum(form_count + activation) conversions, -- 转化数
         sum(bclick) bClick,-- 行为数
+
         (
         CASE
-        WHEN sum(form_count) != 0 THEN
-        sum(form_count)
-        WHEN sum(activation) != 0 THEN
-        sum(activation)
-        ELSE
-        0
-        END
-        ) conversions, -- 转化数
-        (
-        CASE
-        WHEN sum(form_count) != 0 THEN
-        sum(charge) / sum(form_count)
-        WHEN sum(activation) != 0 THEN
-        sum(charge) / sum(activation)
+        WHEN sum(activation + form_count) != 0 THEN
+        sum(charge) / sum(activation + form_count)
         ELSE
         0
         END
         ) conversionPrice, -- 转化单价
         (
         CASE
-        WHEN sum(form_count) != 0 THEN
-        (sum(charge) / sum(form_count)) / #{discount}
-        WHEN sum(activation) != 0 THEN
-        (sum(charge) / sum(activation)) / #{discount}
+        WHEN sum(activation + form_count) != 0 THEN
+        (sum(charge) / sum(activation + form_count)) / #{discount}
         ELSE
         0
         END

+ 7 - 33
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/DailyReportMapper.xml

@@ -26,7 +26,6 @@
             </if>
         </where>
         ) contractRebateRealCharged -- 激励花费
-
         FROM (
         SELECT
         sum(charge) cost, -- 消耗
@@ -73,25 +72,12 @@
         0
         END
         ) impression1kCost, -- 平均千次展现花费
+        sum(form_count + activation) conversions, -- 转化数
         (
         CASE
-        WHEN sum(form_count) != 0 THEN
-        sum(form_count)
-        WHEN sum(activation) != 0 THEN
-        sum(activation)
-        ELSE
-        0
-        END
-        ) conversions, -- 转化数
-        (
-        CASE
-        WHEN sum(form_count) != 0 THEN
-        (
-        truncate(sum(charge) / sum(form_count),2)
-        )
-        WHEN sum(activation) != 0 THEN
+        WHEN sum(form_count + activation) != 0 THEN
         (
-        truncate(sum(charge) / sum(activation),2)
+        truncate(sum(charge) / sum(form_count + activation),2)
         )
         ELSE
         0
@@ -184,25 +170,13 @@
         0
         END
         ) photoClickCost, -- 平均点击花费
+
+        sum(form_count + activation) conversions, -- 转化数
         (
         CASE
-        WHEN sum(form_count) != 0 THEN
-        sum(form_count)
-        WHEN sum(activation) != 0 THEN
-        sum(activation)
-        ELSE
-        0
-        END
-        ) conversions, -- 转化数
-        (
-        CASE
-        WHEN sum(form_count) != 0 THEN
-        (
-        truncate(sum(charge) / sum(form_count),2)
-        )
-        WHEN sum(activation) != 0 THEN
+        WHEN sum(form_count + activation) != 0 THEN
         (
-        truncate(sum(charge) / sum(activation),2)
+        truncate(sum(charge) / sum(form_count + activation),2)
         )
         ELSE
         0

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

@@ -402,6 +402,53 @@ public class AccountReportServiceImpl implements IAccountReportService {
                             chainRatioJson.put("bClickProportion", 0);
                         }
 
+                        // 转化数
+                        Long nowConversionNum = nowAccountSummary.getLong("conversionNum");
+                        Long yesterdayConversionNum = yesterdayAccountSummary.getLong("conversionNum");
+                        //表单提交数环比
+                        if (!Check.isNull(nowConversionNum) && !Check.isNull(yesterdayConversionNum)) {
+                            if (yesterdayAClick != 0L) {
+                                double nowConversionNumProportion = (nowConversionNum.doubleValue() - yesterdayConversionNum.doubleValue()) / yesterdayConversionNum.doubleValue();
+                                chainRatioJson.put("nowConversionNumProportion", nowConversionNumProportion);
+                            } else {
+                                chainRatioJson.put("nowConversionNumProportion", 0);
+                            }
+                        } else {
+                            chainRatioJson.put("nowConversionNumProportion", 0);
+                        }
+
+
+                        // 折后转化单价
+                        BigDecimal nowAfterConversionPrice = nowAccountSummary.getBigDecimal("afterConversionPrice");
+                        BigDecimal yesterdayAfterConversionPrice = yesterdayAccountSummary.getBigDecimal("afterConversionPrice");
+                        // 折前消耗单价
+                        if (!Check.isNull(nowAfterConversionPrice) && !Check.isNull(yesterdayAfterConversionPrice)) {
+                            if (yesterdayAfterConversionPrice.compareTo(new BigDecimal(0)) != 0) {
+                                BigDecimal afterConversionPriceProportion = (nowAfterConversionPrice.subtract(yesterdayAfterConversionPrice)).divide(yesterdayAfterConversionPrice, 2, RoundingMode.HALF_UP);
+                                chainRatioJson.put("afterConversionPriceProportion", afterConversionPriceProportion);
+                            } else {
+                                chainRatioJson.put("afterConversionPriceProportion", 0);
+                            }
+                        } else {
+                            chainRatioJson.put("afterConversionPriceProportion", 0);
+                        }
+
+                        // 折前转化单价
+                        BigDecimal nowConversionPrice = nowAccountSummary.getBigDecimal("conversionPrice");
+                        BigDecimal yesterdayConversionPrice = yesterdayAccountSummary.getBigDecimal("conversionPrice");
+                        // 折前消耗单价
+                        if (!Check.isNull(nowConversionPrice) && !Check.isNull(yesterdayConversionPrice)) {
+                            if (yesterdayConversionPrice.compareTo(new BigDecimal(0)) != 0) {
+                                BigDecimal beforeConversionPriceProportion = (nowConversionPrice.subtract(yesterdayConversionPrice)).divide(yesterdayConversionPrice, 2, RoundingMode.HALF_UP);
+                                chainRatioJson.put("beforeConversionPriceProportion", beforeConversionPriceProportion);
+                            } else {
+                                chainRatioJson.put("beforeConversionPriceProportion", 0);
+                            }
+                        } else {
+                            chainRatioJson.put("beforeConversionPriceProportion", 0);
+                        }
+
+
                         // 表单提交数
                         Long nowFormCount = nowAccountSummary.getLong("formCount");
                         Long yesterdayFormCount = yesterdayAccountSummary.getLong("formCount");
@@ -421,7 +468,7 @@ public class AccountReportServiceImpl implements IAccountReportService {
                         // 激活数
                         Long nowActivationCount = nowAccountSummary.getLong("activationCount");
                         Long yesterdayActivationCount = yesterdayAccountSummary.getLong("activationCount");
-                        //表单提交数环比
+                        //激活数环比
                         if (!Check.isNull(nowActivationCount) && !Check.isNull(yesterdayActivationCount)) {
                             if (yesterdayAClick != 0L) {
                                 double activationCountProportion = (nowActivationCount.doubleValue() - yesterdayActivationCount.doubleValue()) / yesterdayActivationCount.doubleValue();