Browse Source

快手操作记录接口

hcst_sunzhen 4 years ago
parent
commit
471d337ae4

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

@@ -851,4 +851,41 @@ public class TestController {
 
 
 
 
     }
     }
+
+
+
+
+    @GetMapping(value = "/getOperationRecord")
+    public void getOperationRecord(){
+        try {
+            //1:查询当日数据
+            QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("media_id", 2);
+            queryWrapper.orderByDesc("create_time");
+            List<CtopOauthToken> tokens = tokenService.list(queryWrapper);
+            if (null == tokens || tokens.size() <= 0) {
+                log.info("定时获取快手数据异常:未获取到可用的token");
+                return;
+            }
+
+            tokens.forEach(token -> {
+
+               // kuaishouInterfaceService.getOperationRecordByPage(token.getAccountId(),token.getAccessToken());
+                //suzhaoService.submit(new Runnable() {
+                //    @Override
+                //    public void run() {
+                //        //1: 获取广告主信息数据
+                //        log.info("获取素造素材:accountId:{}", token.getAccountId());
+                //        kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, null, null);
+                //    }
+                //});
+            });
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+
 }
 }

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

@@ -178,6 +178,7 @@ public class KuaishouInterfaceConstant {
      */
      */
     public static final String ADVERTISER_INFO = "/rest/openapi/v1/advertiser/info";
     public static final String ADVERTISER_INFO = "/rest/openapi/v1/advertiser/info";
 
 
+
     /**
     /**
      * 修改广告创意
      * 修改广告创意
      */
      */
@@ -208,6 +209,11 @@ public class KuaishouInterfaceConstant {
      */
      */
     public static final String PAGE_LIST = "/rest/openapi/v2/lp/page/list";
     public static final String PAGE_LIST = "/rest/openapi/v2/lp/page/list";
 
 
+    /**
+     * 获取操作记录
+     */
+    public static final String OPERATION_RECORD = "/rest/openapi/v1/tool/operation_record/list";
+
 
 
     /**
     /**
      * 登录
      * 登录
@@ -231,4 +237,6 @@ public class KuaishouInterfaceConstant {
     public static final String HTTPS_PREFIX = "https:";
     public static final String HTTPS_PREFIX = "https:";
 
 
 
 
+
+
 }
 }

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

@@ -0,0 +1,39 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 操作记录
+ * @author jeecg-boot
+ * @date   2020-04-26
+ * @version V1.0
+ */
+@Data
+@TableName("ctop_kuaishou_operation_record")
+public class KuaishouOperationRecord {
+
+	private Long id;
+
+	private Long accountId;
+
+	private Date operationTime;
+
+	private Integer operationType;
+
+	private Integer roleType;
+
+	private String objectName;
+
+	private Integer operationTarget;
+
+	private String objectId;
+
+	private String fieldName;
+
+	private String originalData;
+
+	private String updateData;
+}

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

@@ -0,0 +1,41 @@
+package cn.com.ctop.kuaishou.modules.batch.mapper;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouOperationRecord;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.List;
+
+
+public interface KuaishouOperationRecordMapper extends BaseMapper<KuaishouOperationRecord> {
+
+    void deleteOperationRecordInfoAccount(@Param("record")KuaishouOperationRecord record);
+
+    void insertOperationRecordInfoAccount(@Param("records")List<KuaishouOperationRecord> records);
+
+    void deleteOperationRecordInfoCampaign(@Param("record")KuaishouOperationRecord record);
+
+    void insertOperationRecordInfoCampaign(@Param("records")List<KuaishouOperationRecord> records);
+
+    void deleteOperationRecordInfoUnit(@Param("record")KuaishouOperationRecord record);
+
+    void insertOperationRecordInfoUnit(@Param("records")List<KuaishouOperationRecord> records);
+
+    void deleteOperationRecordInfoCreative(@Param("record")KuaishouOperationRecord record);
+
+    void insertOperationRecordInfoCreative(@Param("records")List<KuaishouOperationRecord> records);
+
+    void deleteOperationRecordInfoVideo(@Param("record")KuaishouOperationRecord record);
+
+    void insertOperationRecordInfoVideo(@Param("records")List<KuaishouOperationRecord> records);
+
+    void deleteOperationRecordInfoApp(@Param("record")KuaishouOperationRecord record);
+
+    void insertOperationRecordInfoApp(@Param("records")List<KuaishouOperationRecord> records);
+
+    void deleteOperationRecordInfoPackage(@Param("record")KuaishouOperationRecord record);
+
+    void insertOperationRecordInfoPackage(@Param("records")List<KuaishouOperationRecord> records);
+
+}

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

@@ -0,0 +1,364 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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.KuaishouOperationRecordMapper">
+
+    <delete id="deleteOperationRecordInfoAccount">
+        delete
+        from
+        ctop_kuaishou_operation_record_account
+        where
+        account_id = #{record.account_id}
+        and
+        object_id = #{record.objectId}
+        and
+        operation_type = #{record.operationType}
+        and
+        operation_target = #{record.operationTarget}
+        and
+        role_type = #{record.roleType}
+        and
+        operation_time = #{record.operationTime}
+    </delete>
+
+    <insert id="insertOperationRecordInfoAccount">
+        insert into
+        ctop_kuaishou_operation_record_account
+        (
+            account_id,
+            operation_time,
+            operation_type,
+            role_type,
+            object_name,
+            operation_target,
+            object_id,
+            field_name,
+            original_data
+        )
+        values
+        <foreach item="record" index="index" collection="records"  separator="," >
+            (
+                #{record.accountId},
+                #{record.operationTime},
+                #{record.operationType},
+                #{record.roleType},
+                #{record.objectName},
+                #{record.operationTarget},
+                #{record.objectId},
+                #{record.fieldName},
+                #{record.originalData}
+            )
+        </foreach>
+
+    </insert>
+
+
+
+
+
+    <delete id="deleteOperationRecordInfoCampaign">
+        delete
+        from
+        ctop_kuaishou_operation_record_campaign
+        where
+        account_id = #{record.account_id}
+        and
+        object_id = #{record.objectId}
+        and
+        operation_type = #{record.operationType}
+        and
+        operation_target = #{record.operationTarget}
+        and
+        role_type = #{record.roleType}
+        and
+        operation_time = #{record.operationTime}
+    </delete>
+
+    <insert id="insertOperationRecordInfoCampaign">
+        insert into
+        ctop_kuaishou_operation_record_campaign
+        (
+        account_id,
+        operation_time,
+        operation_type,
+        role_type,
+        object_name,
+        operation_target,
+        object_id,
+        field_name,
+        original_data
+        )
+        values
+        <foreach item="record" index="index" collection="records"  separator="," >
+            (
+            #{record.accountId},
+            #{record.operationTime},
+            #{record.operationType},
+            #{record.roleType},
+            #{record.objectName},
+            #{record.operationTarget},
+            #{record.objectId},
+            #{record.fieldName},
+            #{record.originalData}
+            )
+        </foreach>
+
+    </insert>
+
+
+    <delete id="deleteOperationRecordInfoUnit">
+        delete
+        from
+        ctop_kuaishou_operation_record_unit
+        where
+        account_id = #{record.account_id}
+        and
+        object_id = #{record.objectId}
+        and
+        operation_type = #{record.operationType}
+        and
+        operation_target = #{record.operationTarget}
+        and
+        role_type = #{record.roleType}
+        and
+        operation_time = #{record.operationTime}
+    </delete>
+
+    <insert id="insertOperationRecordInfoUnit">
+        insert into
+        ctop_kuaishou_operation_record_unit
+        (
+        account_id,
+        operation_time,
+        operation_type,
+        role_type,
+        object_name,
+        operation_target,
+        object_id,
+        field_name,
+        original_data
+        )
+        values
+        <foreach item="record" index="index" collection="records"  separator="," >
+            (
+            #{record.accountId},
+            #{record.operationTime},
+            #{record.operationType},
+            #{record.roleType},
+            #{record.objectName},
+            #{record.operationTarget},
+            #{record.objectId},
+            #{record.fieldName},
+            #{record.originalData}
+            )
+        </foreach>
+
+    </insert>
+
+
+
+
+    <delete id="deleteOperationRecordInfoCreative">
+        delete
+        from
+        ctop_kuaishou_operation_record_creative
+        where
+        account_id = #{record.account_id}
+        and
+        object_id = #{record.objectId}
+        and
+        operation_type = #{record.operationType}
+        and
+        operation_target = #{record.operationTarget}
+        and
+        role_type = #{record.roleType}
+        and
+        operation_time = #{record.operationTime}
+    </delete>
+
+    <insert id="insertOperationRecordInfoCreative">
+        insert into
+        ctop_kuaishou_operation_record_creative
+        (
+        account_id,
+        operation_time,
+        operation_type,
+        role_type,
+        object_name,
+        operation_target,
+        object_id,
+        field_name,
+        original_data
+        )
+        values
+        <foreach item="record" index="index" collection="records"  separator="," >
+            (
+            #{record.accountId},
+            #{record.operationTime},
+            #{record.operationType},
+            #{record.roleType},
+            #{record.objectName},
+            #{record.operationTarget},
+            #{record.objectId},
+            #{record.fieldName},
+            #{record.originalData}
+            )
+        </foreach>
+
+    </insert>
+
+
+
+    <delete id="deleteOperationRecordInfoVideo">
+        delete
+        from
+        ctop_kuaishou_operation_record_video
+        where
+        account_id = #{record.account_id}
+        and
+        object_id = #{record.objectId}
+        and
+        operation_type = #{record.operationType}
+        and
+        operation_target = #{record.operationTarget}
+        and
+        role_type = #{record.roleType}
+        and
+        operation_time = #{record.operationTime}
+    </delete>
+
+    <insert id="insertOperationRecordInfoVideo">
+        insert into
+        ctop_kuaishou_operation_record_video
+        (
+        account_id,
+        operation_time,
+        operation_type,
+        role_type,
+        object_name,
+        operation_target,
+        object_id,
+        field_name,
+        original_data
+        )
+        values
+        <foreach item="record" index="index" collection="records"  separator="," >
+            (
+            #{record.accountId},
+            #{record.operationTime},
+            #{record.operationType},
+            #{record.roleType},
+            #{record.objectName},
+            #{record.operationTarget},
+            #{record.objectId},
+            #{record.fieldName},
+            #{record.originalData}
+            )
+        </foreach>
+
+    </insert>
+
+
+
+
+    <delete id="deleteOperationRecordInfoApp">
+        delete
+        from
+        ctop_kuaishou_operation_record_app
+        where
+        account_id = #{record.account_id}
+        and
+        object_id = #{record.objectId}
+        and
+        operation_type = #{record.operationType}
+        and
+        operation_target = #{record.operationTarget}
+        and
+        role_type = #{record.roleType}
+        and
+        operation_time = #{record.operationTime}
+    </delete>
+
+    <insert id="insertOperationRecordInfoApp">
+        insert into
+        ctop_kuaishou_operation_record_app
+        (
+        account_id,
+        operation_time,
+        operation_type,
+        role_type,
+        object_name,
+        operation_target,
+        object_id,
+        field_name,
+        original_data
+        )
+        values
+        <foreach item="record" index="index" collection="records"  separator="," >
+            (
+            #{record.accountId},
+            #{record.operationTime},
+            #{record.operationType},
+            #{record.roleType},
+            #{record.objectName},
+            #{record.operationTarget},
+            #{record.objectId},
+            #{record.fieldName},
+            #{record.originalData}
+            )
+        </foreach>
+
+    </insert>
+
+
+
+    <delete id="deleteOperationRecordInfoPackage">
+        delete
+        from
+        ctop_kuaishou_operation_record_package
+        where
+        account_id = #{record.account_id}
+        and
+        object_id = #{record.objectId}
+        and
+        operation_type = #{record.operationType}
+        and
+        operation_target = #{record.operationTarget}
+        and
+        role_type = #{record.roleType}
+        and
+        operation_time = #{record.operationTime}
+    </delete>
+
+    <insert id="insertOperationRecordInfoPackage">
+        insert into
+        ctop_kuaishou_operation_record_package
+        (
+        account_id,
+        operation_time,
+        operation_type,
+        role_type,
+        object_name,
+        operation_target,
+        object_id,
+        field_name,
+        original_data
+        )
+        values
+        <foreach item="record" index="index" collection="records"  separator="," >
+            (
+            #{record.accountId},
+            #{record.operationTime},
+            #{record.operationType},
+            #{record.roleType},
+            #{record.objectName},
+            #{record.operationTarget},
+            #{record.objectId},
+            #{record.fieldName},
+            #{record.originalData}
+            )
+        </foreach>
+
+    </insert>
+
+
+</mapper>

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

@@ -0,0 +1,10 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+
+public interface IKuaishouInterfaceService2 {
+
+    //void getOperationRecordByPage(Long advertiserId, String accessToken);
+}
+
+
+

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

@@ -0,0 +1,161 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouOperationRecord;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouOperationRecordMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService2;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.ArrayStack;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+@Slf4j
+@Service
+public class KuaishouInterfaceServiceImpl2 implements IKuaishouInterfaceService2 {
+
+    @Autowired
+    private KuaishouOperationRecordMapper kuaishouOperationRecordMapper;
+
+
+    public void getOperationRecord(){
+
+
+    }
+
+    private void getOperationRecordByPage(Long advertiserId, String accessToken, Integer page, Integer pageSize, Integer operationTarget) {
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.OPERATION_RECORD;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", " application/json");
+        JSONObject json = new JSONObject();
+        json.put("advertiser_id", advertiserId);
+        //if(operationType != null){
+        //    json.put("operation_type", operationType);
+        //}
+        if(operationTarget != null){
+            json.put("operation_target", operationTarget);
+        }
+
+        json.put("page", page);
+        json.put("page_size", pageSize);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, json.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+
+        if(!Check.isNull(resultJson)){
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                JSONObject data = resultJson.getJSONObject("data");
+                if (!Check.isNull(data)) {
+                    List<KuaishouOperationRecord> recordList =  new ArrayList();
+
+                    Integer totalCount = data.getInteger("total_count");
+                    JSONArray dataArr = data.getJSONArray("details");
+                    for (int i = 0; i < dataArr.size(); i++) {
+                        JSONObject dataJson = JSONObject.parseObject(dataArr.get(i).toString());
+                        if (!Check.isNull(dataJson)) {
+
+                            Date operationTime = dataJson.getDate("operation_time");
+                            Integer operationType = dataJson.getInteger("operation_type");
+                            operationTarget = dataJson.getInteger("operation_target");
+                            Integer roleType = dataJson.getInteger("role_type");
+                            String objectId = dataJson.getString("object_id");
+                            String objectName = dataJson.getString("object_name");
+
+                            if (page == 1) { //如果页数为1,删除原来的数据
+                                KuaishouOperationRecord recordDelete = new KuaishouOperationRecord();
+                                recordDelete.setAccountId(advertiserId);
+                                recordDelete.setOperationTime(operationTime);
+                                recordDelete.setOperationType(operationType);
+                                recordDelete.setRoleType(roleType);
+                                recordDelete.setObjectName(objectName);
+                                recordDelete.setOperationTarget(operationTarget);
+                                recordDelete.setObjectId(objectId);
+                                operationRecordDelete(recordDelete,operationTarget);
+                            }
+
+                            JSONArray contentLogArray =  dataJson.getJSONArray("content_log");
+                            int jsize =  contentLogArray.size();
+                            for(int j=0; j<jsize;j++){
+                                JSONObject log = contentLogArray.getJSONObject(j);
+                                KuaishouOperationRecord record = new KuaishouOperationRecord();
+                                record.setAccountId(advertiserId);
+                                record.setOperationTime(operationTime);
+                                record.setOperationType(operationType);
+                                record.setRoleType(roleType);
+                                record.setObjectName(objectName);
+                                record.setOperationTarget(operationTarget);
+                                record.setObjectId(objectId);
+                                record.setFieldName(log.getString("field_name"));
+                                record.setOriginalData(log.getString("original_data"));
+                                record.setUpdateData(log.getString("update_data"));
+
+                                recordList.add(record);
+                            }
+                        }
+                    }
+                    operationRecordInsert(recordList,operationTarget);
+
+                    Integer totalPage = (totalCount - 1) / pageSize + 1;
+                    if (page < totalPage) {
+                        getOperationRecordByPage(advertiserId, accessToken, page + 1, pageSize, operationTarget);
+                    }
+                }
+            }
+        } else {
+            log.error("获取地域列表返回结果为空");
+        }
+
+    }
+
+    private void operationRecordDelete(KuaishouOperationRecord recordDelete, Integer operationTarget){
+        if(operationTarget == 1){
+            kuaishouOperationRecordMapper.deleteOperationRecordInfoAccount(recordDelete);
+        }else if(operationTarget == 2){
+            kuaishouOperationRecordMapper.deleteOperationRecordInfoCampaign(recordDelete);
+        }else if(operationTarget == 3){
+            kuaishouOperationRecordMapper.deleteOperationRecordInfoUnit(recordDelete);
+        }else if(operationTarget == 4){
+            kuaishouOperationRecordMapper.deleteOperationRecordInfoCreative(recordDelete);
+        }else if(operationTarget == 5){
+            kuaishouOperationRecordMapper.deleteOperationRecordInfoVideo(recordDelete);
+        }else if(operationTarget == 6){
+            kuaishouOperationRecordMapper.deleteOperationRecordInfoApp(recordDelete);
+        }else if(operationTarget == 7){
+            kuaishouOperationRecordMapper.deleteOperationRecordInfoPackage(recordDelete);
+        }
+    }
+
+    private void operationRecordInsert(List<KuaishouOperationRecord> recordList, Integer operationTarget){
+        if(operationTarget == 1){
+            kuaishouOperationRecordMapper.insertOperationRecordInfoAccount(recordList);
+        }else if(operationTarget == 2){
+            kuaishouOperationRecordMapper.insertOperationRecordInfoCampaign(recordList);
+        }else if(operationTarget == 3){
+            kuaishouOperationRecordMapper.insertOperationRecordInfoUnit(recordList);
+        }else if(operationTarget == 4){
+            kuaishouOperationRecordMapper.insertOperationRecordInfoCreative(recordList);
+        }else if(operationTarget == 5){
+            kuaishouOperationRecordMapper.insertOperationRecordInfoVideo(recordList);
+        }else if(operationTarget == 6){
+            kuaishouOperationRecordMapper.insertOperationRecordInfoApp(recordList);
+        }else if(operationTarget == 7){
+            kuaishouOperationRecordMapper.insertOperationRecordInfoPackage(recordList);
+        }
+
+
+
+    }
+
+
+
+
+
+
+}