瀏覽代碼

出价预警

zhaoxian 3 年之前
父節點
當前提交
f71218551d

+ 15 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/entity/Project.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.common.module.entity;
 
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
@@ -116,9 +117,15 @@ public class Project {
     private Date updateTime;
 
 
+    //优化目标出价类型
     private String bidType;
+
+    //转化目标
     private String ocpxActionType;
 
+    //深度转化目标
+    private String deepConversionType;
+
     @TableField(exist = false)
     private String responsibleId_dictText; // 运营负责人
 
@@ -135,4 +142,12 @@ public class Project {
     private Integer needExamine;
     @TableField(exist = false)
     private String supplierCode_dictText;
+
+    //转化目标
+    @TableField(exist = false)
+    private JSONArray ocpxActionTypeArray;
+
+    //深度转化目标
+    @TableField(exist = false)
+    private JSONArray deepConversionTypeArray;
 }

+ 9 - 8
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/ProjectMapper.xml

@@ -16,14 +16,15 @@
     </select>
 
     <select id="getWarningInfoByProjectId" resultType="com.alibaba.fastjson.JSONObject">
-     select
-     id projectId,
-     project_name projectName,
-     max_bid maxBid,
-     bid_type bidType,
-     ocpx_action_type ocpxActionType
-     from ctop_project
-     where id = #{projectId}
+        select
+            id projectId,
+            project_name projectName,
+            max_bid maxBid,
+            bid_type bidType,
+            ocpx_action_type ocpxActionType,
+            deep_conversion_type deepConversionType
+        from ctop_project
+        where id = #{projectId}
     </select>
 
     <select id="querySupplierCodeById" resultType="java.lang.String">

+ 331 - 142
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -8,18 +8,68 @@ import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.IMaterialCutFrameService;
 import cn.com.ctop.common.module.service.IOauthConfigService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
-import cn.com.ctop.common.module.utils.*;
-import cn.com.ctop.kuaishou.modules.ai.service.*;
-import cn.com.ctop.kuaishou.modules.batch.entity.*;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.CtopAdConstant;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.JsonUtil;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiCreativeLimitService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAppPackageService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalPackageService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouPopulationGroupService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAdvertiserBaseInfo;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
+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.KuaiShouDailyFlows;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouRegionListChildren;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouRegionListParent;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouTargetingTags;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.ConvertVo;
-import cn.com.ctop.kuaishou.modules.batch.mapper.*;
-import cn.com.ctop.kuaishou.modules.batch.service.*;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouAdvertiserBaseInfoMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouAppListMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouRegionListChildrenMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouRegionListParentMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouTargetingTagsMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyFlowsService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouOverRunSendMessageService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
+import cn.com.ctop.kuaishou.modules.batch.service.IWarningOperationService;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
-import cn.com.ctop.kuaishou.modules.report.entity.*;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAccount;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyCampaign;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyCreative;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyCreativeStatistic;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyAccount;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyCampaign;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyCreative;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyCreativeStatistic;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyGroup;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCampaignMapper;
-import cn.com.ctop.kuaishou.modules.report.service.*;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyCampaignService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyCreativeService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportHourlyAccountService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportHourlyCampaignService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportHourlyCreativeService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportHourlyGroupService;
+import cn.com.ctop.kuaishou.modules.report.service.IRuleKuaiShouPlanService;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -54,7 +104,11 @@ import java.io.IOException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+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;
 
@@ -130,6 +184,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private IKuaishouAppPackageService appPackageService;
     @Autowired
     private UserAllocationMapper allocationMapper;
+    private static ExecutorService cutExecutorService = Executors.newFixedThreadPool(10);
 
     @Override
     public void getAdvertiserReportHourly(CtopOauthToken token, Date startDate, Date endDate) {
@@ -164,6 +219,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         }
         JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
         if (null == details || details.size() <= 0) {
+            log.error("快手时报返回详情为空,accountId:{}", token.getAccountId());
             return;
         }
         List<KuaishouReportHourlyAccount> addList = new ArrayList<>();
@@ -180,6 +236,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             addList.add(kuaishouReportHourlyAccount);
         }
         hourlyAccountService.replaceBatch(addList);
