提交 cab48713 authored 作者: Matrix's avatar Matrix

修复BUG后的单导版本

上级 4ecd2240
流水线 #208 已失败 于阶段
...@@ -8,5 +8,6 @@ package com.zjty.fp.acq.misc.entity; ...@@ -8,5 +8,6 @@ package com.zjty.fp.acq.misc.entity;
*/ */
public class ImportAds { public class ImportAds {
public static final String IMPORT_URL = "/Users/matrix/code/test/"; //实际的地址 "/home/fp/data/" 本地的地址"/Users/matrix/code/test/"
public static final String IMPORT_URL = "/home/fp/data/";
} }
...@@ -238,7 +238,7 @@ public class FileCreator { ...@@ -238,7 +238,7 @@ public class FileCreator {
if (count <= 0) count = 0; if (count <= 0) count = 0;
String psspFileName = subName + "-" + catalog + count + ".txt"; String psspFileName = subName + "-" + catalog + count + ".txt";
log.info("[pssp]成功生成文件名:{}", psspFileName); log.info("[pssp] 成功生成文件名:{}", psspFileName);
return psspFileName; return psspFileName;
} }
......
...@@ -65,7 +65,7 @@ public class PsspInitialRunner { ...@@ -65,7 +65,7 @@ public class PsspInitialRunner {
private void createCountFile(String countFileName, String CountAddress, String dirPath, boolean countExists) { private void createCountFile(String countFileName, String CountAddress, String dirPath, boolean countExists) {
int countVar; int countVar;
if (countExists) { if (countExists) {
log.info("[pssp]磁盘已存在 {} 文件,跳过初始化流程,将磁盘的 {} 读取入内存中", countFileName, countFileName); log.info("[pssp] 磁盘已存在 {} 文件,跳过初始化流程,将磁盘的 {} 读取入内存中", countFileName, countFileName);
//读取文件获得文件编号后缀值 //读取文件获得文件编号后缀值
Path path = Paths.get(CountAddress); Path path = Paths.get(CountAddress);
List<String> data = Lists.newArrayList(); List<String> data = Lists.newArrayList();
...@@ -91,12 +91,12 @@ public class PsspInitialRunner { ...@@ -91,12 +91,12 @@ public class PsspInitialRunner {
if (countMake) { if (countMake) {
try { try {
Files.write(Paths.get(CountAddress), String.valueOf(countVar).getBytes()); Files.write(Paths.get(CountAddress), String.valueOf(countVar).getBytes());
log.info("[pssp]磁盘 {} 值更新成功:count = {}", countFileName, countVar); log.info("[pssp] 磁盘 {} 值更新成功:count = {}", countFileName, countVar);
} catch (IOException e) { } catch (IOException e) {
log.info("[pssp]生成文件时出现异常:" + e); log.info("[pssp] 生成文件时出现异常:" + e);
} }
} }
log.info("[pssp]初始化 {} 文件完毕!", countFileName); log.info("[pssp] 初始化 {} 文件完毕!", countFileName);
if (CountAddress.equals(COUNT_ADDRESS_ALERT)) { if (CountAddress.equals(COUNT_ADDRESS_ALERT)) {
alert_count = countVar; alert_count = countVar;
......
...@@ -68,7 +68,7 @@ public class AlertServiceImpl implements AlertService { ...@@ -68,7 +68,7 @@ public class AlertServiceImpl implements AlertService {
String key = dynamicNow.getYear() + "-" + dynamicNow.getMonthValue(); String key = dynamicNow.getYear() + "-" + dynamicNow.getMonthValue();
Integer lastedDataId = DicMapUtil.readDictFile(alertName).getOrDefault(key, 0); Integer lastedDataId = DicMapUtil.readDictFile(alertName).getOrDefault(key, 0);
log.info("[pssp] 执行更新数据任务,本地数据库 {} 月最新数据的id为 {} ,向源数据库采集在这id之后的数据....", key, lastedDataId); log.info("[pssp] [alert] 执行更新数据任务,本地数据库 {} 月最新数据的id为 {} ,向源数据库采集在这id之后的数据....", key, lastedDataId);
log.debug("[pssp] [id_check],supposeId = {},actuallyId = {}", supposeId, lastedDataId); log.debug("[pssp] [id_check],supposeId = {},actuallyId = {}", supposeId, lastedDataId);
List<Alert> updatedData = remoteAlertRepo.findDataFromId(Long.valueOf(lastedDataId)).stream() List<Alert> updatedData = remoteAlertRepo.findDataFromId(Long.valueOf(lastedDataId)).stream()
...@@ -76,9 +76,9 @@ public class AlertServiceImpl implements AlertService { ...@@ -76,9 +76,9 @@ public class AlertServiceImpl implements AlertService {
.collect(toList()); .collect(toList());
if (CollectionUtils.isEmpty(updatedData)) { if (CollectionUtils.isEmpty(updatedData)) {
log.info("[pssp] 本次更新采集没有要更新的数据"); log.info("[pssp] [alert] 本次更新采集没有要更新的数据");
} else { } else {
log.info("[pssp] 采集完成,本次采集了 {} 条数据,数据写入本机数据库与Es数据库", updatedData.size()); log.info("[pssp] [alert] 采集完成,本次采集了 {} 条数据,数据写入本机数据库与Es数据库", updatedData.size());
supposeId = updatedData.stream() supposeId = updatedData.stream()
.map(Alert::getId) .map(Alert::getId)
...@@ -89,11 +89,11 @@ public class AlertServiceImpl implements AlertService { ...@@ -89,11 +89,11 @@ public class AlertServiceImpl implements AlertService {
fileCreator.createFileAndZip(COUNT_ADDRESS_ALERT,"pssp", alertName, webJson); fileCreator.createFileAndZip(COUNT_ADDRESS_ALERT,"pssp", alertName, webJson);
//2.记住最大ID值 //2.记住最大ID值
long maxId = updatedData.stream().mapToLong(Alert::getId).max().orElse(0L); long maxId = updatedData.stream().mapToLong(Alert::getId).max().orElse(0L);
log.info("[pssp]更新后的最大报警数据id为:{},记录到文件中", maxId); log.info("[pssp] [alert] 更新后的最大报警数据id为:{},记录到文件中", maxId);
Map<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>();
map.put(key, (int) maxId); map.put(key, (int) maxId);
DicMapUtil.createDictFile(alertName, map); DicMapUtil.createDictFile(alertName, map);
log.info("[pssp]报警数据更新完成"); log.info("[pssp] [alert] 报警数据更新完成");
} }
} }
......
...@@ -59,36 +59,36 @@ public class WebsiteServiceImpl implements WebsiteService { ...@@ -59,36 +59,36 @@ public class WebsiteServiceImpl implements WebsiteService {
@Override @Override
public void fetchUpdatedData() { public void fetchUpdatedData() {
log.info("[pssp]正在执行网站数据的增量更新"); log.info("[pssp] [website] 正在执行网站数据的增量更新");
//读取文件中的最新id , 获得当前月的时间 //读取文件中的最新id , 获得当前月的时间
Integer lastedId = DicMapUtil.readDictFile(websiteName).getOrDefault("web", 0); Integer lastedId = DicMapUtil.readDictFile(websiteName).getOrDefault("web", 0);
if (lastedId == 0) { if (lastedId == 0) {
log.info("[pssp] 当前文件中没有任何网站,请先执行网站历史采集任务"); log.info("[pssp] [website] 当前文件中没有任何网站,请先执行网站历史采集任务");
return; return;
} }
Long lastedDataId = Long.valueOf(lastedId); Long lastedDataId = Long.valueOf(lastedId);
log.info("[pssp]当前本机网站表数据的最新id为 {} ,向源数据库采集在这id之后的数据....", lastedDataId); log.info("[pssp] [website] 当前本机网站表数据的最新id为 {} ,向源数据库采集在这id之后的数据....", lastedDataId);
List<Website> updatedData = remoteWebsiteRepository.findDataFromId(lastedDataId).stream() List<Website> updatedData = remoteWebsiteRepository.findDataFromId(lastedDataId).stream()
.map(RemoteWebsite::toDo) .map(RemoteWebsite::toDo)
.collect(toList()); .collect(toList());
if (CollectionUtils.isEmpty(updatedData)) { if (CollectionUtils.isEmpty(updatedData)) {
log.info("[pssp] 本次网站更新采集没有要更新的数据"); log.info("[pssp] [website] 本次网站更新采集没有要更新的数据");
} else { } else {
log.info("[pssp] 网站数据采集完成,本次采集了 {}条数据,数据写入本机数据库", updatedData.size()); log.info("[pssp] [website] 网站数据采集完成,本次采集了 {}条数据,数据写入本机数据库", updatedData.size());
// 异步写入数据库 // 异步写入数据库
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
log.info("[pssp]正在异步写入网站更新数据到本地文件"); log.info("[pssp] [website] 正在异步写入网站更新数据到本地文件");
String webJson = JacksonUtil.toJSon(updatedData).replace("\n", ""); String webJson = JacksonUtil.toJSon(updatedData).replace("\n", "");
fileCreator.createFileAndZip(COUNT_ADDRESS_WEBSITE, "pssp", "website", webJson); fileCreator.createFileAndZip(COUNT_ADDRESS_WEBSITE, "pssp", "website", webJson);
//写完要把最新的id给记录住 //写完要把最新的id给记录住
long maxId = updatedData.stream().mapToLong(Website::getId).max().orElse(0L); long maxId = updatedData.stream().mapToLong(Website::getId).max().orElse(0L);
log.info("[pssp]更新后的最大网站数据id为:{},记录到文件中", maxId); log.info("[pssp] [website] 更新后的最大网站数据id为:{},记录到文件中", maxId);
Map<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>();
map.put("web", (int) maxId); map.put("web", (int) maxId);
DicMapUtil.createDictFile(websiteName, map); DicMapUtil.createDictFile(websiteName, map);
log.info("[pssp]异步网站更新数据写入完成"); log.info("[pssp] [website]异步网站更新数据写入完成");
}); });
} }
......
...@@ -78,7 +78,7 @@ public class CollectDataTask { ...@@ -78,7 +78,7 @@ public class CollectDataTask {
* 抓取更新的网站的数据,当前为1h/次 * 抓取更新的网站的数据,当前为1h/次
*/ */
@EnablePsspSchProtect @EnablePsspSchProtect
@Scheduled(cron = "0 0/1 * * * ?") @Scheduled(cron = "17 11 0/1 * * ?")
public void collectWebsiteData() { public void collectWebsiteData() {
log.info("[pssp] [定时任务]抓取更新的网站数据"); log.info("[pssp] [定时任务]抓取更新的网站数据");
websiteService.fetchUpdatedData(); websiteService.fetchUpdatedData();
...@@ -95,10 +95,10 @@ public class CollectDataTask { ...@@ -95,10 +95,10 @@ public class CollectDataTask {
} }
/** /**
* 抓取更新的报警数据,当前为1min/次 * 抓取更新的报警数据,当前为3min/次
*/ */
@EnablePsspSchProtect @EnablePsspSchProtect
@Scheduled(cron = "30 0/1 * * * ?") @Scheduled(cron = "33 0/3 * * * ?")
public void collectAlertData() { public void collectAlertData() {
log.info("[pssp] [定时任务] 抓取更新的报警数据"); log.info("[pssp] [定时任务] 抓取更新的报警数据");
alertService.fetchUpdatedData(); alertService.fetchUpdatedData();
...@@ -108,7 +108,6 @@ public class CollectDataTask { ...@@ -108,7 +108,6 @@ public class CollectDataTask {
* 用于检查计划任务开关的任务,如果开关连续5次检查失败,则手动打开 * 用于检查计划任务开关的任务,如果开关连续5次检查失败,则手动打开
* 该任务每30分钟执行一次 * 该任务每30分钟执行一次
*/ */
@EnablePsspSchProtect
@Scheduled(cron = "0 0/30 * * * ?") @Scheduled(cron = "0 0/30 * * * ?")
public void checkTrigger() { public void checkTrigger() {
log.info("[pssp] 开关检查任务,当前trigger为 {}", trigger); log.info("[pssp] 开关检查任务,当前trigger为 {}", trigger);
......
...@@ -32,21 +32,21 @@ public class DicMapUtil { ...@@ -32,21 +32,21 @@ public class DicMapUtil {
//每次写入前先删除文件从而达到更新的效果 //每次写入前先删除文件从而达到更新的效果
try { try {
log.info("[pssp]正在删除原始dict文件:{}", pathname + filename); log.info("[pssp] 正在删除原始dict文件:{}", pathname + filename);
Files.deleteIfExists(path); Files.deleteIfExists(path);
log.info("[pssp]删除成功,删除文件名为:{}", pathname + filename); log.info("[pssp] 删除成功,删除文件名为:{}", pathname + filename);
} catch (IOException e) { } catch (IOException e) {
log.warn("[pssp]删除文件时发生异常,信息为:{}", e.toString()); log.warn("[pssp] 删除文件时发生异常,信息为:{}", e.toString());
} }
boolean make = createFilePath(new File(pathname)); boolean make = createFilePath(new File(pathname));
List<String> stringList = new ArrayList<>(); List<String> stringList = new ArrayList<>();
idMap.forEach((k, v) -> stringList.add(k + "," + v)); idMap.forEach((k, v) -> stringList.add(k + "," + v));
log.info("[pssp] 正在重新生成dict文件 : {}",path); log.info("[pssp] 正在重新生成dict文件 : {}", path);
if (make) { if (make) {
try { try {
Files.write(path, stringList); Files.write(path, stringList);
log.info("[pssp] 重新生成 {} 文件成功",path); log.info("[pssp] 重新生成 {} 文件成功", path);
} catch (IOException e) { } catch (IOException e) {
log.info("[pssp]生成文件时出现异常:{}", e.toString()); log.info("[pssp]生成文件时出现异常:{}", e.toString());
} }
...@@ -72,6 +72,7 @@ public class DicMapUtil { ...@@ -72,6 +72,7 @@ public class DicMapUtil {
for (String d : data) { for (String d : data) {
String[] strings = d.split(","); String[] strings = d.split(",");
if (strings.length != 2) continue;
map.put(strings[0], Integer.valueOf(strings[1])); map.put(strings[0], Integer.valueOf(strings[1]));
} }
return map; return map;
......
...@@ -26,7 +26,7 @@ public class SqlInterceptor extends EmptyInterceptor { ...@@ -26,7 +26,7 @@ public class SqlInterceptor extends EmptyInterceptor {
String tableMonth = CollectDataTask.getDynamicTableMonth(); String tableMonth = CollectDataTask.getDynamicTableMonth();
// replace指定月份 if trigger false 替换当前月 // replace指定月份 if trigger false 替换当前月
String realTableName = "t_doc_" + tableMonth; String realTableName = "t_doc_" + tableMonth;
log.info("[pssp]正在进行sql拦截 拦截的表为 {},替换后的表名为{}", "remote.alert", realTableName); log.info("[pssp] 正在进行sql拦截 拦截的表为 {},替换后的表名为{}", "remote.alert", realTableName);
prepareStatement = prepareStatement.replaceAll(originalTableName, realTableName); prepareStatement = prepareStatement.replaceAll(originalTableName, realTableName);
} }
return prepareStatement; return prepareStatement;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论