|
@@ -1,20 +1,23 @@
|
|
package org.jeecg.modules.adweb.serp.service.impl;
|
|
package org.jeecg.modules.adweb.serp.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.xkcoding.http.util.StringUtil;
|
|
|
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
import org.jeecg.common.util.FastJsonUtil;
|
|
import org.jeecg.common.util.FastJsonUtil;
|
|
import org.jeecg.modules.adweb.common.util.DateUtil;
|
|
import org.jeecg.modules.adweb.common.util.DateUtil;
|
|
import org.jeecg.modules.adweb.common.util.ListUtil;
|
|
import org.jeecg.modules.adweb.common.util.ListUtil;
|
|
-import org.jeecg.modules.adweb.serp.entity.ComprehensiveStatistics;
|
|
|
|
-import org.jeecg.modules.adweb.serp.entity.HistoryReachStandardSite;
|
|
|
|
-import org.jeecg.modules.adweb.serp.entity.SeoKpiStatistics;
|
|
|
|
-import org.jeecg.modules.adweb.serp.entity.SeoPlanSubscription;
|
|
|
|
|
|
+import org.jeecg.modules.adweb.serp.entity.*;
|
|
import org.jeecg.modules.adweb.serp.mapper.SeoKeywordsMapper;
|
|
import org.jeecg.modules.adweb.serp.mapper.SeoKeywordsMapper;
|
|
-import org.jeecg.modules.adweb.serp.mapper.SeoMarketPlanMapper;
|
|
|
|
|
|
+import org.jeecg.modules.adweb.serp.mapper.SeoPlanSubscriptionMapper;
|
|
import org.jeecg.modules.adweb.serp.service.*;
|
|
import org.jeecg.modules.adweb.serp.service.*;
|
|
import org.jeecg.modules.adweb.serp.vo.RankInfoVO;
|
|
import org.jeecg.modules.adweb.serp.vo.RankInfoVO;
|
|
import org.jeecg.modules.adweb.serp.vo.SeoRankInfoVO;
|
|
import org.jeecg.modules.adweb.serp.vo.SeoRankInfoVO;
|
|
@@ -24,8 +27,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
-import java.time.LocalDate;
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author Zenas
|
|
* @author Zenas
|
|
@@ -36,12 +39,14 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
|
|
|
|
@Autowired private ISeoKpiStatisticsService seoKpiStatisticsService;
|
|
@Autowired private ISeoKpiStatisticsService seoKpiStatisticsService;
|
|
|
|
|
|
- @Resource private SeoMarketPlanMapper seoMarketPlanMapper;
|
|
|
|
|
|
+ @Resource private SeoPlanSubscriptionMapper seoPlanSubscriptionMapper;
|
|
|
|
|
|
@Resource private SeoKeywordsMapper seoKeywordsMapper;
|
|
@Resource private SeoKeywordsMapper seoKeywordsMapper;
|
|
|
|
|
|
@Autowired private ISeoKeywordsService seoKeywordsService;
|
|
@Autowired private ISeoKeywordsService seoKeywordsService;
|
|
|
|
|
|
|
|
+ @Autowired private ISeoKeywordsSerpService seoKeywordsSerpService;
|
|
|
|
+
|
|
@Autowired private ISeoPlanSubscriptionService seoPlanSubscriptionService;
|
|
@Autowired private ISeoPlanSubscriptionService seoPlanSubscriptionService;
|
|
|
|
|
|
@Autowired private IHistoryReachStandardSiteService historyReachStandardSiteService;
|
|
@Autowired private IHistoryReachStandardSiteService historyReachStandardSiteService;
|
|
@@ -75,7 +80,7 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if ("APPOINT_KEYWORDS".equals(kpiStatistics.getKpiCode())) {
|
|
if ("APPOINT_KEYWORDS".equals(kpiStatistics.getKpiCode())) {
|
|
- Integer standard = seoMarketPlanMapper.getKeywordStandard(siteCode);
|
|
|
|
|
|
+ Integer standard = seoPlanSubscriptionMapper.getKeywordStandard(siteCode);
|
|
String datesStr = "";
|
|
String datesStr = "";
|
|
List<String> dateList =
|
|
List<String> dateList =
|
|
seoKeywordsService.getKeywordsLastSevenDays(siteCode, 1, historyId);
|
|
seoKeywordsService.getKeywordsLastSevenDays(siteCode, 1, historyId);
|
|
@@ -150,12 +155,12 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
@Override
|
|
@Override
|
|
public Map getRankInfo(String siteCode, String historyId) throws ParseException {
|
|
public Map getRankInfo(String siteCode, String historyId) throws ParseException {
|
|
List<SeoRankInfoVO> seoRankInfos = this.getSeoRankInfo(siteCode, historyId);
|
|
List<SeoRankInfoVO> seoRankInfos = this.getSeoRankInfo(siteCode, historyId);
|
|
- ServerTimeVO ServerTimeVO = this.getServerTimeVO(siteCode, historyId);
|
|
|
|
|
|
+ ServerTimeVO ServerTimeVO = this.getServerTime(siteCode, historyId);
|
|
|
|
|
|
Map map = new HashMap<>();
|
|
Map map = new HashMap<>();
|
|
map.put("appointKeyword", seoRankInfos.get(0));
|
|
map.put("appointKeyword", seoRankInfos.get(0));
|
|
map.put("longTailKeyword", seoRankInfos.get(1));
|
|
map.put("longTailKeyword", seoRankInfos.get(1));
|
|
- map.put("ServerTimeVO", ServerTimeVO);
|
|
|
|
|
|
+ map.put("ServerTime", ServerTimeVO);
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -209,7 +214,7 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
* @param historyId 营销方案id
|
|
* @param historyId 营销方案id
|
|
* @return 服务情况,达标时间以及剩余时间
|
|
* @return 服务情况,达标时间以及剩余时间
|
|
*/
|
|
*/
|
|
- private ServerTimeVO getServerTimeVO(String siteCode, String historyId) {
|
|
|
|
|
|
+ private ServerTimeVO getServerTime(String siteCode, String historyId) {
|
|
ServerTimeVO ServerTimeVO = new ServerTimeVO();
|
|
ServerTimeVO ServerTimeVO = new ServerTimeVO();
|
|
|
|
|
|
// 获取套餐
|
|
// 获取套餐
|
|
@@ -227,7 +232,8 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
// 达成时间
|
|
// 达成时间
|
|
Date achieveTime = history.getKeywordsAchieveTime();
|
|
Date achieveTime = history.getKeywordsAchieveTime();
|
|
if (achieveTime != null) {
|
|
if (achieveTime != null) {
|
|
- ServerTimeVO.setReachStandardTime(new SimpleDateFormat(DateUtil.DATE_PATTERN).format(achieveTime));
|
|
|
|
|
|
+ ServerTimeVO.setReachStandardTime(
|
|
|
|
+ new SimpleDateFormat(DateUtil.DATE_PATTERN).format(achieveTime));
|
|
}
|
|
}
|
|
|
|
|
|
// 达成天数
|
|
// 达成天数
|
|
@@ -239,12 +245,14 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
List<HistoryReachStandardSite> historyReachStandardSiteList =
|
|
List<HistoryReachStandardSite> historyReachStandardSiteList =
|
|
historyReachStandardSiteService.list(historyReachStandardSiteQueryWrapper);
|
|
historyReachStandardSiteService.list(historyReachStandardSiteQueryWrapper);
|
|
if (ListUtil.isEmpty(historyReachStandardSiteList)) {
|
|
if (ListUtil.isEmpty(historyReachStandardSiteList)) {
|
|
- reachStandardDays = DateUtil.diffDay(achieveTime, new Date());
|
|
|
|
|
|
+ reachStandardDays = (int) DateUtil.diffDays(achieveTime, new Date());
|
|
} else {
|
|
} else {
|
|
HistoryReachStandardSite historyReachStandardSite =
|
|
HistoryReachStandardSite historyReachStandardSite =
|
|
historyReachStandardSiteList.get(0);
|
|
historyReachStandardSiteList.get(0);
|
|
int newDays =
|
|
int newDays =
|
|
- DateUtil.diffDay(historyReachStandardSite.getCreateTime(), new Date());
|
|
|
|
|
|
+ (int)
|
|
|
|
+ DateUtil.diffDays(
|
|
|
|
+ historyReachStandardSite.getCreateTime(), new Date());
|
|
reachStandardDays = historyReachStandardSite.getReachStandardDays() + newDays;
|
|
reachStandardDays = historyReachStandardSite.getReachStandardDays() + newDays;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -259,14 +267,14 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
int compensateDay = history.getCompensateDay();
|
|
int compensateDay = history.getCompensateDay();
|
|
int totalGiveAndCompensateDay = giveDay + compensateDay;
|
|
int totalGiveAndCompensateDay = giveDay + compensateDay;
|
|
log.info(
|
|
log.info(
|
|
- "getServerTimeVO -- historyId:{},giveDay:{},compensateDay:{},totalGiveAndCompensateDay:{}",
|
|
|
|
|
|
+ "getServerTime -- historyId:{},giveDay:{},compensateDay:{},totalGiveAndCompensateDay:{}",
|
|
history.getId(),
|
|
history.getId(),
|
|
giveDay,
|
|
giveDay,
|
|
compensateDay,
|
|
compensateDay,
|
|
totalGiveAndCompensateDay);
|
|
totalGiveAndCompensateDay);
|
|
remainServerDays = serverDay + totalGiveAndCompensateDay - reachStandardDays;
|
|
remainServerDays = serverDay + totalGiveAndCompensateDay - reachStandardDays;
|
|
log.info(
|
|
log.info(
|
|
- "getServerTimeVO -- 剩余服务天数:{},服务天数:{},赠、补天数:{},达成天数:{}",
|
|
|
|
|
|
+ "getServerTime -- 剩余服务天数:{},服务天数:{},赠、补天数:{},达成天数:{}",
|
|
remainServerDays,
|
|
remainServerDays,
|
|
serverDay,
|
|
serverDay,
|
|
totalGiveAndCompensateDay,
|
|
totalGiveAndCompensateDay,
|
|
@@ -279,27 +287,27 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
int compensateDay = history.getCompensateDay();
|
|
int compensateDay = history.getCompensateDay();
|
|
int totalGiveAndCompensateDay = giveDay + compensateDay;
|
|
int totalGiveAndCompensateDay = giveDay + compensateDay;
|
|
log.info(
|
|
log.info(
|
|
- "getServerTimeVO -- historyId:{},giveDay:{},compensateDay:{},totalGiveAndCompensateDay:{}",
|
|
|
|
|
|
+ "getServerTime -- historyId:{},giveDay:{},compensateDay:{},totalGiveAndCompensateDay:{}",
|
|
history.getId(),
|
|
history.getId(),
|
|
giveDay,
|
|
giveDay,
|
|
compensateDay,
|
|
compensateDay,
|
|
totalGiveAndCompensateDay);
|
|
totalGiveAndCompensateDay);
|
|
Date serverEndTime = history.getServiceEndTime();
|
|
Date serverEndTime = history.getServiceEndTime();
|
|
log.info(
|
|
log.info(
|
|
- "getServerTimeVO -- 原来的serverEndTime:{}",
|
|
|
|
|
|
+ "getServerTime -- 原来的serverEndTime:{}",
|
|
new SimpleDateFormat(DateUtil.DATE_PATTERN).format(serverEndTime));
|
|
new SimpleDateFormat(DateUtil.DATE_PATTERN).format(serverEndTime));
|
|
- serverEndTime = DateUtil.addDate(serverEndTime, totalGiveAndCompensateDay, 3);
|
|
|
|
|
|
+ serverEndTime = DateUtil.addDays(serverEndTime, totalGiveAndCompensateDay);
|
|
log.info(
|
|
log.info(
|
|
- "getServerTimeVO -- 增加赠、补天数:{},赠送天数、补偿天数后的serverEndTime:{}",
|
|
|
|
|
|
+ "getServerTime -- 增加赠、补天数:{},赠送天数、补偿天数后的serverEndTime:{}",
|
|
totalGiveAndCompensateDay,
|
|
totalGiveAndCompensateDay,
|
|
new SimpleDateFormat(DateUtil.DATE_PATTERN).format(serverEndTime));
|
|
new SimpleDateFormat(DateUtil.DATE_PATTERN).format(serverEndTime));
|
|
if (serverEndTime.compareTo(new Date()) <= 0) {
|
|
if (serverEndTime.compareTo(new Date()) <= 0) {
|
|
remainServerDays = 0;
|
|
remainServerDays = 0;
|
|
} else {
|
|
} else {
|
|
- remainServerDays = DateUtil.diffDay(serverEndTime, new Date());
|
|
|
|
|
|
+ remainServerDays = (int) DateUtil.diffDays(serverEndTime, new Date());
|
|
}
|
|
}
|
|
log.info(
|
|
log.info(
|
|
- "getServerTimeVO -- 剩余服务天数:{},赠、补天数:{},达成天数:{}",
|
|
|
|
|
|
+ "getServerTime -- 剩余服务天数:{},赠、补天数:{},达成天数:{}",
|
|
remainServerDays,
|
|
remainServerDays,
|
|
totalGiveAndCompensateDay,
|
|
totalGiveAndCompensateDay,
|
|
reachStandardDays);
|
|
reachStandardDays);
|
|
@@ -356,4 +364,108 @@ public class SearchKeywordsServiceImpl implements ISearchKeywordsService {
|
|
}
|
|
}
|
|
return KeywordsRankMap;
|
|
return KeywordsRankMap;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 给列表中的关键字增加排名信息
|
|
|
|
+ * 根据关键词类型
|
|
|
|
+ * @param keywordList 关键词列表
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void addRankInfoByIntervalTimeByType(List<SeoKeywords> keywordList, Integer keywordType, String siteCode, String historyId, List<String> dateList) throws Exception {
|
|
|
|
+ if (ListUtil.isEmpty(keywordList)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String datesStr = "";
|
|
|
|
+ if(ListUtil.isEmpty(dateList)){
|
|
|
|
+ return;
|
|
|
|
+ }else{
|
|
|
|
+ for(int i = 0; i < dateList.size(); i++){
|
|
|
|
+ if(i == dateList.size() - 1){
|
|
|
|
+ datesStr += "'" + dateList.get(i) + "'";
|
|
|
|
+ }else{
|
|
|
|
+ datesStr += "'" + dateList.get(i) + "'" + ",";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ datesStr = "(" + datesStr + ")";
|
|
|
|
+ }
|
|
|
|
+ List<Integer> keywordIds = keywordList.stream().map(SeoKeywords::getId).collect(Collectors.toList());
|
|
|
|
+ List<SeoKeywordsSerp> serpList = seoKeywordsSerpService.list(new LambdaQueryWrapper<SeoKeywordsSerp>()
|
|
|
|
+ .in(SeoKeywordsSerp::getKeywordsId, keywordIds)
|
|
|
|
+ .in(SeoKeywordsSerp::getSeDate, dateList));
|
|
|
|
+ List<SeoKeywordsSerp> noRepeatSerpList = new ArrayList<>();
|
|
|
|
+ Map<String, Integer> serpMap = new HashMap<>();
|
|
|
|
+ if(ListUtil.notEmpty(serpList)){
|
|
|
|
+ for (SeoKeywordsSerp seoKeywordsSerp : serpList) {
|
|
|
|
+ seoKeywordsSerp.setKey(seoKeywordsSerp.getKeywordsId() + "_" + seoKeywordsSerp.getSeDate());
|
|
|
|
+ if(ListUtil.notEmpty(noRepeatSerpList)){
|
|
|
|
+ List<SeoKeywordsSerp> have = noRepeatSerpList.stream().filter(o -> o.getKey().equals(seoKeywordsSerp.getKey())).collect(Collectors.toList());
|
|
|
|
+ if(ListUtil.isEmpty(have)){
|
|
|
|
+ serpMap.put(seoKeywordsSerp.getKey(),seoKeywordsSerp.getRankAbsolute());
|
|
|
|
+ noRepeatSerpList.add(seoKeywordsSerp);
|
|
|
|
+ }else{
|
|
|
|
+ log.info("重复的数据:" + seoKeywordsSerp.getKey());
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ serpMap.put(seoKeywordsSerp.getKey(),seoKeywordsSerp.getRankAbsolute());
|
|
|
|
+ noRepeatSerpList.add(seoKeywordsSerp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (SeoKeywords keyword : keywordList) {
|
|
|
|
+ Map<String, String> rankInfo = new LinkedHashMap<>();
|
|
|
|
+ for (String date : dateList) {
|
|
|
|
+
|
|
|
|
+ // 从Map中获取那天的排名信息
|
|
|
|
+ Integer rankAbsolute = serpMap.get(keyword.getId() + "_" + date);
|
|
|
|
+
|
|
|
|
+ if(rankAbsolute == null){
|
|
|
|
+ rankAbsolute = 0;
|
|
|
|
+ }
|
|
|
|
+ rankInfo.put(date, rankAbsolute + "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ keyword.setRankInfo(rankInfo);
|
|
|
|
+ keyword.setIpAddress("223.112.18.226");
|
|
|
|
+
|
|
|
|
+ keyword.setDateList(dateList);
|
|
|
|
+ if(StringUtil.isEmpty(keyword.getSearchUrl())){
|
|
|
|
+ keyword.setSearchUrl("https://www.google.com/");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 自适应宽度(中文支持)
|
|
|
|
+ * @param sheet
|
|
|
|
+ * @param size 因为for循环从0开始,size值为 列数-1
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void setSizeColumn(Sheet sheet, int size) {
|
|
|
|
+ for (int columnNum = 0; columnNum <= size; columnNum++) {
|
|
|
|
+ int columnWidth = sheet.getColumnWidth(columnNum) / 256;
|
|
|
|
+ for (int rowNum = 0; rowNum <= sheet.getLastRowNum(); rowNum++) {
|
|
|
|
+ Row currentRow;
|
|
|
|
+ //当前行未被使用过
|
|
|
|
+ if (sheet.getRow(rowNum) == null) {
|
|
|
|
+ currentRow = sheet.createRow(rowNum);
|
|
|
|
+ } else {
|
|
|
|
+ currentRow = sheet.getRow(rowNum);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (currentRow.getCell(columnNum) != null) {
|
|
|
|
+ Cell currentCell = currentRow.getCell(columnNum);
|
|
|
|
+ if (currentCell.getCellType() == CellType.STRING) {
|
|
|
|
+ int length = currentCell.getStringCellValue().getBytes().length;
|
|
|
|
+ if (columnWidth < length) {
|
|
|
|
+ columnWidth = length;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sheet.setColumnWidth(columnNum, columnWidth * 256);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|