瀏覽代碼

数据汇聚

孙永军 2 年之前
父節點
當前提交
53bd8f855a

+ 1 - 0
build.gradle

@@ -62,6 +62,7 @@ dependencies {
     implementation 'org.apache.commons:commons-pool2'
     implementation 'com.opencsv:opencsv:4.5'
     implementation 'cn.hutool:hutool-http:5.7.20'
+    implementation 'cn.hutool:hutool-poi:5.7.20'
     implementation 'org.apache.poi:poi-ooxml:5.0.0'
     implementation 'com.alibaba:easyexcel:2.2.6'
     implementation 'org.springframework.retry:spring-retry:1.3.1'

+ 51 - 0
src/main/java/com/sxtvs/open/api/odata/controller/NewMediaController.java

@@ -0,0 +1,51 @@
+package com.sxtvs.open.api.odata.controller;
+
+
+import com.sxtvs.open.api.odata.dto.Agg;
+import com.sxtvs.open.api.odata.dto.NewMedia;
+import com.sxtvs.open.api.odata.dto.RequestDTO;
+import com.sxtvs.open.api.odata.service.impl.OpenDataServiceImpl;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.http.util.TextUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("new-media")
+public class NewMediaController {
+
+    @Resource
+    private OpenDataServiceImpl openDataService;
+
+    @RequestMapping("agg")
+    public List<Agg> aggList(@RequestBody RequestDTO requestDTO){
+        return openDataService.aggList(requestDTO);
+    }
+
+    @RequestMapping("list")
+    public List<NewMedia> newMediaList(@RequestBody RequestDTO requestDTO){
+        return openDataService.newMediaList(requestDTO);
+    }
+
+    @RequestMapping("platform")
+    public  List<Map<String, Object>>  platform(@RequestParam(value = "kh", defaultValue = "0") String kh){
+//        return new String[]{"微博", "微信", "头条", "抖音", "快手", "B站"};
+        return openDataService.platform(kh);
+    }
+
+    @RequestMapping("export")
+    @ResponseBody
+    public void export(HttpServletResponse response, HttpServletRequest request){
+        String end = request.getParameter("end");
+        String start = request.getParameter("start");
+        String sort = request.getParameter("sort");
+        if(TextUtils.isEmpty(sort)){
+            sort = "";
+        }
+        openDataService.export(start, end, sort, response);
+    }
+}

+ 10 - 12
src/main/java/com/sxtvs/open/api/odata/controller/OauthController.java

@@ -35,9 +35,9 @@ public class OauthController {
     public String douyinCallback(String code, String state) {
         var token = oauthService.loadStateMapping(state);
         logger.info("key", "oauth/douyin/callback", "code", code, "state", state, "token", token);
-        // todo 用户数据入库
+
         douyinAccountService.upsert(code);
-        return "redirect:/oauth/close";
+        return "redirect:https://open.sxtvs.net/oauth/close";
     }
 
     @Autowired
@@ -47,9 +47,9 @@ public class OauthController {
     public String kuaishouCallback(String code, String state) {
         var token = oauthService.loadStateMapping(state);
         logger.info("key", "oauth/kuaishou/callback", "code", code, "state", state, "token", token);
-        // todo 用户数据入库
+
         kuaishouAccountService.upsert(code);
-        return "redirect:https://cxzx.smcic.net/mediaAll/index.html#/main_home/convergence";
+        return "redirect:https://open.sxtvs.net/oauth/close";
     }
 
     @Autowired
@@ -59,9 +59,9 @@ public class OauthController {
     public String toutiaoCallback(String code, String state) {
         var token = oauthService.loadStateMapping(state);
         logger.info("key", "oauth/toutiao/callback", "code", code, "state", state, "token", token);
-        // todo 用户数据入库
+
         toutiaoAccountService.upsert(code);
-        return "redirect:https://cxzx.smcic.net/mediaAll/index.html#/main_home/convergence";
+        return "redirect:https://open.sxtvs.net/oauth/close";
     }
 
     @Autowired
@@ -70,9 +70,9 @@ public class OauthController {
     @RequestMapping("weibo/callback")
     public String weiboCallback(@RequestParam("network_group_id") String networkGroupId, String state) throws JsonProcessingException {
         logger.info("key", "oauth/weibo/callback", "code", networkGroupId);
-        // todo 用户数据入库
+
         weiboAccountService.upsert(networkGroupId);
-        return "redirect:/oauth/close";
+        return "redirect:https://open.sxtvs.net/oauth/close";
     }
 
     @Autowired
@@ -82,9 +82,8 @@ public class OauthController {
     public String bilibiliCallback(String code, String state) {
         var token = oauthService.loadStateMapping(state);
         logger.info("key", "oauth/bilibili/callback", "code", code, "state", state, "token", token);
-        // todo 用户数据入库
         bilibiliAccountService.upsert(code);
-        return "redirect:https://cxzx.smcic.net/mediaAll/index.html#/main_home/convergence";
+        return "redirect:https://open.sxtvs.net/oauth/close";
     }
 
     @Autowired
@@ -105,9 +104,8 @@ public class OauthController {
                 e.printStackTrace();
             }
         }
-        // todo 用户数据入库
         wxRestService.apiQueryAuth(authCode);
-        return "redirect:https://open.sxtvs.net/login.html?platform=weixin";
+        return "redirect:https://open.sxtvs.net/oauth/close";
     }
 
     @RequestMapping("close")

+ 1 - 1
src/main/java/com/sxtvs/open/api/odata/controller/OauthRestController.java

@@ -138,7 +138,7 @@ public class OauthRestController {
     }
 
     @RequestMapping("weixin/code/v1")
-    public ModelAndView weixinQrCodeV1()  throws UnsupportedEncodingException {
+    public ModelAndView weixinQrCodeV1(){
 //        var token = HttpContextUtil.mustToken();
 //        logger.info("key", "oauth/weixin/code", "token", token);
         WxApiCreatePreAuthCodeResponse preAuthCodeResponse = wxRestService.createPreAuthCodeResponse();

+ 73 - 0
src/main/java/com/sxtvs/open/api/odata/dao/OpenDataMapper.java

@@ -0,0 +1,73 @@
+package com.sxtvs.open.api.odata.dao;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sxtvs.open.api.odata.dto.Agg;
+import com.sxtvs.open.api.odata.dto.NewMedia;
+import com.sxtvs.open.api.odata.entity.OpenData;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface OpenDataMapper extends BaseMapper<OpenData> {
+
+    List<NewMedia> newMediaList(@Param("platform") String platform,
+                                @Param("start") String start,
+                                @Param("end") String end,
+                                @Param("match") String match,
+                                @Param("nickNames") List<String> nikeNames,
+                                @Param("sort") String sort,
+                                @Param("order") Integer order);
+
+    List<Agg> weiboAggList(@Param("start") String start,
+                           @Param("end") String end,
+                           @Param("match") String match,
+                           @Param("nickNames") List<String> nikeNames,
+                           @Param("sort") String sort,
+                           @Param("order") Integer order);
+
+    List<Agg> weixinAggList(@Param("start") String start,
+                            @Param("end") String end,
+                            @Param("match") String match,
+                            @Param("nickNames") List<String> nikeNames,
+                            @Param("sort") String sort,
+                            @Param("order") Integer order);
+
+    List<Agg> toutiaoAggList(@Param("start") String start,
+                             @Param("end") String end,
+                             @Param("match") String match,
+                             @Param("nickNames") List<String> nikeNames,
+                             @Param("sort") String sort,
+                             @Param("order") Integer order);
+
+    List<Agg> douyinAggList(@Param("start") String start,
+                            @Param("end") String end,
+                            @Param("match") String match,
+                            @Param("nickNames") List<String> nikeNames,
+                            @Param("sort") String sort,
+                            @Param("order") Integer order);
+
+    List<Agg> kuaishouAggList(@Param("start") String start,
+                              @Param("end") String end,
+                              @Param("match") String match,
+                              @Param("nickNames") List<String> nikeNames,
+                              @Param("sort") String sort,
+                              @Param("order") Integer order);
+
+    List<Agg> biliAggList(@Param("start") String start,
+                          @Param("end") String end,
+                          @Param("match") String match,
+                          @Param("nickNames") List<String> nikeNames,
+                          @Param("sort") String sort,
+                          @Param("order") Integer order);
+
+    String weiboLastDt();
+    String weixinLastDt();
+    String toutiaoLastDt();
+    String douyinLastDt();
+    String kuaishouLastDt();
+    String biliLastDt();
+
+    List<String> departmentGroup(@Param("groupName") String groupName,@Param("platform") String platform);
+    String getDepGroup(@Param("userId") String userId);
+}

+ 27 - 0
src/main/java/com/sxtvs/open/api/odata/dto/Agg.java

@@ -0,0 +1,27 @@
+package com.sxtvs.open.api.odata.dto;
+
+import lombok.Data;
+
+@Data
+public class Agg {
+
+    private String userName;
+
+    private String depName;
+
+    private Long readCount;
+
+
+    private Long fans;
+
+    private Integer publishCount;
+
+
+    private Integer shareCount;
+
+    private Integer commentCount;
+
+    private Integer likeCount;
+
+    private Integer favCount;
+}

+ 27 - 0
src/main/java/com/sxtvs/open/api/odata/dto/NewMedia.java

@@ -0,0 +1,27 @@
+package com.sxtvs.open.api.odata.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class NewMedia {
+
+    private String userName;
+
+    private String depName;
+
+    private String title;
+
+    private Long shareCount;
+
+    private Long playCount;
+
+    private Long likeCount;
+
+    private Long commentCount;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date publishTime;
+}

+ 114 - 0
src/main/java/com/sxtvs/open/api/odata/dto/RequestDTO.java

@@ -0,0 +1,114 @@
+package com.sxtvs.open.api.odata.dto;
+
+import java.time.LocalDate;
+
+public class RequestDTO {
+    private String platform;
+
+//    兼容旧版
+    private LocalDate dt;
+
+    private LocalDate start;
+
+    private LocalDate end;
+
+    private String match;
+
+    private String groupName;
+
+    private String userId;
+
+    private String sort = "";
+
+    private Integer order;
+
+    public RequestDTO() {
+    }
+
+    public RequestDTO(String platform, LocalDate dt) {
+        this.platform = platform;
+        this.start = dt;
+        this.end = dt;
+    }
+
+    public RequestDTO(String platform, LocalDate start, LocalDate end, String sort) {
+        this.platform = platform;
+        this.start = start;
+        this.end = end;
+        this.sort = sort;
+    }
+
+    public String getPlatform() {
+        return platform;
+    }
+
+    public void setPlatform(String platform) {
+        this.platform = platform;
+    }
+
+    public LocalDate getDt() {
+        return dt;
+    }
+
+    public void setDt(LocalDate dt) {
+        this.start = dt;
+        this.end = dt;
+        this.dt = dt;
+    }
+
+    public String getMatch() {
+        return match;
+    }
+
+    public void setMatch(String match) {
+        this.match = match;
+    }
+
+    public String getGroupName() {
+        return groupName;
+    }
+
+    public void setGroupName(String groupName) {
+        this.groupName = groupName;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public LocalDate getStart() {
+        return start;
+    }
+
+    public void setStart(LocalDate start) {
+        this.start = start;
+    }
+
+    public LocalDate getEnd() {
+        return end;
+    }
+
+    public void setEnd(LocalDate end) {
+        this.end = end;
+    }
+
+    public String getSort() {
+        return sort;
+    }
+
+    public void setSort(String sort) {
+        this.sort = sort;
+    }
+
+    public Integer getOrder() {
+        return order;
+    }
+
+    public void setOrder(Integer order) {
+        this.order = order;
+    }
+}

+ 30 - 0
src/main/java/com/sxtvs/open/api/odata/entity/OpenData.java

@@ -0,0 +1,30 @@
+package com.sxtvs.open.api.odata.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Data
+public class OpenData {
+    @TableId
+    private String id;
+
+    private String nickName;
+
+    private String platForm;
+
+    private String openId;
+
+    private String title;
+
+    private Integer playCount;
+
+    private Integer likeCount;
+
+    private Integer favCount;
+
+    private String depName;
+
+    private LocalDateTime publishTime;
+}

+ 8 - 0
src/main/java/com/sxtvs/open/api/odata/service/IOpenDataService.java

@@ -0,0 +1,8 @@
+package com.sxtvs.open.api.odata.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.sxtvs.open.api.odata.entity.OpenData;
+
+
+public interface IOpenDataService extends IService<OpenData> {
+}

+ 236 - 0
src/main/java/com/sxtvs/open/api/odata/service/impl/OpenDataServiceImpl.java

@@ -0,0 +1,236 @@
+package com.sxtvs.open.api.odata.service.impl;
+
+import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.sxtvs.open.api.odata.dao.OpenDataMapper;
+import com.sxtvs.open.api.odata.dto.Agg;
+import com.sxtvs.open.api.odata.dto.NewMedia;
+import com.sxtvs.open.api.odata.dto.RequestDTO;
+import com.sxtvs.open.api.odata.entity.OpenData;
+import com.sxtvs.open.api.odata.service.IOpenDataService;
+import jakarta.servlet.ServletOutputStream;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.http.util.TextUtils;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class OpenDataServiceImpl extends ServiceImpl<OpenDataMapper, OpenData> implements IOpenDataService {
+    public List<Agg> aggList(RequestDTO requestDTO){
+        DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMdd");
+//        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMM");
+        DateTimeFormatter dtf3 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+//        DateTimeFormatter dtf4 = DateTimeFormatter.ofPattern("yyyy-MM");
+        List<Agg> newMediaList = new ArrayList<>();
+        List<String> names = new ArrayList<>();
+        if(!TextUtils.isEmpty(requestDTO.getUserId())){
+            requestDTO.setGroupName(baseMapper.getDepGroup(requestDTO.getUserId()));
+        }
+        if (!TextUtils.isEmpty(requestDTO.getGroupName())){
+            names = baseMapper.departmentGroup(requestDTO.getGroupName(), null);
+        }
+        switch (requestDTO.getPlatform()){
+            case "微博":
+                newMediaList = baseMapper.weiboAggList(dtf1.format(requestDTO.getStart()), dtf1.format(requestDTO.getEnd()), requestDTO.getMatch(), names, aggSort(requestDTO.getSort()), requestDTO.getOrder());
+                break;
+            case "微信":
+                newMediaList = baseMapper.weixinAggList(dtf1.format(requestDTO.getStart()), dtf1.format(requestDTO.getEnd()), requestDTO.getMatch(), names, aggSort(requestDTO.getSort()), requestDTO.getOrder());
+                break;
+            case "头条":
+                newMediaList = baseMapper.toutiaoAggList(dtf3.format(requestDTO.getStart()), dtf3.format(requestDTO.getEnd()), requestDTO.getMatch(), names, aggSort(requestDTO.getSort()), requestDTO.getOrder());
+                break;
+            case "抖音":
+                newMediaList = baseMapper.douyinAggList(dtf1.format(requestDTO.getStart()), dtf1.format(requestDTO.getEnd()), requestDTO.getMatch(), names, aggSort(requestDTO.getSort()), requestDTO.getOrder());
+                break;
+            case "快手":
+                newMediaList = baseMapper.kuaishouAggList(dtf3.format(requestDTO.getStart()), dtf3.format(requestDTO.getEnd()), requestDTO.getMatch(), names, aggSort(requestDTO.getSort()), requestDTO.getOrder());
+                break;
+            case "B站":
+                newMediaList = baseMapper.biliAggList(dtf3.format(requestDTO.getStart()), dtf3.format(requestDTO.getEnd()), requestDTO.getMatch(), names, aggSort(requestDTO.getSort()), requestDTO.getOrder());
+                break;
+        }
+        return newMediaList;
+    }
+
+    public List<NewMedia> newMediaList(RequestDTO requestDTO){
+        DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        List<String> names = new ArrayList<>();
+        if(!TextUtils.isEmpty(requestDTO.getUserId())){
+            requestDTO.setGroupName(baseMapper.getDepGroup(requestDTO.getUserId()));
+            names = baseMapper.departmentGroup(requestDTO.getGroupName(), requestDTO.getPlatform());
+        }
+
+        return baseMapper.newMediaList(requestDTO.getPlatform(), dtf1.format(requestDTO.getStart()), dtf1.format(requestDTO.getEnd()), requestDTO.getMatch(), names, listSort(requestDTO.getSort()), requestDTO.getOrder());
+    }
+
+    private String listSort(String sort){
+        String rs = "publish_time";
+        switch (sort){
+            case "playCount":
+                rs = "play_count";
+                break;
+            case "likeCount":
+                rs = "like_count";
+                break;
+            case "commentCount":
+                rs = "comment_count";
+                break;
+            case "shareCount":
+                rs = "share_count";
+                break;
+        }
+        return rs;
+    }
+
+    private String aggSort(String sort){
+        String rs = "read_count";
+        switch (sort){
+            case "fans":
+                rs = "fans";
+                break;
+            case "publishCount":
+                rs = "publish_count";
+                break;
+            case "commentCount":
+                rs = "comment_count";
+                break;
+            case "shareCount":
+                rs = "share_count";
+                break;
+            case "likeCount":
+                rs = "like_count";
+                break;
+            case "favCount":
+                rs = "fav_count";
+                break;
+        }
+        return rs;
+    }
+
+    public void export(String start, String end, String sort, HttpServletResponse response){
+        String[] platforms = new String[]{"微博", "微信", "头条", "抖音", "快手", "B站"};
+        ExcelWriter writer = ExcelUtil.getWriter();
+        for(String platform : platforms){
+            if (platform.equals("微博")){
+                writer.renameSheet(platform);
+            }else{
+                writer.setSheet(platform);
+            }
+            List<Agg> aggs = aggList(new RequestDTO(platform, LocalDate.parse(start), LocalDate.parse(end), sort));
+            writer.clearHeaderAlias();
+            writer.addHeaderAlias("userName", "账号");
+            writer.addHeaderAlias("depName", "部门");
+            writer.addHeaderAlias("publishCount", "发稿量");
+//            writer.addHeaderAlias("monthPublishCount", "月发稿量");
+            writer.addHeaderAlias("readCount", "阅读量");
+//            writer.addHeaderAlias("monthReadCount", "本月累计阅读量");
+            if (platform.equals("抖音") || platform.equals("微博") || platform.equals("微信")){
+                writer.addHeaderAlias("fans", "粉丝数");
+                writer.addHeaderAlias("shareCount", "转发量");
+            }
+            if (platform.equals("抖音") || platform.equals("微博") || platform.equals("快手")){
+                writer.addHeaderAlias("likeCount", "点赞量");
+            }
+            if (platform.equals("微博") || platform.equals("快手")){
+                writer.addHeaderAlias("commentCount", "评论量");
+            }
+            if (platform.equals("微信")){
+                writer.addHeaderAlias("favCount", "收藏量");
+            }
+            writer.setOnlyAlias(true);
+
+            writer.write(aggs, true);
+            for(int i = 0; i < 6; i++){
+                writer.setColumnWidth(i, 18);
+            }
+
+            List<NewMedia> newMediaList = newMediaList(new RequestDTO(platform, LocalDate.parse(start), LocalDate.parse(end), sort));
+            if(newMediaList.size() > 60000){
+                newMediaList = newMediaList.subList(0,60000);
+            }
+            writer.clearHeaderAlias();
+            writer.setSheet(platform + "【清单】");
+            writer.addHeaderAlias("userName", "账号");
+            writer.addHeaderAlias("depName", "部门");
+            writer.addHeaderAlias("title", "篇名");
+            writer.addHeaderAlias("playCount", "传播量");
+            if (!platform.equals("快手") && !platform.equals("微博")){
+                writer.addHeaderAlias("shareCount", "转发量");
+            }
+            writer.addHeaderAlias("publishTime", "发布时间");
+
+            writer.setOnlyAlias(true);
+            writer.write(newMediaList, true);
+            for(int i = 0; i < 6; i++){
+                writer.setColumnWidth(i, 18);
+            }
+        }
+
+        String name = "";
+        try {
+            name = URLEncoder.encode("新媒体报表" + start + "~" + "end", "UTF8");
+        } catch (UnsupportedEncodingException e) {
+            name = "media-"+ start + "~" + "end";
+        }
+
+        response.setContentType("application/vnd.ms-excel;charset=utf-8");
+        //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
+
+        response.setHeader("Content-Disposition","attachment;filename="+ name +".xls");
+
+        ServletOutputStream out= null;
+        try {
+            out = response.getOutputStream();
+            writer.flush(out, true);
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+        }
+        finally {
+            // 关闭writer,释放内存
+            writer.close();
+        }
+        //此处记得关闭输出Servlet流
+        IoUtil.close(out);
+    }
+
+    public List<Map<String, Object>> platform(String kh){
+//        return new String[]{"微博", "微信", "头条", "抖音", "快手", "B站"};
+        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyyMMdd");
+
+        ArrayList<Map<String, Object>> ls = ListUtil.toList(
+                MapUtil.builder(new HashMap<String, Object>())
+                        .put("platform", "微博").put("dt", dtf.format(dtf1.parse(baseMapper.weiboLastDt()))).build(),
+                MapUtil.builder(new HashMap<String, Object>())
+                        .put("platform", "微信").put("dt", dtf.format(dtf1.parse(baseMapper.weixinLastDt()))).build(),
+                MapUtil.builder(new HashMap<String, Object>())
+                        .put("platform", "抖音").put("dt", dtf.format(dtf1.parse(baseMapper.douyinLastDt()))).build()
+        );
+        if (kh.equals("0")){
+            ls.addAll(ListUtil.toList(
+                    MapUtil.builder(new HashMap<String, Object>())
+                            .put("platform", "头条").put("dt", dtf.format(dtf1.parse(baseMapper.toutiaoLastDt()))).build(),
+                    MapUtil.builder(new HashMap<String, Object>())
+                            .put("platform", "快手").put("dt", dtf.format(dtf1.parse(baseMapper.kuaishouLastDt()))).build(),
+                    MapUtil.builder(new HashMap<String, Object>())
+                            .put("platform", "B站").put("dt", dtf.format(dtf1.parse(baseMapper.biliLastDt()))).build()
+            ));
+        }
+        return ls;
+    }
+}

+ 236 - 0
src/main/resources/com/sxtvs/OpenDataMapper.xml

@@ -0,0 +1,236 @@
+<?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="com.sxtvs.open.api.odata.dao.OpenDataMapper">
+    <sql id="orderSc">
+        <choose>
+            <when test='order == 0'>
+                asc
+            </when>
+            <otherwise>
+                desc
+            </otherwise>
+        </choose>
+    </sql>
+    <select id="newMediaList" resultType="com.sxtvs.open.api.odata.dto.NewMedia">
+        select nick_name user_name,dep_name,title,
+               <if test="platform != '微博' and platform != '快手'">
+                   share_count,
+               </if>
+               play_count,like_count,comment_count, publish_time
+        from open_data  where platform = #{platform}
+                          and publish_time >= #{start} and publish_time &lt;= CONCAT(#{end} ,' 23:59:59')
+        <if test="match != null and match != ''">
+            and (nick_name like concat('%', #{match},'%') or dep_name like concat('%', #{match},'%') or title like concat('%', #{match},'%'))
+        </if>
+        <if test="nickNames.size() > 0">
+            and nick_name in
+            <foreach collection="nickNames" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        <include refid="orderSc" />
+    </select>
+
+    <select id="weiboAggList" resultType="com.sxtvs.open.api.odata.dto.Agg">
+        select a.user_name, a.dep_name, b.read_count, b.share_count, b.comment_count, b.like_count, b.followers_count fans, b.publish_count publish_count
+        from (
+                 select *
+                 from department_v2
+                 where platform = '微博') a
+                 join (select nick_name,
+                              sum(read_count)                                                as read_count,
+        sum(reposts)      as share_count,
+        sum(comments)      as comment_count,
+        sum(likes)      as like_count,
+                              max(followers_count) as followers_count,
+                              sum(publish_count) publish_count
+                       from weibo_total
+                       where dt >= #{start} and dt &lt;= #{end}
+                       group by nick_name) b
+                      on a.user_name = b.nick_name
+        <if test="match != null and match != ''">
+            where a.user_name like concat('%', #{match},'%') or a.dep_name like concat('%', #{match},'%')
+        </if>
+        <if test="nickNames.size() > 0">
+            and nick_name in
+            <foreach collection="nickNames" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        <include refid="orderSc" />
+    </select>
+
+    <select id="weiboLastDt" resultType="java.lang.String">
+        select IFNULL( max(dt), REPLACE(DATE_SUB(CURDATE(), INTERVAL 1 DAY),'-','')) dt from schedule_queue where `event` = 'open_data.微博'
+    </select>
+
+    <select id="weixinAggList" resultType="com.sxtvs.open.api.odata.dto.Agg">
+        select nick_name user_name, b.dep_name,  a.read_count, a.share_count, a.fav_count,cumulate_user fans, a.publish_count
+        from (select nick_name,
+                     sum(int_page_read_count)                                           as read_count,
+                     sum(share_count) as share_count,
+                     sum(add_to_fav_count) as fav_count,
+                     max(cumulate_user)       as cumulate_user,
+                     sum(publish_count) publish_count
+              from wx_total
+              where dt >= #{start} and dt &lt;= #{end}
+              group by nick_name) a,
+             department_v2 b
+        where a.nick_name = b.user_name
+          and b.platform = '微信'
+        <if test="match != null and match != ''">
+            and (a.nick_name like concat('%', #{match},'%') or b.dep_name like concat('%', #{match},'%'))
+        </if>
+        <if test="nickNames.size() > 0">
+            and nick_name in
+            <foreach collection="nickNames" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        <include refid="orderSc" />
+    </select>
+
+    <select id="weixinLastDt" resultType="java.lang.String">
+        select max(dt) dt from wx_total
+    </select>
+
+    <select id="toutiaoAggList" resultType="com.sxtvs.open.api.odata.dto.Agg">
+        select a.nick_name user_name, b.dep_name, a.read_count, a.publish_count
+        from (
+                 select nick_name,
+                        sum(play_count)                                                                 as read_count,
+                        count(1) publish_count
+                 from open_data
+                 where platform = '头条'
+                   and publish_time >= #{start} and publish_time &lt;= concat(#{end}, ' 23:59:59')
+                 group by nick_name) a,
+             department_v2 b
+        where a.nick_name = b.user_name
+          and b.platform = '头条'
+        <if test="match != null and match != ''">
+            and (a.nick_name like concat('%', #{match},'%') or b.dep_name like concat('%', #{match},'%'))
+        </if>
+        <if test="nickNames.size() > 0">
+            and nick_name in
+            <foreach collection="nickNames" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        <include refid="orderSc" />
+    </select>
+
+    <select id="toutiaoLastDt" resultType="java.lang.String">
+        select IFNULL( max(dt), REPLACE(DATE_SUB(CURDATE(), INTERVAL 1 DAY),'-','')) dt from schedule_queue where `event` = 'open_data.头条'
+    </select>
+
+    <select id="douyinAggList" resultType="com.sxtvs.open.api.odata.dto.Agg">
+        select b.nick_name user_name, c.dep_name, a.read_count, a.share_count, a.like_count, a.total_fans fans, a.publish_count
+        from (select open_id,
+                     sum(new_play)                                             as read_count,
+                     sum(new_share)   as share_count,
+                     sum(new_like)   as like_count,
+                     sum(total_fans) as total_fans,
+                     sum(new_issue) publish_count
+              from douyin_snapshot
+              where dt >= #{start} and dt &lt;= #{end}
+              group by open_id) a,
+             douyin_account b,
+             department_v2 c
+        where a.open_id = b.open_id
+          and b.nick_name = c.user_name
+          and c.platform = '抖音'
+        <if test="match != null and match != ''">
+            and (b.nick_name like concat('%', #{match},'%') or c.dep_name like concat('%', #{match},'%'))
+        </if>
+        <if test="nickNames.size() > 0">
+            and nick_name in
+            <foreach collection="nickNames" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        <include refid="orderSc" />
+    </select>
+
+    <select id="douyinLastDt" resultType="java.lang.String">
+        select max(dt) dt from douyin_snapshot
+    </select>
+
+    <select id="kuaishouAggList" resultType="com.sxtvs.open.api.odata.dto.Agg">
+        select a.nick_name user_name, b.dep_name, a.read_count, a.comment_count, a.like_count, a.publish_count
+        from (
+                 select nick_name,
+                        sum(play_count)                                                                 as read_count,
+                        sum(comment_count) as comment_count,
+                        sum(like_count) as like_count,
+                        count(1) publish_count
+                 from open_data
+                 where platform = '快手'
+                   and publish_time >= #{start} and publish_time &lt;= concat(#{end}, ' 23:59:59')
+                 group by nick_name) a,
+             department_v2 b
+        where a.nick_name = b.user_name
+          and b.platform = '快手'
+        <if test="match != null and match != ''">
+            and (a.nick_name like concat('%', #{match},'%') or b.dep_name like concat('%', #{match},'%'))
+        </if>
+        <if test="nickNames.size() > 0">
+            and nick_name in
+            <foreach collection="nickNames" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        <include refid="orderSc" />
+    </select>
+
+    <select id="kuaishouLastDt" resultType="java.lang.String">
+        select IFNULL( max(dt), REPLACE(DATE_SUB(CURDATE(), INTERVAL 1 DAY),'-','')) dt from schedule_queue where `event` = 'open_data.快手'
+    </select>
+
+    <select id="biliAggList" resultType="com.sxtvs.open.api.odata.dto.Agg">
+        select a.nick_name user_name, b.dep_name, a.read_count, a.publish_count
+        from (
+                 select nick_name,
+                        sum(play_count)                                                                 as read_count,
+                        count(1) publish_count
+                 from open_data
+                 where platform = 'B站'
+                and publish_time >= #{start} and publish_time &lt;= concat(#{end}, ' 23:59:59')
+                 group by nick_name) a,
+             department_v2 b
+        where a.nick_name = b.user_name
+          and b.platform = 'B站'
+        <if test="match != null and match != ''">
+            and (a.nick_name like concat('%', #{match},'%') or b.dep_name like concat('%', #{match},'%'))
+        </if>
+        <if test="nickNames.size() > 0">
+            and nick_name in
+            <foreach collection="nickNames" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        <include refid="orderSc" />
+    </select>
+
+    <select id="biliLastDt" resultType="java.lang.String">
+        select IFNULL( max(dt), REPLACE(DATE_SUB(CURDATE(), INTERVAL 1 DAY),'-','')) dt from schedule_queue where `event` = 'open_data.B站'
+    </select>
+
+    <select id="departmentGroup" resultType="java.lang.String">
+        select nick_name from department_group where group_name = #{groupName}
+        <if test="platform != null and platform != ''">
+            and platform = #{platform}
+        </if>
+    </select>
+
+    <select id="getDepGroup" resultType="java.lang.String">
+        select bigdata_dep FROM bigdata_account WHERE user_id = #{userId} LIMIT 1
+    </select>
+
+</mapper>

+ 12 - 0
src/main/resources/templates/close.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+<script th:inline="javascript">
+    window.close();
+</script>
+</body>
+</html>