|
@@ -1,17 +1,32 @@
|
|
package com.caimei365.manager.service.caimei.user.impl;
|
|
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.caimei365.manager.dao.user.CmMarketShopDao;
|
|
import com.caimei365.manager.dao.user.CmMarketShopDao;
|
|
import com.caimei365.manager.entity.PaginationVo;
|
|
import com.caimei365.manager.entity.PaginationVo;
|
|
import com.caimei365.manager.entity.ResponseJson;
|
|
import com.caimei365.manager.entity.ResponseJson;
|
|
import com.caimei365.manager.entity.caimei.CmShop;
|
|
import com.caimei365.manager.entity.caimei.CmShop;
|
|
-import com.caimei365.manager.entity.caimei.shopImport.CmMarketReport;
|
|
|
|
-import com.caimei365.manager.entity.caimei.shopImport.CmMarketShop;
|
|
|
|
|
|
+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.service.caimei.user.CmMarketShopService;
|
|
|
|
+import com.caimei365.manager.utils.FileUtil;
|
|
|
|
+import com.caimei365.manager.utils.formDataUtils;
|
|
import com.github.pagehelper.PageHelper;
|
|
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.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 javax.annotation.Resource;
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Description
|
|
* Description
|
|
@@ -19,63 +34,19 @@ import java.util.List;
|
|
* @author : hzg
|
|
* @author : hzg
|
|
* @date : 2023/12/14
|
|
* @date : 2023/12/14
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class CmMarketShopServiceImpl implements CmMarketShopService {
|
|
public class CmMarketShopServiceImpl implements CmMarketShopService {
|
|
|
|
|
|
- @Resource private CmMarketShopDao marketShopDao;
|
|
|
|
|
|
+ private final static String ZIP_FILE = "zip";
|
|
|
|
+ private final static String RAR_FILE = "rar";
|
|
|
|
|
|
- /**
|
|
|
|
- * 供应商列表
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public ResponseJson<PaginationVo<CmShop>> getShop(String shopName, int pageNum, int pageSize) {
|
|
|
|
- PageHelper.startPage(pageNum, pageSize);
|
|
|
|
- List<CmShop> shopList = marketShopDao.getShopList(shopName);
|
|
|
|
- List<Integer> marketShopIdList = marketShopDao.getMarketShopIdList();
|
|
|
|
- shopList.forEach(shop -> {
|
|
|
|
- if (marketShopIdList.contains(shop.getShopId())) {
|
|
|
|
- shop.setFlag(false);
|
|
|
|
- } else {
|
|
|
|
- shop.setFlag(true);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- PaginationVo<CmShop> page = new PaginationVo<>(shopList);
|
|
|
|
- return ResponseJson.success(page);
|
|
|
|
- }
|
|
|
|
|
|
+// private final static String extract = "/mnt/newdatadrive/data/runtime/jar-instance/manager-api/extract";
|
|
|
|
+ private final static String extract = "E:\\Users\\Desktop\\extract";
|
|
|
|
|
|
- /**
|
|
|
|
- * 营销供应商列表
|
|
|
|
- *
|
|
|
|
- * @param shopName
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public ResponseJson<PaginationVo<CmMarketShop>> getMarkShopList(String shopName, int pageNum, int pageSize) {
|
|
|
|
- PageHelper.startPage(pageNum, pageSize);
|
|
|
|
- List<CmMarketShop> marketShopList = marketShopDao.getMarketShopList(shopName);
|
|
|
|
- PaginationVo<CmMarketShop> page = new PaginationVo<>(marketShopList);
|
|
|
|
- return ResponseJson.success(page);
|
|
|
|
- }
|
|
|
|
|
|
+ @Resource private CmMarketShopDao marketShopDao;
|
|
|
|
|
|
- /**
|
|
|
|
- * 添加营销供应商
|
|
|
|
- *
|
|
|
|
- * @param ids
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public ResponseJson saveMarketShop(String ids) {
|
|
|
|
- if (ids.contains(",")) {
|
|
|
|
- String[] split = ids.split(",");
|
|
|
|
- for(String id : split) {
|
|
|
|
- marketShopDao.insertMarketShop(Integer.parseInt(id));
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- marketShopDao.insertMarketShop(Integer.parseInt(ids));
|
|
|
|
- }
|
|
|
|
- return ResponseJson.success();
|
|
|
|
- }
|
|
|
|
|
|
+ @Resource private formDataUtils formDataUtils;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 上传供应商营销logo
|
|
* 上传供应商营销logo
|
|
@@ -141,4 +112,189 @@ public class CmMarketShopServiceImpl implements CmMarketShopService {
|
|
marketShopDao.updateMarketReport(id);
|
|
marketShopDao.updateMarketReport(id);
|
|
return ResponseJson.success();
|
|
return ResponseJson.success();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 上传zip、rar文件到服务器并解压
|
|
|
|
+ *
|
|
|
|
+ * @param reportFile
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson saveMarketReport( MultipartFile reportFile) throws IOException {
|
|
|
|
+
|
|
|
|
+ boolean isZipPack = true;
|
|
|
|
+
|
|
|
|
+ //不存在则创建
|
|
|
|
+ File packFile = new File(extract);
|
|
|
|
+ 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, extract);
|
|
|
|
+ }
|
|
|
|
+ //获取压缩包名称
|
|
|
|
+ filename = filename.substring(0, filename.lastIndexOf("."));
|
|
|
|
+ log.info("filename===="+filename);
|
|
|
|
+ log.info("packFilePath===="+packFilePath);
|
|
|
|
+ if (file.exists()) {
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ String filePath = extract + "/" + filename;
|
|
|
|
+ return ResponseJson.success(filePath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存报表数据
|
|
|
|
+ *
|
|
|
|
+ * @param marketId
|
|
|
|
+ * @param reportDate
|
|
|
|
+ * @param reportName
|
|
|
|
+ * @param filePath
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson saveReport(Integer marketId, String reportDate, String reportName, String filePath) throws IOException {
|
|
|
|
+ CmMarketReport marketReport = new CmMarketReport();
|
|
|
|
+ marketReport.setMarketId(marketId);
|
|
|
|
+ marketReport.setReportDate(reportDate);
|
|
|
|
+ marketReport.setReportName(reportName);
|
|
|
|
+ marketShopDao.insertMarketReport(marketReport);
|
|
|
|
+ // 读取文件,处理数据
|
|
|
|
+ readFile(marketReport.getId(), filePath);
|
|
|
|
+ return ResponseJson.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 报表数据预览
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<Map<String, Object>> preview(Integer id) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ seoImagePathList.put(filex.getName(), seoImagePath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (fileSpecific.getName().equals("广告图片") && fileSpecific.exists() && fileSpecific.isDirectory()) {
|
|
|
|
+ for (File fileSpecificContain : fileSpecific.listFiles()) {
|
|
|
|
+ if (fileSpecificContain.getName().contains("首页")) {
|
|
|
|
+ // 上传图到服务器并获取图链接,存入数据库,图片顺序需与 广告图点击量 列表顺序一致
|
|
|
|
+ MultipartFile filex = FileUtil.fileToMultipartFileConverter(fileSpecificContain);
|
|
|
|
+ String advertImagePath = formDataUtils.saveShopFile(filex);
|
|
|
|
+ advertImageHomeList.put(filex.getName(), advertImagePath);
|
|
|
|
+ }
|
|
|
|
+ if (fileSpecificContain.getName().contains("信息中心")) {
|
|
|
|
+ // 上传图到服务器并获取图链接,存入数据库,图片顺序需与 广告图点击量 列表顺序一致
|
|
|
|
+ MultipartFile filex = FileUtil.fileToMultipartFileConverter(fileSpecificContain);
|
|
|
|
+ String advertImagePath = formDataUtils.saveShopFile(filex);
|
|
|
|
+ advertImageInfoList.put(filex.getName(), advertImagePath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|