Browse Source

聚划算报表

syh 4 years ago
parent
commit
14e147241e

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

@@ -1,6 +1,7 @@
 package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.common.module.annotation.AutoLog;
+import com.alibaba.excel.event.AnalysisEventListener;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -11,11 +12,20 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.modules.ctop.entity.KuaishouChannelRegInfo;
 import org.jeecg.modules.ctop.service.IKuaishouChannelRegInfoService;
+import org.jeecg.modules.excelutil.ExcelUtils;
+import org.jeecg.modules.excelutil.KuaishouChannelRegInfoExcelListener;
+import org.jeecg.modules.excelutil.entity.KuaishouChannelRegInfoEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.Arrays;
+import java.util.Map;
 
 /**
  * 快手渠道注册信息表
@@ -161,4 +171,39 @@ public class KuaishouChannelRegInfoController {
         }
         return result;
     }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        //1.读Excel
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            FileInputStream fis = null;
+            try {
+                MultipartFile file = entity.getValue();
+                fis = (FileInputStream) file.getInputStream();
+                AnalysisEventListener listener = new KuaishouChannelRegInfoExcelListener();
+                Boolean flag = ExcelUtils.readExcel(fis, KuaishouChannelRegInfoEntity.class, listener);
+                System.out.println("导入是否成功:" + flag);
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                if (fis != null) {
+                    try {
+                        fis.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+        return Result.ok("文件导入成功!");
+    }
 }

+ 59 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/JhsBakendDataExcelListener.java

@@ -0,0 +1,59 @@
+package org.jeecg.modules.excelutil;
+
+import cn.com.ctop.common.module.utils.SpringUtils;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.ctop.service.impl.KuaishouChannelRegInfoServiceImpl;
+import org.jeecg.modules.excelutil.entity.KuaishouChannelRegInfoEntity;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class JhsBakendDataExcelListener extends AnalysisEventListener {
+    //自定义用于暂时存储data。
+    //可以通过实例获取该值
+    private List<Object> datas = new ArrayList<>();
+
+    @Override
+    public void invoke(Object object, AnalysisContext context) {
+        //数据存储到list,供批量处理,或后续自己业务逻辑处理。
+        datas.add(object);
+        //根据自己业务做处理
+        doSomething(object);
+    }
+
+    private void doSomething(Object object) {
+        //入库调用接口
+        KuaishouChannelRegInfoEntity regInfo = (KuaishouChannelRegInfoEntity) object;
+        regInfo.setCreateTime(new Date());
+        regInfo.setUpdateTime(new Date());
+        regInfo.setChannelCode(regInfo.getChannelCode() + "_" + regInfo.getChildChannelCode());
+        String date = regInfo.getStateDate();
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
+        try {
+            date = DateUtils.formatDate(dateFormat.parse(date));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        regInfo.setStateDate(date);
+        KuaishouChannelRegInfoServiceImpl regInfoService = SpringUtils.getApplicationContext().getBean(KuaishouChannelRegInfoServiceImpl.class);
+        regInfoService.saveOrUpdateBychannelCodeAndDate(regInfo);
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext context) {
+        // datas.clear();//解析结束销毁不用的资源
+    }
+
+    public List<Object> getDatas() {
+        return datas;
+    }
+
+    public void setDatas(List<Object> datas) {
+        this.datas = datas;
+    }
+}

+ 123 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/JhsBakendDataEntity.java

@@ -0,0 +1,123 @@
+package org.jeecg.modules.excelutil.entity;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.metadata.BaseRowModel;
+
+import java.util.Date;
+
+/**
+ * 聚划算后端数据
+ */
+public class JhsBakendDataEntity extends BaseRowModel {
+    @ExcelProperty(index = 0, value = "日期")
+    private String stateDate;
+    @ExcelProperty(index = 1, value = "业务线")
+    private String productLine;
+    @ExcelProperty(index = 2, value = "任务名称")
+    private String taskName;
+    @ExcelProperty(index = 3, value = "客户端")
+    private String clientName;
+    @ExcelProperty(index = 4, value = "渠道id")
+    private String channelId;
+    @ExcelProperty(index = 5, value = "渠道名称")
+    private String channelName;
+    @ExcelProperty(index = 5, value = "adid")
+    private String adId;
+    @ExcelProperty(index = 5, value = "页面访问UV x")
+    private Long pageView;
+    @ExcelProperty(index = 5, value = "成交笔数 y")
+    private Long dealNumber;
+    private Date createTime;
+    private Date updateTime;
+
+    public JhsBakendDataEntity() {
+    }
+
+    public String getStateDate() {
+        return stateDate;
+    }
+
+    public void setStateDate(String stateDate) {
+        this.stateDate = stateDate;
+    }
+
+    public String getProductLine() {
+        return productLine;
+    }
+
+    public void setProductLine(String productLine) {
+        this.productLine = productLine;
+    }
+
+    public String getTaskName() {
+        return taskName;
+    }
+
+    public void setTaskName(String taskName) {
+        this.taskName = taskName;
+    }
+
+    public String getClientName() {
+        return clientName;
+    }
+
+    public void setClientName(String clientName) {
+        this.clientName = clientName;
+    }
+
+    public String getChannelId() {
+        return channelId;
+    }
+
+    public void setChannelId(String channelId) {
+        this.channelId = channelId;
+    }
+
+    public String getChannelName() {
+        return channelName;
+    }
+
+    public void setChannelName(String channelName) {
+        this.channelName = channelName;
+    }
+
+    public String getAdId() {
+        return adId;
+    }
+
+    public void setAdId(String adId) {
+        this.adId = adId;
+    }
+
+    public Long getPageView() {
+        return pageView;
+    }
+
+    public void setPageView(Long pageView) {
+        this.pageView = pageView;
+    }
+
+    public Long getDealNumber() {
+        return dealNumber;
+    }
+
+    public void setDealNumber(Long dealNumber) {
+        this.dealNumber = dealNumber;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+}

+ 2 - 2
jeecg-boot-module-system/src/main/resources/jeecg/jeecg_database.properties

@@ -1,9 +1,9 @@
 #mysql
 diver_name=com.mysql.jdbc.Driver
-url=jdbc:mysql://39.106.184.70:3306/jeecg-boot?useUnicode=true&characterEncoding=UTF-8
+url=jdbc:mysql://139.186.27.96:3306/okr?characterEncoding=UTF-8&useUnicode=true&useSSL=false
 username=hcst
 password=test@20190531
-database_name=jeecg-boot
+database_name=okr
 #oracle
 #diver_name=oracle.jdbc.driver.OracleDriver
 #url=jdbc:oracle:thin:@192.168.1.200:1521:ORCL

+ 11 - 13
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -122,21 +122,19 @@ public class SampleTest {
 
     @Test
     public void loadKuaishouAgentData() {
-//        for(int i=0;i<20;i++){
-//            String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(),-i));
-//            kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
-//        }
-//
         kuaishouReportDailyAgentService.loginAgent();
-        try {
-            for (int i = 1; i < 30; i++) {
-                kuaishouReportDailyAgentService.getAccount(i);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
+        for(int i=0;i<20;i++){
+            String currentDate = DateUtils.formatDate(DateUtils.addDay(new Date(),-i));
+            kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
         }
-//        String currentDate = D  ateUtils.formatDate(DateUtils.addDay(new Date(),-1));
-//        kuaishouReportDailyAgentService.getReport(currentDate,DateUtils.getNowDate("yyyy-MM-dd"));
+//
+//        try {
+//            for (int i = 1; i < 30; i++) {
+//                kuaishouReportDailyAgentService.getAccount(i);
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
     }
 
     @Autowired