+        log.info("获取账户时报数据完成,accountId:{}", token.getAccountId());
     }
 
 
@@ -221,9 +278,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 log.info("快手视频列表信息为空=》accountId:{}", token.getAccountId());
                 return;
             }
-            Boolean doGet = true;
-            if (details.size() < page_size) {
-                doGet = false;
+            Boolean toGet = false;
+            if (details.size() >= page_size) {
+                toGet = true;
             }
 
             List<KuaiShouVideoGet> videoGetList = new ArrayList<>();
@@ -264,27 +321,33 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     videoGet.setMaterialType(type);
                 }
                 videoGetList.add(videoGet);
-                Thread thread = new Thread() {
-                    @Override
-                    public void run() {
-                        videoGetService.getKeyFrame(token.getAccessToken(), token.getAccountId(), signature, photo_id);
-                    }
-                };
-                thread.start();
+                getCut(token.getAccessToken(), token.getAccountId(), signature, photo_id);
             }
             if (!Check.isNull(videoGetList)) {
                 videoGetService.replaceBatch(videoGetList);
             }
-            if (doGet) {
+
+            if (toGet) {
                 getVideoListByPage(token, startDate, endDate, page + 1);
             }
-
         } catch (Exception e) {
             e.printStackTrace();
         }
 
     }
 
+
+    private void getCut(String token, Long accountId, String signature, String photo_id) {
+        cutExecutorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                videoGetService.getKeyFrame(token, accountId, signature, photo_id);
+            }
+        });
+
+    }
+
+
     @Override
     public void getAdvertiserReportDaily(CtopOauthToken token, Date startDate, Date endDate, String reportDims) {
         try {
@@ -973,7 +1036,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     }
 
                 } else {
-                    if (code == 400001 && "/rest/openapi/v2/ad_unit/create调用已超日限,次日可恢复调用".equals(resultJson.getString("message"))) {
+                    if (code == 400001 && resultJson.getString("message").equals("/rest/openapi/v2/ad_unit/create调用已超日限,次日可恢复调用")) {
                         String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
                         String key = advertiserId + "_" + nowDate + "unit_create_overrun";
                         redisUtil.set(key, 1, 60 * 60 * 24);
@@ -1192,6 +1255,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     }
 
 
+    @Autowired
+    IRuleKuaiShouPlanService ruleKuaiShouPlanService;
+
     private void getGroupListByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
         JSONObject param = new JSONObject();
@@ -1222,128 +1288,160 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             return;
         }
         addGroup(token.getAccountId(), details);
+        //   ruleKuaiShouPlanService.insertTarget(token.getAccountId(), details);
         getGroupListByPage(token, startDate, endDate, page + 1);
     }
 
     static ExecutorService executorBidTypeService = Executors.newFixedThreadPool(20);
     static ExecutorService executorMaxBidService = Executors.newFixedThreadPool(5);
 
