瀏覽代碼

盯盘-项目、账户数据导出

yangzian 3 年之前
父節點
當前提交
f95a0edef7

+ 2 - 2
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -217,7 +217,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/kuaishou/batch/*", "anon");
         filterChainDefinitionMap.put("/dimension/kuaiShouDimensionAccount/*", "anon");
         filterChainDefinitionMap.put("/ai/projectCreate/*", "anon");
-        //filterChainDefinitionMap.put("/cwjsPolicyInfo/**", "anon");
+        filterChainDefinitionMap.put("/cwjsPolicyInfo/**", "anon");
         filterChainDefinitionMap.put("/ruleIndicator/**", "anon");
         filterChainDefinitionMap.put("/explores/**", "anon");
         filterChainDefinitionMap.put("/estimatePeopleNumber/**", "anon");
@@ -227,7 +227,7 @@ public class ShiroConfig {
 
         filterChainDefinitionMap.put("/importPolicyController/importPolicyInit", "anon");
         //filterChainDefinitionMap.put("/settLementController/**", "anon");
-//        filterChainDefinitionMap.put("/settLementFileController/**", "anon");
+        filterChainDefinitionMap.put("/settLementFileController/**", "anon");
 
         filterChainDefinitionMap.put("/ctop/projectMember/**", "anon");
         filterChainDefinitionMap.put("/agent/**", "anon");

+ 14 - 3
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/constants/Check.java

@@ -3,10 +3,10 @@ package org.jeecg.ctop.material.constants;
 import com.alibaba.fastjson.JSONArray;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.util.ReflectionUtils;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Slf4j
 public class Check {
@@ -63,4 +63,15 @@ public class Check {
     public static boolean isNullMap(Map<?, ?> map) {
         return map == null || map.isEmpty();
     }
+
+
+    public static Map<String, Object> parseObj2Map(Object args) {
+        return Arrays.stream(BeanUtils.getPropertyDescriptors(args.getClass()))
+                .filter(pd -> !"class".equals(pd.getName()))
+                .collect(HashMap::new,
+                        (map, pd) -> map.put(pd.getName(), ReflectionUtils.invokeMethod(pd.getReadMethod(), args)),
+                        HashMap::putAll);
+    }
+
+
 }

+ 172 - 1
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/KuaiShouMaterialStareController.java

@@ -1,16 +1,30 @@
 package org.jeecg.ctop.material.controller;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.ctop.material.constants.Check;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateAccountVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateProjectVo;
 import org.jeecg.ctop.material.mapper.MaterialStareMapper;
 import org.jeecg.ctop.material.service.MaterialStareService;
 import org.jeecg.ctop.material.service.impl.MaterialStareServiceImpl;
+import org.jeecgframework.poi.excel.ExcelExportUtil;
+import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedOutputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -28,6 +42,9 @@ public class KuaiShouMaterialStareController {
     @Autowired
     MaterialStareService materialStareService;
 
+    @Autowired
+    private MaterialStareMapper materialStareMapper;
+
 
     /**
      *
@@ -296,7 +313,7 @@ public class KuaiShouMaterialStareController {
     /**
      * 获取用户下级的项目以及账户信息
      *
-     * @param requestJson
+     * @param
      * @return
      */
     @GetMapping(value = "/participateListByMediaIdAllSubordinate")
