提交 566183d3 authored 作者: Matrix's avatar Matrix

first commit

上级
# dir files
/target/
/log/*
/file
/files
# Compiled class file
*.class
# Log file
*.log
.log
**/.log
# publisher file
schemes.json
# BlueJ files
*.ctxt
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# other files
!.mvn/wrapper/maven-wrapper.jar
*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html
.DS_Store
.classpath
.factorypath
.gradle
.idea
.metadata
.project
.recommenders
.settings
.springBeans
/build
/code
MANIFEST.MF
_site/
activemq-data
bin
build
build.log
dependency-reduced-pom.xml
dump.rdb
interpolated*.xml
lib/
manifest.yml
overridedb.*
settings.xml
target
transaction-logs
.flattened-pom.xml
secrets.yml
.gradletasknamecache
.sts4-cache
\ No newline at end of file
stages:
- build
- test
- deploy
variables:
JAR_LOCATION: 'acq-union/target/acq-union-0.0.1-SNAPSHOT.jar'
REMOTE_USER: 'root'
REMOTE_IP: '192.168.1.159'
REMOTE_LOCATION: '/root/projects/fp-api'
# 缓存jar 文件
cache:
paths:
- $JAR_LOCATION
api-build-159:
stage: build
only:
- master
tags:
- fp-api
script:
- mvn clean package -DskipTests=true -P prod
artifacts:
name: "$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-prod"
when: on_success
expire_in: 1 days
paths:
- acq-union/target/*.jar
api-build-A3:
stage: build
only:
- master
tags:
- fp-api
environment:
name: A3-env
when: manual
script:
- mvn clean package -DskipTests=true -P deploy
artifacts:
name: "$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-deploy"
when: on_success
expire_in: 1 days
paths:
- acq-union/target/*.jar
api-test:
stage: test
only:
- master
tags:
- fp-api
script:
- export
- echo "This is just a test example echo!"
api-deploy-159:
stage: deploy
only:
- master
tags:
- fp-api
environment:
name: production
# 可选执行
# when: manual
script:
# 将jar包上传到指定的远程服务器的指定目录
- scp -r $JAR_LOCATION $REMOTE_USER@$REMOTE_IP:$REMOTE_LOCATION
# 通过ssh远程执行
- ssh $REMOTE_USER@$REMOTE_IP sh /root/projects/fp-api/shutdown.sh 8087
- ssh $REMOTE_USER@$REMOTE_IP service fp-api start
api-rebuild-deploy-159:
stage: deploy
only:
- master
tags:
- fp-api
environment:
name: production
# 可选执行
when: manual
script:
- mvn clean package -DskipTests=true -P prod
# 将jar包上传到指定的远程服务器的指定目录
- scp -r $JAR_LOCATION $REMOTE_USER@$REMOTE_IP:$REMOTE_LOCATION
# 通过ssh远程执行
- ssh $REMOTE_USER@$REMOTE_IP sh /root/projects/fp-api/shutdown.sh 8087
- ssh $REMOTE_USER@$REMOTE_IP service fp-api start
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>fp-acq-wz</artifactId>
<groupId>com.zjty.fp</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>acq-misc</artifactId>
<!-- Java版本 与 编码格式控制 -->
<properties>
<swagger.version>2.9.0</swagger.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.1</version>
</dependency>
<!--easy-poi excel导入导出工具包-->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.yy/android-util -->
<dependency>
<groupId>com.yy</groupId>
<artifactId>android-util</artifactId>
<version>1.0.2</version>
</dependency>
<!--swagger2 enable dependency-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>com.github.caspar-chen</groupId>
<artifactId>swagger-ui-layer</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${swagger.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!--跳过测试插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<skipTests>true</skipTests> <!--默认关掉单元测试 -->
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.zjty.fp.acq.misc.config;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* fusion-platform. swagger2 autoDocument interface for {@link Swagger2Config}
*
* @author : Matrix [xhyrzldf@gmail.com]
* 19-1-10 .
*/
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Documented
public @interface AutoDocument {
String value() default "";
}
package com.zjty.fp.acq.misc.config;
import com.google.common.collect.Sets;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* fusion-platform.
*
* @author : Matrix [xhyrzldf@gmail.com]
* 19-1-10 .
*/
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.produces(Sets.newHashSet("application/json"))
.consumes(Sets.newHashSet("application/json"))
.protocols(Sets.newHashSet("http"))
.apiInfo(apiInfo())
.forCodeGeneration(true)
.useDefaultResponseMessages(true)
// .globalResponseMessage(RequestMethod.GET, getResMsg())
.select()
// 指定controller存放的目录路径
.apis(RequestHandlerSelectors.withClassAnnotation(AutoDocument.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// 文档标题
.title("融合平台接口文档")
// 文档描述
.description("融合平台的接口文档与测试页面")
.termsOfServiceUrl("http://192.168.1.155:8080/fusion-group/fusion-platform")
.version("v1")
.contact(new Contact("fusion-group", "http://192.168.1.155:8080/fusion-group/fusion-platform", "fusion-group@example.com"))
.build();
}
// private ArrayList<ResponseMessage> getResMsg() {
// return newArrayList(new ResponseMessageBuilder()
// .code(500)
// .message("服务器内部发生了某种错误")
// .responseModel(new ModelRef("Error"))
// .build(),
// new ResponseMessageBuilder()
// .code(404)
// .message("用户发出的请求针对的是不存在的记录,服务器没有进行操作")
// .responseModel(new ModelRef("Exception"))
// .build(),
// new ResponseMessageBuilder()
// .code(406)
// .message("用户请求的格式不可得(比如用户请求JSON格式,但是只有XML格式)")
// .responseModel(new ModelRef("Exception"))
// .build(),
// new ResponseMessageBuilder()
// .code(501)
// .message("不支持的HTTP请求,请检查HTTP TYPE与资源路径是否正确")
// .responseModel(new ModelRef("Exception"))
// .build());
// }
}
package com.zjty.fp.acq.misc.entity;
/**
* ImportAds.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/7/29 at 6:31 下午
*/
public class ImportAds {
//实际的地址 "/home/fp/data/" 本地的地址"/Users/matrix/code/test/"
public static final String IMPORT_URL = "/home/fp/data/";
}
package com.zjty.fp.acq.misc.entity;
/**
* PsspCount.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/7/29 at 12:20 下午
*/
public class PsspCount {
/**
* 代表下一个报警文件应当用的后缀号
*/
public static int alert_count = -1;
/**
* 代表下一个网站文件应当用的后缀号
*/
public static int website_count = -1;
public static final String COUNT_PATH = "/files/pssp/count";
public static final String GLOBAL_COUNT_PATH = ImportAds.IMPORT_URL + "files/pssp/count";
public static final String COUNT_ADDRESS_ALERT = "/files/pssp/count/alert.txt";
public static final String COUNT_ADDRESS_WEBSITE = "/files/pssp/count/website.txt";
}
package com.zjty.fp.acq.misc.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* fp-fp.
*
* @author : Matrix [xhyrzldf@gmail.com]
* 18-11-12 .
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UnionEvent {
@ExcelIgnore
private String platform;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Excel(name = "数据抓取时间", orderNum = "3", exportFormat = "yyyy-MM-dd HH:mm:ss", width = 25)
private Date tmFetch;
}
package com.zjty.fp.acq.misc.utils;
import java.text.NumberFormat;
/**
* <p>Description : fp-fp
* <p>Date : 2018/10/30 15:31
* <p>@author : Mcj
*/
public class AlgorithmUtil {
/**
* 计算百分比
*
* @param num1 被除数
* @param num2 除数
* @return 百分比字符串
*/
public static String percentage(double num1, double num2) {
if (num1 == 0 && num2 == 0) {
return "0%";
}
double ratio = num1 / num2;
NumberFormat format = NumberFormat.getPercentInstance();
format.setMaximumFractionDigits(2);//设置保留几位小数
return format.format(ratio);
}
/**
* 计算环比
*
* @param num1 今日报警
* @param num2 昨日报警
* @return 百分比
*/
public static String linkRatio(double num1, double num2) {
if (num1 == 0) {
return "0%";
}
if (num2 == 0) {
return "100%";
}
double ratio = num1 - num2;
double linkRatio = ratio / num2;
NumberFormat format = NumberFormat.getPercentInstance();
format.setMaximumFractionDigits(2);//设置保留几位小数
return format.format(linkRatio);
}
}
package com.zjty.fp.acq.misc.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* fp-fp.
*
* @author : Matrix [xhyrzldf@gmail.com]
* 18-11-15 .
*/
public class CollectionUtil {
@SafeVarargs
public static <T, K extends Collection<T>> List<T> contact(K... datas) {
return contact(Arrays.asList(datas));
}
public static <T, K extends Collection<T>> List<T> contact(Collection<K> datas) {
List<T> result = new ArrayList<>();
for (K k : datas) {
result.addAll(k);
}
return result;
}
/**
* 将一个list均分成n个list,主要通过偏移量来实现的
*
* @param source
* @return
*/
public static <T> List<List<T>> averageAssign(List<T> source, int n) {
List<List<T>> result = new ArrayList<>();
int remaider = source.size() % n; //(先计算出余数)
int number = source.size() / n; //然后是商
int offset = 0;//偏移量
for (int i = 0; i < n; i++) {
List<T> value;
if (remaider > 0) {
value = source.subList(i * number + offset, (i + 1) * number + offset + 1);
remaider--;
offset++;
} else {
value = source.subList(i * number + offset, (i + 1) * number + offset);
}
result.add(value);
}
return result;
}
}
package com.zjty.fp.acq.misc.utils;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* <p>Description : nsrsapi
* <p>Date : 2018/9/13 16:58
* <p>@author : Mcj
*/
public class DateUtil {
/**
* 以今日为基准,获得x天后的日期
*
* @param days 数字,代表几天后,参数可以是正数也可以是负数
* @return 例:20181101
*/
public static String getPlusDays(int days) {
LocalDate now = LocalDate.now();
LocalDate localDate = now.plusDays(days);
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
return localDate.format(yyyyMMdd);
}
/**
* 以今日为基准,获得x天后的日期精确到时分秒
*
* @param days 几天后或者几天前,参数可以是正数也可以是负数
* @return Date类型
* 例:2018-11-01 23:59:59
*/
public static Date getPlusDaysMax(int days) {
ZoneId zoneId = ZoneId.systemDefault();
LocalDate now = LocalDate.now();
LocalDate localDate = now.plusDays(days);
LocalDateTime localDateTime = LocalDateTime.of(localDate, LocalTime.MAX);
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
/**
* 以今日为基准,获得x天后的日期精确到时分秒
*
* @param days 几天后或者几天前,参数可以是正数也可以是负数
* @return Date类型
* 例:2018-11-01 00:00:00
*/
public static Date getPlusDaysMin(int days) {
ZoneId zoneId = ZoneId.systemDefault();
LocalDate now = LocalDate.now();
LocalDate localDate = now.plusDays(days);
LocalDateTime localDateTime = LocalDateTime.of(localDate, LocalTime.MIN);
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
}
package com.zjty.fp.acq.misc.utils;
import com.loopj.android.http.Base64;
import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
/**
* DeflaterUtils 压缩字符串
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/7/29 at 9:43 上午
*/
public class DeflaterUtils {
/**
* 压缩
*/
public static String zipString(String unzipString) {
/**
*
* 0 ~ 9 压缩等级 低到高
* public static final int BEST_COMPRESSION = 9; 最佳压缩的压缩级别。
* public static final int BEST_SPEED = 1; 压缩级别最快的压缩。
* public static final int DEFAULT_COMPRESSION = -1; 默认压缩级别。
* public static final int DEFAULT_STRATEGY = 0; 默认压缩策略。
* public static final int DEFLATED = 8; 压缩算法的压缩方法(目前唯一支持的压缩方法)。
* public static final int FILTERED = 1; 压缩策略最适用于大部分数值较小且数据分布随机分布的数据。
* public static final int FULL_FLUSH = 3; 压缩刷新模式,用于清除所有待处理的输出并重置拆卸器。
* public static final int HUFFMAN_ONLY = 2; 仅用于霍夫曼编码的压缩策略。
* public static final int NO_COMPRESSION = 0; 不压缩的压缩级别。
* public static final int NO_FLUSH = 0; 用于实现最佳压缩结果的压缩刷新模式。
* public static final int SYNC_FLUSH = 2; 用于清除所有未决输出的压缩刷新模式; 可能会降低某些压缩算法的压缩率。
*/
//使用指定的压缩级别创建一个新的压缩器。
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
//设置压缩输入数据。
deflater.setInput(unzipString.getBytes());
//当被调用时,表示压缩应该以输入缓冲区的当前内容结束。
deflater.finish();
final byte[] bytes = new byte[256];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
while (!deflater.finished()) {
//压缩输入数据并用压缩数据填充指定的缓冲区。
int length = deflater.deflate(bytes);
outputStream.write(bytes, 0, length);
}
//关闭压缩器并丢弃任何未处理的输入。
deflater.end();
return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_PADDING);
}
/**
* 解压缩
*/
@Nullable
public static String unzipString(String zipString) {
byte[] decode = Base64.decode(zipString, Base64.NO_PADDING);
//创建一个新的解压缩器 https://www.yiibai.com/javazip/javazip_inflater.html
Inflater inflater = new Inflater();
//设置解压缩的输入数据。
inflater.setInput(decode);
final byte[] bytes = new byte[256];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
try {
//finished() 如果已到达压缩数据流的末尾,则返回true。
while (!inflater.finished()) {
//将字节解压缩到指定的缓冲区中。
int length = inflater.inflate(bytes);
outputStream.write(bytes, 0, length);
}
} catch (DataFormatException e) {
e.printStackTrace();
return null;
} finally {
//关闭解压缩器并丢弃任何未处理的输入。
inflater.end();
}
return outputStream.toString();
}
}
package com.zjty.fp.acq.misc.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.net.ftp.FTPClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* <p>Description : Downloader
* <p>Date : 2018/9/11 16:15
* <p>@author : C
* 访问FTP服务器并下载文件的工具类
* 已作为bean在spring中注册
* 需要使用时自动注入(@Autowired)即可
* 需要的参数从properties文件中读取
* 请保证properties文件中有配置这些参数
* 有以下参数:
* ftp.server.ip FTP服务器的ip地址
* ftp.server.port FTP服务器的端口号
* ftp.server.username 用户名
* ftp.server.password 密码
*/
@SuppressWarnings({"unused", "UnusedReturnValue"})
@Component
@Scope("prototype")
@Slf4j
public class Downloader {
@Value("${ftp.server.ip}")
private String ip;
@Value("${ftp.server.port}")
private Integer port;
@Value("${ftp.server.username}")
private String userName;
@Value("${ftp.server.password}")
private String password;
private FTPClient ftpClient = new FTPClient();
/**
* @param subName 平台文件夹名 (FTP服务器上存有多个平台的文件)
* @param catalog 种类文件夹名 (每个平台又有多种种类的文件)
* @return boolean 是否下载成功
* 从指定的文件夹路径下载当天的文件
* 文件夹路径与上传时的相同:平台文件夹名/种类文件夹名/
* 文件名也为相同的自动生成 格式:平台名-种类-时间(yyyyMMdd).txt
* 默认下载目的地路径是:项目根目录/file/平台文件夹名/种类文件夹名/
* 若项目是以jar包形式运行的状态,则是:项目jar包同级目录/file/平台文件夹名/种类文件夹名/
*/
public boolean download(String subName, String catalog) {
return downloadFile(subName, catalog);
}
/**
* @param subName 平台文件夹名 (FTP服务器上存有多个平台的文件)
* @param catalog 种类文件夹名 (每个平台又有多种种类的文件)
* @return boolean 是否下载成功
* 从指定的文件夹路径下载当天的文件
* 文件夹路径与上传时的相同:平台文件夹名/种类文件夹名/
* 文件名也为相同的自动生成 格式:平台名-种类-时间(yyyyMMdd).txt
* 默认下载目的地路径是:项目根目录/file/平台文件夹名/种类文件夹名/
* 若项目是以jar包形式运行的状态,则是:项目jar包同级目录/file/平台文件夹名/种类文件夹名/
*/
public boolean download(String subName, String catalog, String Time) {
return downloadFile(subName, catalog, Time);
}
/*
私有方法
*/
private boolean downloadFile(String subName, String catalog, String Time) {
boolean downloaded = false;
FileOutputStream fos = null;
if (connectServer()) {
try {
ftpClient.setControlEncoding("UTF-8");
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
String fileName = getFileNameByDate(subName, catalog, Time);
boolean subEnter = ftpClient.changeWorkingDirectory(subName);
if (subEnter) {
//log.info("进入平台级文件夹-当前工作路径为:" + ftpClient.printWorkingDirectory());
boolean catalogEnter = ftpClient.changeWorkingDirectory(catalog);
if (catalogEnter) {
// log.info("进入类型级文件夹-当前工作路径为:" + ftpClient.printWorkingDirectory());
String localFilePath = "file/" + subName + "/" + catalog + "/";
// log.info("确认本地路径");
createFilePath(new File(localFilePath));
fos = new FileOutputStream(localFilePath + fileName);
// log.info("开始下载文件到本地:" + fileName);
downloaded = ftpClient.retrieveFile(getFileNameByDate(subName, catalog, Time), fos);
}
}
} catch (IOException e) {
log.info("下载文件异常:{}", e);
} finally {
try {
if (fos != null) {
fos.close();
}
ftpClient.disconnect();
} catch (IOException e) {
log.info("关闭连接异常:{}", e);
}
}
}
return downloaded;
}
/*
私有方法
*/
private boolean downloadFile(String subName, String catalog) {
boolean downloaded = false;
FileOutputStream fos = null;
if (connectServer()) {
try {
ftpClient.setControlEncoding("UTF-8");
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
String fileName = getFileNameByDate(subName, catalog);
boolean subEnter = ftpClient.changeWorkingDirectory(subName);
if (subEnter) {
// log.info("进入平台级文件夹-当前工作路径为:" + ftpClient.printWorkingDirectory());
boolean catalogEnter = ftpClient.changeWorkingDirectory(catalog);
if (catalogEnter) {
// log.info("进入类型级文件夹-当前工作路径为:" + ftpClient.printWorkingDirectory());
String localFilePath = "file/" + subName + "/" + catalog + "/";
// log.info("确认本地路径");
createFilePath(new File(localFilePath));
fos = new FileOutputStream(localFilePath + fileName);
// log.info("下载文件到本地:" + fileName);
downloaded = ftpClient.retrieveFile(getFileNameByDate(subName, catalog), fos);
}
}
if (!downloaded) {
log.info("指定的文件不存在:{}", fileName);
}
} catch (IOException e) {
log.info("下载文件异常:{}", e);
} finally {
try {
if (fos != null) {
fos.close();
}
ftpClient.disconnect();
} catch (IOException e) {
log.info("关闭连接异常:{}", e);
}
}
} else {
connectServer();
}
return downloaded;
}
private boolean connectServer() {
boolean isSuccess = false;
try {
ftpClient.connect(ip, port);
isSuccess = ftpClient.login(userName, password);
} catch (IOException e) {
log.error("连接FTP服务器异常:{}", e);
}
return isSuccess;
}
private boolean checkConnect() {
boolean connected = ftpClient.isConnected();
if (!connected) {
connectServer();
}
return ftpClient.isConnected();
}
/**
* 根据日期生成文件名
* 以天为单位
* 文件名格式:平台名-种类-时间(yyyyMMdd).txt
*/
private String getFileNameByDate(String subName, String catalog) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return subName + "-" + catalog + "-" + sdf.format(new Date()) + ".txt";
}
/**
* 根据日期生成文件名
* 以天为单位
* 文件名格式:平台名-种类-时间(yyyyMMdd).txt
*/
private String getFileNameByDate(String subName, String catalog, String Time) {
return subName + "-" + catalog + "-" + Time + ".txt";
}
/**
* 生成指定的文件夹路径
* 若文件夹不存在则创建
*/
private boolean createFilePath(File file) {
return file.exists() || file.mkdirs();
}
}
package com.zjty.fp.acq.misc.utils;
import com.google.common.collect.Lists;
import com.zjty.fp.acq.misc.entity.ImportAds;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import static com.zjty.fp.acq.misc.entity.PsspCount.*;
@Slf4j
@Scope("prototype")
@Component
public class FileCreator {
public File createFile(String subName, String catalog, String data) {
String pathname = ImportAds.IMPORT_URL + "files/" + subName + "/" + catalog + "/";
String filename = getFileNameByDate(subName, catalog);
Path path = Paths.get(pathname + filename);
boolean make = createFilePath(new File(pathname));
if (make) {
try {
Files.write(path, data.getBytes());
} catch (IOException e) {
log.info("生成文件时出现异常:" + e);
}
}
return new File(pathname + filename);
}
public File createFileAndZip(String countAddress, String subName, String catalog, String data) {
String zipData = DeflaterUtils.zipString(data);
String pathname = ImportAds.IMPORT_URL + "files/" + subName + "/" + catalog + "/";
String filename = getPsspFileName(countAddress, subName, catalog);
Path path = Paths.get(pathname + filename);
boolean make = createFilePath(new File(pathname));
if (make) {
try {
Files.write(path, zipData.getBytes());
} catch (IOException e) {
log.info("生成文件时出现异常:" + e);
}
}
//生成完毕后需要更新一下count的值
updateCount(countAddress);
return new File(pathname + filename);
}
/**
* 更新Count值,Count+1
*/
private void updateCount(String countAddress) {
if (countAddress.equals(COUNT_ADDRESS_ALERT)) {
alert_count += 1;
} else if (countAddress.equals(COUNT_ADDRESS_WEBSITE)) {
website_count += 1;
}
//写入到count文件中去
Path countPath = Paths.get(countAddress);
//再写入一份到单导另外一端供API端参考
String globalPath = ImportAds.IMPORT_URL + countAddress;
Path globalCountPath = Paths.get(globalPath);
//先删除原有的count文件,再写入现有的
try {
Files.deleteIfExists(countPath);
Files.deleteIfExists(countPath);
} catch (IOException e) {
log.warn("删除原count文件失败!原因:{}", e.toString());
}
boolean countMake = createFilePath(new File(COUNT_PATH));
if (countMake) {
try {
if (countAddress.equals(COUNT_ADDRESS_ALERT)) {
Files.write(countPath, String.valueOf(alert_count).getBytes());
log.info("[pssp] 磁盘 count_alert 值更新成功:count = {}", alert_count);
Files.write(globalCountPath, String.valueOf(alert_count).getBytes());
log.info("[pssp] 全局 count_alert 值更新成功:count = {}", alert_count);
} else if (countAddress.equals(COUNT_ADDRESS_WEBSITE)) {
Files.write(countPath, String.valueOf(website_count).getBytes());
log.info("[pssp] 磁盘 count_website 值更新成功:count = {}", website_count);
Files.write(globalCountPath, String.valueOf(website_count).getBytes());
log.info("[pssp] 全局 count_website 值更新成功:count = {}", website_count);
}
} catch (IOException e) {
log.info("[pssp]生成文件时出现异常:" + e);
}
}
}
public File createFileNoTime(String subName, String catalog, String data) {
String pathname = "/files/" + subName + "/" + catalog + "/";
String filename = subName + "-" + catalog + ".txt";
Path path = Paths.get(pathname + filename);
boolean make = createFilePath(new File(pathname));
if (make) {
try {
Files.write(path, data.getBytes());
} catch (IOException e) {
log.info("生成文件时出现异常:" + e);
}
}
return new File(pathname + filename);
}
public File createFileInUTF(String subName, String catalog, Long index, List<String> list) {
String pathname = "/files/" + subName + "/" + catalog + "/";
String filename = subName + "-" + catalog + "-" + index + ".txt";
Path path = Paths.get(pathname + filename);
boolean make = createFilePath(new File(pathname));
if (make) {
try {
Files.write(path, list);
} catch (IOException e) {
log.info("生成文件时出现异常: " + e);
}
}
return new File(pathname + filename);
}
public File createFile(String subName, String catalog, List<String> list) {
String pathname = "/files/" + subName + "/" + catalog + "/";
String filename = getFileNameByDate(subName, catalog);
Path path = Paths.get(pathname + filename);
boolean make = createFilePath(new File(pathname));
if (make) {
try {
Files.write(path, list);
} catch (IOException e) {
log.info("生成文件时出现异常:" + e.getMessage());
}
}
return new File(pathname + filename);
}
public File createFileStms(String subName, String catalog, List<String> list) {
String pathname = "/files/" + subName + "/" + catalog + "/";
String filename = getFileNameByDateStms(subName, catalog);
String fileNameTmp = getFileNameByDateStmsTmp(subName, catalog);
Path path = Paths.get(pathname + filename);
boolean make = createFilePath(new File(pathname));
if (make) {
try {
File file = File.createTempFile(filename, ".tmp", new File(pathname));
Files.write(path, list);
new File(pathname + filename).renameTo(new File(pathname + fileNameTmp));
file.delete();
} catch (IOException e) {
log.info("生成文件时出现异常:" + e.getMessage());
}
}
return new File(pathname + filename);
}
public File createFileStms(String subName, String catalog, List<String> list, int count) {
String pathname = "/files/" + subName + "/" + catalog + "/";
String filename = getFileNameByDateStms(subName, catalog, count);
String fileNameTmp = getFileNameByDateStmsTmp(subName, catalog, count);
Path path = Paths.get(pathname + filename);
boolean make = createFilePath(new File(pathname));
if (make) {
try {
File file = File.createTempFile(filename, ".tmp", new File(pathname));
Files.write(path, list);
new File(pathname + filename).renameTo(new File(pathname + fileNameTmp));
file.delete();
} catch (IOException e) {
log.info("生成文件时出现异常:" + e.getMessage());
}
}
return new File(pathname + filename);
}
/**
* 根据日期生成文件名
* 以天为单位
* 文件名格式:平台名-种类-时间(yyyyMMdd).txt
*/
private String getFileNameByDate(String subName, String catalog) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return subName + "-" + catalog + "-" + sdf.format(new Date()) + ".txt";
}
private String getFileNameByDateStms(String subName, String catalog, int count) {
return subName + "-" + catalog + count + ".tmp";
}
private String getFileNameByDateStmsTmp(String subName, String catalog, int count) {
return subName + "-" + catalog + count + ".txt";
}
private String getFileNameByDateStms(String subName, String catalog) {
return subName + "-" + catalog + ".tmp";
}
private String getFileNameByDateStmsTmp(String subName, String catalog) {
return subName + "-" + catalog + ".txt";
}
private String getPsspFileName(String countAddress, String subName, String catalog) {
//count 先从内存里取读 内存里读不到从磁盘读
int count = -1;
if (countAddress.equals(COUNT_ADDRESS_ALERT)) {
count = alert_count;
} else if (countAddress.equals(COUNT_ADDRESS_WEBSITE)) {
count = website_count;
}
//如果count为初始值-1,则代表还没有从文件中读取之前的记录
if (count == -1) {
//读取文件获得文件编号后缀值
Path path = Paths.get(countAddress);
List<String> data = Lists.newArrayList();
try {
data = Files.readAllLines(path);
} catch (IOException e) {
log.info("[pssp]读取文件时出现异常:" + e);
}
count = data.get(0) == null ? 0 : Integer.parseInt(data.get(0));
}
if (count <= 0) count = 0;
String psspFileName = subName + "-" + catalog + count + ".txt";
log.info("[pssp] 成功生成文件名:{}", psspFileName);
return psspFileName;
}
/**
* 生成指定的文件夹路径
* 若文件夹不存在则创建
*/
private boolean createFilePath(File file) {
return file.exists() || file.mkdirs();
}
}
package com.zjty.fp.acq.misc.utils;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* <p>Description : vompin
* <p>Date : 2018/9/29 15:44
* <p>@author : Matrix [xhyrzldf@foxmail.com]
*/
@SuppressWarnings({"unused", "UnusedReturnValue"})
@Component
@Scope("prototype")
@Slf4j
public class FileReader {
public List<String> readFileData(String subName, String catalog) {
List<String> data = Lists.newArrayList();
String localFilePath = "file/" + subName + "/" + catalog + "/";
String fileName = getFileNameByDate(subName, catalog);
File file = new File(localFilePath + fileName);
Path path = Paths.get(localFilePath + fileName);
try {
data = Files.readAllLines(path);
} catch (IOException e) {
log.info("读取文件时出现异常:" + e);
}
return data;
}
/**
* 根据日期生成文件名
* 以天为单位
* 文件名格式:平台名-种类-时间(yyyyMMdd).txt
*/
private String getFileNameByDate(String subName, String catalog) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return subName + "-" + catalog + "-" + sdf.format(new Date()) + ".txt";
}
/**
* 生成指定的文件夹路径
* 若文件夹不存在则创建
*/
private boolean createFilePath(File file) {
return file.exists() || file.mkdirs();
}
}
package com.zjty.fp.acq.misc.utils;
/**
* fusion-platform String utils class
*
* @author : Matrix [xhyrzldf@gmail.com]
* 18-11-21 .
*/
public class FpStringUtils {
public static String toUpperFirstChar(String string) {
char[] charArray = string.toCharArray();
charArray[0] -= 32;
return String.valueOf(charArray);
}
}
package com.zjty.fp.acq.misc.utils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public final class JacksonUtil {
private static ObjectMapper objectMapper;
/**
* 使用泛型方法,把json字符串转换为相应的JavaBean对象。
* (1)转换为普通JavaBean:readValue(json,Student.class)
* (2)转换为List,如List<Student>,将第二个参数传递为Student
* [].class.然后使用Arrays.asList();方法把得到的数组转换为特定类型的List
*/
public static <T> T readValue(String jsonStr, Class<T> valueType) {
if (objectMapper == null) {
objectMapper = new ObjectMapper();
}
try {
return objectMapper.readValue(jsonStr, valueType);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 转换为指定类型的集合
*
* @param jsonStr 待转换的json字符串
* @param valueType 指定类型的Class对象
* @return 指定类型的集合
*/
public static <T> List<T> readValueToList(String jsonStr, Class<T> valueType) {
T[] arrays = readValue(jsonStr, new TypeReference<T[]>() {
});
List<T> list = Collections.emptyList();
if (arrays != null) {
list = Arrays.asList(arrays);
}
return list;
}
/**
* json数组转List
*
* @param jsonStr 待转换的json字符串
* @param valueTypeRef 指定类型的Class对象
* @return 指定类型的集合
*/
public static <T> T readValue(String jsonStr, TypeReference<T> valueTypeRef) {
if (objectMapper == null) {
objectMapper = new ObjectMapper();
}
try {
return objectMapper.readValue(jsonStr, valueTypeRef);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 把JavaBean转换为json字符串
*/
public static String toJSon(Object object) {
if (objectMapper == null) {
objectMapper = new ObjectMapper();
}
try {
return objectMapper.writeValueAsString(object);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
package com.zjty.fp.acq.misc.utils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
public class RsaUtil {
//指定加密算法为RSA
private static String ALGORITHM = "RSA";
//指定key的大小
private static int KEYSIZE = 1024;
//指定公钥存放文件和私钥存放文件
private static String PUBLIC_KEY_FILE = "src/private.key";
private static String PRIVATE_KEY_FILE = "src/public.key";
//生成公钥和私钥并分别存放在文件中
private static void generateKeyPair() throws Exception {
//生成密钥对
KeyPairGenerator kpg = KeyPairGenerator.getInstance(ALGORITHM);
kpg.initialize(KEYSIZE, new SecureRandom());
KeyPair kp = kpg.generateKeyPair();
//通过密钥对分别得到公钥和私钥
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
//将生成的密钥写入文件
ObjectOutputStream output1 = new ObjectOutputStream(new FileOutputStream(PUBLIC_KEY_FILE));
ObjectOutputStream output2 = new ObjectOutputStream(new FileOutputStream(PRIVATE_KEY_FILE));
output1.writeObject(publicKey);
output2.writeObject(privateKey);
output1.close();
output2.close();
}
//RSA加密方法
public static String encrypt(String source, String publicKeyFile) throws Exception {
//读出文件中的公钥对象
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(publicKeyFile));
Key key = (Key) ois.readObject();
ois.close();
//得到Cipher对象来实现对源数据的RSA加密
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, key);
BASE64Encoder encoder = new BASE64Encoder();
byte[] b = source.getBytes();
String cryptograph = encoder.encode(cipher.doFinal(b));
return cryptograph;
}
//RSA解密方法
public static String decrypt(String cryptograph, String privateKeyFile) throws Exception {
//读出文件中的私钥对象
ObjectInputStream input = new ObjectInputStream(new FileInputStream(privateKeyFile));
Key key = (Key) input.readObject();
input.close();
//对已经加密的数据进行RSA解密
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key);
BASE64Decoder decoder = new BASE64Decoder();
byte[] b1 = decoder.decodeBuffer(cryptograph);
//执行解密操作
byte[] b = cipher.doFinal(b1);
String source = new String(b);
return source;
}
public static String getInvalid(String str) throws Exception {
String cryptograph = encrypt(str, PUBLIC_KEY_FILE);
return cryptograph;
}
public static String getAdmin(String str) throws Exception {
String admin = decrypt(str, PRIVATE_KEY_FILE);
return admin;
}
//调用方法举例
public static void main(String[] args) {
String source = "Spinfo0123-secadmin";
System.out.println("明文字符串:[" + source + "]");
try {
//生成可用的密钥对并分别保存在文件中
System.out.println("生成的公钥文件为:" + PUBLIC_KEY_FILE + ", 生成的私钥文件为:" + PRIVATE_KEY_FILE);
String cryptograph = encrypt(source, PUBLIC_KEY_FILE);//生成的密文
System.out.println("加密之后的字符串为:[" + cryptograph + "]");
String text = decrypt(cryptograph, PRIVATE_KEY_FILE);//解密密文
System.out.println("解密之后的字符串为:[" + text + "]");
} catch (Exception e) {
System.out.println("加解密过程中发生错误:" + e.getMessage());
return;
}
}
}
package com.zjty.fp.acq.misc.utils;
import lombok.extern.slf4j.Slf4j;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
/**
* @author LJJ
* on 18-12-27
*/
@Slf4j
public class TimeUtil {
/**
* 获取上一小时时间string 用于拼接restful fp 的url
*
* @return yyyy-MM-dd%20HH
*/
public static String getMinusHoursTime() {
return LocalDateTime.now().minusHours(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd%20HH"));
}
/**
* 获取今日时间string
*
* @return yyyyMMdd
*/
public static String getToday() {
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
}
/**
* 获取今天开始时间的时间戳
*
* @return long
*/
public static Long getTodayStartTime() {
String a = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00";
return stringToLong("yyyy-MM-dd HH:mm:ss", a);
}
/**
* 获取今天结束事件的时间戳
*
* @return long 13
*/
public static Long getTodayEndTime() {
String a = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 23:59:59";
return stringToLong("yyyy-MM-dd HH:mm:ss", a);
}
/**
* long -> String
*
* @param format 指定格式,如:yyyy-MM-dd HH:mm:ss
* @param time long
* @return String
*/
public static String longToString(String format, Long time) {
DateTimeFormatter df = DateTimeFormatter.ofPattern(format);
return df.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.of("Asia/Shanghai")));
}
/**
* String -> long
*
* @param format 指定格式,如:yyyy-MM-dd HH:mm:ss
* @param time yyyy-MM-dd HH:mm:ss
* @return 13位long
*/
public static Long stringToLong(String format, String time) {
DateTimeFormatter df = DateTimeFormatter.ofPattern(format);
LocalDateTime parse = LocalDateTime.parse(time, df);
return LocalDateTime.from(parse).atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
}
}
package com.zjty.fp.acq.misc.utils.httpclientutil;
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
/**
* @author LJJ
* on 18-12-27
*/
public class HttpClientUtil {
/**
* 缺省超时时间 单位:ms
*/
private static final int TIMEOUT = 60000;
/**
* 是否重定向标识
*/
private static final boolean IS_REDIRECTS = false;
private static String EMPTY_STR = "";
/**
* 字符集编码格式
*/
private static String UTF_8 = "UTF-8";
private HttpClientUtil() {
}
/**
* 发送 get 请求
*
* @param url 请求地址
* @return String
*/
public static String httpGetRequest(String url) {
HttpGet httpGet = new HttpGet(url);
return execute(httpGet);
}
/**
* 发送 get 请求
*
* @param url 请求地址
* @param headers 头信息
* @return String
*/
public static String httpGetRequestWithHeaders(String url, Map<String, Object> headers) {
HttpGet httpGet = new HttpGet(url);
for (Map.Entry<String, Object> param : headers.entrySet()) {
httpGet.addHeader(param.getKey(), String.valueOf(param.getValue()));
}
return execute(httpGet);
}
/**
* 发送 get 请求
*
* @param url 请求地址
* @param headers 头信息
* @param params 参数
* @return String
*/
public static String httpGetRequest(String url, Map<String, Object> headers,
Map<String, Object> params) {
HttpGet httpGet = new HttpGet(createParamUrl(url, params));
for (Map.Entry<String, Object> param : headers.entrySet()) {
httpGet.addHeader(param.getKey(), String.valueOf(param.getValue()));
}
return execute(httpGet);
}
/**
* 发送 get 请求
*
* @param url 请求地址
* @return String
*/
public static String httpGetRequestWithParams(String url, Map<String, Object> params) {
HttpGet httpGet = new HttpGet(createParamUrl(url, params));
return execute(httpGet);
}
/**
* 创建带参数的 URL
*
* @param url 无参URL
* @param params 参数
* @return String 带参数URL
*/
private static String createParamUrl(String url, Map<String, Object> params) {
Iterator<String> it = params.keySet().iterator();
StringBuilder sb = new StringBuilder();
boolean isIncludeQuestionMark = url.contains("?");
if (!isIncludeQuestionMark) {
sb.append("?");
}
while (it.hasNext()) {
String key = it.next();
String value = (String) params.get(key);
sb.append("&");
sb.append(key);
sb.append("=");
sb.append(value);
}
url += sb.toString();
return url;
}
/**
* 发送 post 请求
*
* @param url 请求地址
* @return String
*/
public static String httpPostRequest(String url) {
HttpPost httpPost = new HttpPost(url);
return execute(httpPost);
}
/**
* 发送 post 请求
*
* @param url 地址
* @param params 参数
* @return String
*/
public static String httpPostRequest(String url, Map<String, Object> params) {
HttpPost httpPost = new HttpPost(url);
ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
try {
httpPost.setEntity(new UrlEncodedFormEntity(pairs, UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return execute(httpPost);
}
/**
* 发送 post 请求
*
* @param url 地址
* @param headers 头信息
* @param params 参数
* @return String
*/
public static String httpPostRequest(String url, Map<String, Object> headers,
Map<String, Object> params) {
HttpPost httpPost = new HttpPost(url);
for (Map.Entry<String, Object> headerParam : headers.entrySet()) {
httpPost.addHeader(headerParam.getKey(), String.valueOf(headerParam.getValue()));
}
ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
try {
httpPost.setEntity(new UrlEncodedFormEntity(pairs, UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return execute(httpPost);
}
/**
* 发送 post 请求
*
* @param url 地址
* @param headers 头信息
* @param json json 格式参数
* @return String
*/
public static String httpPostRequestByJson(String url, Map<String, Object> headers,
String json) {
HttpPost httpPost = new HttpPost(url);
for (Map.Entry<String, Object> headerParam : headers.entrySet()) {
httpPost.addHeader(headerParam.getKey(), String.valueOf(headerParam.getValue()));
}
try {
httpPost.setEntity(new StringEntity(json, UTF_8));
} catch (UnsupportedCharsetException e) {
e.printStackTrace();
}
return execute(httpPost);
}
/**
* 把参数转换为名值对数组
*
* @param params 参数
* @return ArrayList<NameValuePair>
*/
private static ArrayList<NameValuePair> covertParams2NVPS(Map<String, Object> params) {
ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
for (Map.Entry<String, Object> param : params.entrySet()) {
pairs.add(new BasicNameValuePair(param.getKey(), String.valueOf(param.getValue())));
}
return pairs;
}
/**
* 执行 HTTP 请求 若重定向返回重定向地址
*
* @return String
*/
private static String execute(HttpRequestBase request) {
String result = EMPTY_STR;
request.setConfig(createConfig(TIMEOUT, IS_REDIRECTS));
CloseableHttpClient httpClient = getHttpClient();
try {
CloseableHttpResponse response = httpClient.execute(request);
if (isRedirected(response)) {
result = getRedirectedUrl(response);
} else {
result = getEntityData(response);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* 创建HTTP请求配置
*
* @param timeout 超时时间
* @param redirectsEnabled 是否开启重定向
* @return RequestConfig
*/
private static RequestConfig createConfig(int timeout, boolean redirectsEnabled) {
return RequestConfig.custom()
// 读取数据超时时间(毫秒)
.setSocketTimeout(timeout)
// 建立连接超时时间(毫秒)
.setConnectTimeout(timeout)
// 从连接池获取连接的等待时间(毫秒)
.setConnectionRequestTimeout(timeout)
// 当响应状态码为302时,是否进行重定向
.setRedirectsEnabled(redirectsEnabled)
.build();
}
/**
* 通过连接池获取 httpclient
*/
private static CloseableHttpClient getHttpClient() {
return HttpClients.custom().setConnectionManager(
HttpConnectionManager.POOLING_CONNECTION_MANAGER).build();
}
/**
* 判断发送请求是否重定向跳转过
*
* @param response 请求响应
* @return boolean
*/
private static boolean isRedirected(CloseableHttpResponse response) {
int statusCode = response.getStatusLine().getStatusCode();
return statusCode == HttpStatus.SC_MOVED_PERMANENTLY
|| statusCode == HttpStatus.SC_MOVED_TEMPORARILY;
}
/**
* 获得重定向跳转地址
*
* @param response 请求响应
* @return String 重定向地址
*/
private static String getRedirectedUrl(CloseableHttpResponse response) {
String result = EMPTY_STR;
Header[] hs = response.getHeaders("Location");
if (hs.length > 0) {
result = hs[0].getValue();
}
return result;
}
/**
* 获得响应实体信息
*
* @param response 请求响应
* @return String 消息实体信息
*/
private static String getEntityData(CloseableHttpResponse response)
throws ParseException, IOException {
String result = EMPTY_STR;
HttpEntity entity = response.getEntity();
if (entity != null) {
result = EntityUtils.toString(entity);
response.close();
}
return result;
}
}
package com.zjty.fp.acq.misc.utils.httpclientutil;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
/**
* @author LJJ
* on 18-12-27
*/
public class HttpConnectionManager {
/**
* 普通连接管理器
*/
public static final HttpClientConnectionManager BASIC_CONNECTION_MANAGER;
/**
* 连接池管理器
*/
public static final HttpClientConnectionManager POOLING_CONNECTION_MANAGER;
static {
Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SslSelfSigned.SSL_CONNECTION_SOCKET_FACTORY).build();
// 普通连接管理器
BASIC_CONNECTION_MANAGER = new BasicHttpClientConnectionManager(r);
// 连接池管理器
PoolingHttpClientConnectionManager pooling = new PoolingHttpClientConnectionManager(r);
// 设置最大连接数
pooling.setMaxTotal(1000);
// 设置每个路由基础上的最大连接数
pooling.setDefaultMaxPerRoute(300);
POOLING_CONNECTION_MANAGER = pooling;
}
private HttpConnectionManager() {
}
/**
* @param max httpClient 最大连接数
*/
public static void setMaxTotal(int max) {
((PoolingHttpClientConnectionManager) POOLING_CONNECTION_MANAGER).setMaxTotal(max);
}
/**
* @param max 每个路由基础上的最大连接数
*/
public static void setDefaultMaxPerRoute(int max) {
((PoolingHttpClientConnectionManager) POOLING_CONNECTION_MANAGER).setDefaultMaxPerRoute(max);
}
}
package com.zjty.fp.acq.misc.utils.httpclientutil;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.ssl.SSLContexts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
/**
* @author LJJ
* on 18-12-27
*/
public class SslSelfSigned {
public static final SSLConnectionSocketFactory SSL_CONNECTION_SOCKET_FACTORY;
protected static final Logger logger = LoggerFactory.getLogger(SslSelfSigned.class);
static {
SSLContext sslContext = null;
try {
sslContext = SSLContexts.custom().loadTrustMaterial(TrustSelfSignedStrategy.INSTANCE).build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
logger.error("{}", e);
}
SSL_CONNECTION_SOCKET_FACTORY = new SSLConnectionSocketFactory(sslContext,
NoopHostnameVerifier.INSTANCE);
}
private SslSelfSigned() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>fp-acq-wz</artifactId>
<groupId>com.zjty.fp</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>acq-pssp</artifactId>
<dependencies>
<dependency>
<groupId>com.zjty.fp</groupId>
<artifactId>acq-misc</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-jdbc-core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--springboot-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--mysql 用于实际环境 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--easy-poi excel导入导出工具包-->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<skipTests>true</skipTests> <!--默认关掉单元测试 -->
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.zjty.fp.acq.pssp;
import org.springframework.context.annotation.ComponentScan;
/**
* fusion-platform.
*
* @author : Matrix [xhyrzldf@gmail.com]
* 18-11-27 .
*/
@ComponentScan(basePackages = {
"com.zjty.fp.acq.pssp",
"com.zjty.fp.acq.es",
"com.zjty.fp.acq.redis",
"com.zjty.fp.acq.tm"
})
public class PsspApplication {
}
package com.zjty.fp.acq.pssp.base.aspect;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* fusion-platform.
* 用于保护Pssp计划任务,使得不同计划任务不会冲突进行
* 实现逻辑由AOP{@link PsspScheduleTrigger}控制,
*
* @author : Matrix [xhyrzldf@gmail.com]
* 19-1-24 .
*/
@Target(METHOD)
@Retention(RUNTIME)
@Documented
public @interface EnablePsspSchProtect {
}
package com.zjty.fp.acq.pssp.base.aspect;
import com.zjty.fp.acq.pssp.task.CollectDataTask;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
/**
* fusion-platform.
*
* @author : Matrix [xhyrzldf@gmail.com]
* 19-1-24 .
*/
@Component
@Aspect
@Slf4j
public class PsspScheduleTrigger {
/**
* 设自定义注解@ThreemLoginValidation为AOP切点
*/
@Pointcut("@annotation(com.zjty.fp.acq.pssp.base.aspect.EnablePsspSchProtect)")
public void schTriggerPointCut() {
}
/**
* 在标有@ThreemLoginValidation注解的方法之前执行的逻辑
*/
@Around("schTriggerPointCut()")
public Object aroundSchTrigger(ProceedingJoinPoint joinPoint) throws Throwable {
if (!CollectDataTask.trigger) {
log.info("[pssp] 检测到定时任务开关状态为关闭状态,本次{}类执行的任务结束", joinPoint.getSignature().getName());
return null;
} else {
CollectDataTask.trigger = false;
Object proceed = joinPoint.proceed();
CollectDataTask.trigger = true;
return proceed;
}
}
}
package com.zjty.fp.acq.pssp.base.beans;
import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 用于存储一些类的bean,以便于直接注入使用
*
* @author : Matrix [xhyrzldf@foxmail.com]
* @Date : 18-8-21
*/
@Configuration
public class BeanHelper {
private static ModelMapper psspMapper = new ModelMapper();
static {
psspMapper.getConfiguration().setAmbiguityIgnored(true);
}
public static ModelMapper getPsspMapper() {
return psspMapper;
}
@Bean
public ModelMapper initModelMapper() {
return psspMapper;
}
}
package com.zjty.fp.acq.pssp.base.beans;
import com.google.common.collect.Lists;
import com.zjty.fp.acq.misc.entity.ImportAds;
import com.zjty.fp.acq.pssp.subject.service.RegionService;
import com.zjty.fp.acq.pssp.subject.service.WebsiteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static com.zjty.fp.acq.misc.entity.PsspCount.*;
/**
* PsspInitialRunner 初始化Runner程序
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2019-04-08 at 17:15
*/
@Slf4j
@Configuration
public class PsspInitialRunner {
@Autowired
private WebsiteService websiteService;
@Autowired
private RegionService regionService;
@Order(100)
@Bean
public CommandLineRunner initializeDictMap() {
return args -> {
initCount("COUNT_ALERT", COUNT_ADDRESS_ALERT);
initCount("COUNT_WEBSITE", COUNT_ADDRESS_WEBSITE);
};
}
private void initCount(String countFileName, String CountAddress) {
log.info("[pssp] 正在尝试初始化 {} 文件", countFileName);
boolean countExists = Files.exists(Paths.get(CountAddress));
String GlobalCountAddress = ImportAds.IMPORT_URL + CountAddress;
boolean globalCountExists = Files.exists(Paths.get(GlobalCountAddress));
log.info("[pssp] 创建本地Count文件");
int localCount = createCountFile(countFileName, CountAddress, COUNT_PATH, countExists, 0);
log.info("[pssp] 创建全局Count文件");
createCountFile(countFileName, GlobalCountAddress, GLOBAL_COUNT_PATH, globalCountExists, localCount);
}
private int createCountFile(String countFileName, String CountAddress, String dirPath, boolean countExists, int initCount) {
int countVar;
if (countExists) {
log.info("[pssp] 磁盘已存在 {} 文件,跳过初始化流程,将磁盘的 {} 读取入内存中", countFileName, countFileName);
//读取文件获得文件编号后缀值
Path path = Paths.get(CountAddress);
List<String> data = Lists.newArrayList();
try {
data = Files.readAllLines(path);
} catch (IOException e) {
log.info("读取文件时出现异常:" + e);
}
countVar = data.get(0) == null ? 0 : Integer.parseInt(data.get(0));
if (CountAddress.equals(COUNT_ADDRESS_ALERT)) {
alert_count = countVar;
} else if (CountAddress.equals(COUNT_ADDRESS_WEBSITE)) {
website_count = countVar;
}
} else {
log.info("[pssp] 磁盘不存在 {} 文件,初始化 {} 文件", countFileName, countFileName);
boolean countMake = createFilePath(new File(dirPath));
countVar = 0;
if (dirPath.equals(GLOBAL_COUNT_PATH)) {
countVar = initCount;
log.info("[pssp] 初始化全局count值为本地count值: {}", countVar);
}
if (countMake) {
try {
Files.write(Paths.get(CountAddress), String.valueOf(countVar).getBytes());
log.info("[pssp] 磁盘 {} 值更新成功:count = {}", countFileName, countVar);
} catch (IOException e) {
log.info("[pssp] 生成文件时出现异常:" + e);
}
}
log.info("[pssp] 初始化 {} 文件完毕!", countFileName);
if (CountAddress.equals(COUNT_ADDRESS_ALERT)) {
alert_count = countVar;
} else if (CountAddress.equals(COUNT_ADDRESS_WEBSITE)) {
website_count = countVar;
}
}
return countVar;
}
private boolean createFilePath(File file) {
return file.exists() || file.mkdirs();
}
}
package com.zjty.fp.acq.pssp.base.constant;
import com.zjty.fp.acq.pssp.subject.entity.location.Region;
import com.zjty.fp.acq.pssp.subject.entity.location.Website;
import java.util.Map;
/**
* DictConst.
* Pssp 字典表常量
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2019-04-08 at 17:09
*/
public class DictConst {
public static Map<Long, Website> WEBSITE_MAP;
public static Map<String, Region> REGION_MAP;
}
package com.zjty.fp.acq.pssp.config.algorithm;
import io.shardingsphere.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.api.algorithm.sharding.standard.PreciseShardingAlgorithm;
import lombok.RequiredArgsConstructor;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
/**
* =
*
* @author : Matrix [xhyrzldf@foxmail.com]
* @Date : 18-8-29
*/
@RequiredArgsConstructor
public class AlertPreShardAlgo implements PreciseShardingAlgorithm<Date> {
private final String tablePrefix;
@Override
public String doSharding(Collection<String> collection, PreciseShardingValue<Date> preciseShardingValue) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
return tablePrefix + formatter.format(preciseShardingValue.getValue());
}
}
package com.zjty.fp.acq.pssp.config.algorithm;
import com.google.common.collect.Range;
import io.shardingsphere.api.algorithm.sharding.RangeShardingValue;
import io.shardingsphere.api.algorithm.sharding.standard.RangeShardingAlgorithm;
import lombok.RequiredArgsConstructor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashSet;
/**
* fusion-platform.
*
* @author : Matrix [xhyrzldf@foxmail.com]
* @Date : 18-8-29
*/
@RequiredArgsConstructor
public class AlertRangeShardAlgo implements RangeShardingAlgorithm<Date> {
private final String tablePrefix;
@Override
public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Date> rangeShardingValue) {
Collection<String> result = new LinkedHashSet<>();
DateFormat sdf = new SimpleDateFormat("yyyyMM");
Range<Date> ranges = rangeShardingValue.getValueRange();
Date startTime = ranges.lowerEndpoint();
Date endTime = ranges.upperEndpoint();
// range.lowerEndpoint() = 2018-08-01
// range.upperEndpoint() = 2018-10-01
// 此处应该返回 tablePrefix+201808 , tablePrefix+201809,tablePrefix+201810,
Calendar cal = Calendar.getInstance();
//noinspection Duplicates
while (startTime.getTime() <= endTime.getTime()) {
result.add(tablePrefix + sdf.format(startTime));
//设置起时间
cal.setTime(startTime);
cal.add(Calendar.MONTH, 1);
startTime = cal.getTime();
}
return result;
}
}
package com.zjty.fp.acq.pssp.subject.controller;
import com.zjty.fp.acq.pssp.subject.service.AlertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author matrix
*/
@RestController
@RequestMapping("/pssp/test")
public class PsspTestController {
@Autowired
AlertService alertService;
/**
* 抓取所有报警数据(当前月)
*/
@GetMapping("/alerts/all")
public ResponseEntity<String> fetchAllAlerts(
@RequestParam("year") int year,
@RequestParam("month") int month,
@RequestParam("day") int day
) {
// alertService.fetchAllData(null);
return ResponseEntity.ok(year + "-" + month + "-" + day + " time alerts fetch job is running success");
}
}
package com.zjty.fp.acq.pssp.subject.entity;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
/**
* TimeTup.
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2020/8/1 at 3:16 下午
*/
public class TimeTup {
private Date startTime;
private LocalDateTime localStartTime;
private Date endTime;
private LocalDateTime localEndTime;
public TimeTup(LocalDateTime startTime) {
setStartTime(startTime);
LocalDateTime endTime = startTime.plusHours(3);
setEndTime(endTime);
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(LocalDateTime startTime) {
ZoneId zoneId = ZoneId.systemDefault();
Instant instant = startTime.atZone(zoneId).toInstant();
this.startTime = Date.from(instant);
this.localStartTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(LocalDateTime endTime) {
ZoneId zoneId = ZoneId.systemDefault();
Instant instant = endTime.atZone(zoneId).toInstant();
this.endTime = Date.from(instant);
this.localEndTime = endTime;
}
public LocalDateTime getLocalStartTime() {
return localStartTime;
}
public LocalDateTime getLocalEndTime() {
return localEndTime;
}
}
package com.zjty.fp.acq.pssp.subject.entity.location;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.zjty.fp.acq.pssp.base.constant.DictConst;
import com.zjty.fp.acq.pssp.subject.entity.vo.PsspEvent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.Date;
/**
* @author matrix
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "pssp_alert")
public class Alert {
/**
* 分布式主键id
*/
@Id
@GeneratedValue
@JsonPropertyOrder("1")
private Long primaryId;
/**
* 源数据主键ID
*/
@JsonPropertyOrder("2")
private Long id;
/**
* 所属地区
*/
@Column(name = "code_org")
private Integer codeOrg;
/**
* 网站入口分类
*/
@Column(name = "id_web_category")
private Integer idWebCategory;
/**
* 网站入口信息
*/
@Column(name = "id_web")
private Integer idWeb;
/**
* 所匹配到的关键字
*/
@Column(name = "match_keyword")
private String matchKeyword;
/**
* 数据的标题
*/
@Column(name = "title")
private String title;
/**
* 数据摘要
*/
@Column(name = "abstract")
private String abs;
/**
* 源网页地址
*/
@Column(name = "web_url")
private String webUrl;
/**
* 本地预览(快照)地址
*/
@Column(name = "web_snapshot")
private String webSnapshot;
/**
* 源附件地址
*/
@Column(name = "doc_url")
private String docUrl;
/**
* 本地预览(快照)地址
*/
@Column(name = "doc_snapshot")
private String docSnapshot;
/**
* 数据抓取时间
*/
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "tm_fetch")
private Date tmFetch;
/**
* 处理人ID
*/
@Column(name = "handler_user")
private Integer handlerUser;
/**
* 数据是否为压缩类型
*/
@Column(name = "e_in_zip")
private Integer eInZip;
/**
* 数据是否已读
*/
@Column(name = "e_ident")
private Integer eIdent;
/**
* 告警等级(红,黄,绿)
*/
@Column(name = "e_alert")
private Integer eAlert;
/**
* 数据类型
*/
@Column(name = "e_type")
private Integer eType;
/**
* 处理状态
*/
@Column(name = "e_status")
private Integer eStatus;
}
\ No newline at end of file
package com.zjty.fp.acq.pssp.subject.entity.location;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
* RemoteRegion. 源仓库地区表
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2019-04-08 at 15:46
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "pssp_region")
public class Region {
/**
* 地区编号
*/
@Id
@GenericGenerator(name = "myGen", strategy = "assigned")
@GeneratedValue(generator = "myGen")
private String code;
/**
* 地区名称
*/
private String name;
/**
* 地区短名称
*/
private String shortName;
/**
* 地区等级
*/
private Integer level;
/**
* 是否被删除
*/
private Integer deleted;
/**
* 该属性用于提供默认为空值的区域对象
*/
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
@Transient
private static Region defaultRegion = new Region(
"99999",
"示例区域",
"示例区域",
0,
0
);
public static Region defaultInstance() {
return defaultRegion;
}
}
package com.zjty.fp.acq.pssp.subject.entity.location;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
* <pre>
* {
* "id":"唯一标识符,四位整数",
* "entry":"网站入口,网址"
* "name":"网站名称",
* "scope":"抓取范围,是一个网址",
* "unit":"网站使用单位名称",
* "code_org":"所属地区的code,取值为四位整数,参见下表t_dic_org",
* "id_web_category":"网站入口分类,取值为 4:政府 5:高校 6:军工 7:金融 8:其他",
* "level_":"重要性, 3:高 2:中 1:低",
* "status_approve":"审批状态,取值为 待定:0,未通过:-1 通过:1"
* "status_web":"网站状态, -2:访问失败 -1:网址格式异常 0:未确认 1:有效"
* "status_collect":"采集状态,0:启用 1:禁用 2:自定义"
* }
* </pre>
*
* @author : Matrix [xhyrzldf@foxmail.com]
* @since : 18-9-3
*/
@Data
@Entity
@NoArgsConstructor
@Table(name = "pssp_website")
public class Website {
@Id
@GenericGenerator(name = "myGen", strategy = "assigned")
@GeneratedValue(generator = "myGen")
private Long id;
private String entry;
private String name;
private String scope;
private String unit;
private Integer codeOrg;
private Integer idWebCategory;
private Integer level;
private Integer statusApprove;
private Integer statusWeb;
private Integer statusCollect;
/**
* 该属性用于提供默认为空值的网站对象
*/
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
@Transient
private static Website defaultWebsite = new Website(
99999L,
"www.example.com",
"默认示例网站",
"example.com",
"示例单位名称",
99999,
8,
1,
1,
0,
1);
public Website(Long id,String entry, String name, String scope, String unit, Integer codeOrg, Integer idWebCategory, Integer level, Integer statusApprove, Integer statusWeb, Integer statusCollect) {
this.id = id;
this.entry = entry;
this.name = name;
this.scope = scope;
this.unit = unit;
this.codeOrg = codeOrg;
this.idWebCategory = idWebCategory;
this.level = level;
this.statusApprove = statusApprove;
this.statusWeb = statusWeb;
this.statusCollect = statusCollect;
}
public static Website defaultInstance() {
return defaultWebsite;
}
}
package com.zjty.fp.acq.pssp.subject.entity.remote;
import com.zjty.fp.acq.pssp.base.beans.BeanHelper;
import com.zjty.fp.acq.pssp.subject.entity.location.Alert;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import javax.persistence.*;
import java.util.Date;
/**
* @author matrix
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "alert", catalog = "remote")
public class RemoteAlert {
/**
* 数据ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* 所属地区编号1
*/
@Column(name = "code_org_l1")
private Integer codeOrgL1;
/**
* 所属地区编号2
*/
@Column(name = "code_org_l2")
private Integer codeOrgL2;
/**
* 网站入口分类
*/
@Column(name = "id_web_category")
private Integer idWebCategory;
/**
* 网站入口信息
*/
@Column(name = "id_web")
private Integer idWeb;
/**
* 所匹配到的关键字
*/
@Column(name = "match_keyword")
private String matchKeyword;
/**
* 数据的标题
*/
@Column(name = "title")
private String title;
/**
* 数据摘要
*/
@Column(name = "abstract")
private String abs;
/**
* 源网页地址
*/
@Column(name = "web_url")
private String webUrl;
/**
* 本地预览(快照)地址
*/
@Column(name = "web_snapshot")
private String webSnapshot;
/**
* 源附件地址
*/
@Column(name = "doc_url")
private String docUrl;
/**
* 本地预览(快照)地址
*/
@Column(name = "doc_snapshot")
private String docSnapshot;
/**
* 数据创建时间
*/
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "tm_create")
private Date tmCreate;
/**
* 数据抓取时间
*/
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "tm_fetch")
private Date tmFetch;
/**
* 处理人ID
*/
@Column(name = "handler_user")
private Integer handlerUser;
@Column(name = "suspicious_user")
private Integer suspiciousUser;
@Column(name = "confidential_user")
private Integer confidentialUser;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "tm_suspicious")
private Date tmSuspicious;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "tm_confidential")
private Date tmConfidential;
@Column(name = "suspicious_remark")
private String susRemark;
@Column(name = "confidential_remark")
private String conRemark;
/**
* 数据是否为压缩类型
*/
@Column(name = "e_in_zip")
private Integer eInZip;
/**
* 数据是否已读
*/
@Column(name = "e_ident")
private Integer eIdent;
/**
* 告警等级(红,黄,绿)
*/
@Column(name = "e_alert")
private Integer eAlert;
/**
* 数据类型
*/
@Column(name = "e_type")
private Integer eType;
/**
* 处理状态
*/
@Column(name = "e_status")
private Integer eStatus;
/**
* 将源数据对象转化为融合平台子平台数据对象
*
* @return {@link Alert}
*/
public Alert toDo() {
ModelMapper mapper = BeanHelper.getPsspMapper();
Alert alert = mapper.map(this, Alert.class);
alert.setCodeOrg(this.codeOrgL1);
alert.setId(this.id);
return alert;
}
}
\ No newline at end of file
package com.zjty.fp.acq.pssp.subject.entity.remote;
import com.zjty.fp.acq.pssp.base.beans.BeanHelper;
import com.zjty.fp.acq.pssp.subject.entity.location.Region;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.modelmapper.ModelMapper;
import javax.persistence.*;
/**
* RemoteRegion. 源仓库地区表
*
* @author Matrix <xhyrzldf@gmail.com>
* @since 2019-04-08 at 15:46
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "t_dic_org")
public class RemoteRegion {
/**
* 地区编号
*/
@Id
@GenericGenerator(name = "myGen", strategy = "assigned")
@GeneratedValue(generator = "myGen")
private String code;
/**
* 地区名称
*/
private String name;
/**
* 地区短名称
*/
@Column(name = "shortname")
private String shortName;
/**
* 地区等级
*/
@Column(name = "level_")
private Integer level;
/**
* 是否被删除
*/
private Integer deleted;
/**
* 将源数据对象转化为融合平台子平台数据对象
*
* @return {@link Region}
*/
public Region toDo() {
ModelMapper mapper = BeanHelper.getPsspMapper();
return mapper.map(this, Region.class);
}
}
package com.zjty.fp.acq.pssp.subject.entity.remote;
import com.zjty.fp.acq.pssp.subject.entity.location.Website;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.modelmapper.ModelMapper;
import javax.persistence.*;
/**
* fusion-platform.
*
* @author : Matrix [xhyrzldf@foxmail.com]
* @Date : 18-9-3
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_web")
public class RemoteWebsite {
@Id
@GeneratedValue
private Long id;
private String entry;
private String name;
private String scope;
private String host;
private String domain;
private String contact;
private String phone;
private String unit;
private Integer codeOrg;
private Integer idWebCategory;
@Column(name = "level_")
private Integer level;
private Integer statusApprove;
private Integer statusWeb;
private Integer statusCollect;
private Integer statusRun;
private Integer statusError;
public Website toDo() {
ModelMapper mapper = new ModelMapper();
mapper.getConfiguration().setAmbiguityIgnored(true);
Website website = mapper.map(this, Website.class);
return website;
}
}
package com.zjty.fp.acq.pssp.subject.entity.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.zjty.fp.acq.misc.entity.UnionEvent;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import javax.persistence.Column;
import java.util.Date;
/**
* fp-api.
*
* @author : Matrix [xhyrzldf@gmail.com]
* 18-11-12 .
*/
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
public class PsspEvent extends UnionEvent {
@JsonPropertyOrder("1")
@Excel(name = "系统分布式id", orderNum = "1", width = 20)
private String primaryId;
/**
* 源数据主键ID
*/
@JsonPropertyOrder("2")
@ExcelIgnore
private Long id;
/**
* 所属地区
*/
@JsonPropertyOrder("4")
@Excel(name = "地区编码", orderNum = "3")
private Integer codeOrg;
/**
* 所属地区名称
*/
@JsonPropertyOrder("6")
@Excel(name = "地区名称", orderNum = "4")
private String regionName;
/**
* 网站入口分类
*/
@JsonPropertyOrder("8")
@Excel(name = "网站入口分类", width = 13, orderNum = "6", replace = {"政府_4", "高校_5", "军工_6", "金融_7", "其他_8"})
private Integer idWebCategory;
/**
* 网站入口信息
*/
@JsonPropertyOrder("10")
@Excel(name = "网站入口信息", width = 13, orderNum = "8")
private Integer idWeb;
@JsonPropertyOrder("11")
@Excel(name = "网站入口名称", width = 13, orderNum = "9")
private String idWebName;
/**
* 所匹配到的关键字
*/
@JsonPropertyOrder("12")
@Excel(name = "命中关键字", width = 13, orderNum = "10")
private String matchKeyword;
/**
* 数据的标题
*/
@JsonPropertyOrder("14")
@Excel(name = "数据标题", orderNum = "12", width = 20, height = 25)
private String title;
/**
* 数据摘要
*/
@JsonPropertyOrder("16")
@Excel(name = "数据摘要", orderNum = "14", width = 40, height = 25)
private String abs;
/**
* 源网页地址
*/
@JsonPropertyOrder("18")
@Excel(name = "源网站地址", orderNum = "16", width = 35, height = 25)
private String webUrl;
/**
* 本地预览(快照)地址
*/
@JsonPropertyOrder("20")
@Excel(name = "本地预览web(快照)地址", orderNum = "18", width = 35, height = 25)
private String webSnapshot;
/**
* 源附件地址
*/
@JsonPropertyOrder("22")
@Excel(name = "源附件地址", orderNum = "20", width = 35, height = 25)
private String docUrl;
/**
* 本地预览(快照)地址
*/
@JsonPropertyOrder("24")
@Excel(name = "本地预览附件(快照)地址", orderNum = "22", width = 35, height = 25)
private String docSnapshot;
/**
* 处理人ID
*/
@JsonPropertyOrder("26")
@Excel(name = "处理人id", orderNum = "24")
private Integer handlerUser;
/**
* 数据是否为压缩类型
*/
@JsonPropertyOrder("28")
@Excel(name = "是否为压缩包", replace = {"是_1", "否_2"}, orderNum = "26")
private Integer eInZip;
/**
* 数据是否已读
*/
@JsonPropertyOrder("30")
@Column(name = "e_ident")
@Excel(name = "是否已读", orderNum = "28", replace = {"否_0", "是_1"})
private Integer eIdent;
/**
* 告警等级(红,黄,绿)
*/
@JsonPropertyOrder("32")
@Excel(name = "告警等级", orderNum = "30", replace = {"绿_1", "黄_2", "红_3"})
private Integer eAlert;
/**
* 数据类型
*/
@JsonPropertyOrder("34")
@Excel(name = "数据类型", orderNum = "32", replace = {"未知_0", "网页_1", "图片_2", "文档_3", "压缩包_4", "多媒体_5"})
private Integer eType;
/**
* 处理状态
*/
@JsonPropertyOrder("36")
@Excel(name = "处理状态", orderNum = "32", replace = {"未处理_0", "正常_10", "疑似_20", "泄密_30"})
private Integer eStatus;
public PsspEvent(
String platform,
Date tmFetch,
String primaryId,
Long id,
Integer codeOrg,
String regionName,
Integer idWebCategory,
Integer idWeb,
String idWebName,
String matchKeyword,
String title,
String abs,
String webUrl,
String webSnapshot,
String docUrl,
String docSnapshot,
Integer handlerUser,
Integer eInZip,
Integer eIdent,
Integer eAlert,
Integer eType,
Integer eStatus) {
super(platform, tmFetch);
this.primaryId = primaryId;
this.id = id;
this.codeOrg = codeOrg;
this.regionName = regionName;
this.idWebCategory = idWebCategory;
this.idWeb = idWeb;
this.idWebName = idWebName;
this.matchKeyword = matchKeyword;
this.title = title;
this.abs = abs;
this.webUrl = webUrl;
this.webSnapshot = webSnapshot;
this.docUrl = docUrl;
this.docSnapshot = docSnapshot;
this.handlerUser = handlerUser;
this.eInZip = eInZip;
this.eIdent = eIdent;
this.eAlert = eAlert;
this.eType = eType;
this.eStatus = eStatus;
}
public String getPrimaryId() {
return primaryId;
}
public void setPrimaryId(String primaryId) {
this.primaryId = primaryId;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getCodeOrg() {
return codeOrg;
}
public void setCodeOrg(Integer codeOrg) {
this.codeOrg = codeOrg;
}
public Integer getIdWebCategory() {
return idWebCategory;
}
public void setIdWebCategory(Integer idWebCategory) {
this.idWebCategory = idWebCategory;
}
public Integer getIdWeb() {
return idWeb;
}
public void setIdWeb(Integer idWeb) {
this.idWeb = idWeb;
}
public String getMatchKeyword() {
return matchKeyword;
}
public void setMatchKeyword(String matchKeyword) {
this.matchKeyword = matchKeyword;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAbs() {
return abs;
}
public void setAbs(String abs) {
this.abs = abs;
}
public String getWebUrl() {
return webUrl;
}
public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
}
public String getWebSnapshot() {
return webSnapshot;
}
public void setWebSnapshot(String webSnapshot) {
this.webSnapshot = webSnapshot;
}
public String getDocUrl() {
return docUrl;
}
public void setDocUrl(String docUrl) {
this.docUrl = docUrl;
}
public String getDocSnapshot() {
return docSnapshot;
}
public void setDocSnapshot(String docSnapshot) {
this.docSnapshot = docSnapshot;
}
public Integer getHandlerUser() {
return handlerUser;
}
public void setHandlerUser(Integer handlerUser) {
this.handlerUser = handlerUser;
}
public Integer geteInZip() {
return eInZip;
}
public void seteInZip(Integer eInZip) {
this.eInZip = eInZip;
}
public Integer geteIdent() {
return eIdent;
}
public void seteIdent(Integer eIdent) {
this.eIdent = eIdent;
}
public Integer geteAlert() {
return eAlert;
}
public void seteAlert(Integer eAlert) {
this.eAlert = eAlert;
}
public Integer geteType() {
return eType;
}
public void seteType(Integer eType) {
this.eType = eType;
}
public Integer geteStatus() {
return eStatus;
}
public void seteStatus(Integer eStatus) {
this.eStatus = eStatus;
}
public String getRegionName() {
return regionName;
}
public void setRegionName(String regionName) {
this.regionName = regionName;
}
public String getIdWebName() {
return idWebName;
}
public void setIdWebName(String idWebName) {
this.idWebName = idWebName;
}
}
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论