Browse Source

代理商账户列表获取

yumeng 2 years ago
parent
commit
8cd92fea0a

+ 6 - 0
ruixuan-common/src/main/java/com/ruixuan/common/utils/DateUtils.java

@@ -50,6 +50,12 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
         return new Date();
         return new Date();
     }
     }
 
 
+
+
+
+
+
+
     public static String getNowDateStr() {
     public static String getNowDateStr() {
         SimpleDateFormat simp = new SimpleDateFormat("yyyy-MM-dd");
         SimpleDateFormat simp = new SimpleDateFormat("yyyy-MM-dd");
         return simp.format(new Date());
         return simp.format(new Date());

+ 1 - 0
ruixuan-framework/src/main/java/com/ruixuan/framework/config/SecurityConfig.java

@@ -124,6 +124,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/system/user/*").permitAll()
                 .antMatchers("/system/user/*").permitAll()
                 .antMatchers("/kuaishou/promoter/*").permitAll()
                 .antMatchers("/kuaishou/promoter/*").permitAll()
                 .antMatchers("/rx/**").permitAll()
                 .antMatchers("/rx/**").permitAll()
+                .antMatchers("/agent/account/**").permitAll()
 
 
                 // 除上面外的所有请求全部需要鉴权认证
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .anyRequest().authenticated()

+ 25 - 14
ruixuan-live/src/main/java/com/ruixuan/jinniu/controller/KuaishouAgentAccountListController.java

@@ -8,6 +8,7 @@ import com.ruixuan.common.core.controller.BaseController;
 import com.ruixuan.common.core.domain.AjaxResult;
 import com.ruixuan.common.core.domain.AjaxResult;
 import com.ruixuan.common.core.page.TableDataInfo;
 import com.ruixuan.common.core.page.TableDataInfo;
 import com.ruixuan.common.enums.BusinessType;
 import com.ruixuan.common.enums.BusinessType;
+import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.poi.ExcelUtil;
 import com.ruixuan.common.utils.poi.ExcelUtil;
 import com.ruixuan.jinniu.entity.KuaishouAgentAccountList;
 import com.ruixuan.jinniu.entity.KuaishouAgentAccountList;
 import com.ruixuan.jinniu.service.IKuaishouAgentAccountListService;
 import com.ruixuan.jinniu.service.IKuaishouAgentAccountListService;
@@ -30,18 +31,33 @@ import org.springframework.web.bind.annotation.RestController;
  */
  */
 @RestController
 @RestController
 @RequestMapping("/agent/account")
 @RequestMapping("/agent/account")
-public class KuaishouAgentAccountListController extends BaseController
-{
+public class KuaishouAgentAccountListController extends BaseController {
     @Autowired
     @Autowired
     private IKuaishouAgentAccountListService kuaishouAgentAccountListService;
     private IKuaishouAgentAccountListService kuaishouAgentAccountListService;
 
 
+
+    @GetMapping("/syncAccounts")
+    public void syncAccounts() {
+        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);
+
+            }
+
+        }
+
+
+    }
+
+
     /**
     /**
      * 查询【请填写功能名称】列表
      * 查询【请填写功能名称】列表
      */
      */
     @PreAuthorize("@ss.hasPermi('system:list:list')")
     @PreAuthorize("@ss.hasPermi('system:list:list')")
     @GetMapping("/list")
     @GetMapping("/list")
-    public TableDataInfo list(KuaishouAgentAccountList kuaishouAgentAccountList)
-    {
+    public TableDataInfo list(KuaishouAgentAccountList kuaishouAgentAccountList) {
         startPage();
         startPage();
         List<KuaishouAgentAccountList> list = kuaishouAgentAccountListService.selectKuaishouAgentAccountListList(kuaishouAgentAccountList);
         List<KuaishouAgentAccountList> list = kuaishouAgentAccountListService.selectKuaishouAgentAccountListList(kuaishouAgentAccountList);
         return getDataTable(list);
         return getDataTable(list);
@@ -53,8 +69,7 @@ public class KuaishouAgentAccountListController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:list:export')")
     @PreAuthorize("@ss.hasPermi('system:list:export')")
     @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
     @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     @PostMapping("/export")
-    public void export(HttpServletResponse response, KuaishouAgentAccountList kuaishouAgentAccountList)
-    {
+    public void export(HttpServletResponse response, KuaishouAgentAccountList kuaishouAgentAccountList) {
         List<KuaishouAgentAccountList> list = kuaishouAgentAccountListService.selectKuaishouAgentAccountListList(kuaishouAgentAccountList);
         List<KuaishouAgentAccountList> list = kuaishouAgentAccountListService.selectKuaishouAgentAccountListList(kuaishouAgentAccountList);
         ExcelUtil<KuaishouAgentAccountList> util = new ExcelUtil<KuaishouAgentAccountList>(KuaishouAgentAccountList.class);
         ExcelUtil<KuaishouAgentAccountList> util = new ExcelUtil<KuaishouAgentAccountList>(KuaishouAgentAccountList.class);
         util.exportExcel(response, list, "【请填写功能名称】数据");
         util.exportExcel(response, list, "【请填写功能名称】数据");
@@ -65,8 +80,7 @@ public class KuaishouAgentAccountListController extends BaseController
      */
      */
     @PreAuthorize("@ss.hasPermi('system:list:query')")
     @PreAuthorize("@ss.hasPermi('system:list:query')")
     @GetMapping(value = "/{accountId}")
     @GetMapping(value = "/{accountId}")
-    public AjaxResult getInfo(@PathVariable("accountId") Long accountId)
-    {
+    public AjaxResult getInfo(@PathVariable("accountId") Long accountId) {
         return AjaxResult.success(kuaishouAgentAccountListService.selectKuaishouAgentAccountListByAccountId(accountId));
         return AjaxResult.success(kuaishouAgentAccountListService.selectKuaishouAgentAccountListByAccountId(accountId));
     }
     }
 
 
@@ -76,8 +90,7 @@ public class KuaishouAgentAccountListController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:list:add')")
     @PreAuthorize("@ss.hasPermi('system:list:add')")
     @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
     @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
     @PostMapping
     @PostMapping
-    public AjaxResult add(@RequestBody KuaishouAgentAccountList kuaishouAgentAccountList)
-    {
+    public AjaxResult add(@RequestBody KuaishouAgentAccountList kuaishouAgentAccountList) {
         return toAjax(kuaishouAgentAccountListService.insertKuaishouAgentAccountList(kuaishouAgentAccountList));
         return toAjax(kuaishouAgentAccountListService.insertKuaishouAgentAccountList(kuaishouAgentAccountList));
     }
     }
 
 
@@ -87,8 +100,7 @@ public class KuaishouAgentAccountListController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:list:edit')")
     @PreAuthorize("@ss.hasPermi('system:list:edit')")
     @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
     @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
     @PutMapping
     @PutMapping
-    public AjaxResult edit(@RequestBody KuaishouAgentAccountList kuaishouAgentAccountList)
-    {
+    public AjaxResult edit(@RequestBody KuaishouAgentAccountList kuaishouAgentAccountList) {
         return toAjax(kuaishouAgentAccountListService.updateKuaishouAgentAccountList(kuaishouAgentAccountList));
         return toAjax(kuaishouAgentAccountListService.updateKuaishouAgentAccountList(kuaishouAgentAccountList));
     }
     }
 
 
@@ -98,8 +110,7 @@ public class KuaishouAgentAccountListController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:list:remove')")
     @PreAuthorize("@ss.hasPermi('system:list:remove')")
     @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
     @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
     @DeleteMapping("/{accountIds}")
     @DeleteMapping("/{accountIds}")
-    public AjaxResult remove(@PathVariable Long[] accountIds)
-    {
+    public AjaxResult remove(@PathVariable Long[] accountIds) {
         return toAjax(kuaishouAgentAccountListService.deleteKuaishouAgentAccountListByAccountIds(accountIds));
         return toAjax(kuaishouAgentAccountListService.deleteKuaishouAgentAccountListByAccountIds(accountIds));
     }
     }
 }
 }

+ 6 - 3
ruixuan-live/src/main/java/com/ruixuan/jinniu/mapper/KuaishouAgentAccountListMapper.java

@@ -1,8 +1,8 @@
 package com.ruixuan.jinniu.mapper;
 package com.ruixuan.jinniu.mapper;
 
 
 
 
-
 import com.ruixuan.jinniu.entity.KuaishouAgentAccountList;
 import com.ruixuan.jinniu.entity.KuaishouAgentAccountList;
+import org.apache.ibatis.annotations.Param;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -13,8 +13,7 @@ import java.util.List;
  * @author ruoyi
  * @author ruoyi
  * @date 2023-03-15
  * @date 2023-03-15
  */
  */
-public interface KuaishouAgentAccountListMapper
-{
+public interface KuaishouAgentAccountListMapper {
     /**
     /**
      * 查询【请填写功能名称】
      * 查询【请填写功能名称】
      *
      *
@@ -62,4 +61,8 @@ public interface KuaishouAgentAccountListMapper
      * @return 结果
      * @return 结果
      */
      */
     public int deleteKuaishouAgentAccountListByAccountIds(Long[] accountIds);
     public int deleteKuaishouAgentAccountListByAccountIds(Long[] accountIds);
+
+    List<String> getCookie();
+
+    void addBatch(@Param("adds") List<KuaishouAgentAccountList> adds);
 }
 }

+ 5 - 2
ruixuan-live/src/main/java/com/ruixuan/jinniu/service/IKuaishouAgentAccountListService.java

@@ -12,8 +12,7 @@ import java.util.List;
  * @author ruoyi
  * @author ruoyi
  * @date 2023-03-15
  * @date 2023-03-15
  */
  */
-public interface IKuaishouAgentAccountListService
-{
+public interface IKuaishouAgentAccountListService {
     /**
     /**
      * 查询【请填写功能名称】
      * 查询【请填写功能名称】
      *
      *
@@ -61,5 +60,9 @@ public interface IKuaishouAgentAccountListService
      * @return 结果
      * @return 结果
      */
      */
     public int deleteKuaishouAgentAccountListByAccountId(Long accountId);
     public int deleteKuaishouAgentAccountListByAccountId(Long accountId);
+
+    List<String> getCookie();
+
+    void kuaishouAgentAccountListService(String cookie, Integer currentPage, Integer pageSize, Long createBeginTime, Long createEndTime);
 }
 }
 
 

+ 85 - 1
ruixuan-live/src/main/java/com/ruixuan/jinniu/service/impl/KuaishouAgentAccountListServiceImpl.java

@@ -1,12 +1,17 @@
 package com.ruixuan.jinniu.service.impl;
 package com.ruixuan.jinniu.service.impl;
 
 
 
 
-import java.util.List;
+import java.util.*;
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.DateUtils;
 import com.ruixuan.common.utils.DateUtils;
+import com.ruixuan.common.utils.http.HttpUtil;
 import com.ruixuan.jinniu.entity.KuaishouAgentAccountList;
 import com.ruixuan.jinniu.entity.KuaishouAgentAccountList;
 import com.ruixuan.jinniu.mapper.KuaishouAgentAccountListMapper;
 import com.ruixuan.jinniu.mapper.KuaishouAgentAccountListMapper;
 import com.ruixuan.jinniu.service.IKuaishouAgentAccountListService;
 import com.ruixuan.jinniu.service.IKuaishouAgentAccountListService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -18,6 +23,7 @@ import org.springframework.stereotype.Service;
  * @date 2023-03-15
  * @date 2023-03-15
  */
  */
 @Service
 @Service
+@Slf4j
 public class KuaishouAgentAccountListServiceImpl implements IKuaishouAgentAccountListService {
 public class KuaishouAgentAccountListServiceImpl implements IKuaishouAgentAccountListService {
     @Autowired
     @Autowired
     private KuaishouAgentAccountListMapper kuaishouAgentAccountListMapper;
     private KuaishouAgentAccountListMapper kuaishouAgentAccountListMapper;
@@ -89,5 +95,83 @@ public class KuaishouAgentAccountListServiceImpl implements IKuaishouAgentAccoun
     public int deleteKuaishouAgentAccountListByAccountId(Long accountId) {
     public int deleteKuaishouAgentAccountListByAccountId(Long accountId) {
         return kuaishouAgentAccountListMapper.deleteKuaishouAgentAccountListByAccountId(accountId);
         return kuaishouAgentAccountListMapper.deleteKuaishouAgentAccountListByAccountId(accountId);
     }
     }
+
+    @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 = HttpUtil.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);
+
+                }
+
+            }
+
+
+        }
+
+
+        //
+
+
+    }
 }
 }
 
 

