소스 검색

增加快手代理商账户接口

xuzuoyun 5 년 전
부모
커밋
0c9f72a163

+ 5 - 0
jeecg-boot-module-system/pom.xml

@@ -145,6 +145,11 @@
             <artifactId>poi</artifactId>
             <version>3.17</version>
         </dependency>
+        <dependency>
+            <groupId>com.bstek.ureport</groupId>
+            <artifactId>ureport2-core</artifactId>
+            <version>2.2.9</version>
+        </dependency>
         <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <!-- <dependency>
             <groupId>org.apache.poi</groupId>

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/config/ureport/ServletConfig.java

@@ -9,7 +9,7 @@ import org.springframework.context.annotation.ImportResource;
 import javax.servlet.Servlet;
 
 @Configuration
-@ImportResource("classpath:ureport-console-context.xml")
+//@ImportResource("classpath:ureport-console-context.xml")
 public class ServletConfig {
 
     @Bean

+ 61 - 12
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaishouAgentAccountController.java

@@ -1,20 +1,21 @@
 package org.jeecg.modules.ctop.controller;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.io.OutputStream;
+import java.util.*;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.util.oConvertUtils;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAgentAccount;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouAgentAccountService;
-import java.util.Date;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -180,7 +181,7 @@ public class KuaishouAgentAccountController {
    * @param response
    */
   @RequestMapping(value = "/exportXls")
-  public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+  public void exportXls(HttpServletRequest request, HttpServletResponse response) throws Exception{
       // Step.1 组装查询条件
       QueryWrapper<KuaishouAgentAccount> queryWrapper = null;
       try {
@@ -197,14 +198,62 @@ public class KuaishouAgentAccountController {
       //Step.2 AutoPoi 导出Excel
       ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
       List<KuaishouAgentAccount> pageList = kuaishouAgentAccountService.list(queryWrapper);
-      //导出文件名称
-      mv.addObject(NormalExcelConstants.FILE_NAME, "快手代理商账户表列表");
-      mv.addObject(NormalExcelConstants.CLASS, KuaishouAgentAccount.class);
-      mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("快手代理商账户表列表数据", "导出人:Jeecg", "导出信息"));
-      mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
-      return mv;
+	  List<List<Object>> result = new ArrayList<>();
+      if(pageList != null && pageList.size() > 0){
+      	for (KuaishouAgentAccount kuaishouAgentAccount : pageList){
+			List<Object> rowData = new ArrayList<>();
+			rowData.add(kuaishouAgentAccount.getId());
+			rowData.add(kuaishouAgentAccount.getUserId());
+			rowData.add(kuaishouAgentAccount.getAccountName());
+			rowData.add(kuaishouAgentAccount.getBalance());
+			rowData.add(kuaishouAgentAccount.getCreditBalance());
+			rowData.add(kuaishouAgentAccount.getRebate());
+			rowData.add(kuaishouAgentAccount.getContractRebate());
+			rowData.add(kuaishouAgentAccount.getDirectRebate());
+			rowData.add(kuaishouAgentAccount.getTotalBalance());
+			rowData.add(kuaishouAgentAccount.getCorporationName());
+			if(kuaishouAgentAccount.getReviewStatus() == 1){
+				rowData.add("审核中");
+			}else if(kuaishouAgentAccount.getReviewStatus() == 2){
+				rowData.add("审核通过");
+			}else if(kuaishouAgentAccount.getReviewStatus() == 3){
+				rowData.add("审核拒绝");
+			}
+			result.add(rowData);
+		}
+	  }
+	  String[] accountHeaders = {"广告主ID", "用户ID", "广告主名称", "现金余额", "信用余额", "返点余额", "框返余额", "激励余额", "总余额", "公司名称", "审核状态"};
+	  OutputStream os = response.getOutputStream();
+	  ExportExcelUtils eeu = new ExportExcelUtils();
+	  XSSFWorkbook workbook = new XSSFWorkbook();
+	  eeu.exportExcel(workbook, 0, "账户列表", accountHeaders, result);
+	  this.setResponseHeader(response, "快手代理商账户列表.xls");
+	  workbook.write(os);
+	  os.flush();
+	  os.close();
+//      //导出文件名称
+//      mv.addObject(NormalExcelConstants.FILE_NAME, "快手代理商账户表列表");
+//      mv.addObject(NormalExcelConstants.CLASS, KuaishouAgentAccount.class);
+//      mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("快手代理商账户表列表数据", "导出人:Jeecg", "导出信息"));
+//      mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+//      return mv;
   }
-
+	 //发送响应流方法
+	 public void setResponseHeader(HttpServletResponse response, String fileName) {
+		 try {
+			 try {
+				 fileName = new String(fileName.getBytes(), "ISO8859-1");
+			 } catch (UnsupportedEncodingException e) {
+				 e.printStackTrace();
+			 }
+			 response.setContentType("application/octet-stream;charset=ISO8859-1");
+			 response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+			 response.addHeader("Pargam", "no-cache");
+			 response.addHeader("Cache-Control", "no-cache");
+		 } catch (Exception ex) {
+			 ex.printStackTrace();
+		 }
+	 }
   /**
       * 通过excel导入数据
    *

+ 4 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouAgentAccount.java

@@ -32,12 +32,12 @@ public class KuaishouAgentAccount {
 	/**id*/
 	@TableId(type = IdType.INPUT)
     @ApiModelProperty(value = "id")
-	@JsonProperty("userId")
+	@JsonProperty("accountId")
 	private Integer id;
 	/**accountId*/
-	@Excel(name = "accountId", width = 15)
-    @ApiModelProperty(value = "accountId")
-	private Integer accountId;
+	@Excel(name = "userId", width = 15)
+    @ApiModelProperty(value = "userId")
+	private Integer userId;
 	/**accountName*/
 	@Excel(name = "accountName", width = 15)
     @ApiModelProperty(value = "accountName")

+ 5 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouReportDailyAgentSum.java

@@ -38,7 +38,7 @@ public class KuaishouReportDailyAgentSum {
 	/**有消费计划数*/
 	@Excel(name = "有消费计划数", width = 15)
     @ApiModelProperty(value = "有消费计划数")
-	private Long costCampaignCount;
+	private Integer costCampaignCount;
 	/**总余额*/
 	@Excel(name = "总余额", width = 15)
     @ApiModelProperty(value = "总余额")
@@ -70,19 +70,19 @@ public class KuaishouReportDailyAgentSum {
 	/**封面曝光数*/
 	@Excel(name = "封面曝光数", width = 15)
     @ApiModelProperty(value = "封面曝光数")
-	private Long fengmianShowCount;
+	private Integer fengmianShowCount;
 	/**封面点击数*/
 	@Excel(name = "封面点击数", width = 15)
     @ApiModelProperty(value = "封面点击数")
-	private Long fengmianClickCount;
+	private Integer fengmianClickCount;
 	/**素材曝光数*/
 	@Excel(name = "素材曝光数", width = 15)
     @ApiModelProperty(value = "素材曝光数")
-	private Long sucaiShowCount;
+	private Integer sucaiShowCount;
 	/**行为数*/
 	@Excel(name = "行为数", width = 15)
     @ApiModelProperty(value = "行为数")
-	private Long convertCount;
+	private Integer convertCount;
 	/**封面点击率*/
 	@Excel(name = "封面点击率", width = 15)
     @ApiModelProperty(value = "封面点击率")

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAgentAccountMapper.xml

@@ -4,7 +4,7 @@
     <insert id="replaceBatch">
         replace into ctop_kuaishou_agent_account(
         `id`,
-        `account_id`,
+        `user_id`,
         `account_name`,
         `balance`,
         `credit_balance`,
@@ -26,7 +26,7 @@
         values
         <foreach collection="list" item="agent" separator=",">
             (#{agent.id},
-            #{agent.accountId},
+            #{agent.userId},
             #{agent.accountName},
             #{agent.balance},
             #{agent.creditBalance},

+ 19 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportDailyAgentServiceImpl.java

@@ -9,6 +9,7 @@ import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAgentMapper
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAgentSumMapper;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.http.client.CookieStore;
@@ -27,6 +28,7 @@ import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -53,7 +55,7 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
 
     public boolean loginAgent(){
         boolean loginStatus = false;
-        System.getProperties().setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
+        System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         String url = "https://agent.e.kuaishou.com";
         ChromeOptions chromeOptions = new ChromeOptions();
         chromeOptions.addArguments("--headless");
@@ -115,8 +117,10 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
     public boolean getAccount(int currentPage){
         boolean hasNextPage = false;
         try {
-            if (!loginAgent()){
-                return hasNextPage;
+            if(currentPage == 1){
+                if (!loginAgent()){
+                    return hasNextPage;
+                }
             }
             Map<String,String> headerMap = new HashMap<String,String>();
             headerMap.put("Accept","application/json");
@@ -127,10 +131,11 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
             headerMap.put("Referer","https://agent.e.kuaishou.com/");
             headerMap.put("Content-Type","application/json;charset=utf-8");
             headerMap.put("User-Agent",HttpUtils2.USER_AGENT);
-            String postData = "{\"pageInfo\":{\"currentPage\":"+currentPage+",\"pageSize\":20,\"total\":1000},\"reviewStatus\":\"-1\",\"selectType\":1,\"selectValue\":\"\",\"createBeginTime\":0,\"createEndTime\":0}";
+            String postData = "{\"pageInfo\":{\"currentPage\":"+currentPage+",\"pageSize\":200,\"total\":1000},\"reviewStatus\":\"-1\",\"selectType\":1,\"selectValue\":\"\",\"createBeginTime\":0,\"createEndTime\":0}";
             String listUrl = "https://agent.e.kuaishou.com/rest/dsp/agent/account/list";
             String result = HttpUtils2.httpPostRequestTest(listUrl,postData,headerMap);
             ObjectMapper mapper = new ObjectMapper();
+            mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
             JsonNode resultNode = mapper.readTree(result);
             Integer code = resultNode.get("result").intValue();
             if(code == 1) {
@@ -141,6 +146,16 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
                     hasNextPage = true;
                     JsonNode dataNode = iterator1.next();
                     KuaishouAgentAccount agentAccount = mapper.readValue(dataNode.toString(),KuaishouAgentAccount.class);
+                    agentAccount.setBalance(agentAccount.getBalance().divide(new BigDecimal(1000)));
+                    agentAccount.setContractRebate(agentAccount.getContractRebate().divide(new BigDecimal(1000)));
+                    agentAccount.setCreditBalance(agentAccount.getCreditBalance().divide(new BigDecimal(1000)));
+                    agentAccount.setDirectRebate(agentAccount.getDirectRebate().divide(new BigDecimal(1000)));
+                    agentAccount.setExtendedBalance(agentAccount.getExtendedBalance().divide(new BigDecimal(1000)));
+                    agentAccount.setKuaibiBalance(agentAccount.getKuaibiBalance().divide(new BigDecimal(1000)));
+                    agentAccount.setPreRebate(agentAccount.getPreRebate().divide(new BigDecimal(1000)));
+                    agentAccount.setPushBalance(agentAccount.getPushBalance().divide(new BigDecimal(1000)));
+                    agentAccount.setRebate(agentAccount.getRebate().divide(new BigDecimal(1000)));
+                    agentAccount.setTotalBalance(agentAccount.getTotalBalance().divide(new BigDecimal(1000)));
                     accountList.add(agentAccount);
                 }
                 if (accountList != null && accountList.size() > 0){