Ver código fonte

金牛代理商账户同步

yumeng 2 anos atrás
pai
commit
62b5413b6f

+ 31 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaiShouJinNiuAccountListJob.java

@@ -0,0 +1,31 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouAgentAccountListService;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.util.List;
+
+public class KuaiShouJinNiuAccountListJob {
+    @Autowired
+    private IKuaishouAgentAccountListService kuaishouAgentAccountListService;
+
+    @XxlJob("syncAccounts")
+    public void execute() throws Exception {
+        List<String> cookies = kuaishouAgentAccountListService.getCookie();
+        if (!Check.isNull(cookies)) {
+            for (int i = 0; i < cookies.size(); i++) {
+                String cookie = cookies.get(i);
+                kuaishouAgentAccountListService.kuaishouAgentAccountListService(cookie, 1, 500, null, null);
+
+            }
+
+        }
+
+
+    }
+
+
+}

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

@@ -0,0 +1,162 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import java.util.Date;
+
+
+/**
+ * 【请填写功能名称】对象 kuaishou_agent_account_list
+ *
+ * @author ruoyi
+ * @date 2023-03-15
+ */
+public class KuaishouAgentAccountList  {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 账户ID
+     */
+    private Long accountId;
+
+    /**
+     * 快手ID
+     */
+
+    private Long userId;
+
+    /**
+     * 账户名称
+     */
+
+    private String accountName;
+
+    /**
+     * 快手名称
+     */
+
+    private String userName;
+
+    /**
+     * 账户创建时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd")
+
+    private Date accountCreateTime;
+
+    /**
+     * 产品名称
+     */
+
+    private String productName;
+
+    /**
+     * 一级行业
+     */
+
+    private String industry;
+
+    /**
+     * 二级行业
+     */
+
+    private String secondIndustry;
+
+    /**
+     * 公司名称
+     */
+
+    private String corporationName;
+
+    public void setAccountId(Long accountId) {
+        this.accountId = accountId;
+    }
+
+    public Long getAccountId() {
+        return accountId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setAccountName(String accountName) {
+        this.accountName = accountName;
+    }
+
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setAccountCreateTime(Date accountCreateTime) {
+        this.accountCreateTime = accountCreateTime;
+    }
+
+    public Date getAccountCreateTime() {
+        return accountCreateTime;
+    }
+
+    public void setProductName(String productName) {
+        this.productName = productName;
+    }
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public void setIndustry(String industry) {
+        this.industry = industry;
+    }
+
+    public String getIndustry() {
+        return industry;
+    }
+
+    public void setSecondIndustry(String secondIndustry) {
+        this.secondIndustry = secondIndustry;
+    }
+
+    public String getSecondIndustry() {
+        return secondIndustry;
+    }
+
+    public void setCorporationName(String corporationName) {
+        this.corporationName = corporationName;
+    }
+
+    public String getCorporationName() {
+        return corporationName;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("accountId", getAccountId())
+                .append("userId", getUserId())
+                .append("accountName", getAccountName())
+                .append("userName", getUserName())
+                .append("accountCreateTime", getAccountCreateTime())
+                .append("productName", getProductName())
+                .append("industry", getIndustry())
+                .append("secondIndustry", getSecondIndustry())
+                .append("corporationName", getCorporationName())
+
+                .toString();
+    }
+}
+

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

@@ -0,0 +1,23 @@
+package cn.com.ctop.kuaishou.modules.batch.mapper;
+
+
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouAgentAccountList;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+
+/**
+ * 【请填写功能名称】Mapper接口
+ *
+ * @author ruoyi
+ * @date 2023-03-15
+ */
+public interface KuaishouAgentAccountListMapper {
+
+
+    List<String> getCookie();
+
+    void addBatch(@Param("adds") List<KuaishouAgentAccountList> adds);
+}

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

@@ -0,0 +1,51 @@
+<?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.KuaishouAgentAccountListMapper">
+
+    <resultMap type="cn.com.ctop.kuaishou.modules.batch.entity.KuaishouAgentAccountList" id="KuaishouAgentAccountListResult">
+        <result property="accountId"    column="account_id"    />
+        <result property="userId"    column="user_id"    />
+        <result property="accountName"    column="account_name"    />
+        <result property="userName"    column="user_name"    />
+        <result property="accountCreateTime"    column="account_create_time"    />
+        <result property="productName"    column="product_name"    />
+        <result property="industry"    column="industry"    />
+        <result property="secondIndustry"    column="second_industry"    />
+        <result property="corporationName"    column="corporation_name"    />
+    </resultMap>
+
+    <select id="getCookie" resultType="java.lang.String">
+        select  cookie  from ruixuan.kuaishou_agent_cookie
+    </select>
+
+    <insert id="addBatch">
+        replace into ruixuan.kuaishou_agent_account_list(
+        account_id,
+        user_id,
+        account_name,
+        user_name,
+        account_create_time,
+        product_name,
+        industry,
+        second_industry,
+        corporation_name
+        )
+        values
+        <foreach collection="adds" item="add" separator=",">
+            (
+            #{add.accountId},
+            #{add.userId},
+            #{add.accountName},
+            #{add.userName},
+            #{add.accountCreateTime},
+            #{add.productName},
+            #{add.industry},
+            #{add.secondIndustry},
+            #{add.corporationName}
+            )
+        </foreach>
+    </insert>
+
+</mapper>

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

@@ -0,0 +1,20 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+
+import java.util.List;
+
+
+/**
+ * 【请填写功能名称】Service接口
+ *
+ * @author ruoyi
+ * @date 2023-03-15
+ */
+public interface IKuaishouAgentAccountListService {
+
+
+    List<String> getCookie();
+
+    void kuaishouAgentAccountListService(String cookie, Integer currentPage, Integer pageSize, Long createBeginTime, Long createEndTime);
+}
+

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

@@ -0,0 +1,105 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouAgentAccountList;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouAgentAccountListMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouAgentAccountListService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+
+/**
+ * 【请填写功能名称】Service业务层处理
+ *
+ * @author ruoyi
+ * @date 2023-03-15
+ */
+@Service
+@Slf4j
+public class KuaishouAgentAccountListServiceImpl implements IKuaishouAgentAccountListService {
+    @Autowired
+    private KuaishouAgentAccountListMapper kuaishouAgentAccountListMapper;
+    @Autowired
+    private ISendMessageService sendMessageService;
+
+
+    @Override
+    public List<String> getCookie() {
+        return kuaishouAgentAccountListMapper.getCookie();
+    }
+
+    @Override
+    public void kuaishouAgentAccountListService(String cookie, Integer currentPage, Integer pageSize, Long createBeginTime, Long createEndTime) {
+        JSONObject requestJson = new JSONObject();
+        if (!Check.isNull(createBeginTime)) {
+            requestJson.put("createBeginTime", createBeginTime);
+        }
+        if (!Check.isNull(createEndTime)) {
+            requestJson.put("createEndTime", createEndTime);
+        }
+        JSONObject pageInfo = new JSONObject();
+        pageInfo.put("currentPage", currentPage);
+        pageInfo.put("pageSize", pageSize);
+        requestJson.put("pageInfo", pageInfo);
+        requestJson.put("accountExpireCertTag", "ALL");
+        requestJson.put("asc", false);
+        requestJson.put("belongType", "ALL");
+        requestJson.put("creatorAgentId", null);
+        requestJson.put("creatorName", null);
+        requestJson.put("creatorUserId", null);
+        requestJson.put("ownerKeyword", "");
+        requestJson.put("ownerType", "ALL");
+        requestJson.put("reviewStatus", "-1");
+        requestJson.put("secondaryAgentKeyword", "");
+        requestJson.put("selectType", "1");
+        requestJson.put("selectValue", "");
+        requestJson.put("sortKey", "");
+        requestJson.put("ucType", "ALL");
+        Map<String, String> map = new HashMap<>();
+        map.put("Cookie", cookie);
+        map.put("Content-Type:", "application/json");
+        String s = HttpUtils.httpPostRequest("https://jinfu.e.kuaishou.com/rest/dsp/agent/account/list", requestJson, map);
+        System.err.println(s);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        if (Check.isNull(jsonObject)) {
+            log.error("获取代理商账户列表返回数据为空");
+            return;
+        }
+        Integer result = jsonObject.getInteger("result");
+        if (result == 1) {
+            JSONArray adDspAccountList = jsonObject.getJSONArray("adDspAccountList");
+            if (!Check.isNull(adDspAccountList)) {
+                List<KuaishouAgentAccountList> addList = new ArrayList<>();
+                for (int i = 0; i < adDspAccountList.size(); i++) {
+                    JSONObject accountJson = adDspAccountList.getJSONObject(i);
+                    KuaishouAgentAccountList account = new KuaishouAgentAccountList();
+                    account.setAccountId(accountJson.getLong("accountId"));
+                    account.setUserId(accountJson.getLong("userId"));
+                    account.setAccountName(accountJson.getString("accountName"));
+                    account.setUserName(accountJson.getString("userName"));
+                    account.setAccountCreateTime(new Date(accountJson.getLong("createTime")));
+                    account.setProductName(accountJson.getString("productName"));
+                    account.setIndustry(accountJson.getString("industry"));
+                    account.setSecondIndustry(accountJson.getString("secondIndustry"));
+                    account.setCorporationName(accountJson.getString("corporationName"));
+                    addList.add(account);
+                }
+                kuaishouAgentAccountListMapper.addBatch(addList);
+                if (adDspAccountList.size() >= pageSize) {
+                    kuaishouAgentAccountListService(cookie, currentPage + 1, pageSize, createBeginTime, createEndTime);
+                }
+            }
+        } else {
+            log.info("快分销数据返回异常:", jsonObject);
+            sendMessageService.sendMessage("113dee46c7df464da78c07a985e92cd1", "磁力金牛cookin失效,请及时更新。媒体返回信息:" + jsonObject);
+        }
+    }
+}