@@ -326,6 +343,160 @@ public class KuaiShouMaterialStareController {
 
 
 
+    @GetMapping("/exportKuaiShouOperateProjectInfo")
+    public Result<JSONObject> getKuaiShouOperateProjectInfo(@RequestParam(name="startTime") String startTime,
+                                                            @RequestParam(name="endTime") String endTime,
+                                                            @RequestParam(name="userId") String userId,HttpServletResponse response) {
+
+        try {
+            JSONObject jsonObject = materialStareMapper.getColumnInfo(userId,"104");
+            JSONArray array = jsonObject.getJSONArray("json");
+             //第一步创建workbook
+            HSSFWorkbook wb = new HSSFWorkbook();
+            //设置样式
+            HSSFCellStyle style = wb.createCellStyle();
+            style.setAlignment(HorizontalAlignment.CENTER);//水平居中
+            //设置字体
+            HSSFFont font = wb.createFont();
+            font.setFontName("黑体");
+            font.setFontHeightInPoints((short) 12);//设置字体大小
+            style.setFont(font);
+            //2:创建sheet 设置sheet名称
+            HSSFSheet sheet = wb.createSheet("项目数据");
+            sheet.autoSizeColumn(0,true);
+            //3:添加 第一行单元格
+            HSSFRow row0 = sheet.createRow(0);
+            HSSFCell cell0 = row0.createCell(0);
+            //设置 第一行 表头
+            cell0.setCellValue("项目数据");
+            CellRangeAddress region = new CellRangeAddress(0, 0, 0, array.size()-1);
+            sheet.addMergedRegion(region);//合并行
+            cell0.setCellStyle(style);
+            //4:添加表头2行
+            HSSFRow row = sheet.createRow(1);
+            //5:创建第2行的单元格
+            for (int i = 0;i < array.size(); i++) {
+                JSONObject json = (JSONObject)array.get(i);
+                HSSFCell cell = row.createCell(i);     //第一个单元格
+                cell.setCellValue(json.getString("title"));         //设定值
+                cell.setCellStyle(style);          //内容居中
+            }
+
+            List< KuaiShouOperateProjectVo > resultList = materialStareService.exportKuaiShouOperateProjectInfo(startTime, endTime, userId);
+
+            for (int j = 0; j < resultList.size(); j++) {
+                KuaiShouOperateProjectVo projectVo = resultList.get(j);
+                Map project = Check.parseObj2Map(projectVo);
+
+                //创建行 (表头占0-1行 所以 从 2开始)
+                row = sheet.createRow(j + 2);
+                for (int k =0;k < array.size();k++) {
+                    JSONObject json = (JSONObject)array.get(k);
+                    String fieldName = KuaiShouOperateProjectVo.class.getDeclaredField(json.getString("dataIndex")).getName();
+                    project.get(fieldName);
+                    row.createCell(k).setCellValue(project.get(fieldName).toString());
+                }
+            }
+
+            response.setCharacterEncoding("UTF-8");
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            response.setDateHeader("Expires", 0);
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("项目列表.xlsx", "UTF-8"));
+            OutputStream output = response.getOutputStream();
+            BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
+            wb.write(bufferedOutPut);
+            bufferedOutPut.flush();
+            bufferedOutPut.close();
+            output.close();
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+         return null;
+    }
+
+
+    @GetMapping("/exportKuaiShouOperateAccountInfo")
+    public Result<JSONObject> exportKuaiShouOperateAccountInfo(@RequestParam(name="startTime") String startTime,
+                                                            @RequestParam(name="endTime") String endTime,
+                                                            @RequestParam(name="projectId") String projectId,
+                                                            @RequestParam(name="userId") String userId,HttpServletResponse response) {
+
+        try {
+            JSONObject jsonObject = materialStareMapper.getColumnInfo(userId,"102");
+            JSONArray array = jsonObject.getJSONArray("json");
+             //第一步创建workbook
+            HSSFWorkbook wb = new HSSFWorkbook();
+            //设置样式
+            HSSFCellStyle style = wb.createCellStyle();
+            style.setAlignment(HorizontalAlignment.CENTER);//水平居中
+            //设置字体
+            HSSFFont font = wb.createFont();
+            font.setFontName("黑体");
+            font.setFontHeightInPoints((short) 12);//设置字体大小
+            style.setFont(font);
+            //2:创建sheet 设置sheet名称
+            HSSFSheet sheet = wb.createSheet("账户数据");
+            sheet.autoSizeColumn(0,true);
+            //3:添加 第一行单元格
+            HSSFRow row0 = sheet.createRow(0);
+            HSSFCell cell0 = row0.createCell(0);
+            //设置 第一行 表头
+            cell0.setCellValue("账户数据");
+            CellRangeAddress region = new CellRangeAddress(0, 0, 0, array.size()-1);
+            sheet.addMergedRegion(region);//合并行
+            cell0.setCellStyle(style);
+            //4:添加表头2行
+            HSSFRow row = sheet.createRow(1);
+            //5:创建第2行的单元格
+            for (int i = 0;i < array.size(); i++) {
+                JSONObject json = (JSONObject)array.get(i);
+                HSSFCell cell = row.createCell(i);     //第一个单元格
+                cell.setCellValue(json.getString("title"));         //设定值
+                cell.setCellStyle(style);          //内容居中
+
+            }
+
+            List<KuaiShouOperateAccountVo> resultList = materialStareService.exportKuaiShouOperateAccountInfo(startTime, endTime, projectId,userId);
+
+            for (int j = 0; j < resultList.size(); j++) {
+                KuaiShouOperateAccountVo accountVo = resultList.get(j);
+                Map account = Check.parseObj2Map(accountVo);
+
+                //创建行 (表头占0-1行 所以 从 2开始)
+                row = sheet.createRow(j + 2);
+                for (int k =0;k < array.size();k++) {
+                    JSONObject json = (JSONObject)array.get(k);
+                    String fieldName = KuaiShouOperateAccountVo.class.getDeclaredField(json.getString("dataIndex")).getName();
+                    account.get(fieldName);
+                    row.createCell(k).setCellValue(account.get(fieldName).toString());
+                }
+            }
+
+            response.setCharacterEncoding("UTF-8");
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            response.setDateHeader("Expires", 0);
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("账户列表.xlsx", "UTF-8"));
+            OutputStream output = response.getOutputStream();
+            BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
+            wb.write(bufferedOutPut);
+            bufferedOutPut.flush();
+            bufferedOutPut.close();
+            output.close();
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+         return null;
+    }
+
+
+
+
 
 
 

+ 4 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/MaterialStareMapper.java

@@ -100,4 +100,8 @@ public interface MaterialStareMapper {
 
 
 
+
+    JSONObject getColumnInfo(@Param("userId") String userId,@Param("columnType") String columnType);
+
+
 }

+ 4 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/MaterialStareService.java

@@ -2,6 +2,8 @@ package org.jeecg.ctop.material.service;
 
 import com.alibaba.fastjson.JSONObject;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateAccountVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateProjectVo;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
@@ -25,8 +27,10 @@ public interface MaterialStareService {
     Result exportKuaiShouOperateInfo(String startTime, String endTime, String userId, HttpServletResponse response);
 
     Result getKuaiShouOperateProjectInfo(Integer pageNum,int pageSize,String startTime, String endTime, String userId);
+    List<KuaiShouOperateProjectVo> exportKuaiShouOperateProjectInfo(String startTime, String endTime, String userId);
 
     Result getKuaiShouOperateAccountInfo(Integer pageNum,int pageSize,String startTime, String endTime, String projectId,String userId);
+    List<KuaiShouOperateAccountVo> exportKuaiShouOperateAccountInfo(String startTime, String endTime, String projectId, String userId);
 
     Result getKuaiShouAccountInfo(long accountId);
 

+ 128 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/MaterialStareServiceImpl.java

@@ -525,6 +525,72 @@ public class MaterialStareServiceImpl implements MaterialStareService {
 
 
 
+    public List<KuaiShouOperateProjectVo> exportKuaiShouOperateProjectInfo(String startTime, String endTime, String userId) {
+        DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+        try {
+            //查询当前人员所有下级
+            Set<String> operatorUserIds = getAffiliateId(userId);
+            //2022-02-15 ==>> 20220215
+            long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+            long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+
+            //计算环比 时间值 上阶段时间 以及 两个日期之间的 间隔天数
+            Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
+            long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
+            long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
+            Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"))+1;
+
+            //计算同比 时间值 只支持7天
+            long startEqually = new Long("0");
+            long endEqually = new Long("0");
+            if (daysBetween <= 7) {
+                startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
+                endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
+            }
+
+            //查询运营数据-项目维度
+            List<KuaiShouOperateProjectVo> listOperate = materialStareMapper.getKuaiShouOperateProjectInfo(startDate,entDate,null,operatorUserIds);
+            for (KuaiShouOperateProjectVo projectInfo : listOperate) {
+
+                //查询 有效 上新视频 爆款视频
+                JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(null,projectInfo.getProjectId(),null,startDate,entDate);
+                projectInfo.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
+                projectInfo.setNewVideoNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newVideoNum"));//上新
+                projectInfo.setNewHotNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newHotNum"));//爆款
+
+
+                String projectId = projectInfo.getProjectId();
+                List<KuaiShouOperateProjectVo> projectYearOnYearInfo = materialStareMapper.getKuaiShouOperateProjectInfo(lastTimeStart,lastTimeEnd,projectId,operatorUserIds);
+                //环比 = (当前 - 上阶段 ) / 上阶段
+                String yearOnYear = "0";
+                if (!Check.isNull(projectYearOnYearInfo)){
+                    Double yearOnYearD = (projectInfo.getTotalCost() - projectYearOnYearInfo.get(0).getTotalCost()) / projectYearOnYearInfo.get(0).getTotalCost();
+                    yearOnYear = decimalFormat.format(yearOnYearD);
+                }
+                projectInfo.setYearOnYear(yearOnYear);
+
+                //同比 日期超过 7 天 则不显示
+                String equallyRate = "-";
+                if (daysBetween <= 7){
+                    List<KuaiShouOperateProjectVo> projectEquallyInfo = materialStareMapper.getKuaiShouOperateProjectInfo(startEqually,endEqually,projectId,operatorUserIds);
+                    if (!Check.isNull(projectEquallyInfo)){
+                        Double equallyRateD = (projectInfo.getTotalCost() - projectEquallyInfo.get(0).getTotalCost()) / projectEquallyInfo.get(0).getTotalCost();
+                        equallyRate = decimalFormat.format(equallyRateD);
+                    }
+                }
+                projectInfo.setEquallyRate(equallyRate);
+
+            }
+
+            return listOperate;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+
     /**
      *
      * @description: 运营数据-账户列表
@@ -603,6 +669,68 @@ public class MaterialStareServiceImpl implements MaterialStareService {
         return Result.errorMsg("哎呀,查询失败了。");
     }
 
+    public List<KuaiShouOperateAccountVo> exportKuaiShouOperateAccountInfo(String startTime, String endTime,String projectId, String userId) {
+        DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+        try {
+            //查询当前人员所有下级
+            Set<String> operatorUserIds = getAffiliateId(userId);
+            //2022-02-15 ==>> 20220215
+            long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+            long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+
+            //计算环比 时间值 上阶段时间 以及 两个日期之间的 间隔天数
+            Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
+            long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
+            long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
+            Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"))+1;
+
+            //计算同比 时间值 只支持7天
+            long startEqually = new Long("0");
+            long endEqually = new Long("0");
+            if (daysBetween <= 7) {
+                startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
+                endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
+            }
+
+            //查询运营数据-账户 维度
+            List<KuaiShouOperateAccountVo> listOperate = materialStareMapper.getKuaiShouOperateAccountInfo(startDate,entDate,projectId,null,operatorUserIds);
+            for (KuaiShouOperateAccountVo accountInfo : listOperate) {
+
+                //查询 有效 上新视频 爆款视频
+                JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(null,null,String.valueOf(accountInfo.getAccountId()),startDate,entDate);
+                accountInfo.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
+                accountInfo.setNewVideoNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newVideoNum"));//上新
+                accountInfo.setNewHotNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newHotNum"));//爆款
+
+                long accountId = accountInfo.getAccountId();
+                List<KuaiShouOperateAccountVo> accountYearOnYearInfo = materialStareMapper.getKuaiShouOperateAccountInfo(lastTimeStart,lastTimeEnd,projectId,accountId,operatorUserIds);
+                //环比 = (当前 - 上阶段 ) / 上阶段
+                String yearOnYear = "0";
+                if (!Check.isNull(accountYearOnYearInfo)){
+                    Double yearOnYearD = (accountInfo.getTotalCost() - accountYearOnYearInfo.get(0).getTotalCost()) / accountYearOnYearInfo.get(0).getTotalCost();
+                    yearOnYear = decimalFormat.format(yearOnYearD);
+                }
+                accountInfo.setYearOnYear(yearOnYear);
+
+                //同比 日期超过 7 天 则不显示
+                String equallyRate = "-";
+                if (daysBetween <= 7){
+                    List<KuaiShouOperateAccountVo> accountEquallyInfo = materialStareMapper.getKuaiShouOperateAccountInfo(startEqually,endEqually,projectId,accountId,operatorUserIds);
+                    if (!Check.isNull(accountEquallyInfo)){
+                        Double equallyRateD = (accountInfo.getTotalCost() - accountEquallyInfo.get(0).getTotalCost()) / accountEquallyInfo.get(0).getTotalCost();
+                        equallyRate = decimalFormat.format(equallyRateD);
+                    }
+                }
+                accountInfo.setEquallyRate(equallyRate);
+            }
+
+            return listOperate;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return null;
+    }
+
 
     /**
      *