+ 31 - 0
ruixuan-live/src/main/resources/mapper/jinniu/KuaishouAgentAccountListMapper.xml

@@ -40,6 +40,9 @@
         <include refid="selectKuaishouAgentAccountListVo"/>
         <include refid="selectKuaishouAgentAccountListVo"/>
         where account_id = #{accountId}
         where account_id = #{accountId}
     </select>
     </select>
+    <select id="getCookie" resultType="java.lang.String">
+        select  cookie  from kuaishou_agent_cookie
+    </select>
 
 
     <insert id="insertKuaishouAgentAccountList" parameterType="com.ruixuan.jinniu.entity.KuaishouAgentAccountList">
     <insert id="insertKuaishouAgentAccountList" parameterType="com.ruixuan.jinniu.entity.KuaishouAgentAccountList">
         insert into kuaishou_agent_account_list
         insert into kuaishou_agent_account_list
@@ -70,6 +73,34 @@
             <if test="updateTime != null">#{updateTime},</if>
             <if test="updateTime != null">#{updateTime},</if>
         </trim>
         </trim>
     </insert>
     </insert>
+    <insert id="addBatch">
+        replace into 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>
 
 
     <update id="updateKuaishouAgentAccountList" parameterType="com.ruixuan.jinniu.entity.KuaishouAgentAccountList">
     <update id="updateKuaishouAgentAccountList" parameterType="com.ruixuan.jinniu.entity.KuaishouAgentAccountList">
         update kuaishou_agent_account_list
         update kuaishou_agent_account_list