Showing
42 changed files
with
4831 additions
and
0 deletions
Too many changes to show.
To preserve performance only 42 of 46 files are displayed.
.gitignore
0 → 100644
pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | + <modelVersion>4.0.0</modelVersion> | |
5 | + | |
6 | + <groupId>com.idss.asset</groupId> | |
7 | + <artifactId>asset-service-vulsync</artifactId> | |
8 | + <version>0.0.1-SNAPSHOT</version> | |
9 | + <name>asset-service-vulsync</name> | |
10 | + | |
11 | + | |
12 | + | |
13 | + <properties> | |
14 | + <package.path>${project.build.directory}</package.path> | |
15 | + <province.classifier/> | |
16 | + <maven.compiler.source>8</maven.compiler.source> | |
17 | + <maven.compiler.target>8</maven.compiler.target> | |
18 | + <asset.service.kafka.version>[2.0.5,2.0.5.9999]</asset.service.kafka.version> | |
19 | + <log4j.version>2.18.0</log4j.version> | |
20 | + <postgresql.version>[42.4,42.999]</postgresql.version> | |
21 | + <fastjson.version>1.2.83</fastjson.version> | |
22 | + <druid.version>1.2.8</druid.version> | |
23 | + <asset.service.common.version>2.1.8.74</asset.service.common.version> | |
24 | + <asset.service.authority.version>2.1.8.45</asset.service.authority.version> | |
25 | + <asset.service.ip.version>2.1.8.7</asset.service.ip.version> | |
26 | + <spring.util.version>2.2.1.7</spring.util.version> | |
27 | + <asset.service.dictionary.version>2.1.8.12</asset.service.dictionary.version> | |
28 | + <logback.classic.version>1.2.10</logback.classic.version> | |
29 | + <spring.security.version>5.7.5</spring.security.version> | |
30 | + <spring.boot>2.5.4</spring.boot> | |
31 | + </properties> | |
32 | + | |
33 | + <dependencies> | |
34 | + | |
35 | + | |
36 | + <dependency> | |
37 | + <groupId>org.springframework.boot</groupId> | |
38 | + <artifactId>spring-boot-starter-web</artifactId> | |
39 | + <version>2.5.4</version> | |
40 | + </dependency> | |
41 | + | |
42 | + <dependency> | |
43 | + <groupId>javax.servlet</groupId> | |
44 | + <artifactId>javax.servlet-api</artifactId> | |
45 | + <version>4.0.1</version> | |
46 | + </dependency> | |
47 | + | |
48 | + | |
49 | + <dependency> | |
50 | + <groupId>org.elasticsearch.client</groupId> | |
51 | + <artifactId>elasticsearch-rest-high-level-client</artifactId> | |
52 | + <version>7.17.12</version> | |
53 | + </dependency> | |
54 | + <dependency> | |
55 | + <groupId>org.apache.commons</groupId> | |
56 | + <artifactId>commons-lang3</artifactId> | |
57 | + <version>[3.12.0,3.999]</version> | |
58 | + </dependency> | |
59 | + <dependency> | |
60 | + <groupId>cloud.agileframework</groupId> | |
61 | + <artifactId>agile-mybatis</artifactId> | |
62 | + <version>2.2.1.13</version> | |
63 | + <exclusions> | |
64 | + <exclusion> | |
65 | + <groupId>cloud.agileframework</groupId> | |
66 | + <artifactId>common-util</artifactId> | |
67 | + </exclusion> | |
68 | + <exclusion> | |
69 | + <groupId>org.postgresql</groupId> | |
70 | + <artifactId>postgresql</artifactId> | |
71 | + </exclusion> | |
72 | + </exclusions> | |
73 | + </dependency> | |
74 | + <dependency> | |
75 | + <groupId>org.springframework.boot</groupId> | |
76 | + <artifactId>spring-boot-starter-data-redis</artifactId> | |
77 | + <version>2.5.4</version> | |
78 | + </dependency> | |
79 | + <dependency> | |
80 | + <groupId>com.jcraft</groupId> | |
81 | + <artifactId>jsch</artifactId> | |
82 | + <version>0.1.55</version> | |
83 | + </dependency> | |
84 | + <dependency> | |
85 | + <groupId>commons-fileupload</groupId> | |
86 | + <artifactId>commons-fileupload</artifactId> | |
87 | + <version>1.3.3</version> | |
88 | + <scope>compile</scope> | |
89 | + </dependency> | |
90 | + <dependency> | |
91 | + <groupId>com.fasterxml.jackson.core</groupId> | |
92 | + <artifactId>jackson-databind</artifactId> | |
93 | + <version>2.17.2</version> | |
94 | + </dependency> | |
95 | + | |
96 | + <dependency> | |
97 | + <groupId>cloud.agileframework</groupId> | |
98 | + <artifactId>spring-util</artifactId> | |
99 | + <version>${spring.util.version}</version> | |
100 | + </dependency> | |
101 | + <dependency> | |
102 | + <groupId>cloud.agileframework</groupId> | |
103 | + <artifactId>common-util</artifactId> | |
104 | + <version>2.2.1.26</version> | |
105 | + <exclusions> | |
106 | + <exclusion> | |
107 | + <groupId>org.apache.commons</groupId> | |
108 | + <artifactId>commons-collections4</artifactId> | |
109 | + </exclusion> | |
110 | + <exclusion> | |
111 | + <groupId>com.alibaba</groupId> | |
112 | + <artifactId>fastjson</artifactId> | |
113 | + </exclusion> | |
114 | + <exclusion> | |
115 | + <groupId>cloud.agileframework</groupId> | |
116 | + <artifactId>spring-util</artifactId> | |
117 | + </exclusion> | |
118 | + <exclusion> | |
119 | + <groupId>org.apache.commons</groupId> | |
120 | + <artifactId>commons-lang3</artifactId> | |
121 | + </exclusion> | |
122 | + </exclusions> | |
123 | + </dependency> | |
124 | + <dependency> | |
125 | + <groupId>cn.hutool</groupId> | |
126 | + <artifactId>hutool-all</artifactId> | |
127 | + <version>5.7.22</version> | |
128 | + </dependency> | |
129 | + <dependency> | |
130 | + <groupId>org.springframework.boot</groupId> | |
131 | + <artifactId>spring-boot-starter-quartz</artifactId> | |
132 | + <version>2.5.4</version> | |
133 | + </dependency> | |
134 | + | |
135 | + <dependency> | |
136 | + <groupId>org.postgresql</groupId> | |
137 | + <artifactId>postgresql</artifactId> | |
138 | + <version>${postgresql.version}</version> | |
139 | + <exclusions> | |
140 | + <exclusion> | |
141 | + <groupId>org.checkerframework</groupId> | |
142 | + <artifactId>checker-qual</artifactId> | |
143 | + </exclusion> | |
144 | + </exclusions> | |
145 | + </dependency> | |
146 | + <!-- <dependency>--> | |
147 | + <!-- <groupId>com.alibaba</groupId>--> | |
148 | + <!-- <artifactId>druid</artifactId>--> | |
149 | + <!-- <version>${druid.version}</version>--> | |
150 | + <!-- </dependency>--> | |
151 | + <!-- 这个依赖需要引入,如果是使用spring缓存时需要使用其初始化缓存数据,不能删除!!! --> | |
152 | + <dependency> | |
153 | + <groupId>org.slf4j</groupId> | |
154 | + <artifactId>slf4j-api</artifactId> | |
155 | + <version>[1.7.32,1.7.999]</version> | |
156 | + <optional>true</optional> | |
157 | + </dependency> | |
158 | + <dependency> | |
159 | + <groupId>org.apache.logging.log4j</groupId> | |
160 | + <artifactId>log4j-api</artifactId> | |
161 | + <version>2.17.1</version> | |
162 | + </dependency> | |
163 | + <dependency> | |
164 | + <groupId>org.apache.logging.log4j</groupId> | |
165 | + <artifactId>log4j-to-slf4j</artifactId> | |
166 | + <version>${log4j.version}</version> | |
167 | + </dependency> | |
168 | + | |
169 | + <dependency> | |
170 | + <groupId>ch.qos.logback</groupId> | |
171 | + <artifactId>logback-classic</artifactId> | |
172 | + <version>${logback.classic.version}</version> | |
173 | + </dependency> | |
174 | + <dependency> | |
175 | + <groupId>com.alibaba</groupId> | |
176 | + <artifactId>fastjson</artifactId> | |
177 | + <version>${fastjson.version}</version> | |
178 | + </dependency> | |
179 | + <dependency> | |
180 | + <groupId>org.apache.logging.log4j</groupId> | |
181 | + <artifactId>log4j-to-slf4j</artifactId> | |
182 | + <exclusions> | |
183 | + <exclusion> | |
184 | + <groupId>org.apache.logging.log4j</groupId> | |
185 | + <artifactId>log4j-api</artifactId> | |
186 | + </exclusion> | |
187 | + </exclusions> | |
188 | + <version>${log4j.version}</version> | |
189 | + </dependency> | |
190 | + <dependency> | |
191 | + <groupId>org.apache.logging.log4j</groupId> | |
192 | + <artifactId>log4j-api</artifactId> | |
193 | + <version>${log4j.version}</version> | |
194 | + </dependency> | |
195 | + <dependency> | |
196 | + <groupId>org.projectlombok</groupId> | |
197 | + <artifactId>lombok</artifactId> | |
198 | + <optional>true</optional> | |
199 | + <version>1.18.12</version> | |
200 | + </dependency> | |
201 | + | |
202 | + <dependency> | |
203 | + <groupId>com.alibaba</groupId> | |
204 | + <artifactId>druid-spring-boot-starter</artifactId> | |
205 | + <version>1.1.9</version> | |
206 | + </dependency> | |
207 | + | |
208 | + <dependency> | |
209 | + <groupId>org.springframework.boot</groupId> | |
210 | + <artifactId>spring-boot-autoconfigure</artifactId> | |
211 | + <version>2.5.4</version> | |
212 | + </dependency> | |
213 | + | |
214 | + <dependency> | |
215 | + <groupId>org.bouncycastle</groupId> | |
216 | + <artifactId>bcpkix-jdk15on</artifactId> | |
217 | + <version>1.60</version> | |
218 | + </dependency> <dependency> | |
219 | + <groupId>com.idss.common</groupId> | |
220 | + <artifactId>common-file-storage</artifactId> | |
221 | + <version>1.0.0.16</version> | |
222 | + </dependency> | |
223 | + <dependency> | |
224 | + <groupId>cloud.agileframework</groupId> | |
225 | + <artifactId>agile-security</artifactId> | |
226 | + <version>2.2.1.18</version> | |
227 | + </dependency> | |
228 | + <dependency> | |
229 | + <groupId>cloud.agileframework</groupId> | |
230 | + <artifactId>agile-validate</artifactId> | |
231 | + <version>2.2.1.3</version> | |
232 | + </dependency> | |
233 | + | |
234 | + <dependency> | |
235 | + <groupId>cloud.agileframework</groupId> | |
236 | + <artifactId>agile-mvc</artifactId> | |
237 | + <version>2.2.1.21</version> | |
238 | + </dependency> | |
239 | + | |
240 | + | |
241 | + </dependencies> | |
242 | + | |
243 | + <repositories> | |
244 | + <repository> | |
245 | + <id>shanghai</id> | |
246 | + <url>http://10.66.11.136:8082/repository/maven-public/</url> | |
247 | + </repository> | |
248 | + </repositories> | |
249 | + | |
250 | + | |
251 | + <build> | |
252 | + <finalName>${project.artifactId}</finalName> | |
253 | + <plugins> | |
254 | + <!-- 开始处理启动模块jar包, --> | |
255 | + <plugin> | |
256 | + <groupId>org.apache.maven.plugins</groupId> | |
257 | + <artifactId>maven-jar-plugin</artifactId> | |
258 | + <configuration> | |
259 | + <!--在启动模块的jar中排除以下文件类型,这是为了避免启动模块jar和后续的config目录下存在两份相同资源文件从而导致项目无法重启--> | |
260 | + <excludes> | |
261 | + <!-- <exclude>**/*.xml</exclude>--> | |
262 | + <!-- <exclude>**/*.yml</exclude>--> | |
263 | + </excludes> | |
264 | + <archive> | |
265 | + <manifest> | |
266 | + <!-- 执行的主程序路径 --> | |
267 | + <mainClass>com.idss.vulsync.VulSyncApp</mainClass> | |
268 | + <!--是否要把第三方jar放到manifest的classpath中--> | |
269 | + <addClasspath>true</addClasspath> | |
270 | + <!--生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/--> | |
271 | + <classpathPrefix>../lib/</classpathPrefix> | |
272 | + <!-- 打包时 MANIFEST.MF 文件不记录的时间戳版本 --> | |
273 | + <useUniqueVersions>false</useUniqueVersions> | |
274 | + </manifest> | |
275 | + <manifestEntries> | |
276 | + <!-- 在 Class-Path 下添加配置文件的路径 --> | |
277 | + <Class-Path>../config/</Class-Path> | |
278 | + </manifestEntries> | |
279 | + </archive> | |
280 | + <!-- 将启动模块的jar包也输出到对应的lib下 --> | |
281 | + <outputDirectory>${package.path}/lib/</outputDirectory> | |
282 | + </configuration> | |
283 | + </plugin> | |
284 | + | |
285 | + <!-- 开始处理依赖包,将所有资源文件拷贝到${package.path}/lib下 --> | |
286 | + <plugin> | |
287 | + <groupId>org.apache.maven.plugins</groupId> | |
288 | + <artifactId>maven-dependency-plugin</artifactId> | |
289 | + <executions> | |
290 | + <execution> | |
291 | + <id>copy-dependencies</id> | |
292 | + <phase>package</phase> | |
293 | + <goals> | |
294 | + <goal>copy-dependencies</goal> | |
295 | + </goals> | |
296 | + <configuration> | |
297 | + <outputDirectory>${package.path}/lib/</outputDirectory> | |
298 | + </configuration> | |
299 | + </execution> | |
300 | + </executions> | |
301 | + </plugin> | |
302 | + | |
303 | + <!-- 开始处理资源文件,将所有资源文件拷贝到${package.path}/config下 --> | |
304 | + <plugin> | |
305 | + <artifactId>maven-resources-plugin</artifactId> | |
306 | + <executions> | |
307 | + <execution> | |
308 | + <id>copy-mapper</id> | |
309 | + <phase>package</phase> | |
310 | + <goals> | |
311 | + <goal>copy-resources</goal> | |
312 | + </goals> | |
313 | + <configuration> | |
314 | + <resources> | |
315 | + <!--把配置文件打包到指定路径--> | |
316 | + <resource> | |
317 | + <directory>src/main/resources/mapper/</directory> | |
318 | + </resource> | |
319 | + </resources> | |
320 | + <outputDirectory>${package.path}/config</outputDirectory> | |
321 | + </configuration> | |
322 | + </execution> | |
323 | + | |
324 | + <execution> | |
325 | + <id>copy-resources</id> | |
326 | + <phase>package</phase> | |
327 | + <goals> | |
328 | + <goal>copy-resources</goal> | |
329 | + </goals> | |
330 | + <configuration> | |
331 | + <resources> | |
332 | + <!--把配置文件打包到指定路径--> | |
333 | + <resource> | |
334 | + <directory>src/main/resources/</directory> | |
335 | + <excludes> | |
336 | + <exclude>**/*.xml</exclude> | |
337 | + </excludes> | |
338 | + </resource> | |
339 | + </resources> | |
340 | + <outputDirectory>${package.path}/config</outputDirectory> | |
341 | + </configuration> | |
342 | + </execution> | |
343 | + <!--copy 脚本,把bin目录下的文件复制到,打包目录下--> | |
344 | + <execution> | |
345 | + <id>copy-bin</id> | |
346 | + <phase>package</phase> | |
347 | + <goals> | |
348 | + <goal>copy-resources</goal> | |
349 | + </goals> | |
350 | + <configuration> | |
351 | + <resources> | |
352 | + <resource> | |
353 | + <!--注意:此处bin脚本目录在src下,根据实际情况填写--> | |
354 | + <directory>src/bin/</directory> | |
355 | + </resource> | |
356 | + </resources> | |
357 | + <outputDirectory>${package.path}/bin</outputDirectory> | |
358 | + </configuration> | |
359 | + </execution> | |
360 | + </executions> | |
361 | + </plugin> | |
362 | + </plugins> | |
363 | + </build> | |
364 | + | |
365 | + | |
366 | +</project> | ... | ... |
1 | +package com.idss.vulsync; | |
2 | + | |
3 | +import org.mybatis.spring.annotation.MapperScan; | |
4 | +import org.springframework.boot.SpringApplication; | |
5 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
6 | +import org.springframework.context.annotation.ComponentScan; | |
7 | +import org.springframework.scheduling.annotation.EnableScheduling; | |
8 | + | |
9 | +/** | |
10 | + * @Author: zc | |
11 | + * @Date: 2024/8/1 14:04 | |
12 | + */ | |
13 | +@SpringBootApplication | |
14 | +@ComponentScan(value = {"com.idss"}) | |
15 | +@EnableScheduling | |
16 | +@MapperScan(value = {"com.idss.vulsync.mvc.mapper", "com.idss.common.file.storage.mapper"}) | |
17 | +public class VulSyncApp { | |
18 | + /** | |
19 | + * main方法 | |
20 | + * | |
21 | + * @param args args | |
22 | + */ | |
23 | + public static void main(String[] args) { | |
24 | + new SpringApplication(VulSyncApp.class).run(args); | |
25 | + } | |
26 | +} | ... | ... |
1 | +package com.idss.vulsync.common; | |
2 | + | |
3 | +/** | |
4 | + * ES索引常量 | |
5 | + * | |
6 | + * @author zhangjiachen | |
7 | + */ | |
8 | +public class EsIndexConstant { | |
9 | + | |
10 | + /** | |
11 | + * 部侧全量数据 | |
12 | + */ | |
13 | + | |
14 | + public static final String GXB_ASSET_FULL_DATA_INDEX = "gxb_asset_full_data_index"; | |
15 | + | |
16 | + | |
17 | + /** | |
18 | + * 默认索引类型 | |
19 | + */ | |
20 | + public static final String DEFAULT_TYPE = "_doc"; | |
21 | + } | ... | ... |
1 | +package com.idss.vulsync.config; | |
2 | + | |
3 | +import lombok.Data; | |
4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
5 | +import org.springframework.context.annotation.Configuration; | |
6 | + | |
7 | +/** | |
8 | + * @Author: zc | |
9 | + * @Date: 2024/8/16 14:29 | |
10 | + */ | |
11 | +@Configuration | |
12 | +@ConfigurationProperties(value = "assetftp") | |
13 | +@Data | |
14 | +public class AssetSftpConfiguration { | |
15 | + private String ip; | |
16 | + private String port; | |
17 | + private String user; | |
18 | + private String pwd; | |
19 | + private String path; | |
20 | +} | ... | ... |
1 | +package com.idss.vulsync.config; | |
2 | + | |
3 | +import cloud.agileframework.mvc.base.AbstractResponseFormat; | |
4 | +import cloud.agileframework.mvc.base.Head; | |
5 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
6 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
7 | +import com.fasterxml.jackson.databind.type.TypeFactory; | |
8 | +import org.springframework.beans.factory.annotation.Autowired; | |
9 | +import org.springframework.stereotype.Component; | |
10 | + | |
11 | +import java.util.HashMap; | |
12 | +import java.util.LinkedHashMap; | |
13 | +import java.util.Map; | |
14 | + | |
15 | +/** | |
16 | + * @Author: zc | |
17 | + * @Date: 2024/8/20 16:41 | |
18 | + */ | |
19 | +@Component | |
20 | +public class CommonResponseFormate extends AbstractResponseFormat { | |
21 | + @Autowired | |
22 | + ObjectMapper objectMapper; | |
23 | + | |
24 | + @Override | |
25 | + public Map<String, Object> buildResponseData(Head head, Object result) { | |
26 | + //head为组件整理后的响应头部信息 | |
27 | + //result为响应体信息 | |
28 | + //自行定制返回结果状态为Map格式返回,该Map将作为ModelAndView中的Model组装成视图写入response | |
29 | + LinkedHashMap<String, Object> map = new LinkedHashMap<>(); | |
30 | + try { | |
31 | + map = objectMapper.readValue(objectMapper.writeValueAsString(result), TypeFactory.defaultInstance().constructMapType(LinkedHashMap.class, String.class, Object.class)); | |
32 | + return map; | |
33 | + } catch (JsonProcessingException e) { | |
34 | + e.printStackTrace(); | |
35 | + } | |
36 | + return map; | |
37 | + } | |
38 | +} | ... | ... |
1 | +package com.idss.vulsync.config; | |
2 | + | |
3 | +import cn.hutool.core.collection.ListUtil; | |
4 | +import lombok.extern.slf4j.Slf4j; | |
5 | +import org.apache.commons.lang3.StringUtils; | |
6 | +import org.apache.http.HttpHost; | |
7 | +import org.apache.http.auth.AuthScope; | |
8 | +import org.apache.http.auth.UsernamePasswordCredentials; | |
9 | +import org.apache.http.client.CredentialsProvider; | |
10 | +import org.apache.http.impl.client.BasicCredentialsProvider; | |
11 | +import org.elasticsearch.client.*; | |
12 | +import org.slf4j.Logger; | |
13 | +import org.slf4j.LoggerFactory; | |
14 | +import org.springframework.beans.factory.annotation.Value; | |
15 | +import org.springframework.context.annotation.Bean; | |
16 | +import org.springframework.context.annotation.Configuration; | |
17 | + | |
18 | +import javax.annotation.PostConstruct; | |
19 | +import java.util.ArrayList; | |
20 | +import java.util.List; | |
21 | + | |
22 | +/** | |
23 | + * @Author: zc | |
24 | + * @Date: 2021/11/19 14:06 | |
25 | + */ | |
26 | +@Configuration | |
27 | +@Slf4j | |
28 | +public class ElasticSearchConfig { | |
29 | + private List<HttpHost> httpHosts = new ArrayList<>(); | |
30 | + /** | |
31 | + * elk集群地址 | |
32 | + */ | |
33 | + @Value("${spring.data.elasticsearch.cluster-hosts}") | |
34 | + private String hostName; | |
35 | + | |
36 | + | |
37 | + | |
38 | + /** | |
39 | + * 用户 | |
40 | + */ | |
41 | + @Value("${spring.data.elasticsearch.userName}") | |
42 | + private String username; | |
43 | + | |
44 | + /** | |
45 | + * 密码 | |
46 | + */ | |
47 | + @Value("${spring.data.elasticsearch.password}") | |
48 | + private String password; | |
49 | + | |
50 | +// /** | |
51 | +// * 连接池 | |
52 | +// */ | |
53 | +// @Value("${elasticsearch.pool}") | |
54 | +// private String poolSize; | |
55 | + | |
56 | + public static final RequestOptions COMMON_OPTIONS; | |
57 | + static { | |
58 | + RequestOptions.Builder builder=RequestOptions.DEFAULT.toBuilder(); | |
59 | + COMMON_OPTIONS=builder.build(); | |
60 | + } | |
61 | + | |
62 | + /** | |
63 | + * 防止netty的bug | |
64 | + * java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4] | |
65 | + */ | |
66 | + @PostConstruct | |
67 | + void init() { | |
68 | + System.setProperty("es.set.netty.runtime.available.processors", "false"); | |
69 | + } | |
70 | + | |
71 | + @Bean | |
72 | + public RestHighLevelClient restHighLevelClient() { | |
73 | + String[] hosts = hostName.split(","); | |
74 | + for (String host : hosts) { | |
75 | + String[] hostStr = host.split(":"); | |
76 | + httpHosts.add(new HttpHost(hostStr[0], Integer.parseInt(hostStr[1]), "http")); | |
77 | + } | |
78 | + RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[0])); | |
79 | + RestHighLevelClient restHighLevelClient=getRestHighLevelClient(builder); | |
80 | + return restHighLevelClient; | |
81 | + } | |
82 | + | |
83 | + /** | |
84 | + * get restHistLevelClient | |
85 | + * | |
86 | + * @return | |
87 | + */ | |
88 | + private RestHighLevelClient getRestHighLevelClient(RestClientBuilder builder) { | |
89 | + // Callback used the default {@link RequestConfig} being set to the {@link CloseableHttpClient} | |
90 | + builder.setRequestConfigCallback(requestConfigBuilder -> { | |
91 | + requestConfigBuilder.setConnectTimeout(1000); | |
92 | + requestConfigBuilder.setSocketTimeout(30000); | |
93 | + requestConfigBuilder.setConnectionRequestTimeout(500); | |
94 | + return requestConfigBuilder; | |
95 | + }); | |
96 | + // Callback used to customize the {@link CloseableHttpClient} instance used by a {@link RestClient} instance. | |
97 | + builder.setHttpClientConfigCallback(httpClientBuilder -> { | |
98 | + httpClientBuilder.setMaxConnTotal(30); | |
99 | + httpClientBuilder.setMaxConnPerRoute(10); | |
100 | + // Callback used the basic credential auth | |
101 | + if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)) { | |
102 | + final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); | |
103 | + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); | |
104 | + httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); | |
105 | + } | |
106 | + return httpClientBuilder; | |
107 | + }); | |
108 | + | |
109 | + return new RestHighLevelClient(builder); | |
110 | + } | |
111 | + | |
112 | +} | ... | ... |
1 | +package com.idss.vulsync.config; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonInclude; | |
4 | +import com.fasterxml.jackson.databind.DeserializationFeature; | |
5 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
6 | +import com.fasterxml.jackson.databind.SerializationFeature; | |
7 | +import org.springframework.context.annotation.Bean; | |
8 | +import org.springframework.context.annotation.Configuration; | |
9 | + | |
10 | +/** | |
11 | + * @Author: zc | |
12 | + * @Date: 2024/8/30 14:37 | |
13 | + */ | |
14 | +@Configuration | |
15 | +public class JacksonConfig { | |
16 | + @Bean | |
17 | + public ObjectMapper objectMapper() { | |
18 | + ObjectMapper mapper = new ObjectMapper(); | |
19 | + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | |
20 | + // 自定义配置 | |
21 | + mapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, false);; | |
22 | + mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, false); | |
23 | + return mapper; | |
24 | + } | |
25 | +} | ... | ... |
1 | +package com.idss.crawl.config; | |
2 | + | |
3 | +import org.springframework.beans.factory.annotation.Value; | |
4 | +import org.springframework.context.annotation.Bean; | |
5 | +import org.springframework.context.annotation.Configuration; | |
6 | +import org.springframework.data.redis.connection.RedisConnectionFactory; | |
7 | +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | |
8 | +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | |
9 | +import org.springframework.data.redis.core.RedisTemplate; | |
10 | +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | |
11 | +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |
12 | +import org.springframework.data.redis.serializer.StringRedisSerializer; | |
13 | + | |
14 | +/** | |
15 | + * RedisConfig | |
16 | + * 设置序列化与反序列化方法 | |
17 | + * | |
18 | + * @author Syouken | |
19 | + */ | |
20 | +@Configuration | |
21 | +public class RedisConfig { | |
22 | + @Value("${spring.redis.host}") | |
23 | + private String host; | |
24 | + @Value("${spring.redis.port}") | |
25 | + private Integer port; | |
26 | + @Value("${spring.redis.password}") | |
27 | + private String password; | |
28 | + @Value("${spring.redis.database}") | |
29 | + private Integer database; | |
30 | + | |
31 | + @Bean | |
32 | + public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { | |
33 | + RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); | |
34 | + redisTemplate.setConnectionFactory(redisConnectionFactory); | |
35 | + Jackson2JsonRedisSerializer jackson2JsonRedisSerializer=new Jackson2JsonRedisSerializer(Object.class); | |
36 | + redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
37 | + redisTemplate.setValueSerializer(new StringRedisSerializer()); | |
38 | + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); | |
39 | + redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); | |
40 | + redisTemplate.afterPropertiesSet(); | |
41 | + return redisTemplate; | |
42 | + } | |
43 | + | |
44 | + @Bean | |
45 | + public RedisConnectionFactory redisConnectionFactory(){ | |
46 | + RedisStandaloneConfiguration redisStandaloneConfiguration=new RedisStandaloneConfiguration(); | |
47 | + redisStandaloneConfiguration.setHostName(host); | |
48 | + redisStandaloneConfiguration.setPort(port); | |
49 | + redisStandaloneConfiguration.setPassword(password); | |
50 | + redisStandaloneConfiguration.setDatabase(database); | |
51 | + LettuceConnectionFactory lettuceConnectionFactory=new LettuceConnectionFactory(redisStandaloneConfiguration); | |
52 | + lettuceConnectionFactory.afterPropertiesSet(); | |
53 | + return lettuceConnectionFactory; | |
54 | + } | |
55 | + | |
56 | +} | ... | ... |
1 | +package com.idss.vulsync.config; | |
2 | + | |
3 | +import cloud.agileframework.spring.util.PropertiesUtil; | |
4 | +import org.quartz.Scheduler; | |
5 | +import org.quartz.ee.servlet.QuartzInitializerListener; | |
6 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
7 | +import org.springframework.context.ApplicationContext; | |
8 | +import org.springframework.context.annotation.Bean; | |
9 | +import org.springframework.context.annotation.Configuration; | |
10 | +import org.springframework.scheduling.quartz.SchedulerFactoryBean; | |
11 | +import org.springframework.scheduling.quartz.SpringBeanJobFactory; | |
12 | + | |
13 | +import java.io.IOException; | |
14 | +import java.util.Properties; | |
15 | + | |
16 | +@Configuration | |
17 | +@ConditionalOnProperty(prefix = "spring", value = "quartz.enable", havingValue = "true", matchIfMissing = false) | |
18 | +public class SchedulerConfig { | |
19 | + | |
20 | + @Bean(name="SchedulerFactory") | |
21 | + public SchedulerFactoryBean schedulerFactoryBean(ApplicationContext applicationContext) throws IOException { | |
22 | + SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); | |
23 | + SpringBeanJobFactory jobFactory = new SpringBeanJobFactory(); | |
24 | + jobFactory.setApplicationContext(applicationContext); | |
25 | + schedulerFactoryBean.setJobFactory(jobFactory); | |
26 | + schedulerFactoryBean.setQuartzProperties(quartzProperties()); | |
27 | + return schedulerFactoryBean; | |
28 | + } | |
29 | + | |
30 | + @Bean(name="QuartzScheduler") | |
31 | + public Scheduler quartzScheduler(ApplicationContext applicationContext) throws IOException { | |
32 | + return schedulerFactoryBean(applicationContext).getScheduler(); | |
33 | + } | |
34 | + | |
35 | + | |
36 | + /** | |
37 | + * quartz初始化监听器 | |
38 | + * 这个监听器可以监听到工程的启动,在工程停止再启动时可以让已有的定时任务继续进行。 | |
39 | + * | |
40 | + * @return | |
41 | + */ | |
42 | + @Bean | |
43 | + public QuartzInitializerListener executorListener() { | |
44 | + return new QuartzInitializerListener(); | |
45 | + } | |
46 | + | |
47 | + @Bean | |
48 | + public Properties quartzProperties() throws IOException { | |
49 | + Properties properties = new Properties(); | |
50 | + properties.put("org.quartz.scheduler.instanceName", "asset-service-vulsync"); | |
51 | + properties.put("org.quartz.scheduler.instanceId", "AUTO"); | |
52 | + properties.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); | |
53 | + properties.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate"); | |
54 | + properties.put("org.quartz.jobStore.tablePrefix", PropertiesUtil.getProperty("spring.quartz.prefix")); | |
55 | + properties.put("org.quartz.jobStore.isClustered", "true"); | |
56 | + properties.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); | |
57 | + properties.put("org.quartz.threadPool.threadCount", "10"); | |
58 | + properties.put("org.quartz.threadPool.threadPriority", "5"); | |
59 | + properties.put("org.quartz.jobStore.dataSource", "myDS"); | |
60 | + properties.put("org.quartz.dataSource.myDS.driver", PropertiesUtil.getProperty("spring.datasource.driver-class-name")); | |
61 | + properties.put("org.quartz.dataSource.myDS.URL", PropertiesUtil.getProperty("spring.datasource.url")); | |
62 | + properties.put("org.quartz.dataSource.myDS.user", PropertiesUtil.getProperty("spring.datasource.username")); | |
63 | + properties.put("org.quartz.dataSource.myDS.password", PropertiesUtil.getProperty("spring.datasource.password")); | |
64 | + properties.put("org.quartz.dataSource.myDS.maxConnections", "10"); | |
65 | + return properties; | |
66 | + } | |
67 | +} | ... | ... |
1 | +//package com.idss.vulsync.config; | |
2 | +// | |
3 | +//import lombok.Data; | |
4 | +//import org.springframework.boot.context.properties.ConfigurationProperties; | |
5 | +//import org.springframework.context.annotation.Configuration; | |
6 | +// | |
7 | +///** | |
8 | +// * @Author: zc | |
9 | +// * @Date: 2024/8/16 14:29 | |
10 | +// */ | |
11 | +//@Configuration | |
12 | +//@ConfigurationProperties(value = "ftp") | |
13 | +//@Data | |
14 | +//public class SftpConfiguration { | |
15 | +// private String ip; | |
16 | +// private Integer port; | |
17 | +// private String user; | |
18 | +// private String pwd; | |
19 | +// private String dir; | |
20 | +// | |
21 | +// private String tmpdir; | |
22 | +//} | ... | ... |
1 | +package com.idss.vulsync.config; | |
2 | + | |
3 | +import javax.net.ssl.X509TrustManager; | |
4 | +import java.security.cert.CertificateException; | |
5 | +import java.security.cert.X509Certificate; | |
6 | + | |
7 | +/** | |
8 | + * @Author: zc | |
9 | + * @Date: 2024/8/8 20:04 | |
10 | + */ | |
11 | +public class TrustAllCertManager implements X509TrustManager { | |
12 | + @Override | |
13 | + public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
14 | + | |
15 | + } | |
16 | + | |
17 | + @Override | |
18 | + public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
19 | + | |
20 | + } | |
21 | + | |
22 | + @Override | |
23 | + public X509Certificate[] getAcceptedIssuers() { | |
24 | + return null; | |
25 | + } | |
26 | + | |
27 | +} | ... | ... |
1 | +package com.idss.vulsync.config; | |
2 | + | |
3 | +import lombok.Data; | |
4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
5 | +import org.springframework.context.annotation.Configuration; | |
6 | + | |
7 | +/** | |
8 | + * @Author: zc | |
9 | + * @Date: 2024/8/16 14:29 | |
10 | + */ | |
11 | +@Configuration | |
12 | +@ConfigurationProperties(value = "vulftp") | |
13 | +@Data | |
14 | +public class VulSftpConfiguration { | |
15 | + private String ip; | |
16 | + private String temp; | |
17 | +} | ... | ... |
1 | +package com.idss.vulsync.constants; | |
2 | + | |
3 | +/** | |
4 | + * @Author: zc | |
5 | + * @Date: 2024/8/16 14:00 | |
6 | + */ | |
7 | +public class RedisConstants { | |
8 | + | |
9 | + //部侧上报全量数据文件 多文件路径用逗号分隔 | |
10 | + public static final String INIT_REPORT_DATA_FILE_NAME = "init-report-data-file-name"; | |
11 | +// public static final String INIT_REPORT_DATA_FILE_NAME = "063c032e-0021-4619-a26f-65e12635594d"; | |
12 | + | |
13 | + //部侧上报全量数据es索引 | |
14 | + public static final String INIT_REPORT_DATA_INDEX = "init-report-data-index"; | |
15 | + | |
16 | +} | ... | ... |
1 | +package com.idss.vulsync.entity; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
4 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +import java.util.List; | |
8 | + | |
9 | +/** | |
10 | + * @Author: zc | |
11 | + * @Date: 2023/4/7 13:10 | |
12 | + */ | |
13 | +@Data | |
14 | +@JsonPropertyOrder(alphabetic=true) | |
15 | +public class AssetInfo { | |
16 | + @JsonProperty("Brand") | |
17 | + private List<Brand> brand; | |
18 | + @JsonProperty("Language") | |
19 | + private String language; | |
20 | + | |
21 | + @JsonProperty("Memory") | |
22 | + private List<Memory> memory; | |
23 | + | |
24 | + @JsonProperty("OpenSource") | |
25 | + private String openSource; | |
26 | + @JsonProperty("HardwareEnvironment") | |
27 | + private String hardwareEnvironment; | |
28 | + @JsonProperty("SoftwareEnvironment") | |
29 | + private String softwareEnvironment; | |
30 | + | |
31 | + @JsonProperty("CPU") | |
32 | + private List<Cpu> cpu; | |
33 | + @JsonProperty("information") | |
34 | + private List<Information> information; | |
35 | + | |
36 | + @JsonProperty("Chip") | |
37 | + private List<Chip> Chip; | |
38 | + | |
39 | + @Data | |
40 | + @JsonPropertyOrder(alphabetic=true) | |
41 | + public static class Brand { | |
42 | + @JsonProperty("Manufacturer") | |
43 | + private String manufacturer; | |
44 | + @JsonProperty("Region") | |
45 | + private String region; | |
46 | + @JsonProperty("Name") | |
47 | + private String name; | |
48 | + } | |
49 | + | |
50 | + @Data | |
51 | + @JsonPropertyOrder(alphabetic=true) | |
52 | + public static class Memory { | |
53 | + @JsonProperty("Manufacturer") | |
54 | + private String manufacturer; | |
55 | + @JsonProperty("Model") | |
56 | + private String model; | |
57 | + } | |
58 | + | |
59 | + @Data | |
60 | + @JsonPropertyOrder(alphabetic=true) | |
61 | + public static class Cpu { | |
62 | + @JsonProperty("Manufacturer") | |
63 | + private String manufacturer; | |
64 | + @JsonProperty("Model") | |
65 | + private String model; | |
66 | + } | |
67 | + | |
68 | + @Data | |
69 | + @JsonPropertyOrder(alphabetic=true) | |
70 | + public static class Information { | |
71 | + @JsonProperty("Version") | |
72 | + private String version; | |
73 | + @JsonProperty("Model") | |
74 | + private String model; | |
75 | + } | |
76 | + | |
77 | + @Data | |
78 | + @JsonPropertyOrder(alphabetic=true) | |
79 | + public static class Chip { | |
80 | + @JsonProperty("Manufacturer") | |
81 | + private String manufacturer; | |
82 | + @JsonProperty("Model") | |
83 | + private String model; | |
84 | + } | |
85 | +} | |
86 | + | |
87 | + | ... | ... |
1 | +package com.idss.vulsync.entity; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
4 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +import java.util.List; | |
8 | + | |
9 | +/** | |
10 | + * @Author: zc | |
11 | + * @Date: 2023/4/7 13:10 | |
12 | + */ | |
13 | +@Data | |
14 | +@JsonPropertyOrder(alphabetic=true) | |
15 | +public class AssetIpInfo { | |
16 | + @JsonProperty("IpType") | |
17 | + private String ipType; | |
18 | + @JsonProperty("Ip") | |
19 | + private String ip; | |
20 | + | |
21 | + @JsonProperty("OpenPort") | |
22 | + private List<Ip> openPort; | |
23 | + | |
24 | + @Data | |
25 | + @JsonPropertyOrder(alphabetic=true) | |
26 | + public static class Ip { | |
27 | + @JsonProperty("protocol") | |
28 | + private String protocol; | |
29 | + @JsonProperty("port") | |
30 | + private String port; | |
31 | + } | |
32 | +} | |
33 | + | |
34 | + | ... | ... |
1 | +package com.idss.vulsync.entity; | |
2 | + | |
3 | +import com.alibaba.fastjson.annotation.JSONField; | |
4 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
5 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
6 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; | |
7 | +import lombok.Data; | |
8 | + | |
9 | +import java.util.List; | |
10 | + | |
11 | +/** | |
12 | + * @Author: zc | |
13 | + * @Date: 2024/8/16 14:18 | |
14 | + */ | |
15 | +@Data | |
16 | +@JsonPropertyOrder(alphabetic=true) | |
17 | +public class AssetReportVO { | |
18 | + @JsonProperty("TaskID") | |
19 | + private String taskID; | |
20 | + @JsonProperty("IspCode") | |
21 | + private String ispCode; | |
22 | + @JsonProperty("OrgCode") | |
23 | + private String orgCode; | |
24 | + @JsonProperty("AssetID") | |
25 | + private String assetId; | |
26 | + @JsonProperty("AssetIPInfo") | |
27 | + private List<AssetIpInfo> assetIPInfo; | |
28 | + @JsonProperty("AssetName") | |
29 | + private String assetName; | |
30 | + @JsonProperty("AssetType") | |
31 | + private String assetType; | |
32 | + @JsonProperty("AssetTag") | |
33 | + private String assetTag; | |
34 | + @JsonProperty("AssetInfo") | |
35 | + private List<AssetInfo> assetInfo; | |
36 | + @JsonProperty("IsAccess") | |
37 | + private String isAccess; | |
38 | + @JsonProperty("State") | |
39 | + private String state; | |
40 | + @JsonProperty("SystemName") | |
41 | + private String systemName; | |
42 | + @JsonProperty("NetworkUnit") | |
43 | + private String networkUnit; | |
44 | + @JsonProperty("NetPosition") | |
45 | + private String netPosition; | |
46 | + @JsonProperty("FoundTypeList") | |
47 | + private String foundTypeList; | |
48 | + @JsonProperty("FoundTypeTime") | |
49 | + private String foundTypeTime; | |
50 | + @JsonProperty("Location") | |
51 | + private String location; | |
52 | + @JsonProperty("ObjectName") | |
53 | + private String objectName; | |
54 | + @JsonProperty("DeviceLevel") | |
55 | + private String deviceLevel; | |
56 | + | |
57 | +// @JsonProperty("SortedJson") | |
58 | +// @JsonIgnore | |
59 | +// private String sortedJson; | |
60 | +} | ... | ... |
1 | +package com.idss.vulsync.entity.vo; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
4 | +import lombok.Data; | |
5 | + | |
6 | +/** | |
7 | + * @Author: zc | |
8 | + * @Date: 2024/8/13 15:11 | |
9 | + */ | |
10 | +@Data | |
11 | +public class BaseRequest { | |
12 | + private String msgID; | |
13 | + private Integer msgType; | |
14 | + @JsonProperty("IspCode") | |
15 | + private String ispCode; | |
16 | + @JsonProperty("OrgCode") | |
17 | + private String orgCode; | |
18 | + @JsonProperty("ReqMsgCnt") | |
19 | + private String reqMsgCnt; | |
20 | + @JsonProperty("Timestamp") | |
21 | + private String timestamp; | |
22 | + @JsonProperty("Sign") | |
23 | + private String sign; | |
24 | +} | ... | ... |
1 | +package com.idss.vulsync.entity.vo; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
4 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +/** | |
8 | + * @Author: zc | |
9 | + * @Date: 2024/8/13 15:11 | |
10 | + */ | |
11 | +@Data | |
12 | +public class BaseResponse <Rsp>{ | |
13 | + private String msgID; | |
14 | + private Integer msgType; | |
15 | + private Integer statusCode; | |
16 | + private String statusText; | |
17 | + @JsonProperty("RspMsgCnt") | |
18 | + private Rsp rspMsgCnt; | |
19 | + @JsonProperty("Timestamp") | |
20 | + private String timestamp; | |
21 | + @JsonProperty("Sign") | |
22 | + private String sign; | |
23 | +} | ... | ... |
1 | +package com.idss.vulsync.entity.vo; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
4 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; | |
5 | +import lombok.Data; | |
6 | + | |
7 | +/** | |
8 | + * @Author: zc | |
9 | + * 同步参数协商 | |
10 | + * @Date: 2024/8/13 15:02 | |
11 | + */ | |
12 | +@Data | |
13 | +@JsonPropertyOrder(value = {"TransID","filePath","user","port","creditType","initDelay","updCycle","credit"}) | |
14 | +public class SyncParamConsultRequestData { | |
15 | + @JsonProperty("TransID") | |
16 | + private String transID; | |
17 | + private String filePath; | |
18 | + private String user; | |
19 | + private Integer creditType; | |
20 | + private String credit; | |
21 | + private String pubKey; | |
22 | + private String initDelay; | |
23 | + private String updCycle; | |
24 | + private Integer port; | |
25 | +} | ... | ... |
1 | +package com.idss.vulsync.enums; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Getter; | |
5 | +import lombok.NoArgsConstructor; | |
6 | + | |
7 | +/** | |
8 | + * TopicTypeEnum | |
9 | + * | |
10 | + */ | |
11 | +@Getter | |
12 | +@AllArgsConstructor | |
13 | +@NoArgsConstructor | |
14 | +public enum TopicTypeEnum { | |
15 | + /** | |
16 | + * crawl-task-begin | |
17 | + */ | |
18 | + CRAWL_BEGIN("crawl-task-begin", "web爬虫程序启动"), | |
19 | + | |
20 | + | |
21 | + /** | |
22 | + * crawl-task-return | |
23 | + */ | |
24 | + CRAWL_RETURN("crawl-task-return", "web爬虫程序应答"), | |
25 | + ; | |
26 | + | |
27 | + private String code; | |
28 | + | |
29 | + private String msg; | |
30 | + | |
31 | + /** | |
32 | + * 根据code查找name | |
33 | + * | |
34 | + * @param name name | |
35 | + * @return TopicTypeEnum | |
36 | + */ | |
37 | + public static TopicTypeEnum getByCode(String name) { | |
38 | + TopicTypeEnum[] enums = TopicTypeEnum.values(); | |
39 | + for (TopicTypeEnum e : enums) { | |
40 | + if (e.getCode().equals(name)) { | |
41 | + return e; | |
42 | + } | |
43 | + } | |
44 | + return null; | |
45 | + } | |
46 | +} | ... | ... |
1 | +package com.idss.vulsync.mvc.controller; | |
2 | + | |
3 | +import cloud.agileframework.common.constant.Constant; | |
4 | +import cloud.agileframework.mvc.base.RETURN; | |
5 | +import cloud.agileframework.mvc.param.AgileReturn; | |
6 | +import cn.hutool.core.date.DateUtil; | |
7 | +import com.fasterxml.jackson.databind.DeserializationFeature; | |
8 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
9 | +import com.fasterxml.jackson.databind.type.TypeFactory; | |
10 | +import com.idss.vulsync.entity.vo.BaseRequest; | |
11 | +import com.idss.vulsync.entity.vo.BaseResponse; | |
12 | +import com.idss.vulsync.entity.vo.SyncParamConsultRequestData; | |
13 | +import com.idss.vulsync.entity.vo.SyncParamConsultResponseData; | |
14 | +import com.idss.vulsync.mvc.service.ConsultVulmanageSyncService; | |
15 | +import com.idss.vulsync.utils.AuthUtils; | |
16 | +import lombok.extern.slf4j.Slf4j; | |
17 | +import org.springframework.beans.factory.annotation.Autowired; | |
18 | +import org.springframework.stereotype.Controller; | |
19 | +import org.springframework.web.bind.annotation.GetMapping; | |
20 | +import org.springframework.web.bind.annotation.PostMapping; | |
21 | +import org.springframework.web.bind.annotation.RequestBody; | |
22 | +import org.springframework.web.bind.annotation.RequestMapping; | |
23 | + | |
24 | +import javax.servlet.http.HttpServletRequest; | |
25 | +import java.security.PublicKey; | |
26 | +import java.util.Base64; | |
27 | +import java.util.LinkedHashMap; | |
28 | + | |
29 | +/** | |
30 | + * @Author: zc | |
31 | + * @Date: 2024/7/17 13:31 | |
32 | + */ | |
33 | +@Slf4j | |
34 | +@Controller | |
35 | +@RequestMapping("/api/v1/") | |
36 | +public class SyncController { | |
37 | + | |
38 | + @Autowired | |
39 | + AuthUtils authUtils; | |
40 | + | |
41 | + @Autowired | |
42 | + ConsultVulmanageSyncService consultVulmanageSyncService; | |
43 | + @Autowired | |
44 | + ObjectMapper objectMapper; | |
45 | + | |
46 | + | |
47 | + @GetMapping("/test") | |
48 | + public RETURN aaa() { | |
49 | + log.info("接收到请求test"); | |
50 | + | |
51 | + PublicKey publicKey = authUtils.getPublicKey(); | |
52 | + AgileReturn.add("test"); | |
53 | + return RETURN.SUCCESS; | |
54 | +// return AgileReturn.build(); | |
55 | + | |
56 | + } | |
57 | + | |
58 | + public static void main(String[] args) { | |
59 | + String a="QWEuMUQwUkQ5TzI2"; | |
60 | + String s = new String(Base64.getDecoder().decode(a.getBytes())); | |
61 | + System.out.println(s); | |
62 | + } | |
63 | + | |
64 | + /** | |
65 | + * 资管侧提供服务 | |
66 | + */ | |
67 | + @PostMapping("/assetSvc") | |
68 | + public RETURN assetSvc(@RequestBody BaseRequest object, HttpServletRequest httpServletRequest) { | |
69 | + | |
70 | + BaseResponse baseResponse = new BaseResponse(); | |
71 | +// boolean validAuth = authUtils.valid(httpServletRequest); | |
72 | +// if (!validAuth) { | |
73 | +// baseResponse.setStatusText("认证失败"); | |
74 | +// baseResponse.setStatusCode(2); | |
75 | +// AgileReturn.add(Constant.ResponseAbout.RESULT, baseResponse); | |
76 | +// return RETURN.SUCCESS; | |
77 | +// } | |
78 | + | |
79 | + | |
80 | + try { | |
81 | + String json = objectMapper.writeValueAsString(object); | |
82 | + log.info("接收到请求{}", json); | |
83 | + | |
84 | + objectMapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, false); | |
85 | + LinkedHashMap<String, Object> requestMap = objectMapper.readValue(json, TypeFactory.defaultInstance().constructMapType(LinkedHashMap.class, String.class, Object.class)); | |
86 | + | |
87 | + String msgID = requestMap.get("msgID").toString(); | |
88 | + Integer msgType = Integer.parseInt(requestMap.get("msgType").toString()); | |
89 | + String reqMsgCnt = requestMap.get("ReqMsgCnt").toString(); | |
90 | + String sign = requestMap.get("Sign").toString(); | |
91 | + | |
92 | + | |
93 | + requestMap.remove("Timestamp"); | |
94 | + requestMap.remove("Sign"); | |
95 | + | |
96 | + if (msgType.equals(1)) { | |
97 | + //资产同步协商 | |
98 | + SyncParamConsultRequestData syncParamConsultRequestData = objectMapper.readValue(reqMsgCnt, SyncParamConsultRequestData.class); | |
99 | + String s = objectMapper.writeValueAsString(syncParamConsultRequestData); | |
100 | + syncParamConsultRequestData=objectMapper.readValue(s, SyncParamConsultRequestData.class); | |
101 | + requestMap.put("ReqMsgCnt", syncParamConsultRequestData); | |
102 | + } else if (msgType.equals(2)) { | |
103 | + //资产ID查询 | |
104 | + } | |
105 | +// String signJson = objectMapper.writeValueAsString(requestMap); | |
106 | +// String validSign = authUtils.generateSHA1Sign(signJson); | |
107 | +// if (!validSign.equals(sign)) { | |
108 | +// log.info("本次请求数据的签名值服务端为{}", validSign); | |
109 | +// baseResponse.setStatusText("sign签名不一致"); | |
110 | +// baseResponse.setStatusCode(2); | |
111 | +// AgileReturn.add(Constant.ResponseAbout.RESULT, baseResponse); | |
112 | +// return RETURN.SUCCESS; | |
113 | +// } | |
114 | + | |
115 | + Object rspObj=new Object(); | |
116 | + | |
117 | + if (msgType.equals(1)) { | |
118 | + //资产同步协商 | |
119 | + SyncParamConsultRequestData syncParamConsultRequestData = objectMapper.readValue(reqMsgCnt, SyncParamConsultRequestData.class); | |
120 | + consultVulmanageSyncService.consultVulmanage(syncParamConsultRequestData); | |
121 | + SyncParamConsultResponseData responseData=new SyncParamConsultResponseData(); | |
122 | + responseData.setInitDelay(syncParamConsultRequestData.getInitDelay()); | |
123 | + responseData.setUpdCycle(syncParamConsultRequestData.getUpdCycle()); | |
124 | + rspObj=responseData; | |
125 | + } else if (msgType.equals(2)) { | |
126 | + //资产ID查询 | |
127 | + } | |
128 | + | |
129 | + baseResponse.setMsgID(msgID); | |
130 | + baseResponse.setMsgType(msgType); | |
131 | + baseResponse.setStatusCode(0); | |
132 | + baseResponse.setStatusText("success"); | |
133 | + baseResponse.setTimestamp(DateUtil.currentSeconds() + ""); | |
134 | + baseResponse.setRspMsgCnt(rspObj); | |
135 | + | |
136 | + LinkedHashMap<String,Object> responseSignMap=new LinkedHashMap<>(); | |
137 | + responseSignMap.put("msgID",baseResponse.getMsgID()); | |
138 | + responseSignMap.put("msgType",baseResponse.getMsgType()); | |
139 | + responseSignMap.put("statusCode",baseResponse.getStatusCode()); | |
140 | + responseSignMap.put("statusText",baseResponse.getStatusText()); | |
141 | + responseSignMap.put("RspMsgCnt",rspObj); | |
142 | + | |
143 | +// String returnSign = authUtils.generateSHA1Sign(objectMapper.writeValueAsString(responseSignMap)); | |
144 | +// String returnSign = ""; | |
145 | +// log.info("本次请求返回数据的签名值为{}", returnSign); | |
146 | +// baseResponse.setSign(returnSign); | |
147 | + | |
148 | + AgileReturn.add(Constant.ResponseAbout.RESULT, baseResponse); | |
149 | + return RETURN.SUCCESS; | |
150 | + } catch (Exception e) { | |
151 | + log.error("参数解析失败,", e); | |
152 | + } | |
153 | + baseResponse.setStatusText("参数解析失败"); | |
154 | + baseResponse.setStatusCode(2); | |
155 | + AgileReturn.add(Constant.ResponseAbout.RESULT, baseResponse); | |
156 | + return RETURN.SUCCESS; | |
157 | + } | |
158 | + | |
159 | + | |
160 | +} | ... | ... |
1 | +package com.idss.vulsync.mvc.mapper; | |
2 | + | |
3 | +import com.idss.vulsync.mvc.pojo.db.ConsultVulmanageSyncEntity; | |
4 | +import com.idss.vulsync.mvc.pojo.db.ConsultVulmanageSyncEntityExample; | |
5 | +import org.apache.ibatis.annotations.Param; | |
6 | + | |
7 | +import java.util.List; | |
8 | + | |
9 | +public interface ConsultVulmanageSyncEntityMapper { | |
10 | + int countByExample(ConsultVulmanageSyncEntityExample example); | |
11 | + | |
12 | + int deleteByExample(ConsultVulmanageSyncEntityExample example); | |
13 | + | |
14 | + int deleteByPrimaryKey(String id); | |
15 | + | |
16 | + int insert(ConsultVulmanageSyncEntity record); | |
17 | + | |
18 | + int insertSelective(ConsultVulmanageSyncEntity record); | |
19 | + | |
20 | + List<ConsultVulmanageSyncEntity> selectByExample(ConsultVulmanageSyncEntityExample example); | |
21 | + | |
22 | + ConsultVulmanageSyncEntity selectByPrimaryKey(String id); | |
23 | + | |
24 | + int updateByExampleSelective(@Param("record") ConsultVulmanageSyncEntity record, @Param("example") ConsultVulmanageSyncEntityExample example); | |
25 | + | |
26 | + int updateByExample(@Param("record") ConsultVulmanageSyncEntity record, @Param("example") ConsultVulmanageSyncEntityExample example); | |
27 | + | |
28 | + int updateByPrimaryKeySelective(ConsultVulmanageSyncEntity record); | |
29 | + | |
30 | + int updateByPrimaryKey(ConsultVulmanageSyncEntity record); | |
31 | +} | ... | ... |
1 | +package com.idss.vulsync.mvc.pojo.db; | |
2 | + | |
3 | +import java.util.Date; | |
4 | + | |
5 | +public class ConsultVulmanageSyncEntity { | |
6 | + private String id; | |
7 | + | |
8 | + private String transId; | |
9 | + | |
10 | + private String filePath; | |
11 | + | |
12 | + private String user; | |
13 | + | |
14 | + private String creditType; | |
15 | + | |
16 | + private String credit; | |
17 | + | |
18 | + private String pubKey; | |
19 | + | |
20 | + private String initDelay; | |
21 | + | |
22 | + private String updCycle; | |
23 | + | |
24 | + private String initFilePath; | |
25 | + | |
26 | + private String latestFilePath; | |
27 | + | |
28 | + private String latestEsId; | |
29 | + | |
30 | + private Date latestUploadTime; | |
31 | + | |
32 | + private Date createTime; | |
33 | + | |
34 | + public String getId() { | |
35 | + return id; | |
36 | + } | |
37 | + | |
38 | + public void setId(String id) { | |
39 | + this.id = id == null ? null : id.trim(); | |
40 | + } | |
41 | + | |
42 | + public String getTransId() { | |
43 | + return transId; | |
44 | + } | |
45 | + | |
46 | + public void setTransId(String transId) { | |
47 | + this.transId = transId == null ? null : transId.trim(); | |
48 | + } | |
49 | + | |
50 | + public String getFilePath() { | |
51 | + return filePath; | |
52 | + } | |
53 | + | |
54 | + public void setFilePath(String filePath) { | |
55 | + this.filePath = filePath == null ? null : filePath.trim(); | |
56 | + } | |
57 | + | |
58 | + public String getUser() { | |
59 | + return user; | |
60 | + } | |
61 | + | |
62 | + public void setUser(String user) { | |
63 | + this.user = user == null ? null : user.trim(); | |
64 | + } | |
65 | + | |
66 | + public String getCreditType() { | |
67 | + return creditType; | |
68 | + } | |
69 | + | |
70 | + public void setCreditType(String creditType) { | |
71 | + this.creditType = creditType == null ? null : creditType.trim(); | |
72 | + } | |
73 | + | |
74 | + public String getCredit() { | |
75 | + return credit; | |
76 | + } | |
77 | + | |
78 | + public void setCredit(String credit) { | |
79 | + this.credit = credit == null ? null : credit.trim(); | |
80 | + } | |
81 | + | |
82 | + public String getPubKey() { | |
83 | + return pubKey; | |
84 | + } | |
85 | + | |
86 | + public void setPubKey(String pubKey) { | |
87 | + this.pubKey = pubKey == null ? null : pubKey.trim(); | |
88 | + } | |
89 | + | |
90 | + public String getInitDelay() { | |
91 | + return initDelay; | |
92 | + } | |
93 | + | |
94 | + public void setInitDelay(String initDelay) { | |
95 | + this.initDelay = initDelay == null ? null : initDelay.trim(); | |
96 | + } | |
97 | + | |
98 | + public String getUpdCycle() { | |
99 | + return updCycle; | |
100 | + } | |
101 | + | |
102 | + public void setUpdCycle(String updCycle) { | |
103 | + this.updCycle = updCycle == null ? null : updCycle.trim(); | |
104 | + } | |
105 | + | |
106 | + public String getInitFilePath() { | |
107 | + return initFilePath; | |
108 | + } | |
109 | + | |
110 | + public void setInitFilePath(String initFilePath) { | |
111 | + this.initFilePath = initFilePath == null ? null : initFilePath.trim(); | |
112 | + } | |
113 | + | |
114 | + public String getLatestFilePath() { | |
115 | + return latestFilePath; | |
116 | + } | |
117 | + | |
118 | + public void setLatestFilePath(String latestFilePath) { | |
119 | + this.latestFilePath = latestFilePath == null ? null : latestFilePath.trim(); | |
120 | + } | |
121 | + | |
122 | + public String getLatestEsId() { | |
123 | + return latestEsId; | |
124 | + } | |
125 | + | |
126 | + public void setLatestEsId(String latestEsId) { | |
127 | + this.latestEsId = latestEsId == null ? null : latestEsId.trim(); | |
128 | + } | |
129 | + | |
130 | + public Date getLatestUploadTime() { | |
131 | + return latestUploadTime; | |
132 | + } | |
133 | + | |
134 | + public void setLatestUploadTime(Date latestUploadTime) { | |
135 | + this.latestUploadTime = latestUploadTime; | |
136 | + } | |
137 | + | |
138 | + public Date getCreateTime() { | |
139 | + return createTime; | |
140 | + } | |
141 | + | |
142 | + public void setCreateTime(Date createTime) { | |
143 | + this.createTime = createTime; | |
144 | + } | |
145 | +} | ... | ... |
1 | +package com.idss.vulsync.mvc.pojo.db; | |
2 | + | |
3 | +import java.util.ArrayList; | |
4 | +import java.util.Date; | |
5 | +import java.util.List; | |
6 | + | |
7 | +public class ConsultVulmanageSyncEntityExample { | |
8 | + protected String orderByClause; | |
9 | + | |
10 | + protected boolean distinct; | |
11 | + | |
12 | + protected List<Criteria> oredCriteria; | |
13 | + | |
14 | + public ConsultVulmanageSyncEntityExample() { | |
15 | + oredCriteria = new ArrayList<Criteria>(); | |
16 | + } | |
17 | + | |
18 | + public void setOrderByClause(String orderByClause) { | |
19 | + this.orderByClause = orderByClause; | |
20 | + } | |
21 | + | |
22 | + public String getOrderByClause() { | |
23 | + return orderByClause; | |
24 | + } | |
25 | + | |
26 | + public void setDistinct(boolean distinct) { | |
27 | + this.distinct = distinct; | |
28 | + } | |
29 | + | |
30 | + public boolean isDistinct() { | |
31 | + return distinct; | |
32 | + } | |
33 | + | |
34 | + public List<Criteria> getOredCriteria() { | |
35 | + return oredCriteria; | |
36 | + } | |
37 | + | |
38 | + public void or(Criteria criteria) { | |
39 | + oredCriteria.add(criteria); | |
40 | + } | |
41 | + | |
42 | + public Criteria or() { | |
43 | + Criteria criteria = createCriteriaInternal(); | |
44 | + oredCriteria.add(criteria); | |
45 | + return criteria; | |
46 | + } | |
47 | + | |
48 | + public Criteria createCriteria() { | |
49 | + Criteria criteria = createCriteriaInternal(); | |
50 | + if (oredCriteria.size() == 0) { | |
51 | + oredCriteria.add(criteria); | |
52 | + } | |
53 | + return criteria; | |
54 | + } | |
55 | + | |
56 | + protected Criteria createCriteriaInternal() { | |
57 | + Criteria criteria = new Criteria(); | |
58 | + return criteria; | |
59 | + } | |
60 | + | |
61 | + public void clear() { | |
62 | + oredCriteria.clear(); | |
63 | + orderByClause = null; | |
64 | + distinct = false; | |
65 | + } | |
66 | + | |
67 | + protected abstract static class GeneratedCriteria { | |
68 | + protected List<Criterion> criteria; | |
69 | + | |
70 | + protected GeneratedCriteria() { | |
71 | + super(); | |
72 | + criteria = new ArrayList<Criterion>(); | |
73 | + } | |
74 | + | |
75 | + public boolean isValid() { | |
76 | + return criteria.size() > 0; | |
77 | + } | |
78 | + | |
79 | + public List<Criterion> getAllCriteria() { | |
80 | + return criteria; | |
81 | + } | |
82 | + | |
83 | + public List<Criterion> getCriteria() { | |
84 | + return criteria; | |
85 | + } | |
86 | + | |
87 | + protected void addCriterion(String condition) { | |
88 | + if (condition == null) { | |
89 | + throw new RuntimeException("Value for condition cannot be null"); | |
90 | + } | |
91 | + criteria.add(new Criterion(condition)); | |
92 | + } | |
93 | + | |
94 | + protected void addCriterion(String condition, Object value, String property) { | |
95 | + if (value == null) { | |
96 | + throw new RuntimeException("Value for " + property + " cannot be null"); | |
97 | + } | |
98 | + criteria.add(new Criterion(condition, value)); | |
99 | + } | |
100 | + | |
101 | + protected void addCriterion(String condition, Object value1, Object value2, String property) { | |
102 | + if (value1 == null || value2 == null) { | |
103 | + throw new RuntimeException("Between values for " + property + " cannot be null"); | |
104 | + } | |
105 | + criteria.add(new Criterion(condition, value1, value2)); | |
106 | + } | |
107 | + | |
108 | + public Criteria andIdIsNull() { | |
109 | + addCriterion("id is null"); | |
110 | + return (Criteria) this; | |
111 | + } | |
112 | + | |
113 | + public Criteria andIdIsNotNull() { | |
114 | + addCriterion("id is not null"); | |
115 | + return (Criteria) this; | |
116 | + } | |
117 | + | |
118 | + public Criteria andIdEqualTo(String value) { | |
119 | + addCriterion("id =", value, "id"); | |
120 | + return (Criteria) this; | |
121 | + } | |
122 | + | |
123 | + public Criteria andIdNotEqualTo(String value) { | |
124 | + addCriterion("id <>", value, "id"); | |
125 | + return (Criteria) this; | |
126 | + } | |
127 | + | |
128 | + public Criteria andIdGreaterThan(String value) { | |
129 | + addCriterion("id >", value, "id"); | |
130 | + return (Criteria) this; | |
131 | + } | |
132 | + | |
133 | + public Criteria andIdGreaterThanOrEqualTo(String value) { | |
134 | + addCriterion("id >=", value, "id"); | |
135 | + return (Criteria) this; | |
136 | + } | |
137 | + | |
138 | + public Criteria andIdLessThan(String value) { | |
139 | + addCriterion("id <", value, "id"); | |
140 | + return (Criteria) this; | |
141 | + } | |
142 | + | |
143 | + public Criteria andIdLessThanOrEqualTo(String value) { | |
144 | + addCriterion("id <=", value, "id"); | |
145 | + return (Criteria) this; | |
146 | + } | |
147 | + | |
148 | + public Criteria andIdLike(String value) { | |
149 | + addCriterion("id like", value, "id"); | |
150 | + return (Criteria) this; | |
151 | + } | |
152 | + | |
153 | + public Criteria andIdNotLike(String value) { | |
154 | + addCriterion("id not like", value, "id"); | |
155 | + return (Criteria) this; | |
156 | + } | |
157 | + | |
158 | + public Criteria andIdIn(List<String> values) { | |
159 | + addCriterion("id in", values, "id"); | |
160 | + return (Criteria) this; | |
161 | + } | |
162 | + | |
163 | + public Criteria andIdNotIn(List<String> values) { | |
164 | + addCriterion("id not in", values, "id"); | |
165 | + return (Criteria) this; | |
166 | + } | |
167 | + | |
168 | + public Criteria andIdBetween(String value1, String value2) { | |
169 | + addCriterion("id between", value1, value2, "id"); | |
170 | + return (Criteria) this; | |
171 | + } | |
172 | + | |
173 | + public Criteria andIdNotBetween(String value1, String value2) { | |
174 | + addCriterion("id not between", value1, value2, "id"); | |
175 | + return (Criteria) this; | |
176 | + } | |
177 | + | |
178 | + public Criteria andTransIdIsNull() { | |
179 | + addCriterion("trans_id is null"); | |
180 | + return (Criteria) this; | |
181 | + } | |
182 | + | |
183 | + public Criteria andTransIdIsNotNull() { | |
184 | + addCriterion("trans_id is not null"); | |
185 | + return (Criteria) this; | |
186 | + } | |
187 | + | |
188 | + public Criteria andTransIdEqualTo(String value) { | |
189 | + addCriterion("trans_id =", value, "transId"); | |
190 | + return (Criteria) this; | |
191 | + } | |
192 | + | |
193 | + public Criteria andTransIdNotEqualTo(String value) { | |
194 | + addCriterion("trans_id <>", value, "transId"); | |
195 | + return (Criteria) this; | |
196 | + } | |
197 | + | |
198 | + public Criteria andTransIdGreaterThan(String value) { | |
199 | + addCriterion("trans_id >", value, "transId"); | |
200 | + return (Criteria) this; | |
201 | + } | |
202 | + | |
203 | + public Criteria andTransIdGreaterThanOrEqualTo(String value) { | |
204 | + addCriterion("trans_id >=", value, "transId"); | |
205 | + return (Criteria) this; | |
206 | + } | |
207 | + | |
208 | + public Criteria andTransIdLessThan(String value) { | |
209 | + addCriterion("trans_id <", value, "transId"); | |
210 | + return (Criteria) this; | |
211 | + } | |
212 | + | |
213 | + public Criteria andTransIdLessThanOrEqualTo(String value) { | |
214 | + addCriterion("trans_id <=", value, "transId"); | |
215 | + return (Criteria) this; | |
216 | + } | |
217 | + | |
218 | + public Criteria andTransIdLike(String value) { | |
219 | + addCriterion("trans_id like", value, "transId"); | |
220 | + return (Criteria) this; | |
221 | + } | |
222 | + | |
223 | + public Criteria andTransIdNotLike(String value) { | |
224 | + addCriterion("trans_id not like", value, "transId"); | |
225 | + return (Criteria) this; | |
226 | + } | |
227 | + | |
228 | + public Criteria andTransIdIn(List<String> values) { | |
229 | + addCriterion("trans_id in", values, "transId"); | |
230 | + return (Criteria) this; | |
231 | + } | |
232 | + | |
233 | + public Criteria andTransIdNotIn(List<String> values) { | |
234 | + addCriterion("trans_id not in", values, "transId"); | |
235 | + return (Criteria) this; | |
236 | + } | |
237 | + | |
238 | + public Criteria andTransIdBetween(String value1, String value2) { | |
239 | + addCriterion("trans_id between", value1, value2, "transId"); | |
240 | + return (Criteria) this; | |
241 | + } | |
242 | + | |
243 | + public Criteria andTransIdNotBetween(String value1, String value2) { | |
244 | + addCriterion("trans_id not between", value1, value2, "transId"); | |
245 | + return (Criteria) this; | |
246 | + } | |
247 | + | |
248 | + public Criteria andFilePathIsNull() { | |
249 | + addCriterion("file_path is null"); | |
250 | + return (Criteria) this; | |
251 | + } | |
252 | + | |
253 | + public Criteria andFilePathIsNotNull() { | |
254 | + addCriterion("file_path is not null"); | |
255 | + return (Criteria) this; | |
256 | + } | |
257 | + | |
258 | + public Criteria andFilePathEqualTo(String value) { | |
259 | + addCriterion("file_path =", value, "filePath"); | |
260 | + return (Criteria) this; | |
261 | + } | |
262 | + | |
263 | + public Criteria andFilePathNotEqualTo(String value) { | |
264 | + addCriterion("file_path <>", value, "filePath"); | |
265 | + return (Criteria) this; | |
266 | + } | |
267 | + | |
268 | + public Criteria andFilePathGreaterThan(String value) { | |
269 | + addCriterion("file_path >", value, "filePath"); | |
270 | + return (Criteria) this; | |
271 | + } | |
272 | + | |
273 | + public Criteria andFilePathGreaterThanOrEqualTo(String value) { | |
274 | + addCriterion("file_path >=", value, "filePath"); | |
275 | + return (Criteria) this; | |
276 | + } | |
277 | + | |
278 | + public Criteria andFilePathLessThan(String value) { | |
279 | + addCriterion("file_path <", value, "filePath"); | |
280 | + return (Criteria) this; | |
281 | + } | |
282 | + | |
283 | + public Criteria andFilePathLessThanOrEqualTo(String value) { | |
284 | + addCriterion("file_path <=", value, "filePath"); | |
285 | + return (Criteria) this; | |
286 | + } | |
287 | + | |
288 | + public Criteria andFilePathLike(String value) { | |
289 | + addCriterion("file_path like", value, "filePath"); | |
290 | + return (Criteria) this; | |
291 | + } | |
292 | + | |
293 | + public Criteria andFilePathNotLike(String value) { | |
294 | + addCriterion("file_path not like", value, "filePath"); | |
295 | + return (Criteria) this; | |
296 | + } | |
297 | + | |
298 | + public Criteria andFilePathIn(List<String> values) { | |
299 | + addCriterion("file_path in", values, "filePath"); | |
300 | + return (Criteria) this; | |
301 | + } | |
302 | + | |
303 | + public Criteria andFilePathNotIn(List<String> values) { | |
304 | + addCriterion("file_path not in", values, "filePath"); | |
305 | + return (Criteria) this; | |
306 | + } | |
307 | + | |
308 | + public Criteria andFilePathBetween(String value1, String value2) { | |
309 | + addCriterion("file_path between", value1, value2, "filePath"); | |
310 | + return (Criteria) this; | |
311 | + } | |
312 | + | |
313 | + public Criteria andFilePathNotBetween(String value1, String value2) { | |
314 | + addCriterion("file_path not between", value1, value2, "filePath"); | |
315 | + return (Criteria) this; | |
316 | + } | |
317 | + | |
318 | + public Criteria andUserIsNull() { | |
319 | + addCriterion("user is null"); | |
320 | + return (Criteria) this; | |
321 | + } | |
322 | + | |
323 | + public Criteria andUserIsNotNull() { | |
324 | + addCriterion("user is not null"); | |
325 | + return (Criteria) this; | |
326 | + } | |
327 | + | |
328 | + public Criteria andUserEqualTo(String value) { | |
329 | + addCriterion("user =", value, "user"); | |
330 | + return (Criteria) this; | |
331 | + } | |
332 | + | |
333 | + public Criteria andUserNotEqualTo(String value) { | |
334 | + addCriterion("user <>", value, "user"); | |
335 | + return (Criteria) this; | |
336 | + } | |
337 | + | |
338 | + public Criteria andUserGreaterThan(String value) { | |
339 | + addCriterion("user >", value, "user"); | |
340 | + return (Criteria) this; | |
341 | + } | |
342 | + | |
343 | + public Criteria andUserGreaterThanOrEqualTo(String value) { | |
344 | + addCriterion("user >=", value, "user"); | |
345 | + return (Criteria) this; | |
346 | + } | |
347 | + | |
348 | + public Criteria andUserLessThan(String value) { | |
349 | + addCriterion("user <", value, "user"); | |
350 | + return (Criteria) this; | |
351 | + } | |
352 | + | |
353 | + public Criteria andUserLessThanOrEqualTo(String value) { | |
354 | + addCriterion("user <=", value, "user"); | |
355 | + return (Criteria) this; | |
356 | + } | |
357 | + | |
358 | + public Criteria andUserLike(String value) { | |
359 | + addCriterion("user like", value, "user"); | |
360 | + return (Criteria) this; | |
361 | + } | |
362 | + | |
363 | + public Criteria andUserNotLike(String value) { | |
364 | + addCriterion("user not like", value, "user"); | |
365 | + return (Criteria) this; | |
366 | + } | |
367 | + | |
368 | + public Criteria andUserIn(List<String> values) { | |
369 | + addCriterion("user in", values, "user"); | |
370 | + return (Criteria) this; | |
371 | + } | |
372 | + | |
373 | + public Criteria andUserNotIn(List<String> values) { | |
374 | + addCriterion("user not in", values, "user"); | |
375 | + return (Criteria) this; | |
376 | + } | |
377 | + | |
378 | + public Criteria andUserBetween(String value1, String value2) { | |
379 | + addCriterion("user between", value1, value2, "user"); | |
380 | + return (Criteria) this; | |
381 | + } | |
382 | + | |
383 | + public Criteria andUserNotBetween(String value1, String value2) { | |
384 | + addCriterion("user not between", value1, value2, "user"); | |
385 | + return (Criteria) this; | |
386 | + } | |
387 | + | |
388 | + public Criteria andCreditTypeIsNull() { | |
389 | + addCriterion("credit_type is null"); | |
390 | + return (Criteria) this; | |
391 | + } | |
392 | + | |
393 | + public Criteria andCreditTypeIsNotNull() { | |
394 | + addCriterion("credit_type is not null"); | |
395 | + return (Criteria) this; | |
396 | + } | |
397 | + | |
398 | + public Criteria andCreditTypeEqualTo(String value) { | |
399 | + addCriterion("credit_type =", value, "creditType"); | |
400 | + return (Criteria) this; | |
401 | + } | |
402 | + | |
403 | + public Criteria andCreditTypeNotEqualTo(String value) { | |
404 | + addCriterion("credit_type <>", value, "creditType"); | |
405 | + return (Criteria) this; | |
406 | + } | |
407 | + | |
408 | + public Criteria andCreditTypeGreaterThan(String value) { | |
409 | + addCriterion("credit_type >", value, "creditType"); | |
410 | + return (Criteria) this; | |
411 | + } | |
412 | + | |
413 | + public Criteria andCreditTypeGreaterThanOrEqualTo(String value) { | |
414 | + addCriterion("credit_type >=", value, "creditType"); | |
415 | + return (Criteria) this; | |
416 | + } | |
417 | + | |
418 | + public Criteria andCreditTypeLessThan(String value) { | |
419 | + addCriterion("credit_type <", value, "creditType"); | |
420 | + return (Criteria) this; | |
421 | + } | |
422 | + | |
423 | + public Criteria andCreditTypeLessThanOrEqualTo(String value) { | |
424 | + addCriterion("credit_type <=", value, "creditType"); | |
425 | + return (Criteria) this; | |
426 | + } | |
427 | + | |
428 | + public Criteria andCreditTypeLike(String value) { | |
429 | + addCriterion("credit_type like", value, "creditType"); | |
430 | + return (Criteria) this; | |
431 | + } | |
432 | + | |
433 | + public Criteria andCreditTypeNotLike(String value) { | |
434 | + addCriterion("credit_type not like", value, "creditType"); | |
435 | + return (Criteria) this; | |
436 | + } | |
437 | + | |
438 | + public Criteria andCreditTypeIn(List<String> values) { | |
439 | + addCriterion("credit_type in", values, "creditType"); | |
440 | + return (Criteria) this; | |
441 | + } | |
442 | + | |
443 | + public Criteria andCreditTypeNotIn(List<String> values) { | |
444 | + addCriterion("credit_type not in", values, "creditType"); | |
445 | + return (Criteria) this; | |
446 | + } | |
447 | + | |
448 | + public Criteria andCreditTypeBetween(String value1, String value2) { | |
449 | + addCriterion("credit_type between", value1, value2, "creditType"); | |
450 | + return (Criteria) this; | |
451 | + } | |
452 | + | |
453 | + public Criteria andCreditTypeNotBetween(String value1, String value2) { | |
454 | + addCriterion("credit_type not between", value1, value2, "creditType"); | |
455 | + return (Criteria) this; | |
456 | + } | |
457 | + | |
458 | + public Criteria andCreditIsNull() { | |
459 | + addCriterion("credit is null"); | |
460 | + return (Criteria) this; | |
461 | + } | |
462 | + | |
463 | + public Criteria andCreditIsNotNull() { | |
464 | + addCriterion("credit is not null"); | |
465 | + return (Criteria) this; | |
466 | + } | |
467 | + | |
468 | + public Criteria andCreditEqualTo(String value) { | |
469 | + addCriterion("credit =", value, "credit"); | |
470 | + return (Criteria) this; | |
471 | + } | |
472 | + | |
473 | + public Criteria andCreditNotEqualTo(String value) { | |
474 | + addCriterion("credit <>", value, "credit"); | |
475 | + return (Criteria) this; | |
476 | + } | |
477 | + | |
478 | + public Criteria andCreditGreaterThan(String value) { | |
479 | + addCriterion("credit >", value, "credit"); | |
480 | + return (Criteria) this; | |
481 | + } | |
482 | + | |
483 | + public Criteria andCreditGreaterThanOrEqualTo(String value) { | |
484 | + addCriterion("credit >=", value, "credit"); | |
485 | + return (Criteria) this; | |
486 | + } | |
487 | + | |
488 | + public Criteria andCreditLessThan(String value) { | |
489 | + addCriterion("credit <", value, "credit"); | |
490 | + return (Criteria) this; | |
491 | + } | |
492 | + | |
493 | + public Criteria andCreditLessThanOrEqualTo(String value) { | |
494 | + addCriterion("credit <=", value, "credit"); | |
495 | + return (Criteria) this; | |
496 | + } | |
497 | + | |
498 | + public Criteria andCreditLike(String value) { | |
499 | + addCriterion("credit like", value, "credit"); | |
500 | + return (Criteria) this; | |
501 | + } | |
502 | + | |
503 | + public Criteria andCreditNotLike(String value) { | |
504 | + addCriterion("credit not like", value, "credit"); | |
505 | + return (Criteria) this; | |
506 | + } | |
507 | + | |
508 | + public Criteria andCreditIn(List<String> values) { | |
509 | + addCriterion("credit in", values, "credit"); | |
510 | + return (Criteria) this; | |
511 | + } | |
512 | + | |
513 | + public Criteria andCreditNotIn(List<String> values) { | |
514 | + addCriterion("credit not in", values, "credit"); | |
515 | + return (Criteria) this; | |
516 | + } | |
517 | + | |
518 | + public Criteria andCreditBetween(String value1, String value2) { | |
519 | + addCriterion("credit between", value1, value2, "credit"); | |
520 | + return (Criteria) this; | |
521 | + } | |
522 | + | |
523 | + public Criteria andCreditNotBetween(String value1, String value2) { | |
524 | + addCriterion("credit not between", value1, value2, "credit"); | |
525 | + return (Criteria) this; | |
526 | + } | |
527 | + | |
528 | + public Criteria andPubKeyIsNull() { | |
529 | + addCriterion("pub_key is null"); | |
530 | + return (Criteria) this; | |
531 | + } | |
532 | + | |
533 | + public Criteria andPubKeyIsNotNull() { | |
534 | + addCriterion("pub_key is not null"); | |
535 | + return (Criteria) this; | |
536 | + } | |
537 | + | |
538 | + public Criteria andPubKeyEqualTo(String value) { | |
539 | + addCriterion("pub_key =", value, "pubKey"); | |
540 | + return (Criteria) this; | |
541 | + } | |
542 | + | |
543 | + public Criteria andPubKeyNotEqualTo(String value) { | |
544 | + addCriterion("pub_key <>", value, "pubKey"); | |
545 | + return (Criteria) this; | |
546 | + } | |
547 | + | |
548 | + public Criteria andPubKeyGreaterThan(String value) { | |
549 | + addCriterion("pub_key >", value, "pubKey"); | |
550 | + return (Criteria) this; | |
551 | + } | |
552 | + | |
553 | + public Criteria andPubKeyGreaterThanOrEqualTo(String value) { | |
554 | + addCriterion("pub_key >=", value, "pubKey"); | |
555 | + return (Criteria) this; | |
556 | + } | |
557 | + | |
558 | + public Criteria andPubKeyLessThan(String value) { | |
559 | + addCriterion("pub_key <", value, "pubKey"); | |
560 | + return (Criteria) this; | |
561 | + } | |
562 | + | |
563 | + public Criteria andPubKeyLessThanOrEqualTo(String value) { | |
564 | + addCriterion("pub_key <=", value, "pubKey"); | |
565 | + return (Criteria) this; | |
566 | + } | |
567 | + | |
568 | + public Criteria andPubKeyLike(String value) { | |
569 | + addCriterion("pub_key like", value, "pubKey"); | |
570 | + return (Criteria) this; | |
571 | + } | |
572 | + | |
573 | + public Criteria andPubKeyNotLike(String value) { | |
574 | + addCriterion("pub_key not like", value, "pubKey"); | |
575 | + return (Criteria) this; | |
576 | + } | |
577 | + | |
578 | + public Criteria andPubKeyIn(List<String> values) { | |
579 | + addCriterion("pub_key in", values, "pubKey"); | |
580 | + return (Criteria) this; | |
581 | + } | |
582 | + | |
583 | + public Criteria andPubKeyNotIn(List<String> values) { | |
584 | + addCriterion("pub_key not in", values, "pubKey"); | |
585 | + return (Criteria) this; | |
586 | + } | |
587 | + | |
588 | + public Criteria andPubKeyBetween(String value1, String value2) { | |
589 | + addCriterion("pub_key between", value1, value2, "pubKey"); | |
590 | + return (Criteria) this; | |
591 | + } | |
592 | + | |
593 | + public Criteria andPubKeyNotBetween(String value1, String value2) { | |
594 | + addCriterion("pub_key not between", value1, value2, "pubKey"); | |
595 | + return (Criteria) this; | |
596 | + } | |
597 | + | |
598 | + public Criteria andInitDelayIsNull() { | |
599 | + addCriterion("init_delay is null"); | |
600 | + return (Criteria) this; | |
601 | + } | |
602 | + | |
603 | + public Criteria andInitDelayIsNotNull() { | |
604 | + addCriterion("init_delay is not null"); | |
605 | + return (Criteria) this; | |
606 | + } | |
607 | + | |
608 | + public Criteria andInitDelayEqualTo(String value) { | |
609 | + addCriterion("init_delay =", value, "initDelay"); | |
610 | + return (Criteria) this; | |
611 | + } | |
612 | + | |
613 | + public Criteria andInitDelayNotEqualTo(String value) { | |
614 | + addCriterion("init_delay <>", value, "initDelay"); | |
615 | + return (Criteria) this; | |
616 | + } | |
617 | + | |
618 | + public Criteria andInitDelayGreaterThan(String value) { | |
619 | + addCriterion("init_delay >", value, "initDelay"); | |
620 | + return (Criteria) this; | |
621 | + } | |
622 | + | |
623 | + public Criteria andInitDelayGreaterThanOrEqualTo(String value) { | |
624 | + addCriterion("init_delay >=", value, "initDelay"); | |
625 | + return (Criteria) this; | |
626 | + } | |
627 | + | |
628 | + public Criteria andInitDelayLessThan(String value) { | |
629 | + addCriterion("init_delay <", value, "initDelay"); | |
630 | + return (Criteria) this; | |
631 | + } | |
632 | + | |
633 | + public Criteria andInitDelayLessThanOrEqualTo(String value) { | |
634 | + addCriterion("init_delay <=", value, "initDelay"); | |
635 | + return (Criteria) this; | |
636 | + } | |
637 | + | |
638 | + public Criteria andInitDelayLike(String value) { | |
639 | + addCriterion("init_delay like", value, "initDelay"); | |
640 | + return (Criteria) this; | |
641 | + } | |
642 | + | |
643 | + public Criteria andInitDelayNotLike(String value) { | |
644 | + addCriterion("init_delay not like", value, "initDelay"); | |
645 | + return (Criteria) this; | |
646 | + } | |
647 | + | |
648 | + public Criteria andInitDelayIn(List<String> values) { | |
649 | + addCriterion("init_delay in", values, "initDelay"); | |
650 | + return (Criteria) this; | |
651 | + } | |
652 | + | |
653 | + public Criteria andInitDelayNotIn(List<String> values) { | |
654 | + addCriterion("init_delay not in", values, "initDelay"); | |
655 | + return (Criteria) this; | |
656 | + } | |
657 | + | |
658 | + public Criteria andInitDelayBetween(String value1, String value2) { | |
659 | + addCriterion("init_delay between", value1, value2, "initDelay"); | |
660 | + return (Criteria) this; | |
661 | + } | |
662 | + | |
663 | + public Criteria andInitDelayNotBetween(String value1, String value2) { | |
664 | + addCriterion("init_delay not between", value1, value2, "initDelay"); | |
665 | + return (Criteria) this; | |
666 | + } | |
667 | + | |
668 | + public Criteria andUpdCycleIsNull() { | |
669 | + addCriterion("upd_cycle is null"); | |
670 | + return (Criteria) this; | |
671 | + } | |
672 | + | |
673 | + public Criteria andUpdCycleIsNotNull() { | |
674 | + addCriterion("upd_cycle is not null"); | |
675 | + return (Criteria) this; | |
676 | + } | |
677 | + | |
678 | + public Criteria andUpdCycleEqualTo(String value) { | |
679 | + addCriterion("upd_cycle =", value, "updCycle"); | |
680 | + return (Criteria) this; | |
681 | + } | |
682 | + | |
683 | + public Criteria andUpdCycleNotEqualTo(String value) { | |
684 | + addCriterion("upd_cycle <>", value, "updCycle"); | |
685 | + return (Criteria) this; | |
686 | + } | |
687 | + | |
688 | + public Criteria andUpdCycleGreaterThan(String value) { | |
689 | + addCriterion("upd_cycle >", value, "updCycle"); | |
690 | + return (Criteria) this; | |
691 | + } | |
692 | + | |
693 | + public Criteria andUpdCycleGreaterThanOrEqualTo(String value) { | |
694 | + addCriterion("upd_cycle >=", value, "updCycle"); | |
695 | + return (Criteria) this; | |
696 | + } | |
697 | + | |
698 | + public Criteria andUpdCycleLessThan(String value) { | |
699 | + addCriterion("upd_cycle <", value, "updCycle"); | |
700 | + return (Criteria) this; | |
701 | + } | |
702 | + | |
703 | + public Criteria andUpdCycleLessThanOrEqualTo(String value) { | |
704 | + addCriterion("upd_cycle <=", value, "updCycle"); | |
705 | + return (Criteria) this; | |
706 | + } | |
707 | + | |
708 | + public Criteria andUpdCycleLike(String value) { | |
709 | + addCriterion("upd_cycle like", value, "updCycle"); | |
710 | + return (Criteria) this; | |
711 | + } | |
712 | + | |
713 | + public Criteria andUpdCycleNotLike(String value) { | |
714 | + addCriterion("upd_cycle not like", value, "updCycle"); | |
715 | + return (Criteria) this; | |
716 | + } | |
717 | + | |
718 | + public Criteria andUpdCycleIn(List<String> values) { | |
719 | + addCriterion("upd_cycle in", values, "updCycle"); | |
720 | + return (Criteria) this; | |
721 | + } | |
722 | + | |
723 | + public Criteria andUpdCycleNotIn(List<String> values) { | |
724 | + addCriterion("upd_cycle not in", values, "updCycle"); | |
725 | + return (Criteria) this; | |
726 | + } | |
727 | + | |
728 | + public Criteria andUpdCycleBetween(String value1, String value2) { | |
729 | + addCriterion("upd_cycle between", value1, value2, "updCycle"); | |
730 | + return (Criteria) this; | |
731 | + } | |
732 | + | |
733 | + public Criteria andUpdCycleNotBetween(String value1, String value2) { | |
734 | + addCriterion("upd_cycle not between", value1, value2, "updCycle"); | |
735 | + return (Criteria) this; | |
736 | + } | |
737 | + | |
738 | + public Criteria andInitFilePathIsNull() { | |
739 | + addCriterion("init_file_path is null"); | |
740 | + return (Criteria) this; | |
741 | + } | |
742 | + | |
743 | + public Criteria andInitFilePathIsNotNull() { | |
744 | + addCriterion("init_file_path is not null"); | |
745 | + return (Criteria) this; | |
746 | + } | |
747 | + | |
748 | + public Criteria andInitFilePathEqualTo(String value) { | |
749 | + addCriterion("init_file_path =", value, "initFilePath"); | |
750 | + return (Criteria) this; | |
751 | + } | |
752 | + | |
753 | + public Criteria andInitFilePathNotEqualTo(String value) { | |
754 | + addCriterion("init_file_path <>", value, "initFilePath"); | |
755 | + return (Criteria) this; | |
756 | + } | |
757 | + | |
758 | + public Criteria andInitFilePathGreaterThan(String value) { | |
759 | + addCriterion("init_file_path >", value, "initFilePath"); | |
760 | + return (Criteria) this; | |
761 | + } | |
762 | + | |
763 | + public Criteria andInitFilePathGreaterThanOrEqualTo(String value) { | |
764 | + addCriterion("init_file_path >=", value, "initFilePath"); | |
765 | + return (Criteria) this; | |
766 | + } | |
767 | + | |
768 | + public Criteria andInitFilePathLessThan(String value) { | |
769 | + addCriterion("init_file_path <", value, "initFilePath"); | |
770 | + return (Criteria) this; | |
771 | + } | |
772 | + | |
773 | + public Criteria andInitFilePathLessThanOrEqualTo(String value) { | |
774 | + addCriterion("init_file_path <=", value, "initFilePath"); | |
775 | + return (Criteria) this; | |
776 | + } | |
777 | + | |
778 | + public Criteria andInitFilePathLike(String value) { | |
779 | + addCriterion("init_file_path like", value, "initFilePath"); | |
780 | + return (Criteria) this; | |
781 | + } | |
782 | + | |
783 | + public Criteria andInitFilePathNotLike(String value) { | |
784 | + addCriterion("init_file_path not like", value, "initFilePath"); | |
785 | + return (Criteria) this; | |
786 | + } | |
787 | + | |
788 | + public Criteria andInitFilePathIn(List<String> values) { | |
789 | + addCriterion("init_file_path in", values, "initFilePath"); | |
790 | + return (Criteria) this; | |
791 | + } | |
792 | + | |
793 | + public Criteria andInitFilePathNotIn(List<String> values) { | |
794 | + addCriterion("init_file_path not in", values, "initFilePath"); | |
795 | + return (Criteria) this; | |
796 | + } | |
797 | + | |
798 | + public Criteria andInitFilePathBetween(String value1, String value2) { | |
799 | + addCriterion("init_file_path between", value1, value2, "initFilePath"); | |
800 | + return (Criteria) this; | |
801 | + } | |
802 | + | |
803 | + public Criteria andInitFilePathNotBetween(String value1, String value2) { | |
804 | + addCriterion("init_file_path not between", value1, value2, "initFilePath"); | |
805 | + return (Criteria) this; | |
806 | + } | |
807 | + | |
808 | + public Criteria andLatestFilePathIsNull() { | |
809 | + addCriterion("latest_file_path is null"); | |
810 | + return (Criteria) this; | |
811 | + } | |
812 | + | |
813 | + public Criteria andLatestFilePathIsNotNull() { | |
814 | + addCriterion("latest_file_path is not null"); | |
815 | + return (Criteria) this; | |
816 | + } | |
817 | + | |
818 | + public Criteria andLatestFilePathEqualTo(String value) { | |
819 | + addCriterion("latest_file_path =", value, "latestFilePath"); | |
820 | + return (Criteria) this; | |
821 | + } | |
822 | + | |
823 | + public Criteria andLatestFilePathNotEqualTo(String value) { | |
824 | + addCriterion("latest_file_path <>", value, "latestFilePath"); | |
825 | + return (Criteria) this; | |
826 | + } | |
827 | + | |
828 | + public Criteria andLatestFilePathGreaterThan(String value) { | |
829 | + addCriterion("latest_file_path >", value, "latestFilePath"); | |
830 | + return (Criteria) this; | |
831 | + } | |
832 | + | |
833 | + public Criteria andLatestFilePathGreaterThanOrEqualTo(String value) { | |
834 | + addCriterion("latest_file_path >=", value, "latestFilePath"); | |
835 | + return (Criteria) this; | |
836 | + } | |
837 | + | |
838 | + public Criteria andLatestFilePathLessThan(String value) { | |
839 | + addCriterion("latest_file_path <", value, "latestFilePath"); | |
840 | + return (Criteria) this; | |
841 | + } | |
842 | + | |
843 | + public Criteria andLatestFilePathLessThanOrEqualTo(String value) { | |
844 | + addCriterion("latest_file_path <=", value, "latestFilePath"); | |
845 | + return (Criteria) this; | |
846 | + } | |
847 | + | |
848 | + public Criteria andLatestFilePathLike(String value) { | |
849 | + addCriterion("latest_file_path like", value, "latestFilePath"); | |
850 | + return (Criteria) this; | |
851 | + } | |
852 | + | |
853 | + public Criteria andLatestFilePathNotLike(String value) { | |
854 | + addCriterion("latest_file_path not like", value, "latestFilePath"); | |
855 | + return (Criteria) this; | |
856 | + } | |
857 | + | |
858 | + public Criteria andLatestFilePathIn(List<String> values) { | |
859 | + addCriterion("latest_file_path in", values, "latestFilePath"); | |
860 | + return (Criteria) this; | |
861 | + } | |
862 | + | |
863 | + public Criteria andLatestFilePathNotIn(List<String> values) { | |
864 | + addCriterion("latest_file_path not in", values, "latestFilePath"); | |
865 | + return (Criteria) this; | |
866 | + } | |
867 | + | |
868 | + public Criteria andLatestFilePathBetween(String value1, String value2) { | |
869 | + addCriterion("latest_file_path between", value1, value2, "latestFilePath"); | |
870 | + return (Criteria) this; | |
871 | + } | |
872 | + | |
873 | + public Criteria andLatestFilePathNotBetween(String value1, String value2) { | |
874 | + addCriterion("latest_file_path not between", value1, value2, "latestFilePath"); | |
875 | + return (Criteria) this; | |
876 | + } | |
877 | + | |
878 | + public Criteria andLatestEsIdIsNull() { | |
879 | + addCriterion("latest_es_id is null"); | |
880 | + return (Criteria) this; | |
881 | + } | |
882 | + | |
883 | + public Criteria andLatestEsIdIsNotNull() { | |
884 | + addCriterion("latest_es_id is not null"); | |
885 | + return (Criteria) this; | |
886 | + } | |
887 | + | |
888 | + public Criteria andLatestEsIdEqualTo(String value) { | |
889 | + addCriterion("latest_es_id =", value, "latestEsId"); | |
890 | + return (Criteria) this; | |
891 | + } | |
892 | + | |
893 | + public Criteria andLatestEsIdNotEqualTo(String value) { | |
894 | + addCriterion("latest_es_id <>", value, "latestEsId"); | |
895 | + return (Criteria) this; | |
896 | + } | |
897 | + | |
898 | + public Criteria andLatestEsIdGreaterThan(String value) { | |
899 | + addCriterion("latest_es_id >", value, "latestEsId"); | |
900 | + return (Criteria) this; | |
901 | + } | |
902 | + | |
903 | + public Criteria andLatestEsIdGreaterThanOrEqualTo(String value) { | |
904 | + addCriterion("latest_es_id >=", value, "latestEsId"); | |
905 | + return (Criteria) this; | |
906 | + } | |
907 | + | |
908 | + public Criteria andLatestEsIdLessThan(String value) { | |
909 | + addCriterion("latest_es_id <", value, "latestEsId"); | |
910 | + return (Criteria) this; | |
911 | + } | |
912 | + | |
913 | + public Criteria andLatestEsIdLessThanOrEqualTo(String value) { | |
914 | + addCriterion("latest_es_id <=", value, "latestEsId"); | |
915 | + return (Criteria) this; | |
916 | + } | |
917 | + | |
918 | + public Criteria andLatestEsIdLike(String value) { | |
919 | + addCriterion("latest_es_id like", value, "latestEsId"); | |
920 | + return (Criteria) this; | |
921 | + } | |
922 | + | |
923 | + public Criteria andLatestEsIdNotLike(String value) { | |
924 | + addCriterion("latest_es_id not like", value, "latestEsId"); | |
925 | + return (Criteria) this; | |
926 | + } | |
927 | + | |
928 | + public Criteria andLatestEsIdIn(List<String> values) { | |
929 | + addCriterion("latest_es_id in", values, "latestEsId"); | |
930 | + return (Criteria) this; | |
931 | + } | |
932 | + | |
933 | + public Criteria andLatestEsIdNotIn(List<String> values) { | |
934 | + addCriterion("latest_es_id not in", values, "latestEsId"); | |
935 | + return (Criteria) this; | |
936 | + } | |
937 | + | |
938 | + public Criteria andLatestEsIdBetween(String value1, String value2) { | |
939 | + addCriterion("latest_es_id between", value1, value2, "latestEsId"); | |
940 | + return (Criteria) this; | |
941 | + } | |
942 | + | |
943 | + public Criteria andLatestEsIdNotBetween(String value1, String value2) { | |
944 | + addCriterion("latest_es_id not between", value1, value2, "latestEsId"); | |
945 | + return (Criteria) this; | |
946 | + } | |
947 | + | |
948 | + public Criteria andLatestUploadTimeIsNull() { | |
949 | + addCriterion("latest_upload_time is null"); | |
950 | + return (Criteria) this; | |
951 | + } | |
952 | + | |
953 | + public Criteria andLatestUploadTimeIsNotNull() { | |
954 | + addCriterion("latest_upload_time is not null"); | |
955 | + return (Criteria) this; | |
956 | + } | |
957 | + | |
958 | + public Criteria andLatestUploadTimeEqualTo(Date value) { | |
959 | + addCriterion("latest_upload_time =", value, "latestUploadTime"); | |
960 | + return (Criteria) this; | |
961 | + } | |
962 | + | |
963 | + public Criteria andLatestUploadTimeNotEqualTo(Date value) { | |
964 | + addCriterion("latest_upload_time <>", value, "latestUploadTime"); | |
965 | + return (Criteria) this; | |
966 | + } | |
967 | + | |
968 | + public Criteria andLatestUploadTimeGreaterThan(Date value) { | |
969 | + addCriterion("latest_upload_time >", value, "latestUploadTime"); | |
970 | + return (Criteria) this; | |
971 | + } | |
972 | + | |
973 | + public Criteria andLatestUploadTimeGreaterThanOrEqualTo(Date value) { | |
974 | + addCriterion("latest_upload_time >=", value, "latestUploadTime"); | |
975 | + return (Criteria) this; | |
976 | + } | |
977 | + | |
978 | + public Criteria andLatestUploadTimeLessThan(Date value) { | |
979 | + addCriterion("latest_upload_time <", value, "latestUploadTime"); | |
980 | + return (Criteria) this; | |
981 | + } | |
982 | + | |
983 | + public Criteria andLatestUploadTimeLessThanOrEqualTo(Date value) { | |
984 | + addCriterion("latest_upload_time <=", value, "latestUploadTime"); | |
985 | + return (Criteria) this; | |
986 | + } | |
987 | + | |
988 | + public Criteria andLatestUploadTimeIn(List<Date> values) { | |
989 | + addCriterion("latest_upload_time in", values, "latestUploadTime"); | |
990 | + return (Criteria) this; | |
991 | + } | |
992 | + | |
993 | + public Criteria andLatestUploadTimeNotIn(List<Date> values) { | |
994 | + addCriterion("latest_upload_time not in", values, "latestUploadTime"); | |
995 | + return (Criteria) this; | |
996 | + } | |
997 | + | |
998 | + public Criteria andLatestUploadTimeBetween(Date value1, Date value2) { | |
999 | + addCriterion("latest_upload_time between", value1, value2, "latestUploadTime"); | |
1000 | + return (Criteria) this; | |
1001 | + } | |
1002 | + | |
1003 | + public Criteria andLatestUploadTimeNotBetween(Date value1, Date value2) { | |
1004 | + addCriterion("latest_upload_time not between", value1, value2, "latestUploadTime"); | |
1005 | + return (Criteria) this; | |
1006 | + } | |
1007 | + | |
1008 | + public Criteria andCreateTimeIsNull() { | |
1009 | + addCriterion("create_time is null"); | |
1010 | + return (Criteria) this; | |
1011 | + } | |
1012 | + | |
1013 | + public Criteria andCreateTimeIsNotNull() { | |
1014 | + addCriterion("create_time is not null"); | |
1015 | + return (Criteria) this; | |
1016 | + } | |
1017 | + | |
1018 | + public Criteria andCreateTimeEqualTo(Date value) { | |
1019 | + addCriterion("create_time =", value, "createTime"); | |
1020 | + return (Criteria) this; | |
1021 | + } | |
1022 | + | |
1023 | + public Criteria andCreateTimeNotEqualTo(Date value) { | |
1024 | + addCriterion("create_time <>", value, "createTime"); | |
1025 | + return (Criteria) this; | |
1026 | + } | |
1027 | + | |
1028 | + public Criteria andCreateTimeGreaterThan(Date value) { | |
1029 | + addCriterion("create_time >", value, "createTime"); | |
1030 | + return (Criteria) this; | |
1031 | + } | |
1032 | + | |
1033 | + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { | |
1034 | + addCriterion("create_time >=", value, "createTime"); | |
1035 | + return (Criteria) this; | |
1036 | + } | |
1037 | + | |
1038 | + public Criteria andCreateTimeLessThan(Date value) { | |
1039 | + addCriterion("create_time <", value, "createTime"); | |
1040 | + return (Criteria) this; | |
1041 | + } | |
1042 | + | |
1043 | + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { | |
1044 | + addCriterion("create_time <=", value, "createTime"); | |
1045 | + return (Criteria) this; | |
1046 | + } | |
1047 | + | |
1048 | + public Criteria andCreateTimeIn(List<Date> values) { | |
1049 | + addCriterion("create_time in", values, "createTime"); | |
1050 | + return (Criteria) this; | |
1051 | + } | |
1052 | + | |
1053 | + public Criteria andCreateTimeNotIn(List<Date> values) { | |
1054 | + addCriterion("create_time not in", values, "createTime"); | |
1055 | + return (Criteria) this; | |
1056 | + } | |
1057 | + | |
1058 | + public Criteria andCreateTimeBetween(Date value1, Date value2) { | |
1059 | + addCriterion("create_time between", value1, value2, "createTime"); | |
1060 | + return (Criteria) this; | |
1061 | + } | |
1062 | + | |
1063 | + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { | |
1064 | + addCriterion("create_time not between", value1, value2, "createTime"); | |
1065 | + return (Criteria) this; | |
1066 | + } | |
1067 | + } | |
1068 | + | |
1069 | + public static class Criteria extends GeneratedCriteria { | |
1070 | + | |
1071 | + protected Criteria() { | |
1072 | + super(); | |
1073 | + } | |
1074 | + } | |
1075 | + | |
1076 | + public static class Criterion { | |
1077 | + private String condition; | |
1078 | + | |
1079 | + private Object value; | |
1080 | + | |
1081 | + private Object secondValue; | |
1082 | + | |
1083 | + private boolean noValue; | |
1084 | + | |
1085 | + private boolean singleValue; | |
1086 | + | |
1087 | + private boolean betweenValue; | |
1088 | + | |
1089 | + private boolean listValue; | |
1090 | + | |
1091 | + private String typeHandler; | |
1092 | + | |
1093 | + public String getCondition() { | |
1094 | + return condition; | |
1095 | + } | |
1096 | + | |
1097 | + public Object getValue() { | |
1098 | + return value; | |
1099 | + } | |
1100 | + | |
1101 | + public Object getSecondValue() { | |
1102 | + return secondValue; | |
1103 | + } | |
1104 | + | |
1105 | + public boolean isNoValue() { | |
1106 | + return noValue; | |
1107 | + } | |
1108 | + | |
1109 | + public boolean isSingleValue() { | |
1110 | + return singleValue; | |
1111 | + } | |
1112 | + | |
1113 | + public boolean isBetweenValue() { | |
1114 | + return betweenValue; | |
1115 | + } | |
1116 | + | |
1117 | + public boolean isListValue() { | |
1118 | + return listValue; | |
1119 | + } | |
1120 | + | |
1121 | + public String getTypeHandler() { | |
1122 | + return typeHandler; | |
1123 | + } | |
1124 | + | |
1125 | + protected Criterion(String condition) { | |
1126 | + super(); | |
1127 | + this.condition = condition; | |
1128 | + this.typeHandler = null; | |
1129 | + this.noValue = true; | |
1130 | + } | |
1131 | + | |
1132 | + protected Criterion(String condition, Object value, String typeHandler) { | |
1133 | + super(); | |
1134 | + this.condition = condition; | |
1135 | + this.value = value; | |
1136 | + this.typeHandler = typeHandler; | |
1137 | + if (value instanceof List<?>) { | |
1138 | + this.listValue = true; | |
1139 | + } else { | |
1140 | + this.singleValue = true; | |
1141 | + } | |
1142 | + } | |
1143 | + | |
1144 | + protected Criterion(String condition, Object value) { | |
1145 | + this(condition, value, null); | |
1146 | + } | |
1147 | + | |
1148 | + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { | |
1149 | + super(); | |
1150 | + this.condition = condition; | |
1151 | + this.value = value; | |
1152 | + this.secondValue = secondValue; | |
1153 | + this.typeHandler = typeHandler; | |
1154 | + this.betweenValue = true; | |
1155 | + } | |
1156 | + | |
1157 | + protected Criterion(String condition, Object value, Object secondValue) { | |
1158 | + this(condition, value, secondValue, null); | |
1159 | + } | |
1160 | + } | |
1161 | +} | ... | ... |
1 | +package com.idss.vulsync.mvc.service; | |
2 | + | |
3 | +import cloud.agileframework.common.util.file.FileUtil; | |
4 | +import cn.hutool.core.collection.ListUtil; | |
5 | +import cn.hutool.core.date.DatePattern; | |
6 | +import cn.hutool.core.date.DateUtil; | |
7 | +import cn.hutool.core.util.ObjectUtil; | |
8 | +import com.alibaba.fastjson.JSON; | |
9 | +import com.alibaba.fastjson.serializer.PropertyFilter; | |
10 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
11 | +import com.idss.vulsync.config.VulSftpConfiguration; | |
12 | +import com.idss.vulsync.entity.AssetReportVO; | |
13 | +import com.idss.vulsync.mvc.mapper.ConsultVulmanageSyncEntityMapper; | |
14 | +import com.idss.vulsync.mvc.pojo.db.ConsultVulmanageSyncEntity; | |
15 | +import com.idss.vulsync.utils.MultipartFileToFile; | |
16 | +import com.idss.vulsync.utils.SftpUtil; | |
17 | +import lombok.extern.slf4j.Slf4j; | |
18 | +import org.springframework.beans.factory.annotation.Autowired; | |
19 | +import org.springframework.stereotype.Service; | |
20 | + | |
21 | +import java.io.File; | |
22 | +import java.io.FileOutputStream; | |
23 | +import java.io.OutputStreamWriter; | |
24 | +import java.util.Arrays; | |
25 | +import java.util.Base64; | |
26 | +import java.util.Date; | |
27 | +import java.util.List; | |
28 | +import java.util.stream.Collectors; | |
29 | + | |
30 | +/** | |
31 | + * @Author: zc | |
32 | + * @Date: 2024/8/20 11:10 | |
33 | + */ | |
34 | +@Slf4j | |
35 | +@Service | |
36 | +public class CommonService { | |
37 | + @Autowired | |
38 | + ObjectMapper objectMapper; | |
39 | + @Autowired | |
40 | + ConsultVulmanageSyncEntityMapper consultVulmanageSyncEntityMapper; | |
41 | + @Autowired | |
42 | + VulSftpConfiguration vulSftpConfiguration; | |
43 | + | |
44 | + public void sync(List<AssetReportVO> dataList, ConsultVulmanageSyncEntity syncEntity, Date now, String type) { | |
45 | + try { | |
46 | + String dateFormat = DateUtil.format(now, DatePattern.PURE_DATETIME_FORMAT); | |
47 | + String zipFileName = ""; | |
48 | + zipFileName = syncEntity.getTransId() + "_" + type + "_" + dateFormat; | |
49 | + | |
50 | + String parentPath = vulSftpConfiguration.getTemp(); | |
51 | + | |
52 | + String roundStr = syncEntity.getLatestEsId() + File.separator + dateFormat; | |
53 | + | |
54 | + | |
55 | + File contentLogFile = FileUtil.createFile(parentPath + File.separator + roundStr, "content.log"); | |
56 | + OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(contentLogFile), "utf-8"); | |
57 | + | |
58 | + for (AssetReportVO entity : dataList) { | |
59 | + String json= objectMapper.writeValueAsString(entity); | |
60 | +// String json = JSON.toJSONString(entity, new PropertyFilter() { | |
61 | +// @Override | |
62 | +// public boolean apply(Object object, String name, Object value) { | |
63 | +// return !ListUtil.toList("SortedJson", "sortedJson").contains(name); | |
64 | +// } | |
65 | +// }); | |
66 | + ow.append(json.concat("\r\n")); | |
67 | + ow.flush(); | |
68 | + } | |
69 | + MultipartFileToFile.writeToFile(contentLogFile, parentPath, zipFileName); | |
70 | + String outputDir = parentPath + File.separator + roundStr; | |
71 | + List<String> zipFileUrlList = MultipartFileToFile.splitZip(parentPath, zipFileName, 20 * 1024 * 1024, outputDir); | |
72 | + if(ObjectUtil.isNotEmpty(zipFileUrlList)){ | |
73 | + //最后一个文件后缀改成FFFF | |
74 | + String lastFileUrlOrigin = zipFileUrlList.get(zipFileUrlList.size() - 1); | |
75 | + String[] split = lastFileUrlOrigin.split("_"); | |
76 | + split[split.length-1]="FFFF.zip"; | |
77 | + String lastFileUrl = Arrays.stream(split).collect(Collectors.joining("_")); | |
78 | + cn.hutool.core.io.FileUtil.rename(new File(lastFileUrlOrigin),lastFileUrl,false); | |
79 | + zipFileUrlList.remove(zipFileUrlList.size() - 1); | |
80 | + zipFileUrlList.add(lastFileUrl); | |
81 | + } | |
82 | + | |
83 | + //更新db | |
84 | + syncEntity.setInitFilePath(outputDir); | |
85 | + syncEntity.setLatestFilePath(outputDir); | |
86 | + syncEntity.setLatestUploadTime(now); | |
87 | + consultVulmanageSyncEntityMapper.updateByPrimaryKeySelective(syncEntity); | |
88 | + | |
89 | + if ("1".equals(syncEntity.getCreditType())) { | |
90 | + //账号密码字符串 | |
91 | + String pwd = cn.hutool.core.codec.Base64.decodeStr(syncEntity.getCredit()); | |
92 | + String userAndPort = syncEntity.getUser(); | |
93 | + String[] split = userAndPort.split(":"); | |
94 | + SftpUtil sftpUtil = new SftpUtil(split[0], pwd, vulSftpConfiguration.getIp(), Integer.parseInt(split[1])); | |
95 | + try { | |
96 | + sftpUtil.login(); | |
97 | + if (ObjectUtil.isNotEmpty(zipFileUrlList)) { | |
98 | + log.info("同步初始数据文件{}个", zipFileUrlList.size()); | |
99 | + for (String fileUrl : zipFileUrlList) { | |
100 | + sftpUtil.upload(syncEntity.getFilePath(), fileUrl); | |
101 | + } | |
102 | + } | |
103 | + }catch (Exception e){ | |
104 | + log.error("ftpy异常",e); | |
105 | + }finally { | |
106 | + sftpUtil.logout(); | |
107 | + } | |
108 | + } else if ("2".equals(syncEntity.getCreditType())) { | |
109 | + //账号公钥 | |
110 | + } | |
111 | + } catch (Exception e) { | |
112 | + log.error("{}同步数据异常", type, e); | |
113 | + } | |
114 | + | |
115 | + } | |
116 | + | |
117 | + public static void main(String[] args) throws Exception{ | |
118 | + String a="idss@1234"; | |
119 | + byte[] encode = Base64.getEncoder().encode(a.getBytes()); | |
120 | + String string = new String(encode,"UTF-8"); | |
121 | + System.out.println(string); | |
122 | + } | |
123 | +} | ... | ... |
1 | +package com.idss.vulsync.mvc.service; | |
2 | + | |
3 | +import cn.hutool.core.collection.ListUtil; | |
4 | +import cn.hutool.core.date.DateField; | |
5 | +import cn.hutool.core.date.DateTime; | |
6 | +import cn.hutool.core.date.DateUtil; | |
7 | +import cn.hutool.core.util.ObjectUtil; | |
8 | +import cn.hutool.core.util.StrUtil; | |
9 | +import com.alibaba.fastjson.JSON; | |
10 | +import com.alibaba.fastjson.JSONException; | |
11 | +import com.alibaba.fastjson.serializer.PropertyFilter; | |
12 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
13 | +import com.idss.common.file.storage.FileStorageProxy; | |
14 | +import com.idss.common.file.storage.pojo.dto.FileDownloadInfo; | |
15 | +import com.idss.common.file.storage.pojo.query.OperateQuery; | |
16 | +import com.idss.vulsync.common.EsIndexConstant; | |
17 | +import com.idss.vulsync.config.AssetSftpConfiguration; | |
18 | +import com.idss.vulsync.config.VulSftpConfiguration; | |
19 | +import com.idss.vulsync.constants.CommonConstant; | |
20 | +import com.idss.vulsync.constants.RedisConstants; | |
21 | +import com.idss.vulsync.entity.AssetReportVO; | |
22 | +import com.idss.vulsync.entity.vo.SyncParamConsultRequestData; | |
23 | +import com.idss.vulsync.mvc.mapper.ConsultVulmanageSyncEntityMapper; | |
24 | +import com.idss.vulsync.mvc.pojo.db.ConsultVulmanageSyncEntity; | |
25 | +import com.idss.vulsync.schedule.InitDataSyncJob; | |
26 | +import com.idss.vulsync.utils.MultipartFileToFile; | |
27 | +import com.idss.vulsync.utils.RedisUtil; | |
28 | +import com.idss.vulsync.utils.SftpUtil; | |
29 | +import lombok.extern.slf4j.Slf4j; | |
30 | +import org.apache.commons.lang3.StringUtils; | |
31 | +import org.quartz.*; | |
32 | +import org.springframework.beans.factory.annotation.Autowired; | |
33 | +import org.springframework.beans.factory.annotation.Qualifier; | |
34 | +import org.springframework.data.redis.core.RedisTemplate; | |
35 | +import org.springframework.stereotype.Service; | |
36 | +import org.springframework.web.multipart.MultipartFile; | |
37 | + | |
38 | +import java.io.BufferedReader; | |
39 | +import java.io.IOException; | |
40 | +import java.io.InputStream; | |
41 | +import java.io.InputStreamReader; | |
42 | +import java.util.*; | |
43 | +import java.util.stream.Collectors; | |
44 | + | |
45 | +/** | |
46 | + * @Author: zc | |
47 | + * @Date: 2024/8/16 13:48 | |
48 | + */ | |
49 | +@Service | |
50 | +@Slf4j | |
51 | +public class ConsultVulmanageSyncService { | |
52 | + @Autowired | |
53 | + ObjectMapper objectMapper; | |
54 | + @Autowired | |
55 | + ConsultVulmanageSyncEntityMapper consultVulmanageSyncEntityMapper; | |
56 | + @Autowired | |
57 | + EsService esService; | |
58 | + @Autowired(required = false) | |
59 | + @Qualifier("QuartzScheduler") | |
60 | + private Scheduler scheduler; | |
61 | + @Autowired(required = false) | |
62 | + private FileStorageProxy fileStorageProxy; | |
63 | + @Autowired | |
64 | + private RedisUtil redisUtil; | |
65 | + @Autowired | |
66 | + AssetSftpConfiguration assetSftpConfiguration; | |
67 | + | |
68 | + | |
69 | + | |
70 | + public List<AssetReportVO> getLatestDataGxb() { | |
71 | + List<AssetReportVO> allList = new ArrayList<>(); | |
72 | + Set<String> keys = redisUtil.keys("*" + RedisConstants.INIT_REPORT_DATA_FILE_NAME + "*"); | |
73 | + if(ObjectUtil.isEmpty(keys)){ | |
74 | + log.info("redis未获取到最近一次上报部侧的全量数据文件地址"); | |
75 | + return new ArrayList<>(); | |
76 | + } | |
77 | + | |
78 | + | |
79 | + Object initDataFileName = redisUtil.get(new ArrayList<>(keys).get(0)) ; | |
80 | + if (ObjectUtil.isEmpty(initDataFileName)) { | |
81 | + log.info("redis未获取到最近一次上报部侧的全量数据文件地址{}的值", RedisConstants.INIT_REPORT_DATA_FILE_NAME); | |
82 | + return allList; | |
83 | + } | |
84 | + String fileNames = initDataFileName.toString(); | |
85 | + log.info("redis获取最近一次上报部侧的全量数据文件地址{}", fileNames); | |
86 | + | |
87 | + SftpUtil sftpUtil = new SftpUtil(assetSftpConfiguration.getUser(), assetSftpConfiguration.getPwd(), assetSftpConfiguration.getIp(), Integer.parseInt(assetSftpConfiguration.getPort())); | |
88 | + try { | |
89 | + sftpUtil.login(); | |
90 | + for (String fileName : fileNames.split(",")) { | |
91 | + | |
92 | + InputStream inputStream = sftpUtil.downloadStream(assetSftpConfiguration.getPath(), fileName.split("/")[1]); | |
93 | + | |
94 | + List<AssetReportVO> resultList = resolveZip2AssetList(inputStream); | |
95 | + if (ObjectUtil.isNotEmpty(resultList)) { | |
96 | + allList.addAll(resultList); | |
97 | + } | |
98 | + } | |
99 | + | |
100 | + if (ObjectUtil.isNotEmpty(allList)) { | |
101 | + log.info("解析最近一次上报全量数据{}包含{}条", fileNames, allList.size()); | |
102 | + } | |
103 | + | |
104 | + } catch (Exception e) { | |
105 | + log.error("解析最近一次上报全量数据文件异常", e); | |
106 | + } finally { | |
107 | + sftpUtil.logout(); | |
108 | + } | |
109 | + return allList; | |
110 | + } | |
111 | + | |
112 | + | |
113 | + | |
114 | + public void consultVulmanage(SyncParamConsultRequestData syncParamConsultRequestData) { | |
115 | + Date now = new Date(); | |
116 | + | |
117 | + | |
118 | + //获取最近一次上报部侧的全量数据文件 作为资产同步的初始数据 | |
119 | + List<AssetReportVO> allList = getLatestDataGxb(); | |
120 | + | |
121 | + //删除上次的协商参数和资产数据 | |
122 | + ConsultVulmanageSyncEntity existSync = consultVulmanageSyncEntityMapper.selectByPrimaryKey(CommonConstant.CONSULT_UNIQUE_ID); | |
123 | + if (existSync != null) { | |
124 | + String existIndex = existSync.getLatestEsId(); | |
125 | + if (ObjectUtil.isNotEmpty(existIndex)) { | |
126 | + esService.delete(existIndex); | |
127 | + } | |
128 | + consultVulmanageSyncEntityMapper.deleteByPrimaryKey(CommonConstant.CONSULT_UNIQUE_ID); | |
129 | + } | |
130 | + | |
131 | + | |
132 | + String newIndex = UUID.randomUUID().toString().replace("-", ""); | |
133 | + | |
134 | + | |
135 | + //保存初始资产数据 | |
136 | + esService.addBatch(allList, newIndex); | |
137 | +// esService.addBatch(allList, EsIndexConstant.GXB_ASSET_FULL_DATA_INDEX); | |
138 | + | |
139 | + //保存同步协商参数 | |
140 | + ConsultVulmanageSyncEntity syncEntity = new ConsultVulmanageSyncEntity(); | |
141 | + syncEntity.setId(CommonConstant.CONSULT_UNIQUE_ID); | |
142 | + syncEntity.setTransId(syncParamConsultRequestData.getTransID()); | |
143 | + syncEntity.setFilePath(syncParamConsultRequestData.getFilePath()); | |
144 | + syncEntity.setUser(syncParamConsultRequestData.getUser()+":"+syncParamConsultRequestData.getPort()); | |
145 | + syncEntity.setCreditType(syncParamConsultRequestData.getCreditType().toString()); | |
146 | + syncEntity.setCredit(syncParamConsultRequestData.getCredit()); | |
147 | + syncEntity.setPubKey(syncParamConsultRequestData.getPubKey()); | |
148 | + syncEntity.setInitDelay(syncParamConsultRequestData.getInitDelay()); | |
149 | + syncEntity.setUpdCycle(syncParamConsultRequestData.getUpdCycle()); | |
150 | + syncEntity.setCreateTime(now); | |
151 | + syncEntity.setLatestEsId(newIndex); | |
152 | + consultVulmanageSyncEntityMapper.insertSelective(syncEntity); | |
153 | + | |
154 | + | |
155 | + try { | |
156 | + String initDelay = syncEntity.getInitDelay(); | |
157 | + String numStr = initDelay.substring(0, 2); | |
158 | + String unit = initDelay.substring(2, initDelay.length()); | |
159 | + Integer num = numStr.startsWith("0") ? Integer.parseInt(numStr.substring(1, numStr.length())) : Integer.parseInt(numStr); | |
160 | + | |
161 | + | |
162 | + JobDetail jobDetail = JobBuilder.newJob(InitDataSyncJob.class). | |
163 | + withIdentity(InitDataSyncJob.class.getSimpleName(), InitDataSyncJob.class.getSimpleName()) | |
164 | + .build(); | |
165 | + | |
166 | + | |
167 | + DateTime executionTime = new DateTime(); | |
168 | + | |
169 | + if (unit.equals("分")) { | |
170 | + executionTime = DateUtil.offsetMinute(now, num); | |
171 | + } else if (unit.equals("时")) { | |
172 | + executionTime = DateUtil.offsetHour(now, num); | |
173 | + } else { | |
174 | + executionTime = new DateTime(now); | |
175 | + } | |
176 | + | |
177 | + | |
178 | + Trigger trigger = TriggerBuilder.newTrigger().withIdentity(InitDataSyncJob.class.getSimpleName(), InitDataSyncJob.class.getSimpleName()) | |
179 | + .startAt(executionTime).build(); | |
180 | + JobKey jobKey=new JobKey(InitDataSyncJob.class.getSimpleName(), InitDataSyncJob.class.getSimpleName()); | |
181 | + scheduler.deleteJob(jobKey); | |
182 | + scheduler.scheduleJob(jobDetail, trigger); | |
183 | + log.info("新增初始数据同步任务,下次执行时间{}", DateUtil.formatDateTime(executionTime)); | |
184 | + } catch (Exception e) { | |
185 | + log.error("新增初始数据同步任务异常", e); | |
186 | + } | |
187 | + | |
188 | + } | |
189 | + | |
190 | + | |
191 | + /** | |
192 | + * 解析zip文件为上报数据 | |
193 | + */ | |
194 | + public List<AssetReportVO> resolveZip2AssetList(InputStream inputStream) { | |
195 | + List<AssetReportVO> resultList = new ArrayList<>(); | |
196 | + try { | |
197 | + List<MultipartFile> multipartFiles = MultipartFileToFile.zipParse(inputStream); | |
198 | + for (MultipartFile multipartFile : multipartFiles) { | |
199 | + InputStream ins = multipartFile.getInputStream(); | |
200 | + BufferedReader br = null; | |
201 | + try { | |
202 | + //读取文件信息 | |
203 | + br = new BufferedReader(new InputStreamReader(ins)); | |
204 | + String lines = ""; | |
205 | + // 根据行进行读取数据 | |
206 | + while (StringUtils.isNotBlank((lines = br.readLine()))) { | |
207 | + AssetReportVO entity = new AssetReportVO(); | |
208 | + try { | |
209 | + entity = objectMapper.readValue(lines, AssetReportVO.class); | |
210 | +// String sortedJson = JSON.toJSONString(entity, new PropertyFilter() { | |
211 | +// @Override | |
212 | +// public boolean apply(Object object, String name, Object value) { | |
213 | +// return !ListUtil.toList("TaskID", "AssetID", "taskID", "assetId").contains(name); | |
214 | +// } | |
215 | +// }); | |
216 | + resultList.add(entity); | |
217 | + } catch (JSONException e) { | |
218 | + e.printStackTrace(); | |
219 | + } | |
220 | + } | |
221 | + br.close(); | |
222 | + } catch (IOException e) { | |
223 | + try { | |
224 | + br.close(); | |
225 | + } catch (IOException ex) { | |
226 | + ex.printStackTrace(); | |
227 | + } | |
228 | + e.printStackTrace(); | |
229 | + } | |
230 | + | |
231 | + } | |
232 | + } catch (Exception e) { | |
233 | + e.printStackTrace(); | |
234 | + | |
235 | + } | |
236 | + return resultList; | |
237 | + } | |
238 | + | |
239 | + public static void main(String[] args) { | |
240 | + String var0="M#@*G+q<O8F"; | |
241 | + int var10000 = 5 << 3 ^ 3 ^ 5; | |
242 | + int var10001 = (3 ^ 5) << 4 ^ 3; | |
243 | + int var10002 = 4 << 4 ^ (3 ^ 5) << 1; | |
244 | + String var1; | |
245 | + int var10003 = (var1 = (String)var0).length(); | |
246 | + char[] var10004 = new char[var10003]; | |
247 | + boolean var10006 = true; | |
248 | + int var5 = var10003 - 1; | |
249 | + var10003 = var10002; | |
250 | + int var3; | |
251 | + var10002 = var3 = var5; | |
252 | + char[] a = var10004; | |
253 | + int var4 = var10003; | |
254 | + var10001 = var10000; | |
255 | + var10000 = var10002; | |
256 | + | |
257 | + for(int var2 = var10001; var10000 >= 0; var10000 = var3) { | |
258 | + var10001 = var3; | |
259 | + char var7 = var1.charAt(var3); | |
260 | + --var3; | |
261 | + a[var10001] = (char)(var7 ^ var2); | |
262 | + if (var3 < 0) { | |
263 | + break; | |
264 | + } | |
265 | + | |
266 | + var10002 = var3--; | |
267 | + a[var10002] = (char)(var1.charAt(var10002) ^ var4); | |
268 | + } | |
269 | + | |
270 | + | |
271 | + | |
272 | + | |
273 | + System.out.println(new String(a)); | |
274 | + } | |
275 | +} | ... | ... |
1 | +package com.idss.vulsync.mvc.service; | |
2 | + | |
3 | +import cn.hutool.core.lang.Assert; | |
4 | +import cn.hutool.core.util.ObjectUtil; | |
5 | +import com.alibaba.fastjson.JSON; | |
6 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
7 | +import com.fasterxml.jackson.databind.type.TypeFactory; | |
8 | +import com.idss.vulsync.entity.AssetReportVO; | |
9 | +import lombok.extern.slf4j.Slf4j; | |
10 | +import org.elasticsearch.action.DocWriteRequest; | |
11 | +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; | |
12 | +import org.elasticsearch.action.bulk.*; | |
13 | +import org.elasticsearch.action.delete.DeleteRequest; | |
14 | +import org.elasticsearch.action.delete.DeleteResponse; | |
15 | +import org.elasticsearch.action.index.IndexRequest; | |
16 | +import org.elasticsearch.action.search.SearchRequest; | |
17 | +import org.elasticsearch.action.search.SearchResponse; | |
18 | +import org.elasticsearch.action.search.SearchScrollRequest; | |
19 | +import org.elasticsearch.action.support.IndicesOptions; | |
20 | +import org.elasticsearch.action.support.master.AcknowledgedResponse; | |
21 | +import org.elasticsearch.client.RequestOptions; | |
22 | +import org.elasticsearch.client.RestHighLevelClient; | |
23 | +import org.elasticsearch.client.indices.CreateIndexRequest; | |
24 | +import org.elasticsearch.client.indices.CreateIndexResponse; | |
25 | +import org.elasticsearch.client.indices.GetIndexRequest; | |
26 | +import org.elasticsearch.common.unit.ByteSizeUnit; | |
27 | +import org.elasticsearch.common.unit.ByteSizeValue; | |
28 | +import org.elasticsearch.core.TimeValue; | |
29 | +import org.elasticsearch.index.query.BoolQueryBuilder; | |
30 | +import org.elasticsearch.index.query.QueryBuilder; | |
31 | +import org.elasticsearch.index.query.QueryBuilders; | |
32 | +import org.elasticsearch.index.reindex.BulkByScrollResponse; | |
33 | +import org.elasticsearch.index.reindex.DeleteByQueryRequest; | |
34 | +import org.elasticsearch.search.Scroll; | |
35 | +import org.elasticsearch.search.SearchHit; | |
36 | +import org.elasticsearch.search.builder.SearchSourceBuilder; | |
37 | +import org.elasticsearch.xcontent.XContentType; | |
38 | +import org.springframework.beans.factory.annotation.Autowired; | |
39 | +import org.springframework.stereotype.Component; | |
40 | + | |
41 | +import java.io.IOException; | |
42 | +import java.util.*; | |
43 | +import java.util.concurrent.TimeUnit; | |
44 | +import java.util.stream.Collectors; | |
45 | + | |
46 | +/** | |
47 | + * @Author: zc | |
48 | + * @Date: 2021/11/19 14:35 | |
49 | + */ | |
50 | +@Component | |
51 | +@Slf4j | |
52 | +public class EsService { | |
53 | + | |
54 | + | |
55 | + @Autowired | |
56 | + ObjectMapper objectMapper; | |
57 | + @Autowired | |
58 | + RestHighLevelClient client; | |
59 | + | |
60 | + | |
61 | + | |
62 | + public int delete(String indexName) { | |
63 | + try { | |
64 | + GetIndexRequest indexRequest = new GetIndexRequest(indexName); | |
65 | + boolean inExists = client.indices().exists(indexRequest, RequestOptions.DEFAULT); | |
66 | + | |
67 | + if (inExists) { | |
68 | + DeleteIndexRequest request = new DeleteIndexRequest(indexName); | |
69 | + AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT); | |
70 | + if (!response.isAcknowledged()) { | |
71 | + // 2:索引存在删除失败 | |
72 | + log.info("删除索引失败{}",indexName); | |
73 | + return 2; | |
74 | + } | |
75 | + } else { | |
76 | + // 1:索引不存在 | |
77 | + log.info("删除索引不存在{}",indexName); | |
78 | + return 1; | |
79 | + } | |
80 | + } catch (IllegalArgumentException e) { | |
81 | + throw e; | |
82 | + } catch (Exception e) { | |
83 | + log.error("删除索引异常{}",indexName,e); | |
84 | + } | |
85 | + // 0:索引存在并删除成功 | |
86 | + return 0; | |
87 | + } | |
88 | + | |
89 | + | |
90 | + | |
91 | + /** | |
92 | + * 批量插入 | |
93 | + */ | |
94 | + public void addBatch(List<AssetReportVO> models, String index) { | |
95 | + if (!indexIsExist(index)) { | |
96 | + createIndex(index); | |
97 | + } | |
98 | + BulkProcessor.Listener listener = new BulkProcessor.Listener() { | |
99 | + @Override | |
100 | + public void beforeBulk(long executionId, BulkRequest request) { | |
101 | + log.info("1. 【beforeBulk】批次[{}] 携带 {} 请求数量", executionId, request.numberOfActions()); | |
102 | + } | |
103 | + | |
104 | + @Override | |
105 | + public void afterBulk(long executionId, BulkRequest request, | |
106 | + BulkResponse response) { | |
107 | +// if (!response.hasFailures()) { | |
108 | +// log.info("2. 【afterBulk-成功】批量 [{}] 完成在 {} ms", executionId, response.getTook().getMillis()); | |
109 | +// } else { | |
110 | +// BulkItemResponse[] items = response.getItems(); | |
111 | +// for (BulkItemResponse item : items) { | |
112 | +// if (item.isFailed()) { | |
113 | +// log.info("2. 【afterBulk-失败】批量 [{}] 出现异常的原因 : {}", executionId, item.getFailureMessage()); | |
114 | +// break; | |
115 | +// } | |
116 | +// } | |
117 | +// } | |
118 | + } | |
119 | + | |
120 | + @Override | |
121 | + public void afterBulk(long executionId, BulkRequest request, | |
122 | + Throwable failure) { | |
123 | + log.error("3. 【afterBulk-failure失败】es执行bluk失败", failure); | |
124 | +// List<DocWriteRequest<?>> requests = request.requests(); | |
125 | +// List<String> esIds = requests.stream().map(DocWriteRequest::id).collect(Collectors.toList()); | |
126 | + } | |
127 | + }; | |
128 | + BulkProcessor bulkProcessor = BulkProcessor.builder( | |
129 | + (request, bulkListener) -> | |
130 | + client.bulkAsync(request, RequestOptions.DEFAULT, bulkListener), | |
131 | + listener) | |
132 | + .setBulkActions(10000) // Execute the bulk every 10,000 requests | |
133 | + .setBulkSize(new ByteSizeValue(100, ByteSizeUnit.MB)) // Execute the bulk every 5MB | |
134 | + .build(); | |
135 | + | |
136 | + try { | |
137 | + for (AssetReportVO entity : models) { | |
138 | + LinkedHashMap<String,Object> map = objectMapper.readValue(objectMapper.writeValueAsString(entity), TypeFactory.defaultInstance().constructMapType(LinkedHashMap.class, String.class, Object.class)); | |
139 | + IndexRequest indexRequest = new IndexRequest(index).id(entity.getAssetId()) | |
140 | + .type(index) | |
141 | + .source(map); | |
142 | + bulkProcessor.add(indexRequest); | |
143 | + } | |
144 | + bulkProcessor.flush(); | |
145 | + bulkProcessor.awaitClose(3, TimeUnit.MINUTES); | |
146 | + }catch (Exception e){ | |
147 | + e.printStackTrace(); | |
148 | + } | |
149 | + } | |
150 | + | |
151 | + public boolean createIndex(String indexName) { | |
152 | + if (indexIsExist(indexName)) { | |
153 | + return true; | |
154 | + } | |
155 | + CreateIndexResponse createIndexResponse = null; | |
156 | + try { | |
157 | + CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName); | |
158 | + createIndexResponse = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); | |
159 | + } catch (IOException e) { | |
160 | + throw new RuntimeException(e); | |
161 | + } | |
162 | + if (createIndexResponse.isAcknowledged()) { | |
163 | + log.info("Index created"); | |
164 | + return true; | |
165 | + } else { | |
166 | + log.info("Index creation failed"); | |
167 | + return false; | |
168 | + } | |
169 | + } | |
170 | + | |
171 | + | |
172 | + public boolean indexIsExist(String indexName) { | |
173 | + Assert.notNull(indexName, "exist index name assert null!"); | |
174 | + GetIndexRequest getIndexRequest = new GetIndexRequest("fisher"); | |
175 | + boolean exists = false; | |
176 | + try { | |
177 | + exists = client.indices().exists(getIndexRequest, RequestOptions.DEFAULT); | |
178 | + } catch (IOException e) { | |
179 | + log.info("indexIsExist found exception:" + e); | |
180 | + } | |
181 | + return exists; | |
182 | + } | |
183 | + | |
184 | + | |
185 | +// public boolean addBatch(List<Object> models, String index) { | |
186 | +// for (Object model : models) { | |
187 | +// String id = idGenerator.randomUUID(); | |
188 | +// IndexRequest indexRequest = new IndexRequest(index).id(id).source(JSON.toJSONString(model), XContentType.JSON); | |
189 | +// try { | |
190 | +// client.index(indexRequest, COMMON_OPTIONS); | |
191 | +// } catch (IOException e) { | |
192 | +// log.warn("inserts to es is error, errorMsg " + id, e); | |
193 | +// } | |
194 | +// } | |
195 | +// return true; | |
196 | +// } | |
197 | + | |
198 | + private IndicesOptions setIndicesOptionsParam() { | |
199 | + return IndicesOptions.fromOptions(true, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed()); | |
200 | + } | |
201 | + | |
202 | + /** | |
203 | + * @param index | |
204 | + * @param queryBuilder | |
205 | + * @return | |
206 | + */ | |
207 | + public List<AssetReportVO> selectList(String index, QueryBuilder queryBuilder) { | |
208 | + try { | |
209 | + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); | |
210 | + searchSourceBuilder.query(queryBuilder); | |
211 | + searchSourceBuilder.size(10000); | |
212 | + | |
213 | + Scroll scroll = new Scroll(new TimeValue(600000)); | |
214 | + SearchRequest searchRequest = new SearchRequest(); | |
215 | + searchRequest.indices(index); | |
216 | + searchRequest.scroll(scroll); | |
217 | + searchRequest.source(searchSourceBuilder); | |
218 | + | |
219 | + SearchResponse scrollResp = client.search(searchRequest, RequestOptions.DEFAULT); | |
220 | + List<AssetReportVO> resultList = new ArrayList<>(); | |
221 | + AssetReportVO entity = null; | |
222 | + | |
223 | + | |
224 | + //记录滚动id。 | |
225 | + String scrollId = scrollResp.getScrollId(); | |
226 | + //滚动查询部分,将从第10001条数据开始取。 | |
227 | + SearchHit[] scrollHits = scrollResp.getHits().getHits(); | |
228 | + | |
229 | + for (SearchHit searchHit : scrollHits) { | |
230 | + entity = JSON.parseObject(searchHit.getSourceAsString(), AssetReportVO.class); | |
231 | + resultList.add(entity); | |
232 | + } | |
233 | + log.info("resultList size " + resultList.size()); | |
234 | + | |
235 | + | |
236 | + while (ObjectUtil.isNotNull(scrollHits) && scrollHits.length > 0) { | |
237 | + //构造滚动查询条件 | |
238 | + SearchScrollRequest searchScrollRequest = new SearchScrollRequest(scrollId); | |
239 | + searchScrollRequest.scroll(scroll); | |
240 | + //响应必须是上面的响应对象,需要对上一层进行覆盖。 | |
241 | + scrollResp = client.scroll(searchScrollRequest, RequestOptions.DEFAULT); | |
242 | + scrollId = scrollResp.getScrollId(); | |
243 | + scrollHits = scrollResp.getHits().getHits(); | |
244 | + | |
245 | + for (SearchHit searchHit : scrollHits) { | |
246 | + entity = JSON.parseObject(searchHit.getSourceAsString(), AssetReportVO.class); | |
247 | + resultList.add(entity); | |
248 | + } | |
249 | + log.info("resultList size " + resultList.size()); | |
250 | + | |
251 | + } | |
252 | + log.info("resultList final size " + resultList.size()); | |
253 | + return resultList; | |
254 | + } catch (Exception e) { | |
255 | + log.error("selectList timeindex is error,errorMsg ", e); | |
256 | + } | |
257 | + return new ArrayList<>(); | |
258 | + } | |
259 | + | |
260 | + | |
261 | +} | ... | ... |
1 | +package com.idss.vulsync.schedule; | |
2 | + | |
3 | +import cn.hutool.core.date.DateTime; | |
4 | +import cn.hutool.core.date.DateUtil; | |
5 | +import cn.hutool.core.util.ObjectUtil; | |
6 | +import com.idss.vulsync.constants.CommonConstant; | |
7 | +import com.idss.vulsync.entity.AssetReportVO; | |
8 | +import com.idss.vulsync.mvc.mapper.ConsultVulmanageSyncEntityMapper; | |
9 | +import com.idss.vulsync.mvc.pojo.db.ConsultVulmanageSyncEntity; | |
10 | +import com.idss.vulsync.mvc.service.CommonService; | |
11 | +import com.idss.vulsync.mvc.service.EsService; | |
12 | +import lombok.extern.slf4j.Slf4j; | |
13 | +import org.elasticsearch.index.query.BoolQueryBuilder; | |
14 | +import org.elasticsearch.index.query.QueryBuilders; | |
15 | +import org.quartz.*; | |
16 | +import org.springframework.beans.factory.annotation.Autowired; | |
17 | +import org.springframework.beans.factory.annotation.Qualifier; | |
18 | +import org.springframework.stereotype.Service; | |
19 | + | |
20 | +import java.util.Date; | |
21 | +import java.util.List; | |
22 | + | |
23 | +/** | |
24 | + * @Author: zc | |
25 | + * @Date: 2024/8/16 16:58 | |
26 | + * 漏管初始数据同步 | |
27 | + */ | |
28 | +@Service | |
29 | +@Slf4j | |
30 | +public class InitDataSyncJob implements Job { | |
31 | + @Autowired | |
32 | + ConsultVulmanageSyncEntityMapper consultVulmanageSyncEntityMapper; | |
33 | + @Autowired | |
34 | + EsService esService; | |
35 | + @Autowired(required = false) | |
36 | + @Qualifier("QuartzScheduler") | |
37 | + public Scheduler scheduler; | |
38 | + @Autowired | |
39 | + CommonService commonService; | |
40 | + | |
41 | + @Override | |
42 | + public void execute(JobExecutionContext jobExecutionContext) { | |
43 | + log.info("quartz启动" + this.getClass().getSimpleName()); | |
44 | + this.run(jobExecutionContext); | |
45 | + } | |
46 | + | |
47 | + | |
48 | + public void run(JobExecutionContext jobExecutionContext) { | |
49 | + Date now = new Date(); | |
50 | + log.info("开始同步初始数据--------"); | |
51 | + ConsultVulmanageSyncEntity syncEntity = consultVulmanageSyncEntityMapper.selectByPrimaryKey(CommonConstant.CONSULT_UNIQUE_ID); | |
52 | + if (ObjectUtil.isEmpty(syncEntity) || ObjectUtil.isEmpty(syncEntity.getLatestEsId())) { | |
53 | + log.error("开始同步初始数据失败,未找到初始数据"); | |
54 | + } | |
55 | + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); | |
56 | + List<AssetReportVO> list = esService.selectList(syncEntity.getLatestEsId(), boolQueryBuilder); | |
57 | + | |
58 | + | |
59 | + commonService.sync(list, syncEntity, now, "INIT"); | |
60 | + | |
61 | + try { | |
62 | + jobExecutionContext.getScheduler().deleteJob(jobExecutionContext.getJobDetail().getKey()); | |
63 | + } catch (SchedulerException e) { | |
64 | + e.printStackTrace(); | |
65 | + } | |
66 | + | |
67 | + try { | |
68 | + scheduler.deleteJob(new JobKey(InitDataSyncJob.class.getSimpleName(),InitDataSyncJob.class.getSimpleName())); | |
69 | + }catch (Exception e){ | |
70 | + e.printStackTrace(); | |
71 | + } | |
72 | + | |
73 | + try { | |
74 | + JobKey jobKey=new JobKey(UpdateDataSyncJob.class.getSimpleName(), UpdateDataSyncJob.class.getSimpleName()); | |
75 | + scheduler.deleteJob(jobKey); | |
76 | + }catch (Exception e){ | |
77 | + e.printStackTrace(); | |
78 | + } | |
79 | + | |
80 | + try { | |
81 | + //新增增量更新同步任务 | |
82 | + String updCycle = syncEntity.getUpdCycle(); | |
83 | + String numStr = updCycle.substring(0, 2); | |
84 | + String unit = updCycle.substring(2, updCycle.length()); | |
85 | + Integer num = numStr.startsWith("0") ? Integer.parseInt(numStr.substring(1, numStr.length())) : Integer.parseInt(numStr); | |
86 | + | |
87 | + | |
88 | + JobDetail jobDetail = JobBuilder.newJob(UpdateDataSyncJob.class). | |
89 | + withIdentity(UpdateDataSyncJob.class.getSimpleName(), UpdateDataSyncJob.class.getSimpleName()) | |
90 | + .build(); | |
91 | + | |
92 | + DateTime executionTime = new DateTime(); | |
93 | + | |
94 | + if (unit.equals("天")) { | |
95 | + executionTime = DateUtil.offsetDay(now, num); | |
96 | + } else if (unit.equals("时")) { | |
97 | + executionTime = DateUtil.offsetHour(now, num); | |
98 | + } else { | |
99 | + executionTime = new DateTime(now); | |
100 | + } | |
101 | + | |
102 | + Trigger trigger = TriggerBuilder.newTrigger().withIdentity(UpdateDataSyncJob.class.getSimpleName(), UpdateDataSyncJob.class.getSimpleName()) | |
103 | + .startAt(executionTime).build(); | |
104 | + scheduler.scheduleJob(jobDetail, trigger); | |
105 | + log.error("新增增量更新同步任务,下次执行时间{}", DateUtil.formatDateTime(executionTime)); | |
106 | + | |
107 | + | |
108 | + } catch (Exception e) { | |
109 | + log.error("同步初始数据异常", e); | |
110 | + } | |
111 | + | |
112 | + | |
113 | + log.info("结束同步初始数据--------"); | |
114 | + } | |
115 | + | |
116 | +} | ... | ... |
1 | +package com.idss.vulsync.schedule; | |
2 | + | |
3 | +import cn.hutool.core.date.DateTime; | |
4 | +import cn.hutool.core.date.DateUtil; | |
5 | +import cn.hutool.core.util.ObjectUtil; | |
6 | +import com.idss.vulsync.constants.CommonConstant; | |
7 | +import com.idss.vulsync.entity.AssetReportVO; | |
8 | +import com.idss.vulsync.mvc.mapper.ConsultVulmanageSyncEntityMapper; | |
9 | +import com.idss.vulsync.mvc.pojo.db.ConsultVulmanageSyncEntity; | |
10 | +import com.idss.vulsync.mvc.service.CommonService; | |
11 | +import com.idss.vulsync.mvc.service.ConsultVulmanageSyncService; | |
12 | +import com.idss.vulsync.mvc.service.EsService; | |
13 | +import lombok.extern.slf4j.Slf4j; | |
14 | +import org.elasticsearch.index.query.QueryBuilders; | |
15 | +import org.quartz.*; | |
16 | +import org.springframework.beans.factory.annotation.Autowired; | |
17 | +import org.springframework.beans.factory.annotation.Qualifier; | |
18 | +import org.springframework.data.redis.core.RedisTemplate; | |
19 | +import org.springframework.stereotype.Service; | |
20 | + | |
21 | +import java.util.*; | |
22 | +import java.util.stream.Collectors; | |
23 | + | |
24 | +/** | |
25 | + * @Author: zc | |
26 | + * @Date: 2024/8/16 16:58 | |
27 | + * 漏管增量数据同步 | |
28 | + */ | |
29 | +@Service | |
30 | +@Slf4j | |
31 | +public class UpdateDataSyncJob implements Job { | |
32 | + @Autowired(required = false) | |
33 | + @Qualifier("QuartzScheduler") | |
34 | + public Scheduler scheduler; | |
35 | + @Autowired | |
36 | + EsService esService; | |
37 | + @Autowired | |
38 | + ConsultVulmanageSyncEntityMapper consultVulmanageSyncEntityMapper; | |
39 | + @Autowired | |
40 | + ConsultVulmanageSyncService consultVulmanageSyncService; | |
41 | + @Autowired | |
42 | + CommonService commonService; | |
43 | + @Autowired | |
44 | + private RedisTemplate redisTemplate; | |
45 | + | |
46 | + @Override | |
47 | + public void execute(JobExecutionContext jobExecutionContext) { | |
48 | + log.info("quartz启动" + this.getClass().getSimpleName()); | |
49 | + this.run(jobExecutionContext); | |
50 | + } | |
51 | + | |
52 | + | |
53 | + public void run(JobExecutionContext jobExecutionContext) { | |
54 | + log.info("开始同步增量数据--------"); | |
55 | + Date now = new Date(); | |
56 | + //初始同步任务同步部侧全量指令数据DataGxb为初始漏管数据latestEsId至漏管 | |
57 | + //每次上报部侧数据后更新部侧数据DataGxb ???是否只处理部侧全量指令数据的情况 | |
58 | + //增量同步任务比对DataGxb与latestEsId,然后更新DataVul并同步至漏管 | |
59 | + | |
60 | + //获取最近一次上报部侧的全量数据文件 作为DataGxb | |
61 | + List<AssetReportVO> gxbDataList = consultVulmanageSyncService.getLatestDataGxb(); | |
62 | + | |
63 | + | |
64 | + ConsultVulmanageSyncEntity syncEntity = consultVulmanageSyncEntityMapper.selectByPrimaryKey(CommonConstant.CONSULT_UNIQUE_ID); | |
65 | + String latestEsId = syncEntity.getLatestEsId(); | |
66 | + List<AssetReportVO> vulDataList = esService.selectList(latestEsId, QueryBuilders.boolQuery()); | |
67 | + | |
68 | + log.info("增量同步任务,漏管快照数据{}条,上报部侧数据{}条", vulDataList.size(), gxbDataList.size()); | |
69 | + | |
70 | + List<AssetReportVO> removeList = new ArrayList<>(); | |
71 | + //漏管DataVul为存量数据,最近一次部侧全量数据为本次需要比对的数据 | |
72 | + Set<String> vulDataIds = vulDataList.stream().map(AssetReportVO::getAssetId).collect(Collectors.toSet()); | |
73 | + Set<String> gxbDataIds = gxbDataList.stream().map(AssetReportVO::getAssetId).collect(Collectors.toSet()); | |
74 | + | |
75 | + Set<String> removeIds = new HashSet<>(); | |
76 | + for (String vulDataId : vulDataIds) { | |
77 | + if (!gxbDataIds.contains(vulDataId)) { | |
78 | + removeIds.add(vulDataId); | |
79 | + AssetReportVO remove = new AssetReportVO(); | |
80 | + remove.setAssetId(vulDataId); | |
81 | + remove.setState("3"); | |
82 | + removeList.add(remove); | |
83 | + } | |
84 | + } | |
85 | + //部侧数据中废弃资产 认为0下线 2停用 3删除均为废弃资产, state=1为新增和变更资产 | |
86 | + Set<AssetReportVO> gxbRemoveIds = gxbDataList.stream().filter(s -> !"1".equals(s.getState())).collect(Collectors.toSet()); | |
87 | + for (AssetReportVO reportVO : gxbRemoveIds) { | |
88 | + AssetReportVO remove = new AssetReportVO(); | |
89 | + remove.setAssetId(reportVO.getAssetId()); | |
90 | + remove.setState(reportVO.getState()); | |
91 | + removeList.add(remove); | |
92 | + } | |
93 | + log.info("本次资产废弃或删除{}条", removeList.size()); | |
94 | + | |
95 | + //1资产新增+属性变更 | |
96 | + List<AssetReportVO> addList = gxbDataList.stream().filter(s -> "1".equals(s.getState())).collect(Collectors.toList()); | |
97 | + log.info("本次资产新增和属性变更共{}条", addList.size()); | |
98 | + | |
99 | + //待更新数据 | |
100 | + List<AssetReportVO> syncDataList = new ArrayList<>(); | |
101 | + syncDataList.addAll(addList); | |
102 | + syncDataList.addAll(removeList); | |
103 | + | |
104 | + try { | |
105 | + //latestEsId删除旧数据,插入新增资产和变更资产, *废弃资产不入库 | |
106 | + esService.delete(latestEsId); | |
107 | + if (ObjectUtil.isNotEmpty(addList)) { | |
108 | + esService.addBatch(addList, latestEsId); | |
109 | + log.error("增量更新插入es{}条", addList.size()); | |
110 | + } | |
111 | + } catch (Exception e) { | |
112 | + log.error("增量更新插入es异常", e); | |
113 | + } | |
114 | + | |
115 | + | |
116 | + commonService.sync(syncDataList, syncEntity, now, "UPD"); | |
117 | + | |
118 | + try { | |
119 | + JobKey jobKey=new JobKey(UpdateDataSyncJob.class.getSimpleName(), UpdateDataSyncJob.class.getSimpleName()); | |
120 | + scheduler.deleteJob(jobKey); | |
121 | + }catch (Exception e){ | |
122 | + e.printStackTrace(); | |
123 | + } | |
124 | + | |
125 | + | |
126 | + try { | |
127 | + //新增增量更新同步任务 | |
128 | + String updCycle = syncEntity.getUpdCycle(); | |
129 | + String numStr = updCycle.substring(0, 2); | |
130 | + String unit = updCycle.substring(2, updCycle.length()); | |
131 | + Integer num = numStr.startsWith("0") ? Integer.parseInt(numStr.substring(1, numStr.length())) : Integer.parseInt(numStr); | |
132 | + | |
133 | + | |
134 | + JobDetail jobDetail = JobBuilder.newJob(UpdateDataSyncJob.class). | |
135 | + withIdentity(UpdateDataSyncJob.class.getSimpleName(), UpdateDataSyncJob.class.getSimpleName()) | |
136 | + .build(); | |
137 | + | |
138 | + DateTime executionTime = new DateTime(); | |
139 | + | |
140 | + if (unit.equals("天")) { | |
141 | + executionTime = DateUtil.offsetDay(now, num); | |
142 | + } else if (unit.equals("时")) { | |
143 | + executionTime = DateUtil.offsetHour(now, num); | |
144 | + } else { | |
145 | + executionTime = new DateTime(now); | |
146 | + } | |
147 | + | |
148 | + Trigger trigger = TriggerBuilder.newTrigger().withIdentity(UpdateDataSyncJob.class.getSimpleName(), UpdateDataSyncJob.class.getSimpleName()) | |
149 | + .startAt(executionTime).build(); | |
150 | + scheduler.scheduleJob(jobDetail, trigger); | |
151 | + log.error("新增增量更新同步任务,下次执行时间{}", DateUtil.formatDateTime(executionTime)); | |
152 | + | |
153 | + | |
154 | + } catch (Exception e) { | |
155 | + log.error("同步增量数据异常", e); | |
156 | + } | |
157 | + | |
158 | + | |
159 | + log.info("结束同步增量数据--------"); | |
160 | + } | |
161 | + | |
162 | +} | ... | ... |
1 | +package com.idss.vulsync.utils; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSON; | |
4 | +import com.fasterxml.jackson.core.JsonProcessingException; | |
5 | +import com.fasterxml.jackson.databind.DeserializationFeature; | |
6 | +import com.fasterxml.jackson.databind.JsonNode; | |
7 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
8 | +import com.fasterxml.jackson.databind.type.TypeFactory; | |
9 | +import lombok.extern.slf4j.Slf4j; | |
10 | +import org.springframework.beans.factory.annotation.Autowired; | |
11 | +import org.springframework.beans.factory.annotation.Value; | |
12 | +import org.springframework.stereotype.Component; | |
13 | + | |
14 | +import javax.servlet.http.HttpServletRequest; | |
15 | +import java.math.BigInteger; | |
16 | +import java.nio.charset.StandardCharsets; | |
17 | +import java.security.KeyFactory; | |
18 | +import java.security.MessageDigest; | |
19 | +import java.security.PublicKey; | |
20 | +import java.security.Signature; | |
21 | +import java.security.spec.X509EncodedKeySpec; | |
22 | +import java.util.Base64; | |
23 | +import java.util.LinkedHashMap; | |
24 | + | |
25 | +/** | |
26 | + * @Author: zc | |
27 | + * @Date: 2024/8/13 14:34 | |
28 | + */ | |
29 | +@Component | |
30 | +@Slf4j | |
31 | +public class AuthUtils { | |
32 | + @Value("${auth.publickey:11}") | |
33 | + private String publickey; | |
34 | + | |
35 | + @Autowired | |
36 | + ObjectMapper objectMapper; | |
37 | + | |
38 | + public boolean valid(HttpServletRequest req) { | |
39 | +// 提取Authorization头 | |
40 | + String authHeader = req.getHeader("Authorization"); | |
41 | + try { | |
42 | + if (authHeader == null || !authHeader.startsWith("Basic ")) { | |
43 | + return false; | |
44 | + } | |
45 | + | |
46 | + // 提取base64编码的pubKeyInfo | |
47 | + String base64PubKeyInfo = authHeader.substring("Basic ".length()); | |
48 | + // 解码base64 | |
49 | + byte[] decodedBytes = Base64.getDecoder().decode(base64PubKeyInfo); | |
50 | + String pubKeyInfo = new String(decodedBytes, "UTF-8"); | |
51 | + pubKeyInfo = pubKeyInfo.replace("\\", ""); | |
52 | + | |
53 | + | |
54 | + // 分解pubKeyInfo字符串 | |
55 | + | |
56 | + JsonNode jsonObject = objectMapper.readTree(pubKeyInfo); | |
57 | + | |
58 | + int hashAlgo = jsonObject.get("hashAlgo").asInt(); | |
59 | + String pubKeyHash = jsonObject.get("pubKeyHash").asText(); | |
60 | + byte[] pubKeySign = Base64.getDecoder().decode(jsonObject.get("pubKeySign").asText()); | |
61 | + | |
62 | + // 获取公钥(此处需要替换为实际公钥获取方式) | |
63 | + PublicKey publicKey = getPublicKey(); | |
64 | + | |
65 | + // 根据hashAlgo选择摘要算法 | |
66 | + MessageDigest digest; | |
67 | + Signature verifier; | |
68 | + switch (hashAlgo) { | |
69 | + case 1: | |
70 | + digest = MessageDigest.getInstance("MD5"); | |
71 | + verifier = Signature.getInstance("MD5withRSA"); | |
72 | + break; | |
73 | + case 2: | |
74 | + digest = MessageDigest.getInstance("SHA-1"); | |
75 | + verifier = Signature.getInstance("SHA1withRSA"); | |
76 | + break; | |
77 | + case 3: | |
78 | + digest = MessageDigest.getInstance("SHA-256"); | |
79 | + verifier = Signature.getInstance("SHA256withRSA"); | |
80 | + break; | |
81 | + case 4: | |
82 | + digest = MessageDigest.getInstance("SHA-512"); | |
83 | + verifier = Signature.getInstance("SHA512withRSA"); | |
84 | + break; | |
85 | + default: | |
86 | + throw new IllegalArgumentException("Unsupported hash algorithm"); | |
87 | + } | |
88 | + | |
89 | + // 验证签名 | |
90 | + | |
91 | + verifier.initVerify(publicKey); | |
92 | + verifier.update(pubKeyHash.getBytes()); | |
93 | + boolean isSignatureValid = verifier.verify(pubKeySign); | |
94 | + | |
95 | + if (isSignatureValid) { | |
96 | + // 验证成功 | |
97 | + return true; | |
98 | + } else { | |
99 | + // 验证失败 | |
100 | + return false; | |
101 | + } | |
102 | + } catch (Exception e) { | |
103 | + log.error("解析Authorization异常", e); | |
104 | + return false; | |
105 | + } | |
106 | + } | |
107 | + | |
108 | + | |
109 | + public PublicKey getPublicKey() { | |
110 | + try { | |
111 | + // Base64解码 | |
112 | + byte[] encoded = Base64.getDecoder().decode(publickey); | |
113 | + // 生成公钥对象 | |
114 | + X509EncodedKeySpec spec = new X509EncodedKeySpec(encoded); | |
115 | + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); | |
116 | + return keyFactory.generatePublic(spec); | |
117 | + } catch (Exception e) { | |
118 | + log.error("加载公钥异常{}", publickey, e); | |
119 | + } | |
120 | + return null; | |
121 | + } | |
122 | + | |
123 | + | |
124 | + public static String generateSHA1Sign(String jsonString) { | |
125 | + try { | |
126 | + log.info("参与签名的字符串:{}", jsonString); | |
127 | + // Compute the SHA-1 hash of the JSON string | |
128 | + MessageDigest digest = MessageDigest.getInstance("SHA-1"); | |
129 | + byte[] hashBytes = digest.digest(jsonString.getBytes(StandardCharsets.UTF_8)); | |
130 | + | |
131 | + // Convert the hash bytes to a hexadecimal string | |
132 | + String hashHex = new BigInteger(1, hashBytes).toString(16); | |
133 | + | |
134 | + // Pad the hexadecimal string to ensure it is 40 characters long | |
135 | + while (hashHex.length() < 40) { | |
136 | + hashHex = "0" + hashHex; | |
137 | + } | |
138 | + | |
139 | + // Print the result | |
140 | + log.info("SHA-1 hash: " + hashHex); | |
141 | + return hashHex; | |
142 | + } catch (Exception e) { | |
143 | + log.error("生成签名异常{}", jsonString, e); | |
144 | + } | |
145 | + return null; | |
146 | + } | |
147 | + | |
148 | + | |
149 | + public static void main(String[] args) throws JsonProcessingException { | |
150 | + String a="{\\\"hashAlgo\\\": 3, \\\"pubKeyHash\\\": \\\"a1771141fc41757dd3e2876730c2e4960323f3250f91a64d3ddc30c5535a0e8d\\\", \\\"pubKeySign\\\": \\\"u5JJmfldHBpeW5a6aIvw2BSjl5NxLiZMJ0VF/WZSYNimgiSPX8KfucAm3JcVek6P/ox2BVooJlX2D7m+jdLZHO6iJVmME1aa66hLdsKwYT4fZIpXhI3HrWbe5GJkmo9x2Y/qeerG3IXwIrmAJXBmImz33tQO81gB8F7hsiDeok3AS8VNFP9e+/BvxXBYfTfGrGj06c7xTXMIN8ZHHw46nX0C2zpFuZuNumiqE1sUXv4QNSbaslED8wyqiR/KjRYpYFgk58g417BJUhSdAhREbd0+qJ+ug8o+wanQ+bCVyCiDcjzaw23tXzMs5Fa1sk6TOBapUJy5MJGWfIsvzS3IyA==\\\"}"; | |
151 | + System.out.println(Base64.getEncoder().encodeToString(a.getBytes())); | |
152 | + | |
153 | + //9585914816779ed6001e5e7fe1fa75aa92f20c26 | |
154 | + // | |
155 | + // | |
156 | + String json = "{\"msgID\":\"Q5UB0DR7IQRXQS1952LWXTULP5LTEW8IN0XPXKKENG4MRMDEMMXWNN78OX25SDJGUCH50FPDNM1KS40JZFG9PXXOZOH973QQIIUP2N5A3N619QR7W903J5SSE3HWI8VNT425WDSODPNSEVQ65YYJFCI6700ZATDK50QH4DQ41P7SSKPMJ9XQ3OGHZ9RDPJK6DJ5J12PVK4VDZQQSMRDDBCAMVRQKW2MFTGNWVXHXKVVRF9PBYABP1ZSJVXQ7BHV\",\"msgType\":1,\"IspCode\":\"CUCC\",\"OrgCode\":\"110000\",\"ReqMsgCnt\":{\"TransID\":\"GX8G5ZJG0HZV5EJ28CP2\",\"filePath\":\"/sftpbsau1/tvm_asset_sync\",\"user\":\"sftpbsau1\",\"port\":5048,\"creditType\":1,\"initDelay\":\"1分\",\"updCycle\":\"1时\",\"credit\":\"QWEuMTJJSDdQU0g3\"}}"; | |
157 | + ObjectMapper objectMapper = new ObjectMapper(); | |
158 | + objectMapper.configure(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY, false); | |
159 | + LinkedHashMap<String, Object> bigMap = objectMapper.readValue(json, TypeFactory.defaultInstance().constructMapType(LinkedHashMap.class, String.class, Object.class)); | |
160 | + | |
161 | + | |
162 | + bigMap.remove("timestamp"); | |
163 | + bigMap.remove("sign"); | |
164 | + | |
165 | + | |
166 | + String validSign = generateSHA1Sign(JSON.toJSONString(bigMap)); | |
167 | + | |
168 | + | |
169 | + if (!"2f9240fed4707d960c560f9451d3c0ad10ceb771".equals(validSign)) { | |
170 | + System.out.println("不通过"); | |
171 | + } else { | |
172 | + System.out.println("通过"); | |
173 | + } | |
174 | + } | |
175 | +} | ... | ... |
1 | +package com.idss.vulsync.utils; | |
2 | + | |
3 | + | |
4 | +import cloud.agileframework.common.util.file.FileUtil; | |
5 | +import lombok.extern.slf4j.Slf4j; | |
6 | +import org.apache.commons.fileupload.FileItem; | |
7 | +import org.apache.commons.fileupload.FileItemFactory; | |
8 | +import org.apache.commons.fileupload.disk.DiskFileItemFactory; | |
9 | +import org.apache.commons.io.IOUtils; | |
10 | +import org.springframework.http.MediaType; | |
11 | +import org.springframework.web.multipart.MultipartFile; | |
12 | +import org.springframework.web.multipart.commons.CommonsMultipartFile; | |
13 | + | |
14 | +import java.io.*; | |
15 | +import java.nio.charset.Charset; | |
16 | +import java.util.ArrayList; | |
17 | +import java.util.Enumeration; | |
18 | +import java.util.List; | |
19 | +import java.util.zip.ZipEntry; | |
20 | +import java.util.zip.ZipFile; | |
21 | +import java.util.zip.ZipInputStream; | |
22 | +import java.util.zip.ZipOutputStream; | |
23 | + | |
24 | +@Slf4j | |
25 | +public class MultipartFileToFile { | |
26 | + /** | |
27 | + * MultipartFile 转 File | |
28 | + * | |
29 | + * @param file | |
30 | + * @throws Exception | |
31 | + */ | |
32 | + public static File multipartFileToFile(MultipartFile file) throws Exception { | |
33 | + | |
34 | + File toFile = null; | |
35 | + if (file.equals("") || file.getSize() <= 0) { | |
36 | + file = null; | |
37 | + } else { | |
38 | + InputStream ins = null; | |
39 | + ins = file.getInputStream(); | |
40 | + toFile = new File(file.getOriginalFilename()); | |
41 | + inputStreamToFile(ins, toFile); | |
42 | + ins.close(); | |
43 | + } | |
44 | + return toFile; | |
45 | + } | |
46 | + | |
47 | + /** | |
48 | + * MultipartFile 转 File | |
49 | + * | |
50 | + * @param file | |
51 | + * @throws Exception | |
52 | + */ | |
53 | + public static File multipartFileToFile(MultipartFile file, String rename) throws Exception { | |
54 | + | |
55 | + File toFile = null; | |
56 | + if (file.equals("") || file.getSize() <= 0) { | |
57 | + file = null; | |
58 | + } else { | |
59 | + InputStream ins = null; | |
60 | + ins = file.getInputStream(); | |
61 | + toFile = new File(rename); | |
62 | + inputStreamToFile(ins, toFile); | |
63 | + ins.close(); | |
64 | + } | |
65 | + return toFile; | |
66 | + } | |
67 | + | |
68 | + /** | |
69 | + * MultipartFile 转 File | |
70 | + * | |
71 | + * @param file | |
72 | + * @throws Exception | |
73 | + */ | |
74 | + public static File multipartFileToFile(MultipartFile file, String path, String rename) throws Exception { | |
75 | + | |
76 | + File toFile = null; | |
77 | + if (file.equals("") || file.getSize() <= 0) { | |
78 | + file = null; | |
79 | + } else { | |
80 | + isFileDir(path + "/"); | |
81 | + InputStream ins = null; | |
82 | + ins = file.getInputStream(); | |
83 | + toFile = new File(path + "/" + rename); | |
84 | + inputStreamToFile(ins, toFile); | |
85 | + ins.close(); | |
86 | + } | |
87 | + return toFile; | |
88 | + } | |
89 | + | |
90 | + public static void isFileDir(String path) { | |
91 | + String osName = System.getProperty("os.name"); | |
92 | + //兼容 linux 系统 | |
93 | + if (osName.toLowerCase().startsWith("win")) { | |
94 | + path = path.replaceAll("/", "\\\\"); | |
95 | + } | |
96 | + //判断路径是否存在 | |
97 | + File filePath = new File(path); | |
98 | + if (!filePath.exists()) { | |
99 | + //不存在,创建目录 | |
100 | + filePath.mkdirs(); | |
101 | + } | |
102 | + | |
103 | + } | |
104 | + | |
105 | + //获取流文件 | |
106 | + public static void inputStreamToFile(InputStream ins, File file) { | |
107 | + try { | |
108 | + OutputStream os = new FileOutputStream(file); | |
109 | + int bytesRead = 0; | |
110 | + byte[] buffer = new byte[8192]; | |
111 | + while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { | |
112 | + os.write(buffer, 0, bytesRead); | |
113 | + } | |
114 | + os.close(); | |
115 | + ins.close(); | |
116 | + } catch (Exception e) { | |
117 | + e.printStackTrace(); | |
118 | + } | |
119 | + } | |
120 | + | |
121 | + /** | |
122 | + * 删除本地临时文件 | |
123 | + * | |
124 | + * @param file | |
125 | + */ | |
126 | + public static void deleteTempFile(File file) { | |
127 | + if (file != null) { | |
128 | + File del = new File(file.toURI()); | |
129 | + del.delete(); | |
130 | + } | |
131 | + } | |
132 | + | |
133 | + /** | |
134 | + * 删除本地临时文件 | |
135 | + * | |
136 | + * @param multipartFile | |
137 | + */ | |
138 | + public static void deleteTempFile(MultipartFile multipartFile) { | |
139 | + try { | |
140 | + File file = multipartFileToFile(multipartFile); | |
141 | + if (file != null) { | |
142 | + File del = new File(file.toURI()); | |
143 | + del.delete(); | |
144 | + } | |
145 | + } catch (Exception e) { | |
146 | + e.printStackTrace(); | |
147 | + } | |
148 | + } | |
149 | + | |
150 | + /** | |
151 | + * 将zip文件解压成file集 | |
152 | + * | |
153 | + * @param multipartFile | |
154 | + * @return | |
155 | + * @throws IOException | |
156 | + */ | |
157 | + public static List<MultipartFile> zipToFiles(MultipartFile multipartFile) { | |
158 | + //获取文件输入流 | |
159 | + InputStream input = null; | |
160 | + ZipInputStream zipInputStream = null; | |
161 | + try { | |
162 | + input = multipartFile.getInputStream(); | |
163 | + //获取ZIP输入流(一定要指定字符集Charset.forName("GBK")否则会报java.lang.IllegalArgumentException: MALFORMED) | |
164 | + zipInputStream = new ZipInputStream(new BufferedInputStream(input), Charset.forName("GBK")); | |
165 | + ZipFile zf = toFile(multipartFile); | |
166 | + //定义ZipEntry置为null,避免由于重复调用zipInputStream.getNextEntry造成的不必要的问题 | |
167 | + ZipEntry ze = null; | |
168 | + List<MultipartFile> list = new ArrayList<>(); | |
169 | + //循环遍历 | |
170 | + while ((ze = zipInputStream.getNextEntry()) != null) { | |
171 | + InputStream is = zf.getInputStream(ze); | |
172 | + MultipartFile file = getMultipartFile(is, ze.getName()); | |
173 | + list.add(file); | |
174 | + } | |
175 | + //一定记得关闭流 | |
176 | + zipInputStream.closeEntry(); | |
177 | + input.close(); | |
178 | + return list; | |
179 | + } catch (Exception e) { | |
180 | + try { | |
181 | + zipInputStream.closeEntry(); | |
182 | + input.close(); | |
183 | + } catch (IOException ex) { | |
184 | + ex.printStackTrace(); | |
185 | + } | |
186 | + } | |
187 | + return null; | |
188 | + } | |
189 | + | |
190 | + public static List<MultipartFile> zipParse(InputStream input) { | |
191 | + ZipInputStream zipInputStream = null; | |
192 | + try { | |
193 | + //将包含压缩包信息的字节数组转化为zipInputStream | |
194 | + zipInputStream = new ZipInputStream(new BufferedInputStream(input), Charset.forName("GBK")); | |
195 | + ZipEntry ze = null; | |
196 | + List<MultipartFile> list = new ArrayList<>(); | |
197 | + while ((ze = zipInputStream.getNextEntry()) != null) { | |
198 | + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); | |
199 | + IOUtils.copy(zipInputStream, byteOut); | |
200 | + InputStream inputStream = new ByteArrayInputStream(byteOut.toByteArray()); | |
201 | + MultipartFile mFile = getMultipartFile(inputStream, ze.getName()); | |
202 | + list.add(mFile); | |
203 | + byteOut.close(); | |
204 | + inputStream.close(); | |
205 | + } | |
206 | + zipInputStream.closeEntry(); | |
207 | + input.close(); | |
208 | + return list; | |
209 | + } catch (Exception e) { | |
210 | + try { | |
211 | + zipInputStream.closeEntry(); | |
212 | + input.close(); | |
213 | + } catch (IOException ex) { | |
214 | + ex.printStackTrace(); | |
215 | + } | |
216 | + } | |
217 | + return null; | |
218 | + } | |
219 | + | |
220 | + /** | |
221 | + * 获取封装得MultipartFile | |
222 | + * | |
223 | + * @param inputStream inputStream | |
224 | + * @param fileName fileName | |
225 | + * @return MultipartFile | |
226 | + */ | |
227 | + public static MultipartFile getMultipartFile(InputStream inputStream, String fileName) { | |
228 | + FileItem fileItem = createFileItem(inputStream, fileName); | |
229 | + //CommonsMultipartFile是feign对multipartFile的封装,但是要FileItem类对象 | |
230 | + return new CommonsMultipartFile(fileItem); | |
231 | + } | |
232 | + | |
233 | + | |
234 | + /** | |
235 | + * FileItem类对象创建 | |
236 | + * | |
237 | + * @param inputStream inputStream | |
238 | + * @param fileName fileName | |
239 | + * @return FileItem | |
240 | + */ | |
241 | + public static FileItem createFileItem(InputStream inputStream, String fileName) { | |
242 | + FileItemFactory factory = new DiskFileItemFactory(16, null); | |
243 | + String textFieldName = "file"; | |
244 | + FileItem item = factory.createItem(textFieldName, MediaType.MULTIPART_FORM_DATA_VALUE, true, fileName); | |
245 | + int bytesRead = 0; | |
246 | + byte[] buffer = new byte[8192]; | |
247 | + OutputStream os = null; | |
248 | + //使用输出流输出输入流的字节 | |
249 | + try { | |
250 | + os = item.getOutputStream(); | |
251 | + while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) { | |
252 | + os.write(buffer, 0, bytesRead); | |
253 | + } | |
254 | + inputStream.close(); | |
255 | + } catch (IOException e) { | |
256 | + | |
257 | + throw new IllegalArgumentException("文件上传失败"); | |
258 | + } finally { | |
259 | + if (os != null) { | |
260 | + try { | |
261 | + os.close(); | |
262 | + } catch (IOException e) { | |
263 | + | |
264 | + } | |
265 | + } | |
266 | + if (inputStream != null) { | |
267 | + try { | |
268 | + inputStream.close(); | |
269 | + } catch (IOException e) { | |
270 | + } | |
271 | + } | |
272 | + } | |
273 | + | |
274 | + return item; | |
275 | + } | |
276 | + | |
277 | + private static ZipFile toFile(MultipartFile multipartFile) throws Exception { | |
278 | + if (multipartFile == null || multipartFile.getSize() <= 0) { | |
279 | + return null; | |
280 | + } | |
281 | + File file = multipartFileToFile(multipartFile); | |
282 | + if (file == null || !file.exists()) { | |
283 | + return null; | |
284 | + } | |
285 | + ZipFile zipFile = new ZipFile(file, Charset.forName("GBK")); | |
286 | + return zipFile; | |
287 | + } | |
288 | + | |
289 | + | |
290 | + /** | |
291 | + * 文件内容写入文件 | |
292 | + * | |
293 | + * @param zipFileName 文件名不含序号 | |
294 | + */ | |
295 | + public static void writeToFile(File contentLogFile,String zipDir, String zipFileName) { | |
296 | + //创建文件集合 | |
297 | + List<File> fileList = new ArrayList<>(); | |
298 | + fileList.add(contentLogFile); | |
299 | + try { | |
300 | + //压缩文件 | |
301 | + FileUtil.createZip(fileList, zipDir, zipFileName); | |
302 | + } catch (Exception e) { | |
303 | + log.error("压缩文件失败", e); | |
304 | + } | |
305 | + } | |
306 | + | |
307 | + public static List<String> splitZip(String zipDir,String zipName, int chunkSize, String outputDirectory) throws IOException { | |
308 | + List<String> zipNameList=new ArrayList<>(); | |
309 | + String inputZip=zipDir+"/"+zipName; | |
310 | + try (ZipFile zipFile = new ZipFile(inputZip+".zip")) { | |
311 | + Enumeration<? extends ZipEntry> entries = zipFile.entries(); | |
312 | + int partNumber = 1; | |
313 | + int currentSize = 0; | |
314 | + ZipOutputStream zos = null; | |
315 | + FileOutputStream fos = null; | |
316 | + | |
317 | + while (entries.hasMoreElements()) { | |
318 | + ZipEntry entry = entries.nextElement(); | |
319 | + if (zos == null || currentSize >= chunkSize) { | |
320 | + if (zos != null) { | |
321 | + zos.close(); | |
322 | + } | |
323 | + String partFileName = getPartFileName(zipName, partNumber++,outputDirectory); | |
324 | + fos = new FileOutputStream(partFileName); | |
325 | + zos = new ZipOutputStream(fos); | |
326 | + currentSize = 0; | |
327 | + zipNameList.add(partFileName); | |
328 | + } | |
329 | + | |
330 | + zos.putNextEntry(new ZipEntry(entry.getName())); | |
331 | + try (InputStream is = zipFile.getInputStream(entry)) { | |
332 | + byte[] buffer = new byte[1024]; | |
333 | + int len; | |
334 | + while ((len = is.read(buffer)) > 0) { | |
335 | + zos.write(buffer, 0, len); | |
336 | + currentSize += len; | |
337 | + } | |
338 | + } | |
339 | + zos.closeEntry(); | |
340 | + } | |
341 | + | |
342 | + if (zos != null) { | |
343 | + zos.close(); | |
344 | + } | |
345 | + } | |
346 | + return zipNameList; | |
347 | + } | |
348 | + | |
349 | + private static String getPartFileName(String zipName, int partNumber,String outputDirectory) { | |
350 | + return outputDirectory+File.separator+zipName+"_"+String.format("%04d", partNumber)+".zip"; | |
351 | + } | |
352 | + | |
353 | +} | ... | ... |
1 | +package com.idss.vulsync.utils; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSON; | |
4 | +import lombok.extern.slf4j.Slf4j; | |
5 | +import org.apache.commons.lang3.StringUtils; | |
6 | +import org.springframework.beans.factory.annotation.Autowired; | |
7 | +import org.springframework.data.redis.core.RedisTemplate; | |
8 | +import org.springframework.stereotype.Component; | |
9 | +import org.springframework.util.CollectionUtils; | |
10 | + | |
11 | +import java.util.Map; | |
12 | +import java.util.Set; | |
13 | +import java.util.concurrent.TimeUnit; | |
14 | + | |
15 | +@Slf4j | |
16 | +@Component | |
17 | +public class RedisUtil { | |
18 | + @Autowired | |
19 | + private RedisTemplate redisTemplate; | |
20 | + | |
21 | + | |
22 | + /** | |
23 | + * 查询键 | |
24 | + * | |
25 | + * @param key 键 支持ant | |
26 | + * @return Set | |
27 | + */ | |
28 | + public Set<String> keys(String key) { | |
29 | + return redisTemplate.keys(key); | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * 判断key是否存在 | |
34 | + * | |
35 | + * @param key 键 | |
36 | + * @return true 存在 false不存在 | |
37 | + */ | |
38 | + public boolean hasKey(String key) { | |
39 | + return redisTemplate.hasKey(key); | |
40 | + } | |
41 | + | |
42 | + /** | |
43 | + * 删除缓存 | |
44 | + * | |
45 | + * @param key 可以传一个值 或多个 | |
46 | + */ | |
47 | + public void del(String... key) { | |
48 | + if (key != null && key.length > 0) { | |
49 | + boolean delete; | |
50 | + if (key.length == 1) { | |
51 | + delete = redisTemplate.delete(key[0]); | |
52 | + } else { | |
53 | + delete = 0L < redisTemplate.delete(CollectionUtils.arrayToList(key)); | |
54 | + } | |
55 | + log.info("@@@@@ del处理key值为{},结果delete信息为:{}", JSON.toJSONString(key), delete); | |
56 | + } | |
57 | + } | |
58 | + | |
59 | + /** | |
60 | + * 普通缓存获取 | |
61 | + * | |
62 | + * @param key 键 | |
63 | + * @return 值 | |
64 | + */ | |
65 | + public Object get(String key) { | |
66 | + return key == null ? null : redisTemplate.opsForValue().get(key); | |
67 | + } | |
68 | + | |
69 | + /** | |
70 | + * 普通缓存放入 | |
71 | + * | |
72 | + * @param key 键 | |
73 | + * @param value 值 | |
74 | + */ | |
75 | + public void set(String key, Object value) { | |
76 | + redisTemplate.opsForValue().set(key, value); | |
77 | + } | |
78 | + | |
79 | + /** | |
80 | + * 普通缓存放入并设置时间 | |
81 | + * | |
82 | + * @param key 键 | |
83 | + * @param value 值 | |
84 | + * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 | |
85 | + */ | |
86 | + public void set(String key, Object value, TimeUnit timeUnit, long time) { | |
87 | + if (time > 0) { | |
88 | + redisTemplate.opsForValue().set(key, value, time, timeUnit); | |
89 | + } else { | |
90 | + set(key, value); | |
91 | + } | |
92 | + } | |
93 | + | |
94 | + /** | |
95 | + * 普通缓存放入并设置时间(带返回值) | |
96 | + * | |
97 | + * @param key key | |
98 | + * @param value value | |
99 | + * @param timeUnit timeUnit | |
100 | + * @param time time | |
101 | + * @return boolean | |
102 | + */ | |
103 | + public boolean setIfAbsent(String key, Object value, TimeUnit timeUnit, long time) { | |
104 | + return redisTemplate.opsForValue().setIfAbsent(key, value, time, timeUnit); | |
105 | + } | |
106 | + | |
107 | + /** | |
108 | + * 加锁(单次获取) | |
109 | + * | |
110 | + * @param lockKey lockKey | |
111 | + * @param lockValue lockValue | |
112 | + * @param expireTime expireTime | |
113 | + * @return boolean | |
114 | + */ | |
115 | + public boolean tryLockSingle(String lockKey, String lockValue, long expireTime) { | |
116 | + //SET命令返回true时,则证明加锁成功,设置超时时间间隔,默认超时时间单位为分钟 | |
117 | + return setIfAbsent(lockKey, lockValue, TimeUnit.MINUTES, expireTime); | |
118 | + } | |
119 | + | |
120 | + /** | |
121 | + * 加锁,无阻塞 | |
122 | + * | |
123 | + * @param lockKey lockKey | |
124 | + * @param lockValue lockValue | |
125 | + * @param expireTime expireTime | |
126 | + * @return boolean | |
127 | + */ | |
128 | + public boolean tryLock(String lockKey, String lockValue, long expireTime) throws InterruptedException { | |
129 | + while (true) { | |
130 | + String threadName = Thread.currentThread().getName(); | |
131 | + //SET命令返回true时,则证明加锁成功,设置超时时间间隔,默认超时时间单位为分钟 | |
132 | + boolean isExistFlag = setIfAbsent(lockKey, lockValue, TimeUnit.MINUTES, expireTime); | |
133 | + if (isExistFlag) { | |
134 | + log.info("@@@@@ 进程ID为[{}],加锁成功!", threadName); | |
135 | + return true; | |
136 | + } else { | |
137 | + log.info("@@@@@ 进程ID为[{}],加锁失败!500毫秒后继续尝试加锁!", threadName); | |
138 | + //睡100毫秒继续尝试加锁 | |
139 | + TimeUnit.MILLISECONDS.sleep(500); | |
140 | + } | |
141 | + } | |
142 | + } | |
143 | + | |
144 | + /** | |
145 | + * 解锁处理 | |
146 | + * | |
147 | + * @param lockKey lockKey | |
148 | + * @param lockValue lockValue | |
149 | + */ | |
150 | + public void unLock(String lockKey, String lockValue) { | |
151 | + String threadName = Thread.currentThread().getName(); | |
152 | + try { | |
153 | + log.info("@@@@@ 进程ID为[{}]准备unLock处理lockKey值为:{},lockValue值为:{}", threadName, lockKey, lockValue); | |
154 | + String currentValue = (String) get(lockKey); | |
155 | + log.info("@@@@@ 进程ID为[{}]准备unLock处理currentValue值为:{}", threadName, currentValue); | |
156 | + if (StringUtils.isNotEmpty(currentValue) && currentValue.equals(lockValue)) { | |
157 | + del(lockKey); | |
158 | + } | |
159 | + } catch (Exception e) { | |
160 | + log.error("@@@@@ 进程ID为[{}],unLock处理失败!异常信息为:{}", threadName, e.getMessage(), e); | |
161 | + } | |
162 | + } | |
163 | + | |
164 | + /** | |
165 | + * 获取hashKey对应的所有键值 | |
166 | + * | |
167 | + * @param key 键 | |
168 | + * @return 对应的多个键值 | |
169 | + */ | |
170 | + public Map<String, String> getHashMap(String key) { | |
171 | + return redisTemplate.opsForHash().entries(key); | |
172 | + } | |
173 | +} | ... | ... |
1 | +package com.idss.vulsync.utils; | |
2 | + | |
3 | +import java.io.FileWriter; | |
4 | +import java.io.IOException; | |
5 | +import java.security.Key; | |
6 | +import java.security.KeyPair; | |
7 | +import java.security.KeyPairGenerator; | |
8 | +import java.util.Base64; | |
9 | + | |
10 | +/** | |
11 | + * @Author: zc | |
12 | + * @Date: 2024/8/29 15:51 | |
13 | + */ | |
14 | +public class RsaUtils { | |
15 | + public static void main(String[] args) throws Exception { | |
16 | + generateRSAPemKeyFiles(); | |
17 | + } | |
18 | + | |
19 | + /** | |
20 | + * 生成RSA pem格式的公私钥文件 | |
21 | + * | |
22 | + * @throws Exception | |
23 | + */ | |
24 | + private static void generateRSAPemKeyFiles() throws Exception { | |
25 | + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); | |
26 | + keyPairGenerator.initialize(4096); | |
27 | + KeyPair keyPair = keyPairGenerator.generateKeyPair(); | |
28 | + | |
29 | + savePrivatePemFile(keyPair.getPrivate(), "E:\\工作\\资管探针\\idss\\打包\\测试141\\北京联通\\漏管对接\\资管侧接口程序密钥\\private_key.pem"); | |
30 | + savePublicPemFile(keyPair.getPublic(), "E:\\工作\\资管探针\\idss\\打包\\测试141\\北京联通\\漏管对接\\资管侧接口程序密钥\\public_key.pem"); | |
31 | + } | |
32 | + | |
33 | + private static void savePrivatePemFile(Key key, String filename) | |
34 | + throws IOException { | |
35 | + String encoded = Base64.getEncoder().encodeToString(key.getEncoded()); | |
36 | + | |
37 | + FileWriter fileWriter = null; | |
38 | + try { | |
39 | + fileWriter = new FileWriter(filename); | |
40 | + fileWriter.write("-----BEGIN PRIVATE KEY-----\n"); | |
41 | + fileWriter.write(encoded); | |
42 | + fileWriter.write("\n-----END PRIVATE KEY-----"); | |
43 | + } finally { | |
44 | + if (null != fileWriter) { | |
45 | + fileWriter.close(); | |
46 | + } | |
47 | + } | |
48 | + } | |
49 | + | |
50 | + private static void savePublicPemFile(Key key, String filename) | |
51 | + throws IOException { | |
52 | + String encoded = Base64.getEncoder().encodeToString(key.getEncoded()); | |
53 | + | |
54 | + FileWriter fileWriter = null; | |
55 | + try { | |
56 | + fileWriter = new FileWriter(filename); | |
57 | + fileWriter.write("-----BEGIN PUBLIC KEY-----\n"); | |
58 | + fileWriter.write(encoded); | |
59 | + fileWriter.write("\n-----END PUBLIC KEY-----"); | |
60 | + } finally { | |
61 | + if (null != fileWriter) { | |
62 | + fileWriter.close(); | |
63 | + } | |
64 | + } | |
65 | + } | |
66 | + | |
67 | +} | ... | ... |
1 | +package com.idss.vulsync.utils; | |
2 | +import cn.hutool.core.util.ObjectUtil; | |
3 | +import com.jcraft.jsch.*; | |
4 | +import lombok.extern.slf4j.Slf4j; | |
5 | +import org.apache.commons.io.IOUtils; | |
6 | + | |
7 | +import java.io.*; | |
8 | +import java.util.Vector; | |
9 | + | |
10 | +/** | |
11 | + * FTP服务器工具类: | |
12 | + * JSch类 通过 SFTP 协议上传文件到 freeSSHd 服务器 | |
13 | + * | |
14 | + */ | |
15 | +@Slf4j | |
16 | +public class SftpUtil { | |
17 | + | |
18 | + private ChannelSftp sftp; | |
19 | + | |
20 | + private Session session; | |
21 | + | |
22 | + /** | |
23 | + * 用户名 | |
24 | + */ | |
25 | + private String username; | |
26 | + | |
27 | + /** | |
28 | + * 密码 | |
29 | + */ | |
30 | + private String password; | |
31 | + | |
32 | + /** | |
33 | + * 秘钥 | |
34 | + */ | |
35 | + private String privateKey; | |
36 | + | |
37 | + /** | |
38 | + * FTP服务器Ip | |
39 | + */ | |
40 | + private String host; | |
41 | + | |
42 | + /** | |
43 | + * FTP服务器端口号 | |
44 | + */ | |
45 | + private int port; | |
46 | + | |
47 | + /** | |
48 | + * 构造器:基于密码认证sftp对象 | |
49 | + * @param username 用户名 | |
50 | + * @param password 密码 | |
51 | + * @param host 服务器ip | |
52 | + * @param port 服务器端口号 | |
53 | + */ | |
54 | + public SftpUtil(String username, String password, String host, int port){ | |
55 | + this.username = username; | |
56 | + this.password = password; | |
57 | + this.host = host; | |
58 | + this.port = port; | |
59 | + } | |
60 | + | |
61 | + /** | |
62 | + * 构造器:基于秘钥认证sftp对象 | |
63 | + * @param username 用户名 | |
64 | + * @param privateKey 秘钥 | |
65 | + * @param host 服务器ip | |
66 | + * @param port 服务器端口号 | |
67 | + */ | |
68 | + public SftpUtil(String username, String privateKey, int port, String host){ | |
69 | + this.username = username; | |
70 | + this.privateKey = privateKey; | |
71 | + this.host = host; | |
72 | + this.port = port; | |
73 | + } | |
74 | + | |
75 | + /** | |
76 | + * 连接SFTP服务器 | |
77 | + */ | |
78 | + public boolean login(){ | |
79 | + JSch jsch = new JSch(); | |
80 | + try{ | |
81 | + if(privateKey != null){ | |
82 | + //设置登陆主机的秘钥 | |
83 | + jsch.addIdentity(privateKey); | |
84 | + } | |
85 | + //采用指定的端口连接服务器 | |
86 | + session = jsch.getSession(username,host,port); | |
87 | + if(password != null){ | |
88 | + //设置登陆主机的密码 | |
89 | + session.setPassword(password); | |
90 | + } | |
91 | + //优先使用 password 验证 注:session.connect()性能低,使用password验证可跳过gssapi认证,提升连接服务器速度 | |
92 | + session.setConfig("PreferredAuthentications","password"); | |
93 | + //设置第一次登陆的时候提示,可选值:(ask | yes | no) | |
94 | + session.setConfig("StrictHostKeyChecking","no"); | |
95 | + session.connect(); | |
96 | + //创建sftp通信通道 | |
97 | + Channel channel = session.openChannel("sftp"); | |
98 | + channel.connect(); | |
99 | + sftp = (ChannelSftp) channel; | |
100 | + log.info("sftp server connect success !!"); | |
101 | + }catch (JSchException e){ | |
102 | + log.error("SFTP服务器连接异常!!", e); | |
103 | + return false; | |
104 | + } | |
105 | + return true; | |
106 | + } | |
107 | + | |
108 | + /** | |
109 | + * 关闭SFTP连接 | |
110 | + */ | |
111 | + public void logout(){ | |
112 | + if(sftp != null){ | |
113 | + if(sftp.isConnected()){ | |
114 | + sftp.disconnect(); | |
115 | + log.info("sftp is close already"); | |
116 | + } | |
117 | + } | |
118 | + if(session != null){ | |
119 | + if(session.isConnected()){ | |
120 | + session.disconnect(); | |
121 | + log.info("session is close already"); | |
122 | + } | |
123 | + } | |
124 | + } | |
125 | + | |
126 | + /** | |
127 | + * 将输入流上传到SFTP服务器,作为文件 | |
128 | + * | |
129 | + * @param directory 上传到SFTP服务器的路径 | |
130 | + * @param sftpFileName 上传到SFTP服务器后的文件名 | |
131 | + * @param input 输入流 | |
132 | + * @throws SftpException | |
133 | + */ | |
134 | + public void upload(String directory, String sftpFileName, InputStream input) throws SftpException { | |
135 | + long start = System.currentTimeMillis(); | |
136 | + try{ | |
137 | + //如果文件夹不存在,则创建文件夹 | |
138 | + if(sftp.ls(directory) == null){ | |
139 | + sftp.mkdir(directory); | |
140 | + } | |
141 | + //切换到指定文件夹 | |
142 | + sftp.cd(directory); | |
143 | + }catch (SftpException e){ | |
144 | + //创建不存在的文件夹,并切换到文件夹 | |
145 | + sftp.mkdir(directory); | |
146 | + sftp.cd(directory); | |
147 | + } | |
148 | + sftp.put(input, sftpFileName+".tmp"); | |
149 | + sftp.rename(sftpFileName+".tmp", sftpFileName); | |
150 | + log.info("文件上传成功!! 耗时:{}ms",(System.currentTimeMillis() - start)); | |
151 | + } | |
152 | + | |
153 | + /** | |
154 | + * 上传单个文件 | |
155 | + * | |
156 | + * @param directory 上传到SFTP服务器的路径 | |
157 | + * @param uploadFileUrl 文件路径 | |
158 | + */ | |
159 | + public void upload(String directory, String uploadFileUrl){ | |
160 | + File file = new File(uploadFileUrl); | |
161 | + try{ | |
162 | + upload(directory, file.getName(), new FileInputStream(file)); | |
163 | + }catch (FileNotFoundException | SftpException e){ | |
164 | + log.error("上传文件异常!", e); | |
165 | + } | |
166 | + } | |
167 | + | |
168 | + /** | |
169 | + * 上传单个文件,自定义名称 | |
170 | + * | |
171 | + * @param directory 上传到SFTP服务器的路径 | |
172 | + * @param uploadFileUrl 文件路径 | |
173 | + */ | |
174 | + public void upload(String directory,String fileName, String uploadFileUrl){ | |
175 | + File file = new File(uploadFileUrl); | |
176 | + if(ObjectUtil.isEmpty(fileName)){ | |
177 | + fileName=file.getName(); | |
178 | + } | |
179 | + try{ | |
180 | + upload(directory, fileName, new FileInputStream(file)); | |
181 | + }catch (FileNotFoundException | SftpException e){ | |
182 | + log.error("上传文件异常!", e); | |
183 | + } | |
184 | + } | |
185 | + | |
186 | + /** | |
187 | + * 将byte[] 上传到SFTP服务器,作为文件 | |
188 | + * 注: 从String转换成byte[] 需要指定字符集 | |
189 | + * | |
190 | + * @param directory 上传到SFTP服务器的路径 | |
191 | + * @param sftpFileName 上传SFTP服务器后的文件名 | |
192 | + * @param bytes 字节数组 | |
193 | + */ | |
194 | + public void upload(String directory, String sftpFileName, byte[] bytes){ | |
195 | + try{ | |
196 | + upload(directory, sftpFileName, new ByteArrayInputStream(bytes)); | |
197 | + }catch (SftpException e){ | |
198 | + log.error("上传文件异常!", e); | |
199 | + } | |
200 | + } | |
201 | + | |
202 | + /** | |
203 | + * 将字符串按照指定编码格式上传到SFTP服务器 | |
204 | + * | |
205 | + * @param directory 上传到SFTP服务器的路径 | |
206 | + * @param sftpFileName 上传SFTP服务器后的文件名 | |
207 | + * @param dataStr 字符串 | |
208 | + * @param charsetName 字符串的编码格式 | |
209 | + */ | |
210 | + public void upload(String directory, String sftpFileName, String dataStr, String charsetName){ | |
211 | + try{ | |
212 | + upload(directory, sftpFileName, new ByteArrayInputStream(dataStr.getBytes(charsetName))); | |
213 | + }catch (UnsupportedEncodingException | SftpException e){ | |
214 | + log.error("上传文件异常!", e); | |
215 | + } | |
216 | + } | |
217 | + | |
218 | + /** | |
219 | + * 下载文件 | |
220 | + * | |
221 | + * @param directory SFTP服务器的文件路径 | |
222 | + * @param downloadFile SFTP服务器上的文件名 | |
223 | + * @param saveFile 保存到本地路径 | |
224 | + */ | |
225 | + public void download(String directory, String downloadFile, String saveFile){ | |
226 | + try{ | |
227 | + if(directory != null && !"".equals(directory)){ | |
228 | + sftp.cd(directory); | |
229 | + } | |
230 | + File file = new File(saveFile); | |
231 | + sftp.get(downloadFile, new FileOutputStream(file)); | |
232 | + }catch (SftpException | FileNotFoundException e){ | |
233 | + log.error("文件下载异常!", e); | |
234 | + } | |
235 | + } | |
236 | + | |
237 | + /** | |
238 | + * 下载文件 | |
239 | + * | |
240 | + * @param directory SFTP服务器的文件路径 | |
241 | + * @param downloadFile SFTP服务器上的文件名 | |
242 | + * @return 字节数组 | |
243 | + */ | |
244 | + public byte[] download(String directory, String downloadFile){ | |
245 | + try{ | |
246 | + if(directory != null && !"".equals(directory)){ | |
247 | + sftp.cd(directory); | |
248 | + } | |
249 | + InputStream inputStream = sftp.get(downloadFile); | |
250 | + return IOUtils.toByteArray(inputStream); | |
251 | + }catch (SftpException | IOException e){ | |
252 | + log.error("文件下载异常!", e); | |
253 | + } | |
254 | + return null; | |
255 | + } | |
256 | + | |
257 | + /** | |
258 | + * 下载文件 | |
259 | + * | |
260 | + * @param directory SFTP服务器的文件路径 | |
261 | + * @param downloadFile SFTP服务器上的文件名 | |
262 | + * @return 输入流 | |
263 | + */ | |
264 | + public InputStream downloadStream(String directory, String downloadFile){ | |
265 | + try{ | |
266 | + if(directory != null && !"".equals(directory)){ | |
267 | + sftp.cd(directory); | |
268 | + } | |
269 | + return sftp.get(downloadFile); | |
270 | + }catch (SftpException e){ | |
271 | + log.error("文件下载异常!", e); | |
272 | + } | |
273 | + return null; | |
274 | + } | |
275 | + | |
276 | +// /** | |
277 | +// * 删除文件 | |
278 | +// * | |
279 | +// * @param directory SFTP服务器的文件路径 | |
280 | +// * @param deleteFileName 删除的文件名称 | |
281 | +// */ | |
282 | +// public void delete(String directory, String deleteFileName){ | |
283 | +// try{ | |
284 | +// sftp.cd(directory); | |
285 | +// sftp.rm(deleteFileName); | |
286 | +// }catch (SftpException e){ | |
287 | +// log.error("文件删除异常!", e); | |
288 | +// } | |
289 | +// } | |
290 | +// | |
291 | +// /** | |
292 | +// * 删除文件夹(有问题:remove(0)不一定删除的是上级目录和根目录) | |
293 | +// * | |
294 | +// * @param directory SFTP服务器的文件路径 | |
295 | +// */ | |
296 | +// public void delete(String directory){ | |
297 | +// Vector vector = listFiles(directory); | |
298 | +// vector.remove(0); | |
299 | +// vector.remove(0); | |
300 | +// for(Object v : vector){ | |
301 | +// ChannelSftp.LsEntry lsEntry = (ChannelSftp.LsEntry)v; | |
302 | +// try{ | |
303 | +// sftp.cd(directory); | |
304 | +// sftp.rm(lsEntry.getFilename()); | |
305 | +// }catch (SftpException e){ | |
306 | +// log.error("文件删除异常!", e); | |
307 | +// } | |
308 | +// } | |
309 | +// } | |
310 | + | |
311 | + /** | |
312 | + * 获取文件夹下的文件 | |
313 | + * | |
314 | + * @param directory 路径 | |
315 | + * @return | |
316 | + */ | |
317 | + public Vector<?> listFiles(String directory){ | |
318 | + try{ | |
319 | + if(isDirExist(directory)){ | |
320 | + Vector<?> vector = sftp.ls(directory); | |
321 | +// //移除上级目录和根目录:"." ".." | |
322 | +// vector.remove(0); //不适用 | |
323 | +// vector.remove(0); | |
324 | + | |
325 | +// for (Object object : vector) { | |
326 | +// if (object instanceof ChannelSftp.LsEntry) { | |
327 | +// ChannelSftp.LsEntry lsEntry = (ChannelSftp.LsEntry) object; | |
328 | +// String fileName = lsEntry.getFilename(); | |
329 | +// if (StringUtils.equals(fileName,".")||StringUtils.equals(fileName,"..")) { | |
330 | +// vector.remove(object); | |
331 | +// } | |
332 | +// } | |
333 | +// } | |
334 | + return vector; | |
335 | + } | |
336 | + }catch (SftpException e){ | |
337 | + log.error("获取文件夹信息异常!", e); | |
338 | + } | |
339 | + return null; | |
340 | + } | |
341 | + | |
342 | + /** | |
343 | + * 检测文件夹是否存在 | |
344 | + * | |
345 | + * @param directory 路径 | |
346 | + * @return | |
347 | + */ | |
348 | + public boolean booleanUrl(String directory){ | |
349 | + try{ | |
350 | + if(sftp.ls(directory) == null){ | |
351 | + return false; | |
352 | + } | |
353 | + }catch (Exception e){ | |
354 | + log.error("检测文件夹异常!", e); | |
355 | + } | |
356 | + return true; | |
357 | + } | |
358 | + | |
359 | + /** | |
360 | + * 创建一个文件目录 | |
361 | + * | |
362 | + * @param createpath 路径 | |
363 | + * @return | |
364 | + */ | |
365 | + public boolean createDir(String createpath) { | |
366 | + try { | |
367 | + if (isDirExist(createpath)) { | |
368 | + this.sftp.cd(createpath); | |
369 | + return true; | |
370 | + } | |
371 | + String pathArry[] = createpath.split("/"); | |
372 | + StringBuffer filePath = new StringBuffer("/"); | |
373 | + for (String path : pathArry) { | |
374 | + if (path.equals("")) { | |
375 | + continue; | |
376 | + } | |
377 | + filePath.append(path + "/"); | |
378 | + if (isDirExist(filePath.toString())) { | |
379 | + sftp.cd(filePath.toString()); | |
380 | + } else { | |
381 | + // 建立目录 | |
382 | + sftp.mkdir(filePath.toString()); | |
383 | + // 进入并设置为当前目录 | |
384 | + sftp.cd(filePath.toString()); | |
385 | + } | |
386 | + } | |
387 | + this.sftp.cd(createpath); | |
388 | + } catch (SftpException e) { | |
389 | + log.error("目录创建异常!", e); | |
390 | + return false; | |
391 | + } | |
392 | + return true; | |
393 | + } | |
394 | + | |
395 | + /** | |
396 | + * 判断目录是否存在 | |
397 | + * @param directory 路径 | |
398 | + * @return | |
399 | + */ | |
400 | + public boolean isDirExist(String directory) { | |
401 | + boolean isDirExistFlag = false; | |
402 | + try { | |
403 | + SftpATTRS sftpATTRS = this.sftp.lstat(directory); | |
404 | + isDirExistFlag = true; | |
405 | + return sftpATTRS.isDir(); | |
406 | + } catch (Exception e) { | |
407 | + if (e.getMessage().toLowerCase().equals("no such file")) { | |
408 | + isDirExistFlag = false; | |
409 | + } | |
410 | + log.error("目录不存在:"+directory); | |
411 | + } | |
412 | + return isDirExistFlag; | |
413 | + } | |
414 | + | |
415 | + /** | |
416 | + * 方法功能说明:目录不存在时创建目录 | |
417 | + * @参数: @param path | |
418 | + * @return void | |
419 | + * @throws | |
420 | + */ | |
421 | + public void mkdirs(String path){ | |
422 | + File file = new File(path); | |
423 | + String fs = file.getParent(); | |
424 | + file = new File(fs); | |
425 | + if(!file.exists()){ | |
426 | + file.mkdirs(); | |
427 | + } | |
428 | + } | |
429 | + /** | |
430 | + * 判断文件或目录是否存在 | |
431 | + * @return | |
432 | + */ | |
433 | + public boolean isExist(String path, ChannelSftp sftp){ | |
434 | + boolean isExist=false; | |
435 | + try { | |
436 | + sftp.lstat(path); | |
437 | + isExist = true; | |
438 | + } catch (Exception e) { | |
439 | + if (e.getMessage().toLowerCase().equals("no such file")) { | |
440 | + isExist = false; | |
441 | + } | |
442 | + } | |
443 | + return isExist; | |
444 | + } | |
445 | +} | ... | ... |
Please
register
or
login
to post a comment