Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

syh 4 gadi atpakaļ
vecāks
revīzija
2e7674ab43
13 mainītis faili ar 178 papildinājumiem un 42 dzēšanām
  1. 4 18
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ProjectMemberController.java
  2. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java
  3. 28 10
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml
  4. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java
  5. 26 8
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java
  6. 51 0
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouBatchCampaignTimeStartJob.java
  7. 35 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java
  8. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouBatchCampaignPreview.java
  9. 3 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouBatchCampaignPreviewMapper.java
  10. 10 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouBatchCampaignPreviewMapper.xml
  11. 12 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouBatchCampaignPreviewService.java
  12. 4 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouBatchCampaignPreviewServiceImpl.java
  13. 0 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouBatchCreativePreviewServiceImpl.java

+ 4 - 18
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ProjectMemberController.java

@@ -28,21 +28,10 @@ import org.jeecg.modules.ctop.service.IAdvertiserService;
 import org.jeecg.modules.ctop.service.IProjectMemberService;
 import org.jeecg.modules.system.service.ISysUserService;
 import org.springframework.beans.factory.annotation.Autowired;
-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.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 项目成员
@@ -191,9 +180,10 @@ public class ProjectMemberController {
             List<JSONObject> projectList = projectMemberService.getProjectByUserIdAndMediaIds(userId, mediaIds);
             List<JSONObject> haveList = new ArrayList<>();
             if (!Check.isNull(projectList)) {
+                Map<Long, List<JSONObject>> accountMap = userAllocationService.getAccountListByProjectList(projectList);
                 for (int i = 0; i < projectList.size(); i++) {
                     JSONObject project = projectList.get(i);
-                    List<JSONObject> accountList = userAllocationService.getAccountListByProject(project.getLong("projectId"));
+                    List<JSONObject> accountList = accountMap.get(project.getLong("projectId"));
                     if (!Check.isNull(accountList)) {
                         project.put("accountList", accountList);
                         haveList.add(project);
@@ -596,9 +586,5 @@ public class ProjectMemberController {
 
     }
 
-    public static void main(String[] args) {
-
-    }
-
 
 }

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -42,4 +42,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     String getCompanyNameByUserId(@Param("planId") String planId);
 
     List<UserAllocation> listByMediaId(@Param("mediaId")String mediaId, @Param("accountStatus")Integer accountStatus);
+
+    List<JSONObject> getAccountListByProjectList(@Param("list") List list);
 }

+ 28 - 10
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -31,14 +31,32 @@
 
     <select id="getAccountListByProject" resultType="com.alibaba.fastjson.JSONObject">
        select
-       account_id as 'accountId',
-       user_name as 'userName',
-       auth_name as 'authName'
-       from ctop_user_allocation
-       where project_id = #{projectId}
-       order by create_time desc
+       t1.account_id as 'accountId',
+       (select  realname  from sys_user where  id = t1.user_id ) as 'userName',
+       t1.auth_name as 'authName'
+       from ctop_user_allocation t1
+       where t1.project_id = #{projectId}
+       order by t1.create_time desc
     </select>
 
+    <select id="getAccountListByProjectList" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        t1.project_id as 'projectId',
+        t1.account_id as 'accountId',
+        (select realname from sys_user where id = t1.user_id ) as 'userName',
+        t1.auth_name as 'authName'
+        from ctop_user_allocation t1
+        where t1.project_id in
+        <foreach collection="list" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+
+
+        order by t1.create_time desc
+    </select>
+
+
     <select id="getUserIdListByProjectId" resultType="com.alibaba.fastjson.JSONObject">
    SELECT t1.user_id as 'userId',
     t1.account_id as 'accountId',
@@ -128,10 +146,10 @@
         select a.* from ctop_user_allocation a
         left join ctop_project p on p.id = a.project_id
         where
-            1=1
-            <if test="null!=accountStatus">
-                and a.account_status = #{accountStatus}
-            </if>
+        1=1
+        <if test="null!=accountStatus">
+            and a.account_status = #{accountStatus}
+        </if>
         <if test="null!=mediaId">
             and p.media_id = #{mediaId}
         </if>

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

@@ -43,4 +43,6 @@ public interface IUserAllocationService extends IService<UserAllocation> {
     JSONObject getSwitchStatusByAccount(Long accountId);
 
     List<Long> getAccountsByDeleteComment();
+
+    Map<Long, List<JSONObject>> getAccountListByProjectList(List<JSONObject> projectList);
 }

+ 26 - 8
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -6,7 +6,6 @@ import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.common.module.utils.ResultMapUtils;
 import cn.com.ctop.common.module.utils.StatusCode;
-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;
@@ -96,8 +95,8 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     }
 
     @Override
-    public List<UserAllocation> listByMediaId(String mediaId,int accountStatus) {
-        return userAllocationMapper.listByMediaId(mediaId,accountStatus);
+    public List<UserAllocation> listByMediaId(String mediaId, int accountStatus) {
+        return userAllocationMapper.listByMediaId(mediaId, accountStatus);
     }
 
     @Override
@@ -128,11 +127,11 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
 
     @Override
     public List<JSONObject> getAccountIdsByUserId(String userId) {
-        List<JSONObject> result= new ArrayList<>();
-        if(userId.equals("e9ca23d68d884d4ebb19d07889727dae")){
-            result=userAllocationMapper.getAllAccountIdsByMediaId("2");
-        }else {
-            result=userAllocationMapper.getAccountIdsByUserId(userId);
+        List<JSONObject> result = new ArrayList<>();
+        if (userId.equals("e9ca23d68d884d4ebb19d07889727dae")) {
+            result = userAllocationMapper.getAllAccountIdsByMediaId("2");
+        } else {
+            result = userAllocationMapper.getAccountIdsByUserId(userId);
 
         }
         return result;
@@ -157,4 +156,23 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     public List<Long> getAccountsByDeleteComment() {
         return userAllocationMapper.queryAccountsByDeleteComment();
     }
+
+    @Override
+    public Map<Long, List<JSONObject>> getAccountListByProjectList(List<JSONObject> projectList) {
+        Map<Long, List<JSONObject>> map = new HashMap<>();
+        List list = new ArrayList();
+        for (int i = 0; i < projectList.size(); i++) {
+            JSONObject jsonObject = projectList.get(i);
+            list.add(jsonObject.getLong("projectId"));
+            map.put(jsonObject.getLong("projectId"), new ArrayList<>());
+        }
+        List<JSONObject> jsonList = userAllocationMapper.getAccountListByProjectList(list);
+        for (int i = 0; i < jsonList.size(); i++) {
+            JSONObject jsonObject = jsonList.get(i);
+            Long projectId = jsonObject.getLong("projectId");
+            List<JSONObject> jsonObjects = map.get(projectId);
+            jsonObjects.add(jsonObject);
+        }
+        return map;
+    }
 }

+ 51 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouBatchCampaignTimeStartJob.java

@@ -0,0 +1,51 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+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.KuaishouBatchCampaignPreview;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouBatchCampaignPreviewService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class KuaishouBatchCampaignTimeStartJob {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaishouBatchCampaignPreviewService campaignPreviewService;
+    @Autowired
+    private IKuaiShouUpdateService kuaiShouUpdateService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @XxlJob("kuaishouBatchCampaignTimeStartJob")
+    public void execute() throws Exception {
+        List<KuaishouBatchCampaignPreview> campaignPreviewList = campaignPreviewService.queryListByTime();
+        if (!Check.isNull(campaignPreviewList)) {
+            campaignPreviewList.forEach(campaignPreview -> executorService.submit(() -> {
+                CtopOauthToken token = tokenService.getTokenByAccountId(campaignPreview.getAccountId());
+                if (!Check.isNull(token)) {
+                    Map<String, Object> map = kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), campaignPreview.getAccountId(), campaignPreview.getCampaignId(), 1, "timingStart");
+                    if ((boolean) map.get("success")) {
+                        QueryWrapper<KuaishouBatchCampaignPreview> queryWrapper = new QueryWrapper<>();
+                        queryWrapper.eq("id", campaignPreview.getId());
+                        KuaishouBatchCampaignPreview campaign = new KuaishouBatchCampaignPreview();
+                        campaign.setMessage("定时启动成功!");
+                        campaignPreviewService.update(campaign, queryWrapper);
+                    }
+                }
+            }));
+            XxlJobHelper.log("计划定时启动完成");
+        }
+    }
+
+}

+ 35 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java

@@ -40,6 +40,37 @@ public class KuaiShouMaterialControer {
     @Autowired
     private IKuaishouVideoRelateCreativesService relateCreativesService;
 
+
+    @PostMapping(value = "/getKuaiShouVideoList")
+    public JSONObject getKuaiShouVideoList(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参不能为空");
+            }
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("账户id不能为空");
+            }
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("未获取账号授权信息");
+            }
+
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            iKuaishouInterfaceService.getVideoList(token, nowDate, nowDate);
+            returnJson.put("code", 0);
+            returnJson.put("message", "素材更新成功");
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
     /**
      * 查询上新素材
      *
@@ -48,7 +79,7 @@ public class KuaiShouMaterialControer {
      */
     @PostMapping(value = "/getNewVideoList")
     public JSONObject getNewVideo(@RequestBody JSONObject requestJson) {
-        log.info("获取上新素材入参:{}", requestJson);
+        // log.info("获取上新素材入参:{}", requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(requestJson)) {
@@ -116,7 +147,7 @@ public class KuaiShouMaterialControer {
      */
     @PostMapping(value = "/getHistoryVideoList")
     public JSONObject getHistoryVideoList(@RequestBody JSONObject requestJson) {
-        log.info("获取历史素材入参:{}", requestJson);
+        // log.info("获取历史素材入参:{}", requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(requestJson)) {
@@ -193,7 +224,7 @@ public class KuaiShouMaterialControer {
      */
     @PostMapping(value = "/getHistoryTopVideoList")
     public JSONObject getHistoryTopVideoList(@RequestBody JSONObject requestJson) {
-        log.info("获取历史Top素材入参:{}", requestJson);
+      //   log.info("获取历史Top素材入参:{}", requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(requestJson)) {
@@ -263,7 +294,7 @@ public class KuaiShouMaterialControer {
      */
     @PostMapping(value = "/getCreateZeroVideoList")
     public JSONObject getHistoryCreateVideoList(@RequestBody JSONObject requestJson) {
-        log.info("获取关联创意数为0素材入参:{}", requestJson);
+      //  log.info("获取关联创意数为0素材入参:{}", requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(requestJson)) {

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

@@ -103,7 +103,7 @@ public class KuaishouBatchCampaignPreview {
     /**
      * 是否创建成功 0 失败,1成功
      */
-    private int isSuccess;
+    private Integer isSuccess;
 
     /**
      * 操作说明

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

@@ -3,6 +3,8 @@ package cn.com.ctop.kuaishou.modules.batch.mapper;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import java.util.List;
+
 /**
  * 快手-广告计划预览信息
  *
@@ -12,4 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaishouBatchCampaignPreviewMapper extends BaseMapper<KuaishouBatchCampaignPreview> {
 
+    List<KuaishouBatchCampaignPreview> queryListByTime();
 }

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

@@ -2,4 +2,14 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchCampaignPreviewMapper">
 
+    <select id="queryListByTime" resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview">
+        SELECT id, campaign_id, account_id
+        FROM ctop_kuaishou_batch_campaign_preview
+        WHERE is_time = 1
+          AND is_success = 1
+          AND time_start &gt;= date_sub(now(), interval 5 minute)
+          AND time_start &lt;= now()
+          AND campaign_id is not null
+    </select>
+
 </mapper>

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

@@ -4,6 +4,8 @@ import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * @Description: 快手-广告计划预览信息
  * @Author: jeecg-boot
@@ -15,4 +17,14 @@ public interface IKuaishouBatchCampaignPreviewService extends IService<KuaishouB
     void addPreviewData(JSONObject data) throws Exception;
 
     JSONObject queryByBatchId(String batchId, String accountId);
+
+    /**
+     * 查询定时启动的计划集
+     *
+     * @param
+     * @return java.util.List<cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview>
+     * @throws
+     * @author ZHAOXA
+     */
+    List<KuaishouBatchCampaignPreview> queryListByTime();
 }

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouBatchCampaignPreviewServiceImpl.java

@@ -109,6 +109,10 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
         }
         return campaigns;
     }
+    @Override
+    public List<KuaishouBatchCampaignPreview> queryListByTime() {
+        return campaignPreviewMapper.queryListByTime();
+    }
 
     @Override
     public void addPreviewData(JSONObject data) throws Exception {

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

@@ -18,7 +18,6 @@ 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.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouBatchCreativePreviewService;
-import com.alibaba.fastjson.JSONObject;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;