-    private void addGroup(Long advertiserId, JSONArray details) {
-        JSONObject json = warningOperationService.getBidTypeAndMaxBid(advertiserId);
-        Long maxBid = json.getLong("maxBid");// 最高出价
-        String bidTypeStr = json.getString("bidType"); // 出价方式
-        JSONArray bidTypeArr = JSONArray.parseArray(bidTypeStr);
-        String ocpxActionTypeStr = json.getString("ocpxActionType"); // 优化目标
-        JSONArray ocpxArr = JSONArray.parseArray(ocpxActionTypeStr);
-        if (!Check.isNull(details)) {
-            List<KuaiShouGroup> groups = new ArrayList<>();
-            for (int i = 0; i < details.size(); i++) {
-                JSONObject detail = JSONObject.parseObject(details.get(i).toString());
-                if (!Check.isNull(detail)) {
-                    Integer bid_type = detail.getInteger("bid_type");
-                    Long bid = detail.getLong("bid");
-                    Long cpa_bid = detail.getLong("cpa_bid");
-                    Long day_budget = detail.getLong("day_budget");
-                    Integer ocpx_action_type = detail.getInteger("ocpx_action_type");
-                    Long unitId = detail.getLong("unit_id");
-                    String unit_name = detail.getString("unit_name");
-                    Integer status = detail.getInteger("status");
-                    Integer put_status = detail.getInteger("put_status");
-                    if (put_status == 1) { // 组状态为 投放中的
-                        if (status != 15) { // 广告组状态为非暂停
-                            Boolean bidTypeTrueOrFalse = false;
-                            for (int j = 0; j < bidTypeArr.size(); j++) {
-                                Integer bidType = (Integer) bidTypeArr.get(j);
-                                if (bidType.equals(bid_type)) {
-                                    bidTypeTrueOrFalse = true;
-                                    break;
-                                }
-                            }
-                            Boolean ocpxTrueOrFalse = false;
-                            if (ocpx_action_type == 0) {
-                                ocpxTrueOrFalse = true;
-                            } else {
-                                for (int j = 0; j < ocpxArr.size(); j++) {
-                                    Integer ocpxActionType = (Integer) ocpxArr.get(j);
-                                    if (ocpxActionType.equals(ocpx_action_type)) {
-                                        ocpxTrueOrFalse = true;
-                                        break;
-                                    }
-                                }
-                            }
+    private void addGroup(Long accountId, JSONArray details) {
+        JSONObject project = warningOperationService.getBidTypeAndMaxBid(accountId);
+        if (Check.isNull(project) || Check.isNull(details)) {
+            return;
+        }
 
+        // 最高出价
+        Long maxBid = project.getLong("maxBid");
 
-                            if (!bidTypeTrueOrFalse || !ocpxTrueOrFalse) { // 出价方式设置非法
-                                if (day_budget > 500 * 1000 || day_budget == 0) { // 预算大于500 或者不限制预算 需要发送通知 并且进行暂停操作
-                                    executorBidTypeService.submit(new Runnable() {
-                                        @Override
-                                        public void run() {
-                                            warningOperationService.kuaiShouWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
-                                        }
-                                    });
+        //优化目标集
+        List<Integer> bidList = null;
+        String bidTypeStr = project.getString("bidType");
+        if (!Check.isNull(bidTypeStr)) {
+            bidList = JSONArray.parseArray(bidTypeStr, Integer.class);
+        }
+
+        //转化目标map
+        Map<Integer, Long> ocpxMap = new HashMap<>();
+        String ocpxTypeStr = project.getString("ocpxActionType");
+        if (!Check.isNull(ocpxTypeStr)) {
+            JSONArray ocpxArr = JSONArray.parseArray(ocpxTypeStr);
+            for (int i = 0; i < ocpxArr.size(); i++) {
+                JSONObject obj = ocpxArr.getJSONObject(i);
+                ocpxMap.put(obj.getInteger("ocpxCode"), obj.getLong("maxValue"));
+            }
+        }
+
+        //深度转化目标map
+        Map<Integer, Long> deepMap = new HashMap<>();
+        String deepTypeStr = project.getString("deepConversionType");
+        if (!Check.isNull(deepTypeStr)) {
+            JSONArray deepArr = JSONArray.parseArray(deepTypeStr);
+            for (int i = 0; i < deepArr.size(); i++) {
+                JSONObject obj = deepArr.getJSONObject(i);
+                ocpxMap.put(obj.getInteger("deepCode"), obj.getLong("deepValue"));
+            }
+        }
+
+        List<KuaiShouGroup> groups = new ArrayList<>();
+        for (int i = 0; i < details.size(); i++) {
+            JSONObject detail = JSONObject.parseObject(details.get(i).toString());
+            if (!Check.isNull(detail)) {
+                //优化目标
+                Integer bidType = detail.getInteger("bid_type");
+                //优化出价(只有单击时,才有值)
+                Long bid = detail.getLong("bid");
+                //转化目标
+                Integer ocpxActionType = detail.getInteger("ocpx_action_type");
+                //转化目标出价
+                Long cpaBid = detail.getLong("cpa_bid");
+                //深度转化目标
+                Integer deepConversionType = detail.getInteger("deep_conversion_type");
+                //深度转化目标出价
+                Long deepConversionBid = detail.getLong("deep_conversion_bid");
+                //单日预算
+                Long dayBudget = detail.getLong("day_budget");
+                //组ID
+                Long unitId = detail.getLong("unit_id");
+                //组名称
+                String unitName = detail.getString("unit_name");
+                //状态
+                Integer status = detail.getInteger("status");
+                //投放状态
+                Integer putStatus = detail.getInteger("put_status");
+                if (putStatus == 1 && status != 15) { // 组状态为 投放中的 and 广告组状态为非暂停
+                    Boolean typeFalg = true;
+                    Boolean bidFalg = true;
+
+                    //优化目标
+                    if (!bidList.isEmpty()) {
+                        if (!bidList.contains(bidType)) {
+                            //项目不包含该优化目标,则关停
+                            typeFalg = false;
+                        } else if (bidType == 2 && bid > maxBid) {
+                            //若优化目标为2点击数,并且广告组出价大于项目设置最大出价,则关停
+                            bidFalg = false;
+                        }
+                    }
+                    //转化目标
+                    if (!Check.isNull(ocpxActionType) && ocpxActionType != 0) {
+                        //!=0是设置过转化目标
+                        if (ocpxActionType == 2 && (dayBudget == 0 || dayBudget > 500 * 1000)) {
+                            // 转化目标为2行为数,并且预算大于500 或者不限,则关停
+                            typeFalg = false;
+                        } else if (!Check.isNullMap(ocpxMap)) {
+                            Long ocpxBid = ocpxMap.get(ocpxActionType);
+                            if (Check.isNull(ocpxBid)) {
+                                //通过key未获取值,说明不包含该目标,进行关停
+                                typeFalg = false;
+                            } else {
+                                if (cpaBid > ocpxBid) {
+                                    //组转化出价 大于 项目设置最大转化出价,则关停
+                                    bidFalg = false;
                                 }
                             }
-                            if (bid > maxBid || cpa_bid > maxBid) {
-                                executorMaxBidService.submit(new Runnable() {
-                                    @Override
-                                    public void run() {
-                                        warningOperationService.kuaiShouBidWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
-                                    }
-                                });
+                        }
+                    }
+
+                    //转化目标
+                    if (!Check.isNull(deepConversionType) && deepConversionType != 0 && !Check.isNullMap(ocpxMap)) {
+                        Long deepBid = deepMap.get(deepConversionType);
+                        if (Check.isNull(deepBid)) {
+                            //通过key未获取值,说明不包含该目标,进行关停
+                            typeFalg = false;
+                        } else {
+                            if (deepConversionBid > deepBid) {
+                                //组深度转化出价 大于 项目设置最大转化出价,则关停
+                                bidFalg = false;
                             }
                         }
                     }
 
-                    KuaiShouGroup group = new KuaiShouGroup();
-                    group.setId("" + advertiserId + unitId);
-                    group.setAccountId(advertiserId);
-                    group.setCampaignId(detail.getLong("campaign_id"));
-                    group.setUnitId(unitId);
-                    group.setUnitName(unit_name);
-                    group.setStatus(status);
-                    group.setPutStatus(put_status);
-                    group.setStudyStatus(detail.getInteger("study_status"));
-                    group.setCreateChannel(detail.getInteger("create_channel"));
-                    group.setReviewDetail(detail.getString("review_detail"));
-                    group.setBidType(bid_type);
-                    group.setBid(bid);
-                    group.setStudyStatus(detail.getInteger("study_status"));
-                    group.setCpaBid(cpa_bid);
-                    group.setOcpxActionType(ocpx_action_type);
-                    group.setDeepConversionType(detail.getInteger("deep_conversion_type"));
-                    group.setDeepConversionBid(detail.getLong("deep_conversion_bid"));
-                    group.setDayBudget(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.setSchemaUri(detail.getString("schema_uri"));
-                    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.setAppStore(detail.getJSONArray("app_store") + "");
-                    group.setCreateTime(new Date());
-                    group.setUpdateTime(new Date());
-                    groups.add(group);
-                    // 添加应用信息
-                }
-            }
-            if (!Check.isNull(groups)) {
-                try {
-                    Thread.sleep(200L);
-                    groupMapper.replaceBatch(groups);
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
+                    if (!typeFalg) { // 出价方式设置非法
+                        executorBidTypeService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                warningOperationService.kuaiShouWarningOperation(project.getLong("projectId"), project.getString("projectName"), accountId, unitId, unitName);
+                            }
+                        });
+                    }
+                    if (!bidFalg) {
+                        executorMaxBidService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                warningOperationService.kuaiShouBidWarningOperation(project.getLong("projectId"), project.getString("projectName"), accountId, unitId, unitName);
+                            }
+                        });
+                    }
                 }
 
+                KuaiShouGroup group = JSONObject.parseObject(detail.toJSONString(), KuaiShouGroup.class);
+                group.setId("" + accountId + unitId);
+                group.setAccountId(accountId);
+                group.setGroupCreateTime(detail.getString("create_time"));
+                group.setGroupUpdateTime(detail.getString("update_time"));
+                group.setCreateTime(new Date());
+                group.setUpdateTime(new Date());
+                groups.add(group);
+                // 添加应用信息
+            }
+        }
+        if (!Check.isNull(groups)) {
+            try {
+                Thread.sleep(200L);
+                groupMapper.replaceBatch(groups);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
             }
         }
     }
@@ -1896,13 +1994,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNullMap(dataJson)) {
                         JSONObject returnJson = new JSONObject();
-                        returnJson.put("isAdWatch5times", dataJson.getInteger("is_ad_watch_5_times"));
-                        returnJson.put("isAdWatch20times", dataJson.getInteger("is_ad_watch_20_times"));
-                        returnJson.put("isAdWatch10Times", dataJson.getInteger("is_ad_watch_10_times"));
-                        returnJson.put("isSevenDayRoi", dataJson.getInteger("is_seven_day_roi"));
-                        returnJson.put("isAppointJumpClick", dataJson.getInteger("is_appoint_jump_click"));
-                        returnJson.put("isEventWeekPayTimes", dataJson.getInteger("is_event_week_pay_times"));
-                        returnJson.put("isAppointForm", dataJson.getInteger("is_appoint_form"));
                         returnJson.put("isActivate", dataJson.getInteger("is_activate"));
                         returnJson.put("isFormSubmit", dataJson.getInteger("is_form_submit"));
                         returnJson.put("isCreditGrant", dataJson.getInteger("is_credit_grant"));
@@ -1916,8 +2007,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         returnJson.put("isAppInvoked", dataJson.getInteger("is_app_invoked"));
                         returnJson.put("isMultiConversion", dataJson.getInteger("is_multi_conversion"));
                         returnJson.put("isAdWatchTimes", dataJson.getInteger("is_ad_watch_times"));
+                        returnJson.put("isAppInvoked", dataJson.getInteger("is_app_invoked"));
+                        returnJson.put("isMultiConversion", dataJson.getInteger("is_multi_conversion"));
+                        returnJson.put("isAdWatchTimes", dataJson.getInteger("is_ad_watch_times"));
                         returnJson.put("isOrderPaied", dataJson.getInteger("is_order_paied"));
-                        returnJson.put("isKeyAction", dataJson.getInteger("is_key_action"));
 
                         JSONArray deep_conversion_types = dataJson.getJSONArray("deep_conversion_types");
                         JSONArray deepConversionTypes = new JSONArray();
@@ -2075,15 +2168,15 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 if (code == 0) {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
-                        JSONArray addCreativeIds = dataJson.getJSONArray("add_creative_ids");
-                        if (!Check.isNull(addCreativeIds)) {
+                        JSONArray add_creative_ids = dataJson.getJSONArray("add_creative_ids");
+                        if (!Check.isNull(add_creative_ids)) {
                             Thread thread = new Thread() {
                                 @Override
                                 public void run() {
                                     try {
                                         Thread.sleep(100);
-                                        getCreativeByCreativeIds(accessToken, advertiserId, addCreativeIds);
-                                        createLandPageAndUnit(requestJson, addCreativeIds);
+                                        getCreativeByCreativeIds(accessToken, advertiserId, add_creative_ids);
+                                        createLandPageAndUnit(requestJson, add_creative_ids);
                                     } catch (InterruptedException e) {
                                         e.printStackTrace();
                                     }
@@ -2097,8 +2190,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         returnMap.put("code", 0);
                         returnMap.put("message", "success");
                         returnMap.put("success", true);
-                        returnMap.put("count", addCreativeIds.size());
-                        returnMap.put("ids",addCreativeIds);
+                        returnMap.put("count", add_creative_ids.size());
                     }
                 } else {
                     if (code == 500000 && count <= 4) {
@@ -2863,6 +2955,97 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private IKuaiShouVideoGetService videoGetService;
     static ExecutorService suZhaoService = Executors.newFixedThreadPool(15);
 
+   /* @Override
+    public void getSuZaoList(String token, Long accountId, int page, String startDate, String endDate) {
+        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/ad_creator/video/list";
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token);
+        Map<String, Object> param = new HashMap<String, Object>();
+        param.put("advertiser_id", accountId);
+        param.put("page", page);
+        param.put("page_size", 200);
+        if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
+            param.put("start_date", startDate);
+            param.put("end_date", endDate);
+        }
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        System.err.println(resultJson);
+        if (Check.isNull(resultJson)) {
+            return;
+        }
+        Integer code = resultJson.getInteger("code");
+        String message = resultJson.getString("message");
+        if (null == code || code != 0) {
+            log.error("获取快手素造列表数据异常:{},accountId:{}", message, accountId);
+            return;
+        }
+        JSONObject dataJson = resultJson.getJSONObject("data");
+        if (Check.isNull(dataJson)) {
+            return;
+        }
+
+
+        JSONArray details = dataJson.getJSONArray("details");
+        if (Check.isNull(details)) {
+            return;
+        }
+
+        List<KuaiShouVideoGet> videoGetList = new ArrayList<>();
+        for (int i = 0; i < details.size(); i++) {
+            JSONObject detailJson = details.getJSONObject(i);
+            if (Check.isNull(detailJson)) {
+                continue;
+            }
+            KuaiShouVideoGet videoGet = new KuaiShouVideoGet();
+            String photo_id = detailJson.getString("photo_id");
+            videoGet.setId(accountId + photo_id);
+            videoGet.setAccountId(accountId);
+            videoGet.setCoverUrl(detailJson.getString("cover_url"));
+            videoGet.setPhotoId(photo_id);
+            videoGet.setPhotoName(detailJson.getString("photo_name"));
+            videoGet.setStatDate(detailJson.getDate("upload_time"));
+            String signature = detailJson.getString("signature");
+            videoGet.setSignature(signature);
+            Integer source = detailJson.getInteger("source");
+            if (source == 2) {
+                videoGet.setChannelType(1);
+            } else {
+                videoGet.setChannelType(0);
+            }
+            Integer new_status = detailJson.getInteger("new_status");
+            if (new_status == 1) {
+                videoGet.setStatus(0);
+            } else {
+                videoGet.setStatus(1);
+            }
+            videoGet.setUrl(detailJson.getString("url"));
+            Integer width = detailJson.getInteger("width");
+            videoGet.setWidth(width);
+            Integer height = detailJson.getInteger("height");
+            videoGet.setHeight(height);
+            Integer type = MaterialEnum.getTypeBySize(width, height);
+            if (!Check.isNull(type)) {
+                videoGet.setMaterialType(type);
+            }
+            videoGetList.add(videoGet);
+            Thread thread = new Thread() {
+                @Override
+                public void run() {
+                    videoGetService.getKeyFrame(token, accountId, signature, photo_id);
+                }
+            };
+            thread.start();
+        }
+        if (!Check.isNull(videoGetList)) {
+            videoGetService.replaceBatch(videoGetList);
+        }
+
+        getSuZaoList(token, accountId, page + 1, startDate, endDate);
+
+    }*/
+
     @Autowired
     private IMaterialCutFrameService cutFrameService;
     private static ExecutorService executorService = Executors.newFixedThreadPool(10);
@@ -2879,6 +3062,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             JSONObject param = new JSONObject();
             param.put("advertiser_id", accountId);
             param.put("page_size", 200);
+
+           /* Map<String, Object> deleteMap = new HashMap<>();
+            deleteMap.put("account_id", accountId);
+            deleteMap.put("campaign_id", campaignId);
+            creativeService.removeByMap(deleteMap);*/
             QueryWrapper<KuaiShouGroup> groupQueryWrapper = new QueryWrapper<>();
             groupQueryWrapper.eq("account_id", accountId);
             groupQueryWrapper.eq("campaign_id", campaignId);
@@ -2993,6 +3181,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             e.printStackTrace();
 
         }
+
+
     }
 
     /**
@@ -3177,7 +3367,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             appList.setAppId(dataJson.getLong("app_id"));
                             appList.setAppVersion(dataJson.getString("app_version"));
                             appList.setAppName(dataJson.getString("app_name"));
-                            appList.setAppPrivacyUrl(dataJson.getString("app_privacy_url"));
                             appList.setAppIconUrl(dataJson.getString("app_icon_url"));
                             appList.setImageToken(dataJson.getString("image_token"));
                             appList.setPackageName(dataJson.getString("package_name"));

+ 1 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/mapper/xml/DocumentLibraryMapper.xml

@@ -9,7 +9,7 @@
     </insert>
 
     <insert id="insertBatch" parameterType="cn.com.ctop.kuaishou.modules.document.entity.DocumentLibraryInfo">
-        insert into ctop_document_library
+        replace into ctop_document_library
         (copy_writer_id,copy_writer,account_id,status,create_time)
         values
         <foreach collection="list" item="video" separator=",">

+ 15 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ProjectController.java

@@ -7,6 +7,7 @@ import cn.com.ctop.common.module.entity.Project;
 import cn.com.ctop.common.module.mapper.ProjectMapper;
 import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.Check;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -248,13 +249,19 @@ public class ProjectController {
         project.setProjectName(null);
         QueryWrapper<Project> queryWrapper = QueryGenerator.initQueryWrapper(project, req.getParameterMap());
         Page<Project> page = new Page<>(pageNo, pageSize);
-        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        String roleCode = sysRoleService.getRoleCodeByUserId(sysUser.getId());
+        String userId = project.getUserId();
+        if (Check.isNull(userId)) {
+            LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            if (!Check.isNull(sysUser)) {
+                userId = sysUser.getId();
+            }
+        }
+        String roleCode = sysRoleService.getRoleCodeByUserId(userId);
         if ("operator".equals(roleCode) || "kuaishouOperationManager".equals(roleCode) || "touTiaoOperationManager".equals(roleCode)) {
-            queryWrapper.eq("responsible_id", sysUser.getId());
+            queryWrapper.eq("responsible_id", userId);
 
         } else if ("plane".equals(roleCode) || "plan".equals(roleCode) || "shot".equals(roleCode) || "clip".equals(roleCode) || "designTeamLeader".equals(roleCode) || "planeLeader".equals(roleCode)) {
-            queryWrapper.eq("design_responsible_id", sysUser.getId());
+            queryWrapper.eq("design_responsible_id", userId);
         }
         if (!Check.isNull(projectName)) {
             queryWrapper.like("project_name", projectName);
@@ -286,7 +293,8 @@ public class ProjectController {
 
     @ApiOperation(value = "项目-添加", notes = "项目-添加")
     @PostMapping(value = "/add")
-    public Result<Project> add(@RequestBody Project project) {
+    public Result<Project> add(@RequestBody JSONObject data) {
+        Project project = JSONObject.parseObject(data.toJSONString(), Project.class);
         Result<Project> result = new Result<>();
         try {
             String advertiserId = project.getAdvertiserId();
@@ -353,7 +361,8 @@ public class ProjectController {
      */
     @ApiOperation(value = "项目-编辑", notes = "项目-编辑")
     @PutMapping(value = "/edit")
-    public Result<Project> edit(@RequestBody Project project) {
+    public Result<Project> edit(@RequestBody JSONObject data) {
+        Project project = JSONObject.parseObject(data.toJSONString(), Project.class);
         Result<Project> result = new Result<>();
         SysUser sysUser = sysUserService.getById(project.getResponsibleId());
         if (!Check.isNull(sysUser)) {

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

@@ -36,6 +36,8 @@ import cn.com.ctop.toutiao.modules.report.service.*;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.Param;
@@ -1126,7 +1128,6 @@ public class TestController {
     }
 
 
-
     @GetMapping("/bytedance/effectVideo/get")
     public Map<String, Object> effectVideoGet(String date) {
         Map<String, Object> result = new HashMap<>();
@@ -1353,22 +1354,23 @@ public class TestController {
     static CountDownLatch countDownLatch = null;
     @Resource
     AiKuaishouUnitLevelOperationRecordMapper kuaishouUnitLevelOperationRecordMapper;
+
     @GetMapping(value = "/getAudienceDataNew")
-    public void getAudienceData(@RequestParam(required = false,defaultValue = "2019-01-01") String date) throws Exception {
+    public void getAudienceData(@RequestParam(required = false, defaultValue = "2019-01-01") String date) throws Exception {
         int page = 1;
         int pageSize = 2000;
-        if(date.equals("2019-01-01")){
+        if (date.equals("2019-01-01")) {
             date = DateUtils.formatDate(DateUtils.addDay(DateUtils.getNowDate(), -1), "yyyy-MM-dd");
         }
         List<CtopOauthToken> tokens = tokenService.getByProjectId(458L);    //淘特项目
         for (CtopOauthToken token : tokens) {
             Date startDate = DateUtils.addDay(DateUtils.getNowDate(), -1);
-            if(startDate.after(token.getAccessTokenExpiresIn())){   //过期跳过
+            if (startDate.after(token.getAccessTokenExpiresIn())) {   //过期跳过
                 continue;
             }
             Date enDate = DateUtils.addDay(startDate, -30);
             List<AiKuaishouUnitLevelOperationRecord> planIdsAndUnitIds = kuaishouUnitLevelOperationRecordMapper.selectAllByAccountIdAndDate(token.getAccountId(), enDate, startDate);
-            if(Check.isNull(planIdsAndUnitIds)){
+            if (Check.isNull(planIdsAndUnitIds)) {
                 continue;
             }
             countDownLatch = new CountDownLatch(planIdsAndUnitIds.size());
@@ -1489,4 +1491,12 @@ public class TestController {
             log.info("数据更新完成");
         }
     }
+
+    @GetMapping("checkUnitBid")
+    public Result checkUnitBid(Long accountId) throws Exception {
+        Date nowDate = new Date();
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+        kuaishouInterfaceService.getGroupList(token, nowDate, nowDate);
+        return Result.ok("success");
+    }
 }

+ 7 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/TransferAccountServiceImpl.java

@@ -6,6 +6,7 @@ import cn.com.ctop.common.module.service.ISupplierListService;
 import cn.com.ctop.common.module.service.ISysUserService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.ctop.entity.TransferAccount;
@@ -136,6 +137,12 @@ public class TransferAccountServiceImpl extends ServiceImpl<TransferAccountMappe
             if (!Check.isNullMap(supplierMap)) {
                 project.setSupplierCode_dictText(supplierMap.get(project.getSupplierCode()));
             }
+            if (!Check.isNull(project.getOcpxActionType())&&!project.getOcpxActionType().isEmpty()) {
+                project.setOcpxActionTypeArray(JSONArray.parseArray(project.getOcpxActionType()));
+            }
+            if (!Check.isNull(project.getDeepConversionType())&&!project.getDeepConversionType().isEmpty()) {
+                project.setDeepConversionTypeArray(JSONArray.parseArray(project.getDeepConversionType()));
+            }
         }
         return records;
     }