|
@@ -0,0 +1,684 @@
|
|
|
+package com.caimei365.manager.service.caimei.user.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.caimei.utils.MathUtil;
|
|
|
+import com.caimei.utils.StringUtils;
|
|
|
+import com.caimei365.manager.dao.user.CmMarketShopDao;
|
|
|
+import com.caimei365.manager.entity.PaginationVo;
|
|
|
+import com.caimei365.manager.entity.ResponseJson;
|
|
|
+import com.caimei365.manager.entity.caimei.CmShop;
|
|
|
+import com.caimei365.manager.entity.caimei.ReturnData;
|
|
|
+import com.caimei365.manager.entity.caimei.ReturnEntity;
|
|
|
+import com.caimei365.manager.entity.caimei.shopImport.*;
|
|
|
+import com.caimei365.manager.service.caimei.listener.*;
|
|
|
+import com.caimei365.manager.service.caimei.user.CmMarketShopService;
|
|
|
+import com.caimei365.manager.utils.FileUtil;
|
|
|
+import com.caimei365.manager.utils.formDataUtils;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.fileupload.disk.DiskFileItem;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.*;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : hzg
|
|
|
+ * @date : 2023/12/14
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CmMarketShopServiceImpl implements CmMarketShopService {
|
|
|
+
|
|
|
+ private final static String ZIP_FILE = "zip";
|
|
|
+ private final static String RAR_FILE = "octet";
|
|
|
+
|
|
|
+ private final static String extract = "/mnt/newdatadrive/data/runtime/jar-instance/manager-api/extract";
|
|
|
+
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
|
|
|
+
|
|
|
+ @Resource private CmMarketShopDao marketShopDao;
|
|
|
+
|
|
|
+ @Resource private formDataUtils formDataUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传供应商营销logo
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param logo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson uploadShopLogo(Integer id, String logo) {
|
|
|
+ marketShopDao.updateShopLogo(id, logo);
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据报表列表
|
|
|
+ *
|
|
|
+ * @param marketId
|
|
|
+ * @param reportName
|
|
|
+ * @param pageNum
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PaginationVo<CmMarketReport>> getMarketReport(Integer marketId, String reportName, int pageNum, int pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<CmMarketReport> marketReport = marketShopDao.getMarketReport(marketId, reportName);
|
|
|
+ /*if (null != marketReport && marketReport.size() > 0) {
|
|
|
+ marketReport.forEach(report -> {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotBlank(report.getReportTime())) {
|
|
|
+ report.setReportTime(simpleDateFormat.format(simpleDateFormat.parse(report.getReportTime())));
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }*/
|
|
|
+ PaginationVo<CmMarketReport> page = new PaginationVo<>(marketReport);
|
|
|
+ return ResponseJson.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据数据报表Id 查询报表数据
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<CmMarketReport> getMarketReportById(Integer id) {
|
|
|
+ CmMarketReport marketReportById = marketShopDao.getMarketReportById(id);
|
|
|
+ if (null != marketReportById) {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotBlank(marketReportById.getReportTime())) {
|
|
|
+ marketReportById.setReportTime(simpleDateFormat.format(simpleDateFormat.parse(marketReportById.getReportTime())));
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseJson.success(marketReportById);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启用数据报表
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson updateMarketReportVisible(Integer id) {
|
|
|
+ marketShopDao.updateMarketReportVisible(id);
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据报表
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson updateMarketReport(Integer id) {
|
|
|
+ // 删除数据报表
|
|
|
+ marketShopDao.updateMarketReport(id);
|
|
|
+ // 删除数据报表具体数据
|
|
|
+ marketShopDao.updateMarketStage(id);
|
|
|
+ marketShopDao.updateMarketFunnelModel(id);
|
|
|
+ marketShopDao.updateMarketArticleReadVolume(id);
|
|
|
+ marketShopDao.updateMarketImpressions(id);
|
|
|
+ marketShopDao.updateMarketReadVolume(id);
|
|
|
+ marketShopDao.updateMarketSummary(id);
|
|
|
+ marketShopDao.updateMarketVisits(id);
|
|
|
+ marketShopDao.updateMarketProportion(id);
|
|
|
+ marketShopDao.updateMarketPageDuration(id);
|
|
|
+ marketShopDao.updateMarketAdvertHits(id);
|
|
|
+ marketShopDao.updateMarketRemark(id);
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传zip、rar文件到服务器并解压
|
|
|
+ *
|
|
|
+ * @param reportFile
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson saveMarketReport( MultipartFile reportFile) throws IOException {
|
|
|
+
|
|
|
+ boolean isZipPack = true;
|
|
|
+
|
|
|
+ //不存在则创建
|
|
|
+ File packFile = new File(extract);
|
|
|
+ packFile.delete();
|
|
|
+ if (!packFile.exists()) {
|
|
|
+ boolean mkdirs = packFile.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (reportFile== null) {
|
|
|
+ return ResponseJson.error(-1, "请上传文件", null);
|
|
|
+ }
|
|
|
+ String contentType = reportFile.getContentType();
|
|
|
+ String filename = reportFile.getOriginalFilename();
|
|
|
+ log.info("contentType===="+contentType);
|
|
|
+ //将压缩包保存在指定路径
|
|
|
+ String packFilePath = extract + File.separator + filename;
|
|
|
+ if (contentType.contains(ZIP_FILE)) {
|
|
|
+ //zip解压缩处理
|
|
|
+ } else if (contentType.contains(RAR_FILE)) {
|
|
|
+ //rar解压缩处理
|
|
|
+ isZipPack = false;
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error(-1, "上传的压缩包格式不正确,仅支持rar和zip压缩文件!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ File file = new File(packFilePath);
|
|
|
+
|
|
|
+ try {
|
|
|
+ reportFile.transferTo(file);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseJson.error(-1, "压缩文件到:" + extract + " 失败!", null);
|
|
|
+ }
|
|
|
+ if (isZipPack) {
|
|
|
+ //zip压缩包
|
|
|
+ FileUtil.unZip(packFilePath, extract);
|
|
|
+ } else {
|
|
|
+ //rar压缩包
|
|
|
+ FileUtil.unPackRar(file, filename, extract);
|
|
|
+ }
|
|
|
+ //获取压缩包名称
|
|
|
+ filename = filename.substring(0, filename.lastIndexOf("."));
|
|
|
+ log.info("filename===="+filename);
|
|
|
+ log.info("packFilePath===="+packFilePath);
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ String filePath = "";
|
|
|
+ if (isZipPack) {
|
|
|
+ filePath = extract + "/" + filename;
|
|
|
+ } else {
|
|
|
+ filePath = extract + "/" + filename;
|
|
|
+ }
|
|
|
+ return ResponseJson.success(filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存报表数据
|
|
|
+ *
|
|
|
+ * @param marketId
|
|
|
+ * @param reportDate
|
|
|
+ * @param reportName
|
|
|
+ * @param filePath
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson saveReport(Integer marketId, Integer id, String reportDate, String reportName, String filePath) throws IOException {
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
+ try {
|
|
|
+ String reportTime = dateFormat.format(dateFormat.parse(reportDate));
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (id == null) {
|
|
|
+ CmMarketReport marketReport = new CmMarketReport();
|
|
|
+ marketReport.setMarketId(marketId);
|
|
|
+ marketReport.setReportDate(reportTime);
|
|
|
+ marketReport.setReportName(reportName);
|
|
|
+ marketReport.setFileName(file.getName());
|
|
|
+ marketShopDao.insertMarketReport(marketReport);
|
|
|
+ // 读取文件,处理数据
|
|
|
+ readFile(marketReport.getId(), filePath);
|
|
|
+ file.delete();
|
|
|
+ } else {
|
|
|
+ // 删除数据报表具体数据
|
|
|
+ marketShopDao.updateMarketStage(id);
|
|
|
+ marketShopDao.updateMarketFunnelModel(id);
|
|
|
+ marketShopDao.updateMarketArticleReadVolume(id);
|
|
|
+ marketShopDao.updateMarketImpressions(id);
|
|
|
+ marketShopDao.updateMarketReadVolume(id);
|
|
|
+ marketShopDao.updateMarketSummary(id);
|
|
|
+ marketShopDao.updateMarketVisits(id);
|
|
|
+ marketShopDao.updateMarketProportion(id);
|
|
|
+ marketShopDao.updateMarketPageDuration(id);
|
|
|
+ marketShopDao.updateMarketAdvertHits(id);
|
|
|
+ marketShopDao.updateMarketRemark(id);
|
|
|
+ // 读取文件,处理数据
|
|
|
+ readFile(id, filePath);
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ File extractFile = new File(extract);
|
|
|
+ extractFile.delete();
|
|
|
+ Path path = Paths.get(extract);
|
|
|
+ try {
|
|
|
+ Files.walk(path)
|
|
|
+ .sorted(Comparator.reverseOrder())
|
|
|
+ .map(Path::toFile)
|
|
|
+ .forEach(File::delete);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报表数据预览
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Map<String, Object>> preview(Integer id) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
+ // name集合
|
|
|
+ ArrayList<String> name = new ArrayList<>();
|
|
|
+ // value 集合
|
|
|
+ ArrayList<Integer> value = new ArrayList<>();
|
|
|
+ // 备份(第二value)集合
|
|
|
+ ArrayList<Integer> backupsValues = new ArrayList<>();
|
|
|
+ // 唯一name集合
|
|
|
+ Set<String> set = new HashSet<>();
|
|
|
+ // 获取报表对应供应商数据
|
|
|
+ CmMarketShop shopInfo = marketShopDao.getShopInfoById(id);
|
|
|
+ // 获取阶段描述
|
|
|
+ List<Stage> summarize = new ArrayList<>();
|
|
|
+ List<Stage> summarize1 = new ArrayList<>();
|
|
|
+ List<Stage> summarize2 = new ArrayList<>();
|
|
|
+ List<Stage> marketStage = marketShopDao.getMarketStage(id);
|
|
|
+ if (null != marketStage && marketStage.size() > 0) {
|
|
|
+ for (Stage stage : marketStage) {
|
|
|
+ try {
|
|
|
+ stage.setAddTime(dateFormat.format(dateFormat.parse(stage.getAddTime())));
|
|
|
+ if ("1".equals(stage.getStage())) {
|
|
|
+ summarize.add(stage);
|
|
|
+ }
|
|
|
+ if ("2".equals(stage.getStage())) {
|
|
|
+ summarize1.add(stage);
|
|
|
+ }
|
|
|
+ if ("3".equals(stage.getStage())) {
|
|
|
+ summarize2.add(stage);
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("summarize", summarize);
|
|
|
+ map.put("summarize1", summarize1);
|
|
|
+ map.put("summarize2", summarize2);
|
|
|
+ // 获取漏斗模型数据
|
|
|
+ List<FunnelModel> marketFunnelModel = marketShopDao.getMarketFunnelModel(id);
|
|
|
+ int impressions = 0, hits = 0, visits = 0, consultation = 0, report = 0;
|
|
|
+ if (null != marketFunnelModel && marketFunnelModel.size() > 0) {
|
|
|
+ for (FunnelModel funnelModel : marketFunnelModel) {
|
|
|
+ impressions += funnelModel.getImpressions();
|
|
|
+ hits += funnelModel.getHits();
|
|
|
+ visits += funnelModel.getVisits();
|
|
|
+ consultation += funnelModel.getConsultation();
|
|
|
+ report += funnelModel.getReport();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ shopInfo.setChartTitle("【"+shopInfo.getName()+"】"+dateFormat.format(dateFormat.parse(shopInfo.getAddTime())) + "数据报表");
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ shopInfo.setImpressions(impressions);
|
|
|
+ shopInfo.setHits(hits);
|
|
|
+ shopInfo.setVisits(visits);
|
|
|
+ shopInfo.setConsultation(consultation);
|
|
|
+ shopInfo.setReport(report);
|
|
|
+ map.put("shopInfo", shopInfo);
|
|
|
+ // 获取推文数据
|
|
|
+ List<ArticleReadVolume> marketArticleReadVolume = marketShopDao.getMarketArticleReadVolume(id);
|
|
|
+ List<ArticleReadVolume> articleReadVolumeList = new ArrayList<>();
|
|
|
+ if (null != marketArticleReadVolume && marketArticleReadVolume.size() > 0) {
|
|
|
+ for (ArticleReadVolume articleReadVolume : marketArticleReadVolume) {
|
|
|
+ if (!set.contains(articleReadVolume.getTitle())) {
|
|
|
+ set.add(articleReadVolume.getTitle());
|
|
|
+ articleReadVolumeList.add(articleReadVolume);
|
|
|
+ } else {
|
|
|
+ // 将有重复的推文数据 总阅读量 总展现量相加为一组数据
|
|
|
+ for (ArticleReadVolume readVolume : articleReadVolumeList) {
|
|
|
+ if (articleReadVolume.getTitle().equals(readVolume.getTitle())) {
|
|
|
+ readVolume.setWechatNumber(MathUtil.sub(readVolume.getWechatNumber(), articleReadVolume.getWechatNumber()).intValue());
|
|
|
+ readVolume.setTouchNumber(MathUtil.sub(readVolume.getTouchNumber(), articleReadVolume.getTouchNumber()).intValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("volumeList", articleReadVolumeList);
|
|
|
+ // 公众号推文数据
|
|
|
+ ReturnData articleReturnData = new ReturnData();
|
|
|
+ if (null != articleReadVolumeList && articleReadVolumeList.size() > 0) {
|
|
|
+ name = new ArrayList<>(articleReadVolumeList.stream().map(ArticleReadVolume::getTitleReferred).collect(Collectors.toList()));
|
|
|
+ articleReturnData.setNames(name);
|
|
|
+ value = new ArrayList<>(articleReadVolumeList.stream().map(ArticleReadVolume::getWechatNumber).collect(Collectors.toList()));
|
|
|
+ articleReturnData.setValues(value);
|
|
|
+ backupsValues = new ArrayList<>(articleReadVolumeList.stream().map(ArticleReadVolume::getTouchNumber).collect(Collectors.toList()));
|
|
|
+ articleReturnData.setBackupsValues(backupsValues);
|
|
|
+ }
|
|
|
+ map.put("wechats", articleReturnData);
|
|
|
+ // 获取展现量数据
|
|
|
+ List<Impressions> marketImpressions = marketShopDao.getMarketImpressions(id);
|
|
|
+ int generalNumber = 0, microBlog = 0, redBookNumber = 0, otherNumber = 0;
|
|
|
+ if (null != marketImpressions && marketImpressions.size() > 0) {
|
|
|
+ for (Impressions imp : marketImpressions) {
|
|
|
+ generalNumber += imp.getGeneralNumber();
|
|
|
+ microBlog += imp.getMicroBlog();
|
|
|
+ redBookNumber += imp.getRedBookNumber();
|
|
|
+ otherNumber += imp.getOtherNumber();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ReturnData returnData = new ReturnData();
|
|
|
+ name.add("公众号");
|
|
|
+ name.add("微博");
|
|
|
+ name.add("小红书");
|
|
|
+ name.add("其它自媒体渠道");
|
|
|
+ returnData.setNames(name);
|
|
|
+ value.add(generalNumber);
|
|
|
+ value.add(microBlog);
|
|
|
+ value.add(redBookNumber);
|
|
|
+ value.add(otherNumber);
|
|
|
+ returnData.setValues(value);
|
|
|
+ map.put("intention", returnData);
|
|
|
+ // 获取点击量数据
|
|
|
+ name.clear();
|
|
|
+ value.clear();
|
|
|
+ List<ReadVolume> marketReadVolume = marketShopDao.getMarketReadVolume(id);
|
|
|
+ if (null != marketReadVolume && marketReadVolume.size() > 0) {
|
|
|
+ for (ReadVolume readVolume : marketReadVolume) {
|
|
|
+ generalNumber += readVolume.getGeneralNumber();
|
|
|
+ microBlog += readVolume.getMicroBlog();
|
|
|
+ redBookNumber += readVolume.getRedBookNumber();
|
|
|
+ otherNumber += readVolume.getOtherNumber();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ReturnData readVolumeReturnData = new ReturnData();
|
|
|
+ name.add("公众号");
|
|
|
+ name.add("微博");
|
|
|
+ name.add("小红书");
|
|
|
+ name.add("其它自媒体渠道");
|
|
|
+ returnData.setNames(name);
|
|
|
+ value.add(generalNumber);
|
|
|
+ value.add(microBlog);
|
|
|
+ value.add(redBookNumber);
|
|
|
+ value.add(otherNumber);
|
|
|
+ returnData.setValues(value);
|
|
|
+ map.put("allVisits", readVolumeReturnData);
|
|
|
+ // 获取SEO汇总数据
|
|
|
+ set.clear();
|
|
|
+ List<Summary> marketSummary = marketShopDao.getMarketSummary(id);
|
|
|
+ List<Summary> summaryList = new ArrayList<>();
|
|
|
+ List<ReturnData> returnDataList = new ArrayList<>();
|
|
|
+ if (null != marketSummary && marketSummary.size() > 0) {
|
|
|
+ for (Summary summary : marketSummary) {
|
|
|
+ if (!set.contains(summary.getKeyword())) {
|
|
|
+ set.add(summary.getKeyword());
|
|
|
+ summaryList.add(summary);
|
|
|
+ } else {
|
|
|
+ for (Summary summary1 : summaryList) {
|
|
|
+ if (summary.getKeyword().equals(summary1.getKeyword())) {
|
|
|
+ summary1.setSearchVolume(MathUtil.sub(summary1.getSearchVolume(), summary.getSearchVolume()).intValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != summaryList && summaryList.size() > 0) {
|
|
|
+ for (Summary summary : summaryList) {
|
|
|
+ ReturnData summaryReturnData = new ReturnData();
|
|
|
+ summaryReturnData.setName(summary.getKeyword());
|
|
|
+ summaryReturnData.setValue(summary.getSearchVolume());
|
|
|
+ summaryReturnData.setSeo(summary.getSeoRanking());
|
|
|
+ returnDataList.add(summaryReturnData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("keywordList", summaryList);
|
|
|
+ // 获取访问量数据
|
|
|
+ name.clear();
|
|
|
+ value.clear();
|
|
|
+ List<Visits> marketVisits = marketShopDao.getMarketVisits(id);
|
|
|
+ int clubNumber = 0, touristNumber = 0;
|
|
|
+ if (null != marketVisits && marketVisits.size() > 0) {
|
|
|
+ for (Visits vis : marketVisits) {
|
|
|
+ clubNumber += vis.getClubNumber();
|
|
|
+ touristNumber += vis.getTouristNumber();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ReturnData visitsReturnData = new ReturnData();
|
|
|
+ name.add("机构访问量");
|
|
|
+ name.add("游客访问量");
|
|
|
+ visitsReturnData.setNames(name);
|
|
|
+ value.add(clubNumber);
|
|
|
+ value.add(touristNumber);
|
|
|
+ visitsReturnData.setValues(value);
|
|
|
+ map.put("stationVisits", visitsReturnData);
|
|
|
+ // 获取访客来源分布数据
|
|
|
+ name.clear();
|
|
|
+ value.clear();
|
|
|
+ List<Proportion> marketProportion = marketShopDao.getMarketProportion(id);
|
|
|
+ int search = 0, general = 0, proMicroBlog = 0, directAccess = 0;
|
|
|
+ if (null != marketProportion && marketProportion.size() > 0) {
|
|
|
+ for (Proportion proportion : marketProportion) {
|
|
|
+ search += proportion.getSearch();
|
|
|
+ general += proportion.getGeneral();
|
|
|
+ proMicroBlog += proportion.getMicroBlog();
|
|
|
+ directAccess += proportion.getDirectAccess();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ReturnData proportionReturnData = new ReturnData();
|
|
|
+ name.add("搜索引擎");
|
|
|
+ name.add("微信平台");
|
|
|
+ name.add("微博");
|
|
|
+ name.add("直接访问");
|
|
|
+ proportionReturnData.setNames(name);
|
|
|
+ value.add(search);
|
|
|
+ value.add(general);
|
|
|
+ value.add(proMicroBlog);
|
|
|
+ value.add(directAccess);
|
|
|
+ proportionReturnData.setValues(value);
|
|
|
+ map.put("proportion", proportionReturnData);
|
|
|
+ // 获取页面平均访问时长数据
|
|
|
+ set.clear();
|
|
|
+ List<PageDuration> marketPageDuration = marketShopDao.getMarketPageDuration(id);
|
|
|
+ List<PageDuration> pageDurationList = new ArrayList<>();
|
|
|
+ if (null != marketPageDuration && marketPageDuration.size() > 0) {
|
|
|
+ for (PageDuration pageDuration : marketPageDuration) {
|
|
|
+ if (!set.contains(pageDuration.getPageLabel())) {
|
|
|
+ set.add(pageDuration.getPageLabel());
|
|
|
+ pageDurationList.add(pageDuration);
|
|
|
+ } else {
|
|
|
+ for (PageDuration pageDuration1 : pageDurationList) {
|
|
|
+ if (pageDuration.getPageLabel().equals(pageDuration1.getPageLabel())) {
|
|
|
+ pageDuration1.setAccessDuration(MathUtil.sub(pageDuration1.getAccessDuration(), pageDuration.getAccessDuration()).intValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ReturnData pageDurationReturnData = new ReturnData();
|
|
|
+ name = new ArrayList<>(set);
|
|
|
+ pageDurationReturnData.setNames(name);
|
|
|
+ value = new ArrayList<>(pageDurationList.stream().map(PageDuration::getAccessDuration).collect(Collectors.toList()));
|
|
|
+ pageDurationReturnData.setValues(value);
|
|
|
+
|
|
|
+ map.put("visitTimes", pageDurationReturnData);
|
|
|
+ // 获取广告图点击量数据
|
|
|
+ List<AdvertHits> marketAdvertHits = marketShopDao.getMarketAdvertHits(id);
|
|
|
+ map.put("bannerList", marketAdvertHits);
|
|
|
+ // 获取咨询数量数据
|
|
|
+ name.clear();
|
|
|
+ value.clear();
|
|
|
+ List<Remark> marketRemark = marketShopDao.getMarketRemark(id);
|
|
|
+ if (null != marketRemark && marketRemark.size() > 0) {
|
|
|
+ for (Remark remark : marketRemark) {
|
|
|
+ try {
|
|
|
+ name.add(dateFormat.format(dateFormat.parse(remark.getAddTime())));
|
|
|
+ value.add(remark.getRemarkNumber());
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ReturnData remarkReturnData = new ReturnData();
|
|
|
+ remarkReturnData.setNames(name);
|
|
|
+ remarkReturnData.setValues(value);
|
|
|
+ map.put("leadUserMonthly", remarkReturnData);
|
|
|
+ String accessDate = "";
|
|
|
+ try {
|
|
|
+ dateFormat.format(dateFormat.parse(shopInfo.getAddTime()));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 供应商相关标签
|
|
|
+ List<String> shopKeyword = marketShopDao.getShopKeyword(shopInfo.getShopId());
|
|
|
+
|
|
|
+ Map<String, Integer> regionMap = new HashMap<>();
|
|
|
+ // 访问供应商用户对应身份
|
|
|
+ List<ReturnEntity> userIdentity = new ArrayList<>();
|
|
|
+ // 访问供应商用户对应机构类型
|
|
|
+ List<ReturnEntity> clubType = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotBlank(accessDate) && StringUtils.isNotEmpty(accessDate)) {
|
|
|
+ // 访问供应商用户对于所在地区
|
|
|
+ List<String> region = marketShopDao.getRegion(accessDate, shopKeyword);
|
|
|
+ Set<String> province = new HashSet<>();
|
|
|
+ String com = "";
|
|
|
+ for (String str : region ) {
|
|
|
+ String trim = str.trim();
|
|
|
+ com = trim.substring(0, 2);
|
|
|
+ province.add(com);
|
|
|
+ }
|
|
|
+ for (String str : province) {
|
|
|
+ List<String> collect = region.stream().filter(pro -> pro.substring(0, 3).contains(str)).collect(Collectors.toList());
|
|
|
+ regionMap.put(str, collect.size());
|
|
|
+ }
|
|
|
+ userIdentity = marketShopDao.getUserIdentity(accessDate, shopKeyword);
|
|
|
+ clubType = marketShopDao.getClubType(accessDate, shopKeyword);
|
|
|
+ }
|
|
|
+ map.put("regionMap", regionMap);
|
|
|
+ map.put("userIdentity", userIdentity);
|
|
|
+ map.put("clubType", clubType);
|
|
|
+ return ResponseJson.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取文件夹数据————指定格式 (营销供应商)
|
|
|
+ * @param marketReportId
|
|
|
+ * @param filePath
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private void readFile(Integer marketReportId, String filePath) throws IOException {
|
|
|
+ // SEO 图片集合
|
|
|
+ Map<String, String> seoImagePathList = new HashMap<>();
|
|
|
+ // 广告图点击量 首页图片集合
|
|
|
+ Map<String, String> advertImageHomeList = new HashMap<>();
|
|
|
+ // 广告图点击量 信息中心图片集合
|
|
|
+ Map<String, String> advertImageInfoList = new HashMap<>();
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (file.exists() && file.isDirectory()) {
|
|
|
+ for (File fileSpecific: file.listFiles()) {
|
|
|
+ if (fileSpecific.getName().equals("SEO汇总图片") && fileSpecific.exists() && fileSpecific.isDirectory()) {
|
|
|
+ for (File fileSpecificContain : fileSpecific.listFiles()) {
|
|
|
+ if (fileSpecificContain.getName().contains("seo")) {
|
|
|
+ // 上传图到服务器并获取图链接,存入数据库,图片名称需与 SEO 列表名称一致
|
|
|
+ MultipartFile filex = FileUtil.fileToMultipartFileConverter(fileSpecificContain);
|
|
|
+ String seoImagePath = formDataUtils.saveShopFile(filex);
|
|
|
+ String name = fileSpecificContain.getName().substring(0, fileSpecificContain.getName().lastIndexOf("."));
|
|
|
+ seoImagePathList.put(name, seoImagePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("fileSpecific.getName()======"+fileSpecific.getName());
|
|
|
+ if (fileSpecific.getName().equals("advert广告图片") && fileSpecific.exists() && fileSpecific.isDirectory()) {
|
|
|
+ for (File fileSpecificContain : fileSpecific.listFiles()) {
|
|
|
+ log.info("fileSpecificContain.getName()======"+fileSpecificContain.getName());
|
|
|
+ if (fileSpecificContain.getName().contains("首页")) {
|
|
|
+ // 上传图到服务器并获取图链接,存入数据库,图片名称需与 广告图点击量 列表名称一致
|
|
|
+ MultipartFile filex = FileUtil.fileToMultipartFileConverter(fileSpecificContain);
|
|
|
+ String advertImagePath = formDataUtils.saveShopFile(filex);
|
|
|
+ String name = fileSpecificContain.getName().substring(0, fileSpecificContain.getName().lastIndexOf("."));
|
|
|
+ advertImageHomeList.put(name, advertImagePath);
|
|
|
+ }
|
|
|
+ if (fileSpecificContain.getName().contains("信息中心")) {
|
|
|
+ // 上传图到服务器并获取图链接,存入数据库,图片名称需与 广告图点击量 列表名称一致
|
|
|
+ MultipartFile filex = FileUtil.fileToMultipartFileConverter(fileSpecificContain);
|
|
|
+ String advertImagePath = formDataUtils.saveShopFile(filex);
|
|
|
+ String name = fileSpecificContain.getName().substring(0, fileSpecificContain.getName().lastIndexOf("."));
|
|
|
+ advertImageInfoList.put(name, advertImagePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 读取完图片文件后在读取数据文件 xlsx
|
|
|
+ for (File fileSpecific: file.listFiles()) {
|
|
|
+ if (fileSpecific.getName().endsWith(".xlsx") || fileSpecific.getName().endsWith(".xls")) {
|
|
|
+ readExcel(marketReportId, fileSpecific, seoImagePathList, advertImageHomeList, advertImageInfoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多sheet excel文件读取 -- 指定sheet名称 多sheet读取必须多次创建文件流
|
|
|
+ * @param marketReportId
|
|
|
+ * @param file
|
|
|
+ * @param seoImagePathList
|
|
|
+ * @param advertImageHomeList
|
|
|
+ * @param advertImageInfoList
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ private void readExcel(Integer marketReportId, File file, Map<String, String> seoImagePathList, Map<String, String> advertImageHomeList, Map<String, String> advertImageInfoList) throws IOException {
|
|
|
+ String excelType = "XLSX";
|
|
|
+ if (file.getName().endsWith(".xls")) {
|
|
|
+ excelType = "XLS";
|
|
|
+ }
|
|
|
+ MultipartFile multipartFile = FileUtil.fileToMultipartFileConverter(file);
|
|
|
+ InputStream inputStream = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ InputStream is = inputStream;
|
|
|
+ EasyExcel.read(is, Stage.class, new StageListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("阶段描述").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, FunnelModel.class, new FunnelModelListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("漏斗模型数据").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, ArticleReadVolume.class, new ArticleReadVolumeListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("推文数据").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, Impressions.class, new ImpressionsListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("展现量").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, ReadVolume.class, new ReadVolumeListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("点击量").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, Summary.class, new SummaryListener(marketReportId, marketShopDao, seoImagePathList)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("SEO汇总").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, Visits.class, new VisitsLisener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("访问量").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, Proportion.class, new ProportionListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("访客来源分布").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, PageDuration.class, new PageDurationListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("页面平均时长").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, AdvertHits.class, new AdvertHitsListener(marketReportId, marketShopDao, advertImageHomeList, advertImageInfoList)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("广告图点击量").doRead();
|
|
|
+ is = new BufferedInputStream(multipartFile.getInputStream());
|
|
|
+ EasyExcel.read(is, Remark.class, new RemarkListener(marketReportId, marketShopDao)).excelType(ExcelTypeEnum.valueOf(excelType)).sheet("咨询数量").doRead();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|