Selaa lähdekoodia

Merge branch 'master' of http://git.tjyourong.com.cn/ctop/adsp-boot

yumeng 4 vuotta sitten
vanhempi
commit
6a549c95cc
17 muutettua tiedostoa jossa 515 lisäystä ja 215 poistoa
  1. 20 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java
  2. 3 3
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouProjectVideoGetJob.java
  3. 1 1
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouSupplierVideoGetJob.java
  4. 93 44
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouVideoDirectionalPackageController.java
  5. 4 8
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouVideoDirectionalPackage.java
  6. 89 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouProjectVideoGetController.java
  7. 6 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouProjectVideoGet.java
  8. 6 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouCreativeMapper.java
  9. 7 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java
  10. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouProjectVideoGetMapper.java
  11. 51 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouCreativeMapper.xml
  12. 121 119
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml
  13. 21 8
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouProjectVideoGetMapper.xml
  14. 6 3
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java
  15. 9 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouProjectVideoGetService.java
  16. 5 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java
  17. 72 8
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouProjectVideoGetServiceImpl.java

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

@@ -356,6 +356,26 @@ public class UserAllocationController {
         return result;
     }
 
+    /**
+     * 查询项目下账户集合
+     *
+     * @param
+     * @return
+     */
+    @GetMapping(value = "/queryAccountIdsByProjectId")
+    public Result<Object> queryAccountIdsByProjectId(Long projectId) {
+        if(Check.isNull(projectId)){
+            return Result.error("请选择项目");
+        }
+        try {
+            List<JSONObject> accountListByProject = userAllocationService.getAccountListByProject(projectId);
+            return Result.ok(accountListByProject);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return  Result.error("查询失败");
+    }
+
 
     @GetMapping(value = "/getAccountIdListByUserId")
     public Result<List<JSONObject>> getAccountIdListByUserId(String userId) {

+ 3 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouProjectVideoGetJob.java

@@ -29,11 +29,11 @@ public class KuaishouProjectVideoGetJob {
     static ExecutorService executorService = Executors.newFixedThreadPool(5);
 
     @XxlJob("kuaishouProjectVideoGetJob")
-    public void kuaishouProjectVideoGetJob() {
+    public void execute() throws Exception {
         //2快手,1开启的项目
-        List<Project> projects = projectService.listByMediaType(2, 1);
+        List<Project> projects = projectService.listByMediaType(2, 0);
         projects.forEach(project -> executorService.submit(() -> {
-            projectVideoGetService.clearProjectVideo(project.getId());
+            projectVideoGetService.clearProjectVideo(project.getId(),1);
         }));
         XxlJobHelper.log("清洗项目素材完成");
     }

+ 1 - 1
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouSupplierVideoGetJob.java

@@ -31,7 +31,7 @@ public class KuaishouSupplierVideoGetJob {
     static ExecutorService executorService = Executors.newFixedThreadPool(5);
 
     @XxlJob("kuaishouSupplierVideoGetJob")
-    public void KuaishouSupplierVideoGetJob() {
+    public void execute() throws Exception {
         List<JSONObject> datas = videoGetService.getAccountIds();
         for (JSONObject data : datas) {
             CtopOauthToken token = tokenService.getTokenByAccountId(data.getLong("accountId"));

+ 93 - 44
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouVideoDirectionalPackageController.java

@@ -1,43 +1,47 @@
 package cn.com.ctop.kuaishou.modules.ai.controller;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.QueryGenerator;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouVideoDirectionalPackage;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouVideoDirectionalPackageService;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import org.jeecg.common.api.vo.Result;
-import cn.com.ctop.common.module.utils.QueryGenerator;
-import org.jeecg.common.util.oConvertUtils;
-
-import java.util.Date;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.oConvertUtils;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
-
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 素材绑定的定向包模板
@@ -49,11 +53,12 @@ import io.swagger.annotations.ApiOperation;
 @Slf4j
 @Api(tags = "素材绑定的定向包模板")
 @RestController
-@RequestMapping("/kuais/kuaishouVideoDirectionalPackage")
+@RequestMapping("/kuaishouVideoDirectionalPackage")
 public class KuaishouVideoDirectionalPackageController {
     @Autowired
     private IKuaishouVideoDirectionalPackageService kuaishouVideoDirectionalPackageService;
-
+    @Autowired
+    private IUserAllocationService userAllocationService;
     /**
      * 分页列表查询
      *
@@ -77,27 +82,45 @@ public class KuaishouVideoDirectionalPackageController {
         result.setResult(pageList);
         return result;
     }
-	/**
-	 * 创建定向包
-	 *
-	 * @param
-	 * @return
-	 */
-	@PostMapping(value = "/createDirectionalPackage")
-	public Result<Object> createDirectionalPackage(@RequestBody JSONObject requestJson) {
-		Result<JSONObject> result = new Result<>();
-		try {
-			Long accountId = requestJson.getLong("projectId");
-			if (Check.isNull(accountId)) {
-				return Result.error("请选择账户id");
-			}
-//			return kuaishouVideoDirectionalPackageService.saveOrUpdate(null);
-		} catch (Exception e) {
-			log.error("创建定向包失败", e);
-			return Result.error("创建失败" + e.getMessage());
-		}
-		return null;
-	}
+
+    /**
+     * 创建定向包
+     *
+     * @param
+     * @return
+     */
+    @PostMapping(value = "/saveOrUpdate")
+    public Result<Object> saveOrUpdate(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            String videoGetId = requestJson.getString("videoGetId");
+            if (Check.isNull(videoGetId)) {
+                return Result.error("请选择素材");
+            }
+            KuaishouVideoDirectionalPackage directionalPackage = JSONObject.toJavaObject(requestJson, KuaishouVideoDirectionalPackage.class);
+            if (!Check.isNull(requestJson.getJSONArray("keyword"))) {
+                directionalPackage.setKeyword(JSONObject.toJSONString(requestJson.getJSONArray("keyword")));
+            }
+            kuaishouVideoDirectionalPackageService.saveOrUpdate(directionalPackage);
+            String id = "";
+            if (!Check.isNull(directionalPackage.getId())) {
+                id = directionalPackage.getId();
+            } else {
+                QueryWrapper<KuaishouVideoDirectionalPackage> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("video_get_id", videoGetId);
+                queryWrapper.eq("signature", directionalPackage.getSignature());
+                KuaishouVideoDirectionalPackage one = kuaishouVideoDirectionalPackageService.getOne(queryWrapper);
+                if(!Check.isNull(one)){
+                    id = one.getId();
+                }
+            }
+            return Result.ok(id);
+        } catch (Exception e) {
+            log.error("创建定向包失败", e);
+            return Result.error("创建失败" + e.getMessage());
+        }
+    }
+
     /**
      * 编辑
      *
@@ -179,6 +202,32 @@ public class KuaishouVideoDirectionalPackageController {
     }
 
     /**
+     * 查询素材定向
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping(value = "/queryDirctional")
+    public Result<Object> queryDirctional(String id) {
+        if (Check.isNull(id)) {
+            return Result.error("缺失参数");
+        }
+        Result<KuaishouVideoDirectionalPackage> result = new Result<>();
+        QueryWrapper<KuaishouVideoDirectionalPackage> advertiserQueryWrapper = new QueryWrapper<>();
+        advertiserQueryWrapper.eq("video_get_id", id);
+        KuaishouVideoDirectionalPackage kuaishouVideoDirectionalPackage = kuaishouVideoDirectionalPackageService.getOne(advertiserQueryWrapper);
+        if (kuaishouVideoDirectionalPackage == null) {
+            return Result.ok("该素材未配置定向");
+        } else {
+            JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(kuaishouVideoDirectionalPackage)).toJavaObject(JSONObject.class);
+            if (!Check.isNull(data.getString("keyword"))) {
+                data.put("keyword", data.getJSONArray("keyword"));
+            }
+            return Result.ok(data);
+        }
+    }
+
+    /**
      * 导出excel
      *
      * @param request

+ 4 - 8
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouVideoDirectionalPackage.java

@@ -31,15 +31,11 @@ public class KuaishouVideoDirectionalPackage {
     /**
      * 账户ID
      */
-    @Excel(name = "账户ID", width = 15)
-    @ApiModelProperty(value = "账户ID")
+    @Excel(name = "素材get表主键ID", width = 15)
+    @ApiModelProperty(value = "素材get表主键ID")
     private String videoGetId;
-    /**
-     * 0无效,1有效
-     */
-    @Excel(name = "0无效,1有效", width = 15)
-    @ApiModelProperty(value = "0无效,1有效")
-    private Integer dataStatus;
+
+    private String signature;
     /**
      * 地域
      */

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

@@ -4,8 +4,11 @@ import cn.com.ctop.common.module.annotation.AutoLog;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.QueryGenerator;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProjectVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouProjectVideoGetService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -53,6 +56,8 @@ import java.util.Map;
 public class KuaishouProjectVideoGetController {
     @Autowired
     private IKuaishouProjectVideoGetService kuaishouProjectVideoGetService;
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
 
     /**
      * 分页列表查询
@@ -75,6 +80,26 @@ public class KuaishouProjectVideoGetController {
     }
 
     /**
+     * 素材关联被拒创意
+     */
+    @GetMapping(value = "/queryCreativeByVideo")
+    public Result<Object> queryCreativeByVideo(String signature, Long projectId, Long accountId, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        try {
+            if (Check.isNull(signature) || Check.isNull(projectId)) {
+                return Result.error("缺失参数");
+            }
+            List<String> photoIds = videoGetService.queryPhotoIdsByProjectAndMd5(projectId, signature, null);
+            if (!Check.isNull(photoIds)) {
+                return kuaishouProjectVideoGetService.queryCreativeBySignature(photoIds, accountId, pageNo, pageSize);
+            }
+            return Result.ok("没有查询到素材");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("查询失败");
+        }
+    }
+
+    /**
      * 素材数量统计
      *
      * @return
@@ -93,18 +118,77 @@ public class KuaishouProjectVideoGetController {
     }
 
     /**
+     * 下架素材
+     *
+     * @return
+     */
+    @PostMapping(value = "/offShelfVideo")
+    public Result<Object> offShelfVideo(@RequestBody JSONObject data) {
+        try {
+            if (Check.isNull(data.getString("id"))) {
+                return Result.error("缺失参数");
+            }
+            KuaishouProjectVideoGet videoGet = new KuaishouProjectVideoGet();
+            videoGet.setStatus(1);
+            videoGet.setId(data.getString("id"));
+            kuaishouProjectVideoGetService.updateById(videoGet);
+            return Result.ok("success");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("下架失败");
+    }
+
+    /**
+     * 下架素材
+     *
+     * @return
+     */
+    @PostMapping(value = "/offShelfVideos")
+    public Result<Object> offShelfVideos(@RequestBody JSONObject data) {
+        try {
+            Long projectId = data.getLong("projectId");
+            if (Check.isNull(projectId)) {
+                return Result.error("请选择项目");
+            }
+            JSONArray accountId = data.getJSONArray("accountId");
+            if (Check.isNull(accountId)) {
+                return Result.error("请选择账户");
+            }
+            String signature = data.getString("signature");
+            if (Check.isNull(signature)) {
+                return Result.error("请选择下架的视频");
+            }
+            KuaishouProjectVideoGet videoGet = new KuaishouProjectVideoGet();
+            QueryWrapper<KuaishouProjectVideoGet> queryWrapper = new QueryWrapper<>();
+            videoGet.setStatus(1);
+            queryWrapper.eq("project_id", projectId);
+            queryWrapper.eq("signature", signature);
+            kuaishouProjectVideoGetService.update(videoGet, queryWrapper);
+            List<String> photoIds = videoGetService.queryPhotoIdsByProjectAndMd5(projectId, signature, accountId);
+            for (Object photoId : photoIds) {
+                kuaishouProjectVideoGetService.deleteCreativesByPhotoId(photoId);
+            }
+            return Result.ok("success");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("下架失败");
+    }
+
+    /**
      * 素材详情数据
      * put_start_time
      *
      * @return
      */
     @GetMapping(value = "/getVideoDetails")
-    public Result<Object> getVideoDetails(String signature) {
+    public Result<Object> getVideoDetails(String signature, String id) {
         try {
-            if (Check.isNull(signature)) {
-                return Result.error("请选择素材");
+            if (Check.isNull(signature) || Check.isNull(id)) {
+                return Result.error("缺失参数");
             }
-            return kuaishouProjectVideoGetService.getVideoDetails(signature);
+            return kuaishouProjectVideoGetService.getVideoDetails(signature, id);
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -157,7 +241,7 @@ public class KuaishouProjectVideoGetController {
     @GetMapping(value = "/clearProjectVideo")
     public Result<Object> clearProjectVideo(Long projectId) {
         try {
-            kuaishouProjectVideoGetService.clearProjectVideo(projectId);
+            kuaishouProjectVideoGetService.clearProjectVideo(projectId,1);
         } catch (Exception e) {
             log.error(e.getMessage(), e);
         }

+ 6 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouProjectVideoGet.java

@@ -47,12 +47,6 @@ public class KuaishouProjectVideoGet {
     @ApiModelProperty(value = "0 可用 1 删除")
     private Integer status;
     /**
-     * 视频id
-     */
-    @Excel(name = "视频id", width = 15)
-    @ApiModelProperty(value = "视频id")
-    private String photoId;
-    /**
      * 宽
      */
     @Excel(name = "宽", width = 15)
@@ -82,6 +76,7 @@ public class KuaishouProjectVideoGet {
     @Excel(name = "1 竖版视频 2 横版视频", width = 15)
     @ApiModelProperty(value = "1 竖版视频 2 横版视频")
     private Integer materialType;
+
     /**
      * 0:自产 1:素造
      */
@@ -113,6 +108,11 @@ public class KuaishouProjectVideoGet {
      * 允许投放结束时间
      */
     private String putEndTime;
+    private String supplierAccountName;
+    private Long supplierAccountId;
+
+    private String materialTag;
+
     /**
      * 创建时间
      */

+ 6 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouCreativeMapper.java

@@ -34,4 +34,10 @@ public interface KuaiShouCreativeMapper extends BaseMapper<KuaiShouCreative> {
     Integer getRejectedCountsforAccountId(Long accountId);
 
     String getClickTrackUrl(@Param("accountId") Long accountId, @Param("unitId") Long unitId);
+
+    Long queryCreativeByPhotoIdTotal(@Param("photoIds")  List<String> photoIds, @Param("accountId") Long accountId);
+
+    List<JSONObject> queryCreativeByPhotoId(@Param("photoId") String photoId);
+
+    List<JSONObject> queryCreativeByPhotoIds(@Param("photoIds") List<String> photoIds, @Param("accountId") Long accountId);
 }

+ 7 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java

@@ -3,6 +3,7 @@ package cn.com.ctop.kuaishou.modules.batch.mapper;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProjectVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
@@ -42,13 +43,15 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
 
     Integer getHotMoneyCountByAccountId(Long accountId);
 
-    List<KuaiShouVideoGet> getZeroVideoByParams(@Param("accountId")Long accountId, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("videoCnt")Long videoCnt,@Param("appVersion")String appVersion,@Param("channelType")Integer channelType,@Param("relativeCnt")Integer relativeCnt);
+    List<KuaiShouVideoGet> getZeroVideoByParams(@Param("accountId") Long accountId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("videoCnt") Long videoCnt, @Param("appVersion") String appVersion, @Param("channelType") Integer channelType, @Param("relativeCnt") Integer relativeCnt);
 
-    List<KuaiShouVideoGet> getHistoryTopVideoByParams(@Param("accountId")Long accountId, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("videoCnt")Long videoCnt,@Param("appVersion")String appVersion,@Param("channelType")Integer channelType);
+    List<KuaiShouVideoGet> getHistoryTopVideoByParams(@Param("accountId") Long accountId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("videoCnt") Long videoCnt, @Param("appVersion") String appVersion, @Param("channelType") Integer channelType);
 
-    List<KuaishouProjectVideoGet> selectProjectVideo(@Param("projectId") Long projectId,@Param("updateTime") String updateTime);
+    List<KuaishouProjectVideoGet> selectProjectVideo(@Param("projectId") Long projectId, @Param("updateTime") String updateTime);
 
-    void updateBatch(@Param(value = "videoGetList")  List<KuaiShouVideoGet> videoGetList);
+    void updateBatch(@Param(value = "videoGetList") List<KuaiShouVideoGet> videoGetList);
 
     List<JSONObject> getAccountIds();
+
+    List<String> queryPhotoIdsByProjectAndMd5(@Param("projectId") Long projectId, @Param("signature") String signature, @Param("accountId") JSONArray accountId);
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouProjectVideoGetMapper.java

@@ -27,7 +27,7 @@ public interface KuaishouProjectVideoGetMapper extends BaseMapper<KuaishouProjec
 
     JSONObject getVideoTotalNumber(Map<String, Object> paramsMap);
 
-    JSONObject getVideoDetails(@Param("signature") String signature);
+    JSONObject getVideoDetails(@Param("signature") String signature,@Param("id") String id);
 
     Long getAccountVideosTotal(@Param("signature") String signature, @Param("projectId") Long projectId);
 

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

@@ -170,4 +170,55 @@
 
     </select>
 
+    <select id="queryCreativeByPhotoIdTotal" resultType="java.lang.Long">
+        SELECT
+            IFNULL(COUNT(1),0)
+        FROM ctop_kuaishou_creative t1
+        WHERE t1.photo_id in
+        <foreach collection="photoIds" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+        <if test="accountId!=null">
+            and  t1.account_id = #{accountId}
+        </if>
+        and t1.status = 42
+    </select>
+
+
+    <select id="queryCreativeByPhotoId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            IFNULL(t2.auth_name,'') 'authName',
+            IFNULL(t1.account_id,'') 'accountId',
+            IFNULL(t1.creative_id,'') 'creativeId',
+            IFNULL(t1.creative_name,'') 'creativeName',
+            IFNULL(t1.cover_url,'') 'coverUrl',
+            IFNULL(t1.description,'') 'description',
+            IFNULL(t1.review_detail,'') 'reviewDetail'
+        FROM ctop_kuaishou_creative t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        WHERE t1.photo_id = #{photoId}
+    </select>
+
+    <select id="queryCreativeByPhotoIds" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            IFNULL(t2.auth_name,'') 'authName',
+            IFNULL(t1.account_id,'') 'accountId',
+            IFNULL(t1.creative_id,'') 'creativeId',
+            IFNULL(t1.creative_name,'') 'creativeName',
+            IFNULL(t1.cover_url,'') 'coverUrl',
+            IFNULL(t1.description,'') 'description',
+            IFNULL(t1.review_detail,'') 'reviewDetail'
+        FROM ctop_kuaishou_creative t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        WHERE t1.photo_id in
+        <foreach collection="photoIds" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+        <if test="accountId!=null">
+            and  t1.account_id = #{accountId}
+        </if>
+        and t1.status = 42
+    </select>
 </mapper>

+ 121 - 119
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml

@@ -60,10 +60,10 @@
         </if>
         <if test="signatureList != null and signatureList != '' ">
             and signature in
-              <foreach collection="signatureList" item="item" separator=","
-                             open="(" close=")">
-                    #{item}
-                </foreach>
+            <foreach collection="signatureList" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
         </if>
         group by signature
         order by stat_date desc
@@ -72,31 +72,32 @@
 
     <select id="getHighQualityVideo" parameterType="java.util.Map"
             resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
-        select * from ctop_kuaishou_video_get
+        select *
+        from ctop_kuaishou_video_get
         where account_id = #{accountId}
-        and signature in
-        (
-        select
-            daily_material.signature
-        from
-        ctop_kuaishou_report_daily_material daily_material
-        inner join
-        ctop_user_allocation allocation
-        on daily_material.account_id = allocation.account_id
-        where  allocation.project_id in (select project_id from ctop_user_allocation where account_id = #{accountId})
-        and  to_days(now()) - to_days(daily_material.stat_date) &lt;= #{days}
-        and daily_material.signature is not null
-        GROUP BY daily_material.signature
-        order by sum(daily_material.charge) desc
-        limit #{num}
-        )
+          and signature in
+              (
+                  select daily_material.signature
+                  from ctop_kuaishou_report_daily_material daily_material
+                           inner join
+                       ctop_user_allocation allocation
+                       on daily_material.account_id = allocation.account_id
+                  where allocation.project_id in
+                        (select project_id from ctop_user_allocation where account_id = #{accountId})
+                    and to_days(now()) - to_days(daily_material.stat_date) &lt;= #{days}
+                    and daily_material.signature is not null
+                  GROUP BY daily_material.signature
+                  order by sum(daily_material.charge) desc
+            limit #{num}
+            )
     </select>
 
     <select id="selectPhotoIdsByAccountId" parameterType="java.lang.Long"
             resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
-        select * from ctop_kuaishou_video_get
+        select *
+        from ctop_kuaishou_video_get
         where account_id = #{accountId}
-        and status = 0
+          and status = 0
     </select>
 
     <select id="getVideoListByMap" resultType="com.alibaba.fastjson.JSONObject">
@@ -131,32 +132,32 @@
         order by stat_date desc
     </select>
     <select id="getPhotoIdsByParams" resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
-        select distinct photo_id from ctop_kuaishou_video_get
+        select distinct photo_id
+        from ctop_kuaishou_video_get
         where account_id = #{accountId}
-        and signature = #{signature}
-        and status = 0
+          and signature = #{signature}
+          and status = 0
     </select>
 
     <insert id="etlVideoBaseInfoByStaDate">
-    replace INTO ctop_etl_kuaishou_video_base_info (
+        replace
+        INTO ctop_etl_kuaishou_video_base_info (
 	signature,
 	channel_type,
 	photo_id,
     photo_name,
     material_type
-    ) SELECT
-	signature,
-	channel_type,
-	photo_id,
-    photo_name,
-    material_type
-  FROM
-	ctop_kuaishou_video_get
-	where  stat_date &gt;= #{statDate}
-	and signature is not null
-   GROUP BY
-	photo_id
- </insert>
+    )
+        SELECT signature,
+               channel_type,
+               photo_id,
+               photo_name,
+               material_type
+        FROM ctop_kuaishou_video_get
+        where stat_date &gt;= #{statDate}
+          and signature is not null
+        GROUP BY photo_id
+    </insert>
 
     <select id="getVideoInfoByPhotoIds" resultType="com.alibaba.fastjson.JSONObject">
         select
@@ -175,49 +176,39 @@
         group by photo_id
     </select>
     <select id="getTotalCountByAccount" resultType="java.lang.Integer">
-        select
-        count(distinct signature)
+        select count(distinct signature)
         from ctop_kuaishou_video_get
-        where  account_id = #{accountId}
+        where account_id = #{accountId}
     </select>
     <select id="getTotalCountByAccountAndStatDate" resultType="java.lang.Integer">
-        SELECT
-    	count(DISTINCT signature)
-        FROM
-	    ctop_kuaishou_video_get
-        WHERE
-	    account_id = #{accountId}
-        AND DATE_FORMAT(stat_date, '%Y-%m-%d') = #{statDate}
+        SELECT count(DISTINCT signature)
+        FROM ctop_kuaishou_video_get
+        WHERE account_id = #{accountId}
+          AND DATE_FORMAT(stat_date, '%Y-%m-%d') = #{statDate}
     </select>
     <select id="getEffectiveCountByAccountId" resultType="java.lang.Integer">
-        SELECT
-        count(1)
-        FROM
-        (
-        SELECT
-        signature
-        FROM
-        ctop_kuaishou_video_get
-        WHERE
-        account_id = #{accountId}
-        GROUP BY
-        signature
-        ) t1
-        LEFT JOIN ctop_kuaishou_video_etl_info t2 ON t1.signature = t2.video_code
-        WHERE
-        t2.effect_date IS NOT NULL
-        AND t2.effect_day_num &lt;= 7
+        SELECT count(1)
+        FROM (
+                 SELECT signature
+                 FROM ctop_kuaishou_video_get
+                 WHERE account_id = #{accountId}
+                 GROUP BY signature
+             ) t1
+                 LEFT JOIN ctop_kuaishou_video_etl_info t2 ON t1.signature = t2.video_code
+        WHERE t2.effect_date IS NOT NULL
+          AND t2.effect_day_num &lt;= 7
 
     </select>
     <select id="getZeroVideoByParams" resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
         select
         video.*
         from
-        ctop_kuaishou_video_get video left join ctop_kuaishou_video_relate_creatives creative on video.photo_id = creative.photo_id and video.account_id = creative.account_id
+        ctop_kuaishou_video_get video left join ctop_kuaishou_video_relate_creatives creative on video.photo_id =
+        creative.photo_id and video.account_id = creative.account_id
         where
-              1=1
+        1=1
         <if test="relativeCnt!=null">
-           and creative.creative_count &lt;= #{relativeCnt}
+            and creative.creative_count &lt;= #{relativeCnt}
         </if>
 
         <if test="accountId!=null">
@@ -244,36 +235,29 @@
     </select>
 
     <select id="getHotMoneyCountByAccountId" resultType="java.lang.Integer">
-        SELECT
-        count(1)
-        FROM
-        (
-        SELECT
-        signature
-        FROM
-        ctop_kuaishou_video_get
-        WHERE
-        account_id = #{accountId}
-        GROUP BY
-        signature
-        ) t1
-        LEFT JOIN ctop_kuaishou_video_etl_info t2 ON t1.signature = t2.video_code
-        WHERE
-        t2.faddish_date is not null
-        and faddish_day_num &lt;=14
+        SELECT count(1)
+        FROM (
+                 SELECT signature
+                 FROM ctop_kuaishou_video_get
+                 WHERE account_id = #{accountId}
+                 GROUP BY signature
+             ) t1
+                 LEFT JOIN ctop_kuaishou_video_etl_info t2 ON t1.signature = t2.video_code
+        WHERE t2.faddish_date is not null
+          and faddish_day_num &lt;= 14
     </select>
     <select id="getHistoryTopVideoByParams"
             resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
         select
-            video.*
+        video.*
         from
-            ctop_kuaishou_report_daily_material report
+        ctop_kuaishou_report_daily_material report
         left join (select * from ctop_kuaishou_video_get
-                where
-                    status = 0
-                and signature is not null
+        where
+        status = 0
+        and signature is not null
         <if test="accountId!=null">
-                 and account_id = #{accountId}
+            and account_id = #{accountId}
         </if>
         <if test="channelType!=null">
             and channel_type = #{channelType}
@@ -288,11 +272,11 @@
             and photo_name like concat(#{appVersion},'%')
         </if>
         group by signature) video
-                  on video.signature = report.signature
+        on video.signature = report.signature
         left join (SELECT id, photo_id from ctop_ai_creative_limit WHERE account_id = #{accountId}) t2
-            on video.photo_id = t2.photo_id
-            where video.id is not null
-            group by video.signature
+        on video.photo_id = t2.photo_id
+        where video.id is not null
+        group by video.signature
         order by sum(report.charge) desc
         <if test="videoCnt!=null">
             limit #{videoCnt}
@@ -301,39 +285,57 @@
 
     <select id="selectProjectVideo" resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProjectVideoGet">
         SELECT
-            t1.id,
-            t2.project_id,
-            t1.status,
-            t1.photo_id,
-            t1.width,
-            t1.height,
-            t1.url,
-            t1.cover_url,
-            t1.material_type,
-            t1.channel_type,
-            t1.stat_date,
-            t1.signature,
-            t1.photo_name,
-            t1.update_time
+        t1.id,
+        t2.project_id,
+        t1.status,
+        t1.photo_id,
+        t1.width,
+        t1.height,
+        t1.url,
+        t1.cover_url,
+        t1.material_type,
+        t1.channel_type,
+        t1.stat_date,
+        t1.signature,
+        t1.photo_name,
+        t1.update_time,
+        material_tag,
+        supplier_account_id,
+        supplier_account_name
         FROM ctop_kuaishou_video_get t1
-                 INNER JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        INNER JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         WHERE t1.`status` =0
-          AND t2.project_id=#{projectId}
+        AND t2.project_id=#{projectId}
         <if test="updateTime!=null">
-          AND t1.update_time >=#{updateTime}
+            AND t1.update_time >=#{updateTime}
         </if>
-
+        group by t1.signature
     </select>
 
     <select id="getAccountIds" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT
-            account_id 'accountId',DATE_FORMAT(MAX(create_time),'%Y-%m-%d %H:%i:%s') 'startDate'
+        SELECT account_id 'accountId',DATE_FORMAT(MAX(create_time), '%Y-%m-%d %H:%i:%s') 'startDate'
         FROM ctop_kuaishou_video_get
         where channel_type = 1
-          and  status = 0
+          and status = 0
         GROUP BY account_id
     </select>
 
+    <select id="queryPhotoIdsByProjectAndMd5" resultType="java.lang.String">
+        SELECT t1.photo_id
+        FROM ctop_kuaishou_video_get t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where t1.status = 0
+        AND t2.project_id = #{projectId}
+        AND t1.signature =#{signature}
+        <if test="accountId !=null">
+            AND t1.account_id IN
+            <foreach collection="accountId" item="id" separator="," open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+        GROUP BY photo_id
+    </select>
+
     <update id="updateBatch">
         UPDATE ctop_kuaishou_video_get SET
         material_tag = CASE id
@@ -353,7 +355,7 @@
         END
         WHERE id IN
         <foreach item="videoGet" index="index" collection="videoGetList" open="(" separator="," close=")">
-             #{videoGet.id}
+            #{videoGet.id}
         </foreach>
     </update>
 </mapper>

+ 21 - 8
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouProjectVideoGetMapper.xml

@@ -7,7 +7,6 @@
         id,
         project_id,
         status,
-        photo_id,
         width,
         height,
         url,
@@ -28,7 +27,6 @@
             #{video.id},
             #{video.projectId},
             #{video.status},
-            #{video.photoId},
             #{video.width},
             #{video.height},
             #{video.url},
@@ -38,7 +36,7 @@
             #{video.statDate},
             #{video.signature},
             #{video.photoName},
-            #{video.updateTime}
+            #{video.updateTime},
             #{video.materialTag},
             #{video.supplierAccountId},
             #{video.supplierAccountName}
@@ -73,9 +71,9 @@
     </select>
     <select id="queryPageList" resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProjectVideoGet">
         SELECT
+        id,
         project_id,
         status,
-        photo_id,
         width,
         height,
         url,
@@ -107,6 +105,7 @@
          SELECT
             IFNULL(t1.total,0) 'total',
             IFNULL(t2.validCount,0) 'validCount',
+            IFNULL(tt.yesterdayValidCount,0) 'yesterdayValidCount',
             IFNULL(t3.todayUpCount,0) 'todayUpCount',
             IFNULL(t4.yesterdayUpCount,0) 'yesterdayUpCount',
             IFNULL(t5.thisWeekCount,0) 'thisWeekCount',
@@ -114,6 +113,7 @@
          FROM
          (
          SELECT COUNT(1) total FROM ctop_kuaishou_project_video_get where project_id = #{projectId}
+             and status = 0
          ) t1
          LEFT JOIN
          (
@@ -125,23 +125,35 @@
          ) t2 ON 1=1
          LEFT JOIN
          (
-         SELECT COUNT(1) todayUpCount FROM ctop_kuaishou_project_video_get where project_id = #{projectId}
+             SELECT COUNT(1) yesterdayValidCount FROM ctop_kuaishou_report_daily_material t1
+                                                 INNER JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+             WHERE t2.project_id = #{projectId}
+               AND t1.stat_date = DATE_SUB(#{today},INTERVAL 1 day)
+               AND t1.charge>0
+         ) tt ON 1=1
+         LEFT JOIN
+         (
+         SELECT COUNT(1) todayUpCount FROM ctop_kuaishou_project_video_get where status = 0
+         AND  project_id = #{projectId}
          AND stat_date LIKE CONCAT(#{today},'%')
          ) t3 ON 1=1
          LEFT JOIN
          (
-         SELECT COUNT(1) yesterdayUpCount FROM ctop_kuaishou_project_video_get where project_id = #{projectId}
+         SELECT COUNT(1) yesterdayUpCount FROM ctop_kuaishou_project_video_get where status = 0
+         AND  project_id = #{projectId}
          AND stat_date LIKE CONCAT(DATE_SUB(#{today},INTERVAL 1 day),'%')
          ) t4 ON 1=1
          LEFT JOIN
          (
-         SELECT COUNT(1) thisWeekCount FROM ctop_kuaishou_project_video_get where project_id = #{projectId}
+         SELECT COUNT(1) thisWeekCount FROM ctop_kuaishou_project_video_get where status = 0
+         AND  project_id = #{projectId}
          AND stat_date >= #{monday}
          AND stat_date &lt;= now()
          ) t5 ON 1=1
          LEFT JOIN
          (
-         SELECT COUNT(1) lastWeekCount FROM ctop_kuaishou_project_video_get where project_id = #{projectId}
+         SELECT COUNT(1) lastWeekCount FROM ctop_kuaishou_project_video_get where status = 0
+         AND  project_id = #{projectId}
          AND stat_date >= #{lastStartDate}
          AND stat_date &lt;= CONCAT(#{lastEndDate},' 23:59:59')
          ) t6 ON 1=1
@@ -165,6 +177,7 @@
         FROM ctop_kuaishou_project_video_get t1
                  LEFT JOIN ctop_material_ascription t2 ON t1.signature = t2.material_id
         WHERE t1.signature = #{signature}
+        and t1.id = #{id}
     </select>
 
     <select id="getAccountVideosTotal" resultType="java.lang.Long">

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

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -27,7 +28,7 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
 
     List<KuaiShouVideoGet> getNewVideoDescDate(Long accountId, Integer newVideoCnt);
 
-    List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId, String startTime, String endTime,Integer channelType,String appVersion,Integer videoCnt);
+    List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId, String startTime, String endTime, Integer channelType, String appVersion, Integer videoCnt);
 
     List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
 
@@ -49,11 +50,13 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
 
     Integer getHotMoneyCountByAccountId(Long accountId);
 
-    List<KuaiShouVideoGet> getZeroVideoByParams(Long accountId, String startTime, String endTime, Long videoCnt,String appVersion,Integer channelType,Integer relativeCnt);
+    List<KuaiShouVideoGet> getZeroVideoByParams(Long accountId, String startTime, String endTime, Long videoCnt, String appVersion, Integer channelType, Integer relativeCnt);
 
     List<KuaiShouVideoGet> getHistoryTopVideoByParams(Long accountId, String startTime, String endTime, Long videoCnt, String appVersion, Integer channelType);
 
-    void getSuZaoList(String token, Long accountId, int page,String startDate);
+    void getSuZaoList(String token, Long accountId, int page, String startDate);
 
     List<JSONObject> getAccountIds();
+
+    List<String> queryPhotoIdsByProjectAndMd5(Long projectId, String signature, JSONArray accountId);
 }

+ 9 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouProjectVideoGetService.java

@@ -4,6 +4,8 @@ import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProjectVideoGet;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.api.vo.Result;
 
+import java.util.List;
+
 /**
  * @Description: 快手-项目下视频信息
  * @Author: jeecg-boot
@@ -15,14 +17,17 @@ public interface IKuaishouProjectVideoGetService extends IService<KuaishouProjec
     /**
      * 清洗项目数据
      */
-    void clearProjectVideo(Long projectId);
+    void clearProjectVideo(Long projectId, Integer pageStart);
 
-    Result<Object> queryPageList(KuaishouProjectVideoGet kuaishouProjectVideoGet,Integer pageNo,Integer pageSize);
+    Result<Object> queryPageList(KuaishouProjectVideoGet kuaishouProjectVideoGet, Integer pageNo, Integer pageSize);
 
     Result<Object> getVideoTotalNumber(Long projectId);
 
-    Result<Object> getVideoDetails(String signature);
+    Result<Object> getVideoDetails(String signature, String id);
+
+    Result<Object> getAccountVideos(String signature, Long projectId, Integer pageNo, Integer pageSize);
 
-    Result<Object> getAccountVideos(String signature,Long projectId,Integer pageNo,Integer pageSize);
+    Result<Object> queryCreativeBySignature(List<String> photoIds, Long accountId, Integer pageNo, Integer pageSize);
 
+    void deleteCreativesByPhotoId(Object photoId);
 }

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

@@ -307,7 +307,6 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
         param.put("end_date", DateUtils.formatDate(new Date(),DateUtils.NEW_FORMAT));
         String result = HttpUtils.httpPostRequest(url, param, headers);
         JSONObject resultJson = JSONObject.parseObject(result);
-        System.out.println(result);
         if (Check.isNull(resultJson)) {
             return;
         }
@@ -348,4 +347,9 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     public List<JSONObject> getAccountIds() {
         return videoGetMapper.getAccountIds();
     }
+
+    @Override
+    public List<String> queryPhotoIdsByProjectAndMd5(Long projectId, String signature,JSONArray accountId) {
+        return videoGetMapper.queryPhotoIdsByProjectAndMd5(projectId, signature,accountId);
+    }
 }

+ 72 - 8
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouProjectVideoGetServiceImpl.java

@@ -1,25 +1,37 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProjectVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCreativeMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouProjectVideoGetMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouProjectVideoGetService;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.xxl.job.core.enums.NoEn;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 快手-项目下视频信息
@@ -28,9 +40,10 @@ import java.util.Map;
  * @version V1.0
  * @date 2021-05-21
  */
+@Slf4j
 @Service
 public class KuaishouProjectVideoGetServiceImpl extends ServiceImpl<KuaishouProjectVideoGetMapper, KuaishouProjectVideoGet> implements IKuaishouProjectVideoGetService {
-
+    static ExecutorService kuaiShouExecutorService = Executors.newFixedThreadPool(5);
     @Autowired
     private KuaishouProjectVideoGetMapper projectVideoGetMapper;
     @Autowired
@@ -39,14 +52,30 @@ public class KuaishouProjectVideoGetServiceImpl extends ServiceImpl<KuaishouProj
     private IKuaiShouImageGetService imageGetService;
     @Autowired
     private IKuaiShouMaterialUploadService uploadService;
+    @Resource
+    private KuaiShouCreativeMapper kuaiShouCreativeMapper;
+    @Autowired
+    private IKuaiShouUpdateService kuaiShouUpdateService;
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
 
     @Override
-    public void clearProjectVideo(Long projectId) {
-        String updateTime = projectVideoGetMapper.queryLatestUpdateTime(projectId);
-        System.out.println(updateTime);
-        List<KuaishouProjectVideoGet> list = videoGetMapper.selectProjectVideo(projectId, updateTime);
-        if (!Check.isNull(list)) {
+    public void clearProjectVideo(Long projectId, Integer pageNo) {
+        try {
+            log.info("清洗快手项目素材数据,projectId:{},pageNo:{}", projectId, pageNo);
+            String updateTime = projectVideoGetMapper.queryLatestUpdateTime(projectId);
+            PageHelper.startPage(pageNo, 1500);
+            List<KuaishouProjectVideoGet> list = videoGetMapper.selectProjectVideo(projectId, updateTime);
+            if (Check.isNull(list)) {
+                return;
+            }
             projectVideoGetMapper.replaceBatch(list);
+            Thread.sleep(500);
+            clearProjectVideo(projectId, pageNo + 1);
+        } catch (Exception e) {
+            log.error("清洗项目数据异常", e);
         }
     }
 
@@ -79,8 +108,8 @@ public class KuaishouProjectVideoGetServiceImpl extends ServiceImpl<KuaishouProj
     }
 
     @Override
-    public Result<Object> getVideoDetails(String signature) {
-        return Result.ok(projectVideoGetMapper.getVideoDetails(signature));
+    public Result<Object> getVideoDetails(String signature, String id) {
+        return Result.ok(projectVideoGetMapper.getVideoDetails(signature, id));
     }
 
     @Override
@@ -92,4 +121,39 @@ public class KuaishouProjectVideoGetServiceImpl extends ServiceImpl<KuaishouProj
         return Result.ok(list);
     }
 
+    @Override
+    public Result<Object> queryCreativeBySignature(List<String> photoIds, Long accountId, Integer pageNo, Integer pageSize) {
+        Long total = kuaiShouCreativeMapper.queryCreativeByPhotoIdTotal(photoIds, accountId);
+        PageHelper.startPage(pageNo, pageSize, false);
+        PageInfo<JSONObject> list = new PageInfo<>(kuaiShouCreativeMapper.queryCreativeByPhotoIds(photoIds, accountId));
+        list.setTotal(total);
+        return Result.ok(list);
+
+    }
+
+    @Override
+    public void deleteCreativesByPhotoId(Object photoId) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String userId = "";
+        if (!Check.isNull(user)) {
+            userId = user.getId();
+        }
+        List<JSONObject> list = kuaiShouCreativeMapper.queryCreativeByPhotoId(String.valueOf(photoId));
+        if (!Check.isNull(list)) {
+            for (JSONObject data : list) {
+                Long accountId = data.getLong("accountId");
+                Long creativeId = data.getLong("creativeId");
+                CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+                if (!Check.isNull(token)) {
+                    String finalUserId = userId;
+                    kuaiShouExecutorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            kuaiShouUpdateService.updateCreativeStatus(token.getAccessToken(), accountId, creativeId, NoEn.NO3.valueInt(), finalUserId);
+                        }
+                    });
+                }
+            }
+        }
+    }
 }