├── .gitignore ├── README.md ├── ncov.war ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── wuliang │ │ └── ncov │ │ ├── NcovApplication.java │ │ ├── ServletInitializer.java │ │ ├── controller │ │ ├── ConfirmedInformationController.java │ │ ├── MaskController.java │ │ ├── NcovMapsController.java │ │ ├── NewsController.java │ │ ├── RumorController.java │ │ ├── SameRideController.java │ │ ├── StatisticsController.java │ │ └── VillageController.java │ │ └── core │ │ ├── ResponseMode │ │ ├── Result.java │ │ ├── ResultCode.java │ │ └── ResultGenerator.java │ │ ├── config │ │ ├── CORSFilter.java │ │ ├── SwaggerConfiguration.java │ │ ├── TimeInterceptor.java │ │ └── WebConfig.java │ │ └── redis │ │ ├── AbstractBaseRedisDao.java │ │ ├── RedisConfig.java │ │ ├── RedisDao.java │ │ └── RedisDaoImpl.java └── resources │ └── application.yml └── test └── java └── com └── wuliang └── ncov └── NcovApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # 2019-nCov-api 5 | # 新冠肺炎api 6 | 7 | # 前言 8 | 本项目通过爬取腾讯、新浪、丁香园等疫情数据,获取新冠肺炎相关数据,并整合为api数据,做法简单粗暴,类似于端口转发。数据包含口罩预约、同乘车辆、疫情小区、数据分析、国内外详细数据、实时新闻动态、确诊人员信息流动轨迹、疫情谣言等。 9 | 当前接口部署到我自己的乞丐服务器上面的,可能速度有点慢,希望且用且珍惜。 10 | 11 | 12 | 接口文档浏览及测试:你的服务器ip+端口/doc.html#/home 例如:127.0.0.1:8080/doc.html 13 | 14 | 15 | 另外前期仓促之间也用flutter搞了个app,欢迎star https://github.com/LiangWuCode/2019-nCoV 16 | 17 | 18 | 19 | # 总体图 20 | 21 | 22 | # api说明 23 | 24 | **简介**:新冠肺炎api 25 | 26 | 27 | **HOST**:wuliang.art 28 | 29 | 30 | **联系人**:伍亮(qq:937743837(微信同)) 31 | 32 | 33 | api名称如果包含数字,则表示返回的数据内容类似(但数据格式不一样),只是数据来源不一样,使用时甄选使用。有任何问题call 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | # 口罩信息 43 | 44 | 45 | ## 口罩预约相关信息 46 | 47 | 48 | **接口地址**:`/ncov/mask/gauzeMask` 49 | 50 | 51 | **请求方式**:`GET` 52 | 53 | 54 | **请求数据类型**:`*` 55 | 56 | 57 | **响应数据类型**:`*/*` 58 | 59 | 60 | **接口描述**:`获取相关城市的口罩预约信息` 61 | 62 | 63 | 64 | # 同乘车辆 65 | 66 | 67 | ## 查询同程车辆数据1 68 | 69 | 70 | **接口地址**:`/ncov/sameRide/getSameRide1` 71 | 72 | 73 | **请求方式**:`GET` 74 | 75 | 76 | **接口描述**:根据乘车日期或者是乘车车次返回相关车辆信息 77 | 78 | 79 | **请求参数**: 80 | 81 | 82 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 83 | | -------- | -------- | ----- | -------- | -------- | ------ | 84 | |date|date|query|false|string|| 85 | |no|no|query|false|string|| 86 | 87 | 88 | ## 查询同程车辆数据2 89 | 90 | 91 | **接口地址**:`/ncov/sameRide/getSameRide2` 92 | 93 | 94 | **请求方式**:`GET` 95 | 96 | 97 | **接口描述**:可根据起始日期、结束日期、车次、车站、车辆类型等查询车辆的相关数据信息。 98 | 99 | 100 | **请求参数**: 101 | 102 | 103 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 104 | | -------- | -------- | ----- | -------- | -------- | ------ | 105 | |endDate|endDate|query|false|string|| 106 | |no|no|query|false|string|| 107 | |page|page|query|false|integer(int32)|| 108 | |position|position|query|false|string|| 109 | |size|size|query|false|integer(int32)|| 110 | |startDate|startDate|query|false|string|| 111 | |type|type|query|false|integer(int32)|| 112 | 113 | 114 | 115 | ## 获取所有同乘车辆数据 116 | 117 | 118 | **接口地址**:`/ncov/sameRide/getSameRideAll` 119 | 120 | 121 | **请求方式**:`GET` 122 | 123 | 124 | **接口描述**:获取所有的目前渠道报道出来车次,该接口返回数量较大,可能会缓慢,不建议频繁调取。 125 | 126 | 127 | 128 | # 小区数据 129 | 130 | 131 | ## 获取小区数据1 132 | 133 | 134 | **接口地址**:`/ncov/village/getVillage1` 135 | 136 | 137 | **请求方式**:`GET` 138 | 139 | 140 | 141 | **接口描述**:根据城市的名称获取当前城市确诊小区的信息。例如:西安 142 | 143 | 144 | **请求参数**: 145 | 146 | 147 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 148 | | -------- | -------- | ----- | -------- | -------- | ------ | 149 | |cityName|cityName|query|true|string|| 150 | 151 | 152 | ## 获取小区数据2 153 | 154 | 155 | **接口地址**:`/ncov/village/getVillage2` 156 | 157 | 158 | **请求方式**:`GET` 159 | 160 | 161 | **接口描述**:根据城市的名称获取当前城市确诊小区的信息。例如:西安 162 | 163 | 164 | **请求参数**: 165 | 166 | 167 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 168 | | -------- | -------- | ----- | -------- | -------- | ------ | 169 | |cityName|cityName|query|true|string|| 170 | 171 | 172 | 173 | ## 根据小区名称查询疫情小区 174 | 175 | 176 | **接口地址**:`/ncov/village/getVillageByCommunityName` 177 | 178 | 179 | **请求方式**:`GET` 180 | 181 | 182 | **接口描述**:根据小区的名称进行模糊搜索,查询疫情小区 183 | 184 | 185 | **请求参数**: 186 | 187 | 188 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 189 | | -------- | -------- | ----- | -------- | -------- | ------ | 190 | |communityName|communityName|query|true|string|| 191 | 192 | 193 | 194 | # 数据分析 195 | 196 | 197 | ## 每日数据分析 198 | 199 | 200 | **接口地址**:`/ncov/dnalysis/everyday` 201 | 202 | 203 | **请求方式**:`GET` 204 | 205 | 206 | **接口描述**:对每日的疫情数据进行解读,以及以后趋势的分析,返回的为一个图片链接。 207 | 208 | 209 | 210 | ## 疫情地图数据 211 | 212 | 213 | **接口地址**:`/ncov/dnalysis/ncovMaps` 214 | 215 | 216 | **请求方式**:`GET` 217 | 218 | 219 | **接口描述**:该接口,主要是对于疫情的一些图表信息的整理,方便于进行图表的渲染展示,例如柱状图、折线图等等。 220 | 221 | 222 | 223 | # 数据统计 224 | 225 | 226 | ## 根据省市名称获取当前市区历史数据 227 | 228 | 229 | **接口地址**:`/ncov/statistics/getCityHistoryList` 230 | 231 | 232 | **请求方式**:`GET` 233 | 234 | **接口描述**:根据省的名称、市的名称获取当前市区的历史数据。 235 | 236 | 237 | **请求参数**: 238 | 239 | 240 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 241 | | -------- | -------- | ----- | -------- | -------- | ------ | 242 | |cityName|cityName|query|true|string|| 243 | |provinceName|provinceName|query|true|string|| 244 | 245 | 246 | ## 根据市级名称获取县区级数据 247 | 248 | 249 | **接口地址**:`/ncov/statistics/getCountyList` 250 | 251 | 252 | **请求方式**:`GET` 253 | 254 | 255 | **接口描述**:根据市区的名称获取县级历史数据,该接口可能存在数据缺失的情况。例如:安康 256 | 257 | 258 | **请求参数**: 259 | 260 | 261 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 262 | | -------- | -------- | ----- | -------- | -------- | ------ | 263 | |cityName|cityName|query|true|string|| 264 | 265 | 266 | ## 根据省的名称获取该省的历史数据 267 | 268 | 269 | **接口地址**:`/ncov/statistics/getProvinceHistoryList` 270 | 271 | 272 | **请求方式**:`GET` 273 | 274 | 275 | **接口描述**: 276 | 277 | 278 | **请求参数**:根据省的名称获取该省的历史数据。例如:陕西 279 | 280 | 281 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 282 | | -------- | -------- | ----- | -------- | -------- | ------ | 283 | |provinceName|provinceName|query|true|string|| 284 | 285 | 286 | ## 数据统计1 287 | 288 | 289 | **接口地址**:`/ncov/statistics/totalDataOne` 290 | 291 | 292 | **请求方式**:`GET` 293 | 294 | 295 | **接口描述**:获取国内以及国外的相关疫情数据。 296 | 297 | 298 | **请求参数**: 299 | 300 | 301 | ## 数据统计3 302 | 303 | 304 | **接口地址**:`/ncov/statistics/totalDataThree` 305 | 306 | 307 | **请求方式**:`GET` 308 | 309 | 310 | **接口描述**:取国内以及国外的相关疫情数据。 311 | 312 | 313 | ## 数据统计2 314 | 315 | 316 | **接口地址**:`/ncov/statistics/totalDataTwo` 317 | 318 | 319 | **请求方式**:`GET` 320 | 321 | 322 | 323 | **接口描述**:取国内以及国外的相关疫情数据。 324 | 325 | 326 | 327 | # 新闻数据 328 | 329 | 330 | ## 根据市的名称获取该市的新闻信息 331 | 332 | 333 | **接口地址**:`/ncov/news/getCityNewsList` 334 | 335 | 336 | **请求方式**:`GET` 337 | 338 | 339 | **接口描述**:获取当前市区的新闻,根据市的名称。例如:安康 340 | 341 | 342 | **请求参数**: 343 | 344 | 345 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 346 | | -------- | -------- | ----- | -------- | -------- | ------ | 347 | |cityName|cityName|query|true|string|| 348 | 349 | ## 关于疫情百科知识 (检查诊断) 350 | 351 | 352 | **接口地址**:`/ncov/news/getDiagnoseList` 353 | 354 | 355 | **请求方式**:`GET` 356 | 357 | 358 | 359 | **接口描述**: 360 | 361 | 362 | **请求参数**: 363 | 364 | 365 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 366 | | -------- | -------- | ----- | -------- | -------- | ------ | 367 | |count|count|query|true|integer(int32)|| 368 | 369 | ## 关于疫情百科知识 (预防指南) 370 | 371 | 372 | **接口地址**:`/ncov/news/getGuideList` 373 | 374 | 375 | **请求方式**:`GET` 376 | 377 | 378 | 379 | **接口描述**: 380 | 381 | 382 | **请求参数**: 383 | 384 | 385 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 386 | | -------- | -------- | ----- | -------- | -------- | ------ | 387 | |count|count|query|true|integer(int32)|| 388 | 389 | 390 | # 确诊信息 391 | 392 | 393 | ## 根据省名称,获取确诊人员信息 394 | 395 | 396 | **接口地址**:`/ncov/confirmedInformation/getGuideListByProvinceName` 397 | 398 | 399 | **请求方式**:`GET` 400 | 401 | 402 | **接口描述**:查询当前省,确证人员的信息,包括人员轨迹等。 403 | 404 | 405 | **请求参数**: 406 | 407 | 408 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 409 | | -------- | -------- | ----- | -------- | -------- | ------ | 410 | |num|num|query|true|integer(int32)|| 411 | |page|page|query|true|integer(int32)|| 412 | |provinceName|provinceName|query|true|string|| 413 | 414 | 415 | ## 根据省市名称,获取当前市确诊人员信息 416 | 417 | 418 | **接口地址**:`/ncov/confirmedInformation/getGuideListByProvinceNameAndCityName` 419 | 420 | 421 | **请求方式**:`GET` 422 | 423 | 424 | **接口描述**:查询当前省,确证人员的信息,包括人员轨迹等。 425 | 426 | 427 | **请求参数**: 428 | 429 | 430 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 431 | | -------- | -------- | ----- | -------- | -------- | ------ | 432 | |cityName|cityName|query|true|string|| 433 | |page|page|query|true|integer(int32)|| 434 | |provinceName|provinceName|query|true|string|| 435 | 436 | 437 | # 谣言 438 | 439 | 440 | ## 根据谣言id获取谣言详情 441 | 442 | 443 | **接口地址**:`/ncov/rumor/getRumorDetail` 444 | 445 | 446 | **请求方式**:`GET` 447 | 448 | **接口描述**:根据谣言接口列表,返回的数据的id,查询当前谣言的具体信息。 449 | 450 | 451 | **请求参数**: 452 | 453 | 454 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 455 | | -------- | -------- | ----- | -------- | -------- | ------ | 456 | |id|id|query|true|string|| 457 | 458 | 459 | ## 谣言数据列表 460 | 461 | 462 | **接口地址**:`/ncov/rumor/getRumorList` 463 | 464 | 465 | **请求方式**:`GET` 466 | 467 | **接口描述**:获取谣言列表数据。 468 | 469 | 470 | **请求参数**: 471 | 472 | 473 | | 参数名称 | 参数说明 | in | 是否必须 | 数据类型 | schema | 474 | | -------- | -------- | ----- | -------- | -------- | ------ | 475 | |page|page|query|true|integer(int32)|| 476 | 477 | 478 | # 尾巴 479 | 在家这段时间是大学毕业以后最闲的了,等着复工,也是由于闲才来做一些自己喜欢的东西,写写代码,吹吹牛逼, 480 | 陪陪家人,准备准备面试,疫情结束以后肯定会重新换工作,希望一切顺利吧。 481 | 疫情定会结束,曙光就在前方。武汉加油!中国加油! 482 | 483 | 484 | **另数据为自己爬取的,所以不保证数据的有效性,合法性,如涉及到侵权,请联系删除,定做妥善处理。** 485 | -------------------------------------------------------------------------------- /ncov.war: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiangWuCode/2019-nCov-api/ba01e17b097d56371fc87efe3c1982b4d559fde1/ncov.war -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.4.RELEASE 9 | 10 | 11 | com.wuliang 12 | ncov 13 | 0.0.1-SNAPSHOT 14 | war 15 | ncov 16 | Demo project for Spring Boot 17 | 18 | 19 | 1.8 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-devtools 31 | runtime 32 | true 33 | 34 | 35 | org.projectlombok 36 | lombok 37 | true 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-tomcat 42 | provided 43 | 44 | 45 | org.jsoup 46 | jsoup 47 | 1.12.1 48 | 49 | 50 | 51 | cn.hutool 52 | hutool-all 53 | 5.1.2 54 | 55 | 56 | 57 | io.springfox 58 | springfox-swagger2 59 | 2.9.2 60 | 61 | 62 | com.github.xiaoymin 63 | knife4j-spring-boot-starter 64 | 2.0.1 65 | 66 | 67 | 68 | com.alibaba 69 | fastjson 70 | 1.2.62 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-starter-data-redis 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-starter-test 79 | test 80 | 81 | 82 | org.junit.vintage 83 | junit-vintage-engine 84 | 85 | 86 | 87 | 88 | org.springframework.boot 89 | spring-boot-starter-test 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.springframework.boot 97 | spring-boot-maven-plugin 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/NcovApplication.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cache.annotation.EnableCaching; 6 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 7 | 8 | @SpringBootApplication 9 | @EnableSwagger2 10 | @EnableCaching 11 | public class NcovApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(NcovApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(NcovApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/ConfirmedInformationController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.json.JSONUtil; 4 | import com.alibaba.fastjson.JSON; 5 | import com.wuliang.ncov.core.ResponseMode.Result; 6 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.jsoup.Jsoup; 10 | import org.jsoup.nodes.Document; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.io.IOException; 17 | 18 | /** 19 | * 确诊信息 20 | * 伍亮 21 | */ 22 | @RequestMapping("/confirmedInformation") 23 | @RestController 24 | @Api(value = "/confirmedInformation", tags = "确诊信息") 25 | public class ConfirmedInformationController { 26 | 27 | /** 28 | * 数据来源于夸克 29 | * 根据省市名称,获取当前市确诊人员信息 30 | * 31 | * @return 32 | */ 33 | @GetMapping("/getGuideListByProvinceNameAndCityName") 34 | @ApiOperation("根据省市名称,获取当前市确诊人员信息") 35 | public Result getGuideListByProvinceNameAndCityName(@RequestParam("provinceName") String provinceName, @RequestParam("cityName") String cityName, @RequestParam("page") Integer page) { 36 | Object res = ""; 37 | try { 38 | Document doc = Jsoup.connect("https://m.sm.cn/api/rest?format=json&from=&method=Maskbuy.areaData&prov=" + provinceName + "&city=" + cityName + "&page=" + page) 39 | .ignoreContentType(true) 40 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 41 | .header("content-type", "application/json") 42 | .timeout(5000).get(); 43 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 44 | } catch (IOException e) { 45 | e.printStackTrace(); 46 | } 47 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 48 | } 49 | 50 | /** 51 | * 数据来源于腾讯 52 | * 根据省名称,获取确诊人员信息 53 | * 54 | * @return 55 | */ 56 | @GetMapping("/getGuideListByProvinceName") 57 | @ApiOperation("根据省名称,获取确诊人员信息") 58 | public Result getGuideList(@RequestParam("provinceName") String provinceName, @RequestParam("num") Integer num, @RequestParam("page") Integer page) { 59 | Object res = ""; 60 | try { 61 | Document doc = Jsoup.connect("https://pacaio.match.qq.com/virus/trackList?province=" + provinceName + "&num=" + num + "&page=" + page) 62 | .ignoreContentType(true) 63 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 64 | .header("content-type", "application/json") 65 | .timeout(5000).get(); 66 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 67 | } catch (IOException e) { 68 | e.printStackTrace(); 69 | } 70 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/MaskController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.json.JSONUtil; 4 | import com.alibaba.fastjson.JSON; 5 | import com.alibaba.fastjson.JSONArray; 6 | import com.wuliang.ncov.core.ResponseMode.Result; 7 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.jsoup.Jsoup; 11 | import org.jsoup.nodes.Document; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.io.IOException; 17 | 18 | /** 19 | * 口罩相关信息 20 | * 伍亮 21 | */ 22 | @RequestMapping("/mask") 23 | @RestController 24 | @Api(value = "/mask", tags = "口罩信息") 25 | public class MaskController { 26 | 27 | 28 | /** 29 | * 口罩预约相关信息 30 | * 31 | * @return 32 | */ 33 | @GetMapping("/gauzeMask") 34 | @ApiOperation("口罩预约相关信息") 35 | public Result gauzeMask() { 36 | Object res = ""; 37 | try { 38 | Document doc = Jsoup.connect("https://m.sm.cn/api/rest?format=json&uc_param_str=gicp&method=Maskbuy.mask") 39 | .ignoreContentType(true) 40 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 41 | .header("content-type", "application/json") 42 | .timeout(5000).get(); 43 | res = JSONArray.parse(JSONUtil.parseObj(JSONUtil.parseObj(doc.body().html()).get("data")).get("list").toString()); 44 | } catch (IOException e) { 45 | e.printStackTrace(); 46 | } 47 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/NcovMapsController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.json.JSONUtil; 4 | import com.alibaba.fastjson.JSON; 5 | import com.wuliang.ncov.core.ResponseMode.Result; 6 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.jsoup.Jsoup; 10 | import org.jsoup.nodes.Document; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.io.IOException; 16 | 17 | /** 18 | * 数据分析 19 | * 伍亮 20 | */ 21 | @RequestMapping("/dnalysis") 22 | @RestController 23 | @Api(value = "/dnalysis", tags = "数据分析") 24 | public class NcovMapsController { 25 | /** 26 | * 数据来源于腾讯 27 | * 每日数据分析 28 | * 29 | * @return 30 | */ 31 | @GetMapping("/everyday") 32 | @ApiOperation("每日数据分析") 33 | public Result everyday() { 34 | Object res = ""; 35 | try { 36 | Document doc = Jsoup.connect("https://eyesight.news.qq.com/ncov/alldata") 37 | .ignoreContentType(true) 38 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 39 | .header("content-type", "application/json") 40 | .timeout(5000).get(); 41 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 46 | } 47 | 48 | /** 49 | * 数据来源于第三方 50 | * 疫情地图数据 51 | * 52 | * @return 53 | */ 54 | @GetMapping("/ncovMaps") 55 | @ApiOperation("疫情地图数据") 56 | public Result ncovMaps() { 57 | Object res = ""; 58 | try { 59 | Document doc = Jsoup.connect("http://app.21jingji.com/html/2020yiqing/json/trend.json?19") 60 | .ignoreContentType(true) 61 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 62 | .header("content-type", "application/json") 63 | .timeout(5000).get(); 64 | res = JSONUtil.parseObj(doc.body().html()); 65 | } catch (IOException e) { 66 | e.printStackTrace(); 67 | } 68 | return ResultGenerator.genSuccessResult(res); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/NewsController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.core.text.UnicodeUtil; 4 | import cn.hutool.core.util.CharsetUtil; 5 | import cn.hutool.core.util.StrUtil; 6 | import cn.hutool.http.HttpUtil; 7 | import cn.hutool.json.JSONUtil; 8 | import com.alibaba.fastjson.JSON; 9 | import com.wuliang.ncov.core.ResponseMode.Result; 10 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.jsoup.Jsoup; 14 | import org.jsoup.nodes.Document; 15 | import org.springframework.web.bind.annotation.GetMapping; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RequestParam; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * 新闻数据 24 | * 伍亮 25 | */ 26 | @RequestMapping("/news") 27 | @RestController 28 | @Api(value = "/news", tags = "新闻数据") 29 | public class NewsController { 30 | /** 31 | * 数据来源于夸克 32 | * 根据市的名称获取该市的新闻信息 33 | * 34 | * @return 35 | */ 36 | @GetMapping("/getCityNewsList") 37 | @ApiOperation("根据市的名称获取该市的新闻信息") 38 | public Result getCityNewsList(@RequestParam("cityName") String cityName) { 39 | String result2 = HttpUtil.get("https://m.sm.cn/api/rest?method=yiqing.getZixun&uc_param_str=gi&city=" + cityName, CharsetUtil.CHARSET_UTF_8); 40 | return ResultGenerator.genSuccessResult(JSONUtil.parse(UnicodeUtil.toString(result2))); 41 | } 42 | 43 | /** 44 | * 数据来源于腾讯 45 | * 关于疫情百科知识 (检查诊断) 46 | * 47 | * @return 48 | */ 49 | @GetMapping("/getDiagnoseList") 50 | @ApiOperation("关于疫情百科知识 (检查诊断)") 51 | public Result getDiagnoseList(@RequestParam("count") Integer count) { 52 | String res = ""; 53 | try { 54 | Document doc = Jsoup.connect("https://h5.baike.qq.com/api/jsonp/GetDocsByTag?callback=data&appid=2000000000000050&adtag=txxw.op.fybox&name=94700&count=" + count) 55 | .ignoreContentType(true) 56 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 57 | .header("content-type", "application/json") 58 | .timeout(5000).get(); 59 | String newsHeadlines = StrUtil.removePrefix(doc.body().html(), "data("); 60 | newsHeadlines = StrUtil.removeSuffix(newsHeadlines, ")"); 61 | res = newsHeadlines; 62 | } catch (IOException e) { 63 | e.printStackTrace(); 64 | } 65 | return ResultGenerator.genSuccessResult(JSON.parse(res)); 66 | } 67 | 68 | 69 | /** 70 | * 数据来源于腾讯 71 | * 关于疫情百科知识 (预防指南) 72 | * 73 | * @return 74 | */ 75 | @GetMapping("/getGuideList") 76 | @ApiOperation("关于疫情百科知识 (预防指南)") 77 | public Result getGuideList(@RequestParam("count") Integer count) { 78 | String res = ""; 79 | try { 80 | Document doc = Jsoup.connect("https://h5.baike.qq.com/api/jsonp/GetDocsByTag?callback=data&appid=2000000000000050&adtag=txxw.op.fybox&name=94699&count=" + count) 81 | .ignoreContentType(true) 82 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 83 | .header("content-type", "application/json") 84 | .timeout(5000).get(); 85 | String newsHeadlines = StrUtil.removePrefix(doc.body().html(), "data("); 86 | newsHeadlines = StrUtil.removeSuffix(newsHeadlines, ")"); 87 | res = newsHeadlines; 88 | } catch (IOException e) { 89 | e.printStackTrace(); 90 | } 91 | return ResultGenerator.genSuccessResult(JSON.parse(res)); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/RumorController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.json.JSONUtil; 4 | import com.alibaba.fastjson.JSON; 5 | import com.wuliang.ncov.core.ResponseMode.Result; 6 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.jsoup.Jsoup; 10 | import org.jsoup.nodes.Document; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.io.IOException; 17 | 18 | /** 19 | * 谣言 20 | * 伍亮 21 | */ 22 | @RequestMapping("/rumor") 23 | @RestController 24 | @Api(value = "/rumor", tags = "谣言") 25 | public class RumorController { 26 | /** 27 | * 数据来源于腾讯 28 | * 谣言数据列表 29 | * 30 | * @return 31 | */ 32 | @GetMapping("/getRumorList") 33 | @ApiOperation("谣言数据列表") 34 | public Result getRumorList(@RequestParam("page") Integer page) { 35 | Object res=""; 36 | try { 37 | Document doc = Jsoup.connect("https://vp.fact.qq.com/loadmore?page="+page) 38 | .ignoreContentType(true) 39 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 40 | .header("content-type", "application/json") 41 | .timeout(5000).get(); 42 | res = JSONUtil.parseObj(doc.body().html()).get("content"); 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 47 | } 48 | 49 | /** 50 | * 数据来源于腾讯 51 | * 谣言数据列表 52 | * 53 | * @return 54 | */ 55 | @GetMapping("/getRumorDetail") 56 | @ApiOperation("根据谣言id获取谣言详情") 57 | public Result getRumorDetail(@RequestParam("id") String id) { 58 | Object res=""; 59 | try { 60 | Document doc = Jsoup.connect("https://vp.fact.qq.com/miniArtData?id="+id) 61 | .ignoreContentType(true) 62 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 63 | .header("content-type", "application/json") 64 | .timeout(5000).get(); 65 | res = JSONUtil.parseObj(doc.body().html()).get("content"); 66 | } catch (IOException e) { 67 | e.printStackTrace(); 68 | } 69 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/SameRideController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import cn.hutool.json.JSONObject; 5 | import cn.hutool.json.JSONUtil; 6 | import com.alibaba.fastjson.JSON; 7 | import com.alibaba.fastjson.JSONArray; 8 | import com.wuliang.ncov.core.ResponseMode.Result; 9 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.jsoup.Jsoup; 13 | import org.jsoup.nodes.Document; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RequestParam; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | import java.io.IOException; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * 同乘车辆 26 | * 伍亮 27 | */ 28 | @RequestMapping("/sameRide") 29 | @RestController 30 | @Api(value = "/sameRide", tags = "同乘车辆") 31 | public class SameRideController { 32 | /** 33 | * 数据来源于腾讯 34 | * 同乘车辆查询 35 | * 36 | * @return 37 | */ 38 | @GetMapping("/getSameRideAll") 39 | @ApiOperation("获取所有同乘车辆数据") 40 | public Result getSameRideAll() { 41 | Object res = ""; 42 | try { 43 | Document doc = Jsoup.connect("https://rl.inews.qq.com/taf/travelFront") 44 | .ignoreContentType(true) 45 | .maxBodySize(0) 46 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 47 | .header("content-type", "application/json") 48 | .timeout(5000).get(); 49 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 50 | } catch (IOException e) { 51 | e.printStackTrace(); 52 | } 53 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 54 | } 55 | 56 | /** 57 | * 数据来源于腾讯 58 | * 同乘车辆查询 59 | * 60 | * @return 61 | */ 62 | @GetMapping("/getSameRide1") 63 | @ApiOperation("查询同程车辆数据1") 64 | public Result getSameRide(@RequestParam(value = "no", required = false) String no, @RequestParam(value = "date", required = false) String date) { 65 | Object res = ""; 66 | JSONObject json = JSONUtil.createObj(); 67 | try { 68 | Document doc = Jsoup.connect("https://rl.inews.qq.com/taf/travelFront") 69 | .ignoreContentType(true) 70 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 71 | .header("content-type", "application/json") 72 | .timeout(5000).get(); 73 | List> listObjectFir = (List>) JSONArray.parse(JSONUtil.parseObj(JSONUtil.parseObj(doc.body().html()).get("data")).get("list").toString()); 74 | List realMaps = new ArrayList<>(); 75 | for (int i = 0; i < listObjectFir.size(); i++) { 76 | if (!StrUtil.isEmpty(no) && !StrUtil.isEmpty(date)) { 77 | if (StrUtil.contains(no, listObjectFir.get(i).get("no")) && StrUtil.contains(date, listObjectFir.get(i).get("date"))) { 78 | realMaps.add(listObjectFir.get(i)); 79 | } 80 | } else if (!StrUtil.isEmpty(no)) { 81 | if (StrUtil.contains(no, listObjectFir.get(i).get("no"))) { 82 | realMaps.add(listObjectFir.get(i)); 83 | } 84 | } else { 85 | if (StrUtil.contains(date, listObjectFir.get(i).get("date"))) { 86 | realMaps.add(listObjectFir.get(i)); 87 | } 88 | } 89 | } 90 | json.put("list", realMaps); 91 | json.put("total", realMaps.size()); 92 | } catch (IOException e) { 93 | e.printStackTrace(); 94 | } 95 | return ResultGenerator.genSuccessResult(json); 96 | } 97 | 98 | /** 99 | * 数据来源于夸克 100 | * 同乘车辆查询 101 | * 102 | * @return 103 | */ 104 | @GetMapping("/getSameRide2") 105 | @ApiOperation("查询同程车辆数据2") 106 | public Result getSameRide2(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page, 107 | @RequestParam(value = "size", required = false, defaultValue = "10") Integer size, 108 | @RequestParam(value = "position", required = false, defaultValue = "") String position, 109 | @RequestParam(value = "type", required = false, defaultValue = "0") Integer type, 110 | @RequestParam(value = "no", required = false, defaultValue = "") String no, 111 | @RequestParam(value = "startDate", required = false, defaultValue = "2020-01-01") String startDate, 112 | @RequestParam(value = "endDate", required = false, defaultValue = "2021-01-01") String endDate 113 | ) { 114 | Object res = ""; 115 | try { 116 | String url = "https://m.sm.cn/api/rest?format=json&method=Huoshenshan.trailSearch&page=" + page + "&size=" + size + "&position=" + position + "&type=" + type + "&no=" + no + "&datefrom=" + startDate + "&dateto=" + endDate; 117 | Document doc = Jsoup.connect(url) 118 | .ignoreContentType(true) 119 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 120 | .header("content-type", "application/json") 121 | .timeout(5000).get(); 122 | res = JSONUtil.parseObj(doc.body().html()); 123 | } catch (IOException e) { 124 | e.printStackTrace(); 125 | } 126 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/StatisticsController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.core.text.UnicodeUtil; 4 | import cn.hutool.core.util.CharsetUtil; 5 | import cn.hutool.core.util.StrUtil; 6 | import cn.hutool.http.HttpUtil; 7 | import cn.hutool.json.JSONObject; 8 | import cn.hutool.json.JSONUtil; 9 | import com.alibaba.fastjson.JSON; 10 | import com.wuliang.ncov.core.ResponseMode.Result; 11 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 12 | import io.swagger.annotations.Api; 13 | import io.swagger.annotations.ApiOperation; 14 | import org.jsoup.Jsoup; 15 | import org.jsoup.nodes.Document; 16 | import org.springframework.web.bind.annotation.GetMapping; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestParam; 19 | import org.springframework.web.bind.annotation.RestController; 20 | 21 | import java.io.IOException; 22 | 23 | 24 | /** 25 | * 数据统计接口汇总 26 | * 伍亮 27 | */ 28 | @RequestMapping("/statistics") 29 | @RestController 30 | @Api(value = "/statistics", tags = "数据统计") 31 | public class StatisticsController { 32 | /** 33 | * 数据来源于腾讯 34 | * 数据统计 35 | * 36 | * @return 37 | */ 38 | @GetMapping("/totalDataOne") 39 | @ApiOperation("数据统计1") 40 | public Result totalDataOne() { 41 | Object res = ""; 42 | try { 43 | Document doc = Jsoup.connect("https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5") 44 | .ignoreContentType(true) 45 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 46 | .header("content-type", "application/json") 47 | .timeout(5000).get(); 48 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 53 | } 54 | 55 | 56 | /** 57 | * 数据来源于腾讯 58 | * 数据改变列表 59 | * 60 | * @return 61 | */ 62 | @GetMapping("/dataChangeList") 63 | @ApiOperation("数据改变列表") 64 | public Result dataChangeList() { 65 | Object res = ""; 66 | try { 67 | Document doc = Jsoup.connect("https://view.inews.qq.com/g2/getOnsInfo?name=disease_other") 68 | .ignoreContentType(true) 69 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 70 | .header("content-type", "application/json") 71 | .timeout(5000).get(); 72 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 73 | } catch (IOException e) { 74 | e.printStackTrace(); 75 | } 76 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 77 | } 78 | 79 | /** 80 | * 数据来源于夸克 81 | * 数据统计 82 | * 83 | * @return 84 | */ 85 | @GetMapping("/totalDataTwo") 86 | @ApiOperation("数据统计2") 87 | public Result totalDataTwo() { 88 | Object res = ""; 89 | try { 90 | Document doc = Jsoup.connect("https://api.m.sm.cn/rest?format=json&method=Huoshenshan.healingCity&mapType=1") 91 | .ignoreContentType(true) 92 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 93 | .header("content-type", "application/json") 94 | .timeout(5000).get(); 95 | res = JSONUtil.parseObj(doc.body().html()); 96 | } catch (IOException e) { 97 | e.printStackTrace(); 98 | } 99 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 100 | } 101 | 102 | 103 | /** 104 | * 数据来源于夸克 105 | * 根据省的名称获取该省的历史数据 106 | * 107 | * @return 108 | */ 109 | @GetMapping("/getCountyList") 110 | @ApiOperation("根据市级名称获取县区级数据") 111 | public Result getCountyList(@RequestParam("cityName") String cityName) { 112 | String result2 = HttpUtil.get("https://m.sm.cn/api/rest?method=yiqing.getPlaceInfo&uc_param_str=gi&city=" + cityName, CharsetUtil.CHARSET_UTF_8); 113 | return ResultGenerator.genSuccessResult(JSONUtil.parse(UnicodeUtil.toString(result2))); 114 | } 115 | 116 | /** 117 | * 数据来源于腾讯 118 | * 根据省的名称获取该省的历史数据 119 | * 120 | * @return 121 | */ 122 | @GetMapping("/getProvinceHistoryList") 123 | @ApiOperation("根据省的名称获取该省的历史数据") 124 | public Result getProvinceHistoryList(@RequestParam("provinceName") String provinceName) { 125 | Object res = ""; 126 | try { 127 | Document doc = Jsoup.connect("https://api.inews.qq.com/newsqa/v1/query/pubished/daily/list?province=" + provinceName) 128 | .ignoreContentType(true) 129 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 130 | .header("content-type", "application/json") 131 | .timeout(5000).get(); 132 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 133 | } catch (IOException e) { 134 | e.printStackTrace(); 135 | } 136 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 137 | } 138 | 139 | /** 140 | * 数据来源于腾讯 141 | * 根据省市名称获取当前市区历史数据 142 | * 143 | * @return 144 | */ 145 | @GetMapping("/getCityHistoryList") 146 | @ApiOperation("根据省市名称获取当前市区历史数据") 147 | public Result getCityHistoryList(@RequestParam("provinceName") String provinceName, @RequestParam("cityName") String cityName) { 148 | Object res = ""; 149 | try { 150 | Document doc = Jsoup.connect("https://api.inews.qq.com/newsqa/v1/query/pubished/daily/list?province=" + provinceName + "&city=" + cityName) 151 | .ignoreContentType(true) 152 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 153 | .header("content-type", "application/json") 154 | .timeout(5000).get(); 155 | res = JSONUtil.parseObj(doc.body().html()).get("data"); 156 | } catch (IOException e) { 157 | e.printStackTrace(); 158 | } 159 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 160 | } 161 | 162 | 163 | /** 164 | * 数据统计(丁香园) 165 | * 166 | * @return 167 | */ 168 | @GetMapping("/totalDataThree") 169 | @ApiOperation("数据统计3") 170 | public Result totalDataThree() { 171 | String res = ""; 172 | JSONObject json = JSONUtil.createObj(); 173 | try { 174 | Document doc = Jsoup.connect("https://ncov.dxy.cn/ncovh5/view/pneumonia").get(); 175 | //国际数据统计 176 | String newsHeadlines = doc.select("#getListByCountryTypeService2true").html(); 177 | newsHeadlines = StrUtil.removePrefix(newsHeadlines, "try { window.getListByCountryTypeService2true ="); 178 | newsHeadlines = StrUtil.removeSuffix(newsHeadlines, "}catch(e){}"); 179 | json.put("foreign", JSONUtil.parse(newsHeadlines)); 180 | 181 | //国内数据统计 182 | String newsHeadlines1 = doc.select("#getAreaStat").html(); 183 | newsHeadlines1 = StrUtil.removePrefix(newsHeadlines1, "try { window.getAreaStat ="); 184 | newsHeadlines1 = StrUtil.removeSuffix(newsHeadlines1, "}catch(e){}"); 185 | json.put("china", JSONUtil.parse(newsHeadlines1)); 186 | 187 | //国内新增数据 188 | String newsHeadlines2 = doc.select("#getTimelineService2").html(); 189 | newsHeadlines2 = StrUtil.removePrefix(newsHeadlines2, "try { window.getTimelineService2 ="); 190 | newsHeadlines2 = StrUtil.removeSuffix(newsHeadlines2, "}catch(e){}"); 191 | json.put("enForeign", JSONUtil.parse(newsHeadlines2)); 192 | 193 | //疫情说明 194 | String newsHeadlines3 = doc.select("#getStatisticsService").html(); 195 | newsHeadlines3 = StrUtil.removePrefix(newsHeadlines3, "try { window.getStatisticsService ="); 196 | newsHeadlines3 = StrUtil.removeSuffix(newsHeadlines3, "}catch(e){}"); 197 | json.put("desc", JSONUtil.parse(newsHeadlines3)); 198 | } catch (IOException e) { 199 | e.printStackTrace(); 200 | } 201 | return ResultGenerator.genSuccessResult(json); 202 | } 203 | 204 | 205 | /** 206 | * 数据统计(丁香园) 207 | * 208 | * @return 209 | */ 210 | @GetMapping("/flutterAppForMyself") 211 | @ApiOperation("自己开发的flutterApp使用") 212 | public Result flutterAppForMyself() { 213 | String res = ""; 214 | JSONObject json = JSONUtil.createObj(); 215 | try { 216 | Document doc = Jsoup.connect("https://ncov.dxy.cn/ncovh5/view/pneumonia").get(); 217 | //疫情说明 218 | String newsHeadlines3 = doc.select("#getStatisticsService").html(); 219 | newsHeadlines3 = StrUtil.removePrefix(newsHeadlines3, "try { window.getStatisticsService ="); 220 | newsHeadlines3 = StrUtil.removeSuffix(newsHeadlines3, "}catch(e){}"); 221 | json.put("desc", JSONUtil.parse(newsHeadlines3)); 222 | 223 | // //国内新增数据 224 | // String newsHeadlines2 = doc.select("#getListByCountryTypeService1undefined").html(); 225 | // newsHeadlines2 = StrUtil.removePrefix(newsHeadlines2, "try { window.getListByCountryTypeService1undefined ="); 226 | // newsHeadlines2 = StrUtil.removeSuffix(newsHeadlines2, "}catch(e){}"); 227 | // json.put("chinaAdd", JSONUtil.parse(newsHeadlines2)); 228 | } catch (IOException e) { 229 | e.printStackTrace(); 230 | } 231 | return ResultGenerator.genSuccessResult(json); 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/controller/VillageController.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.controller; 2 | 3 | import cn.hutool.core.collection.CollUtil; 4 | import cn.hutool.core.util.StrUtil; 5 | import cn.hutool.json.JSONObject; 6 | import cn.hutool.json.JSONUtil; 7 | import com.alibaba.fastjson.JSON; 8 | import com.alibaba.fastjson.JSONArray; 9 | import com.wuliang.ncov.core.ResponseMode.Result; 10 | import com.wuliang.ncov.core.ResponseMode.ResultGenerator; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.jsoup.Jsoup; 14 | import org.jsoup.nodes.Document; 15 | import org.springframework.web.bind.annotation.GetMapping; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RequestParam; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | import java.io.IOException; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | * 小区数据 27 | * 伍亮 28 | */ 29 | @RequestMapping("/village") 30 | @RestController 31 | @Api(value = "/village", tags = "小区数据") 32 | public class VillageController { 33 | /** 34 | * 数据来源于第三方 35 | * 通过省市区等信息获取小区信息 36 | * 37 | * @return 38 | */ 39 | @GetMapping("/getVillage1") 40 | @ApiOperation("获取小区数据1") 41 | public Result getVillage1(@RequestParam("cityName") String cityName) { 42 | Object res = ""; 43 | 44 | try { 45 | Document doc = Jsoup.connect("https://lspengine.map.sogou.com/coronavirus/epidemic/search/entity?city=" + cityName + "&keyword=疫情小区") 46 | .ignoreContentType(true) 47 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 48 | .header("content-type", "application/json") 49 | .timeout(5000).get(); 50 | if (!StrUtil.contains("{}", doc.body().html())) { 51 | res = JSONUtil.parseObj(doc.body().html()).get("poiResults"); 52 | } else { 53 | JSONObject json = JSONUtil.createObj(); 54 | List list = new ArrayList(); 55 | json.put("datas", list); 56 | json.put("keyword", "疫情小区"); 57 | res = json; 58 | } 59 | 60 | } catch (IOException e) { 61 | e.printStackTrace(); 62 | } 63 | return ResultGenerator.genSuccessResult(res); 64 | } 65 | 66 | /** 67 | * 数据来源于夸克 68 | * 通过省市区等信息获取小区信息 69 | * 70 | * @return 71 | */ 72 | @GetMapping("/getVillage2") 73 | @ApiOperation("获取小区数据2") 74 | public Result getVillage2(@RequestParam("cityName") String cityName) { 75 | Object res = ""; 76 | 77 | try { 78 | //查询目前所有已经确诊的小区数据 79 | Document doc = Jsoup.connect("https://iflow-api.uc.cn/feiyan/area?uc_param_str=utpclocp&city=1&range=city") 80 | .ignoreContentType(true) 81 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 82 | .header("content-type", "application/json") 83 | .timeout(5000).get(); 84 | List> listObjectFir = (List>) JSONArray.parse(JSONUtil.parseObj(JSONUtil.parseObj(doc.body().html()).get("data")).get("cities").toString()); 85 | Integer j = 0; 86 | String code = ""; 87 | //判断当前城市是否存在确诊的数据 88 | if (!CollUtil.isEmpty(listObjectFir)) { 89 | for (int i = 0; i < listObjectFir.size(); i++) { 90 | if (StrUtil.contains(cityName, listObjectFir.get(i).get("two_level_area"))) { 91 | j++; 92 | code = listObjectFir.get(i).get("citycode"); 93 | } 94 | } 95 | } else { 96 | List list = new ArrayList(); 97 | res = list; 98 | } 99 | //如果存在根据获取的code查询对应的小区疫情数据 100 | if (j > 0) { 101 | Document doc1 = Jsoup.connect("https://iflow-api.uc.cn/feiyan/area?uc_param_str=utpclocp&code=" + code) 102 | .ignoreContentType(true) 103 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 104 | .header("content-type", "application/json") 105 | .timeout(5000).get(); 106 | res = JSONArray.parse(JSONUtil.parseObj(JSONUtil.parseObj(doc1.body().html()).get("data")).get("areaes").toString()); 107 | } else { 108 | List list = new ArrayList(); 109 | res = list; 110 | } 111 | 112 | } catch (IOException e) { 113 | e.printStackTrace(); 114 | } 115 | return ResultGenerator.genSuccessResult(res); 116 | } 117 | 118 | /** 119 | * 数据来源于腾讯 120 | * 根据省市名称获取当前市区历史数据 121 | * 122 | * @return 123 | */ 124 | @GetMapping("/getVillageByCommunityName") 125 | @ApiOperation("根据小区名称查询疫情小区") 126 | public Result getVillageByCommunityName(@RequestParam("communityName") String communityName) { 127 | Object res = ""; 128 | try { 129 | Document doc = Jsoup.connect("https://iflow-api.uc.cn/feiyan/area?uc_param_str=utpclocp&q=" + communityName) 130 | .ignoreContentType(true) 131 | .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)") 132 | .header("content-type", "application/json") 133 | .timeout(5000).get(); 134 | res = JSONArray.parse(JSONUtil.parseObj(JSONUtil.parseObj(doc.body().html()).get("data")).get("areaes").toString()); 135 | } catch (IOException e) { 136 | e.printStackTrace(); 137 | } 138 | return ResultGenerator.genSuccessResult(JSON.parse(res.toString())); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/ResponseMode/Result.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.ResponseMode; 2 | 3 | 4 | import cn.hutool.json.JSONUtil; 5 | 6 | 7 | /** 8 | * 统一API响应结果封装 9 | */ 10 | public class Result { 11 | private int code; 12 | private String message; 13 | private T data; 14 | 15 | public Result setCode(ResultCode resultCode) { 16 | this.code = resultCode.code(); 17 | return this; 18 | } 19 | 20 | public int getCode() { 21 | return code; 22 | } 23 | 24 | public String getMessage() { 25 | return message; 26 | } 27 | 28 | public Result setMessage(String message) { 29 | this.message = message; 30 | return this; 31 | } 32 | 33 | public T getData() { 34 | return data; 35 | } 36 | 37 | public Result setData(T data) { 38 | this.data = data; 39 | return this; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return JSONUtil.toJsonStr(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/ResponseMode/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.ResponseMode; 2 | 3 | /** 4 | * 响应码枚举,参考HTTP状态码的语义 5 | */ 6 | public enum ResultCode { 7 | SUCCESS(200),//成功 8 | FAIL(400),//失败 9 | UNAUTHORIZED(401),//未认证(签名错误) 10 | NOT_FOUND(404),//接口不存在 11 | INTERNAL_SERVER_ERROR(500);//服务器内部错误 12 | 13 | private final int code; 14 | 15 | ResultCode(int code) { 16 | this.code = code; 17 | } 18 | 19 | public int code() { 20 | return code; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/ResponseMode/ResultGenerator.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.ResponseMode; 2 | 3 | /** 4 | * 响应结果 5 | */ 6 | public class ResultGenerator { 7 | private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS"; 8 | 9 | public static Result genSuccessResult() { 10 | return new Result() 11 | .setCode(ResultCode.SUCCESS) 12 | .setMessage(DEFAULT_SUCCESS_MESSAGE); 13 | } 14 | 15 | public static Result genSuccessResult(T data) { 16 | return new Result() 17 | .setCode(ResultCode.SUCCESS) 18 | .setMessage(DEFAULT_SUCCESS_MESSAGE) 19 | .setData(data); 20 | } 21 | 22 | public static Result genSuccessResult(T data,String message) { 23 | return new Result() 24 | .setCode(ResultCode.SUCCESS) 25 | .setMessage(message) 26 | .setData(data); 27 | } 28 | 29 | public static Result genFailResult(String message) { 30 | return new Result() 31 | .setCode(ResultCode.FAIL) 32 | .setData("") 33 | .setMessage(message); 34 | } 35 | 36 | 37 | public static Result unauthorizedResult(String message) { 38 | return new Result() 39 | .setCode(ResultCode.UNAUTHORIZED) 40 | .setMessage(message); 41 | } 42 | public static Result ExceptionResult(String message) { 43 | return new Result() 44 | .setCode(ResultCode.FAIL) 45 | .setMessage(message) 46 | .setData(""); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/config/CORSFilter.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.config; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import javax.servlet.*; 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | @Component 11 | public class CORSFilter implements Filter { 12 | 13 | @Override 14 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 15 | throws IOException, ServletException { 16 | HttpServletResponse res = (HttpServletResponse) response; 17 | res.addHeader("Access-Control-Allow-Credentials", "true"); 18 | res.addHeader("Access-Control-Allow-Origin", "*"); 19 | res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); 20 | res.addHeader("Access-Control-Allow-Headers", "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN"); 21 | if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) { 22 | response.getWriter().println("ok"); 23 | return; 24 | } 25 | chain.doFilter(request, response); 26 | } 27 | 28 | @Override 29 | public void destroy() { 30 | } 31 | 32 | @Override 33 | public void init(FilterConfig filterConfig) throws ServletException { 34 | } 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/config/SwaggerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.config; 2 | 3 | import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | @EnableKnife4j 17 | public class SwaggerConfiguration { 18 | 19 | @Bean 20 | public Docket createRestApi() { 21 | return new Docket(DocumentationType.SWAGGER_2) 22 | .apiInfo(apiInfo()) 23 | .select() 24 | .apis(RequestHandlerSelectors.basePackage("com.wuliang.ncov.controller")) 25 | .paths(PathSelectors.any()) 26 | .build(); 27 | } 28 | 29 | private ApiInfo apiInfo() { 30 | return new ApiInfoBuilder() 31 | .title("新冠肺炎api") 32 | .description("疫情相关数据爬取,代码很简单,收集废了点时间,欢迎star,如果使用希望备注出处") 33 | .contact("伍亮(https://github.com/LiangWuCode/2019-nCov-api)") 34 | .version("1.0") 35 | .build(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/config/TimeInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.config; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.wuliang.ncov.core.redis.RedisDaoImpl; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.method.HandlerMethod; 7 | import org.springframework.web.servlet.HandlerInterceptor; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | import javax.annotation.Resource; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | //@Component 15 | public class TimeInterceptor implements HandlerInterceptor { 16 | @Resource 17 | private RedisDaoImpl redisDao; 18 | 19 | @Override 20 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 21 | 22 | String url = request.getRequestURI(); 23 | if (!StrUtil.contains(url, "error") && !StrUtil.contains(url, ".js") 24 | && !StrUtil.contains(url, ".css") && !StrUtil.contains(url, "swagger") 25 | && !StrUtil.contains(url, "webjars") && !StrUtil.contains(url, "favicon") 26 | ) { 27 | redisDao.hmSetIncrement(url, url, Long.valueOf(1)); 28 | redisDao.hmSetIncrement("total", "total", Long.valueOf(1)); 29 | } 30 | return true; 31 | } 32 | 33 | @Override 34 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object o, ModelAndView modelAndView) throws Exception { 35 | } 36 | 37 | @Override 38 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object o, Exception ex) throws Exception { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/config/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 8 | 9 | //@Configuration 10 | public class WebConfig extends WebMvcConfigurerAdapter { 11 | @Autowired 12 | private TimeInterceptor timeInterceptor; 13 | 14 | /** 15 | * 针对异步的拦截器配置,拦截异步请求 16 | * @param configurer 17 | */ 18 | @Override 19 | public void configureAsyncSupport(AsyncSupportConfigurer configurer) { 20 | super.configureAsyncSupport(configurer); 21 | } 22 | @Override 23 | public void addInterceptors(InterceptorRegistry registry) { 24 | registry.addInterceptor(timeInterceptor); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/redis/AbstractBaseRedisDao.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.redis; 2 | 3 | 4 | import org.springframework.data.redis.core.RedisTemplate; 5 | import org.springframework.data.redis.serializer.RedisSerializer; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * redis 相关的抽象类 11 | * @param 12 | * @param 13 | */ 14 | public abstract class AbstractBaseRedisDao { 15 | 16 | @Resource 17 | protected RedisTemplate redisTemplate; 18 | 19 | /** 20 | * 设置redisTemplate 21 | * 22 | * @param redisTemplate 23 | */ 24 | public void setRedisTemplate(RedisTemplate redisTemplate) { 25 | this.redisTemplate = redisTemplate; 26 | } 27 | 28 | /** 29 | * 获取 RedisSerializer 30 | */ 31 | protected RedisSerializer getRedisSerializer() { 32 | return redisTemplate.getStringSerializer(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/redis/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.redis; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 4 | import com.fasterxml.jackson.annotation.PropertyAccessor; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.data.redis.connection.RedisConnectionFactory; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.data.redis.core.StringRedisTemplate; 12 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 13 | 14 | import java.net.UnknownHostException; 15 | 16 | 17 | @Configuration 18 | public class RedisConfig { 19 | 20 | @Bean 21 | @ConditionalOnMissingBean(name = "redisTemplate") 22 | public RedisTemplate redisTemplate( 23 | RedisConnectionFactory redisConnectionFactory) 24 | throws UnknownHostException { 25 | 26 | Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); 27 | ObjectMapper om = new ObjectMapper(); 28 | om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 29 | om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 30 | jackson2JsonRedisSerializer.setObjectMapper(om); 31 | 32 | RedisTemplate template = new RedisTemplate(); 33 | template.setConnectionFactory(redisConnectionFactory); 34 | template.setKeySerializer(jackson2JsonRedisSerializer); 35 | template.setValueSerializer(jackson2JsonRedisSerializer); 36 | template.setHashKeySerializer(jackson2JsonRedisSerializer); 37 | template.setHashValueSerializer(jackson2JsonRedisSerializer); 38 | template.afterPropertiesSet(); 39 | return template; 40 | } 41 | 42 | @Bean 43 | @ConditionalOnMissingBean(StringRedisTemplate.class) 44 | public StringRedisTemplate stringRedisTemplate( 45 | RedisConnectionFactory redisConnectionFactory) 46 | throws UnknownHostException { 47 | StringRedisTemplate template = new StringRedisTemplate(); 48 | template.setConnectionFactory(redisConnectionFactory); 49 | return template; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/redis/RedisDao.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.redis; 2 | 3 | 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * redis相关接口 10 | */ 11 | public interface RedisDao { 12 | 13 | /** 14 | * 判断缓存中是否有对应的value 15 | * 16 | * @param key 17 | * @return boolean 18 | */ 19 | public boolean existsKey(Object key); 20 | 21 | /** 22 | * 根据key获取key列表(key值可为模糊匹配---taskInfo:taskDetail:* <---> *代表任意字符) 23 | * 24 | * @param pattern 25 | * @return Set 26 | */ 27 | public Set keys(Object pattern); 28 | 29 | /** 30 | * 根据key删除对应的value 31 | * 32 | * @param key 33 | */ 34 | public boolean delete(Object key); 35 | 36 | /** 37 | * 根据key获取个数 38 | * 39 | * @param key 40 | */ 41 | public int count(Object key); 42 | 43 | /** 44 | * 批量删除对应的value 45 | * 46 | * @param keys 47 | */ 48 | public void delete(String[] keys); 49 | 50 | /** 51 | * 批量删除key(key值可为模糊匹配---taskInfo:taskDetail:* <---> *代表任意字符) 52 | * 53 | * @param pattern 54 | */ 55 | public long deletePattern(Object pattern); 56 | 57 | /** 58 | * 批量删除对应的value 59 | * 60 | * @param keys 61 | */ 62 | public long delete(Set keys); 63 | 64 | /** 65 | * 写入缓存(操作字符串) 66 | * 67 | * @param key 68 | * @param value 69 | * @return boolean 70 | */ 71 | public boolean vSet(Object key, Object value); 72 | 73 | /** 74 | * 写入缓存设置时效时间(操作字符串) 75 | * 76 | * @param key 77 | * @param value 78 | * @return boolean 79 | */ 80 | public boolean vSet(Object key, Object value, Long expireTime); 81 | 82 | /** 83 | * 更新写入缓存设置时效时间(操作字符串) 84 | * 85 | * @param key 86 | * @return boolean 87 | */ 88 | public boolean vSetUpdate(Object key, Long expireTime); 89 | 90 | /** 91 | * 读取缓存(操作字符串) 92 | * 93 | * @param key 94 | * @return Object 95 | */ 96 | public Object vGet(Object key); 97 | 98 | /** 99 | * 哈希 添加(操作hash) 100 | * 101 | * @param key 102 | * @param hashKey 103 | * @param value 104 | */ 105 | public void hmSet(Object key, Object hashKey, Object value); 106 | 107 | /** 108 | * 哈希 添加(操作hash) 109 | * 110 | * @param key 111 | * @param map 112 | */ 113 | public void hmSetAll(Object key, Map map); 114 | 115 | /** 116 | * 哈希获取数据(操作hash) 117 | * 118 | * @param key 119 | * @return Map 120 | */ 121 | public Map hmGet(Object key); 122 | 123 | /** 124 | * 哈希获取数据(操作hash) 125 | * 126 | * @param key 127 | * @param hashKey 128 | * @return Object 129 | */ 130 | public Object hmGet(Object key, Object hashKey); 131 | 132 | /** 133 | * 哈希删除数据(操作hash) 134 | * 135 | * @param key 136 | * @param hashKey 137 | * @return Object 138 | */ 139 | public Object hmDel(Object key, Object hashKey); 140 | 141 | /** 142 | * 获取列表中个数 143 | * 144 | * @param k 145 | * @return long 146 | */ 147 | public long lSize(Object k); 148 | 149 | /** 150 | * 通过其索引从列表获取第一个元素(操作list) 151 | * 152 | * @param key 153 | * @return Object 154 | */ 155 | public Object lindexFirst(Object key); 156 | 157 | /** 158 | * 通过其索引从列表获取元素(操作list) 159 | * 160 | * @param key 161 | * @param index:索引位置,从0开始 162 | * @return Object 163 | */ 164 | public Object lindex(Object key, long index); 165 | 166 | /** 167 | * 从左向右添加列表(操作list) 168 | * 169 | * @param k 170 | * @param v 171 | */ 172 | public void lLeftPush(Object k, Object v); 173 | 174 | /** 175 | * 从左向右添加列表(操作list);如果bool=true,会删除列表中已经存在的数据,然后再进行添加(仅针对字符串列表,其它待测) 176 | * 177 | * @param k 178 | * @param v 179 | * @param bool 180 | */ 181 | public void lLeftPush(Object k, Object v, boolean bool); 182 | 183 | /** 184 | * 从左向右添加列表(操作list) 185 | * 186 | * @param k 187 | * @param lst 188 | */ 189 | public void lLeftPushAll(Object k, List lst); 190 | 191 | /** 192 | * 从右向左添加列表(操作list) 193 | * 194 | * @param k 195 | * @param v 196 | */ 197 | public void lRightPush(Object k, Object v); 198 | 199 | /** 200 | * 从右向左添加列表(操作list);如果bool=true,会删除列表中已经存在的数据,然后再进行添加(仅针对字符串列表,其它待测) 201 | * 202 | * @param k 203 | * @param v 204 | * @param bool 205 | */ 206 | public void lRightPush(Object k, Object v, boolean bool); 207 | 208 | /** 209 | * 从右向左添加列表(操作list) 210 | * 211 | * @param k 212 | * @param lst 213 | */ 214 | public void lRightPushAll(Object k, List lst); 215 | 216 | /** 217 | * 删除并获取列表中的第1个元素(操作list) 218 | * 219 | * @param k 220 | * @return Object 221 | */ 222 | public Object lLeftPop(Object k); 223 | 224 | /** 225 | * 删除并获取列表中的最后1个元素(操作list) 226 | * 227 | * @param k 228 | * @return Object 229 | */ 230 | public Object lRightPop(Object k); 231 | 232 | /** 233 | * 移除k中的count个,返回删除的个数;如果没有这个元素则返回0(操作list) 234 | * 235 | * @param k 236 | * @param count 237 | * @return long 238 | */ 239 | public long lRemove(Object k, long count); 240 | 241 | /** 242 | * 移除k中值为v的count个,返回删除的个数;如果没有这个元素则返回0(操作list) 243 | * 244 | * @param k 245 | * @param count 246 | * @param v 247 | * @return long 248 | */ 249 | public long lRemove(Object k, long count, Object v); 250 | 251 | /** 252 | * 移除k中值为v的所有数据,返回删除的个数;如果没有这个元素则返回0(操作list) 253 | * 254 | * @param k 255 | * @param v 256 | * @param v 257 | * @return long 258 | */ 259 | public long lRemove(Object k, Object v); 260 | 261 | /** 262 | * 根据key获取获取List列表(操作list) 263 | * 264 | * @param key 265 | * @return Object 266 | */ 267 | public Object lRange(Object key); 268 | 269 | /** 270 | * 根据key获取列表中第start至end的数据(操作list) 271 | * 272 | * @param k 273 | * @param start 274 | * @param end 275 | * @return List 276 | */ 277 | public List lRange(Object k, long start, long end); 278 | 279 | /** 280 | * 集合添加 281 | * 282 | * @param key 283 | * @param value 284 | */ 285 | public void sAdd(Object key, Object value); 286 | 287 | /** 288 | * 集合获取 289 | * 290 | * @param key 291 | * @return Set 292 | */ 293 | public Set sMembers(Object key); 294 | 295 | /** 296 | * 有序集合添加 297 | * 298 | * @param key 299 | * @param value 300 | * @param scoure 301 | */ 302 | public void zAdd(Object key, Object value, double scoure); 303 | 304 | /** 305 | * 有序集合获取 306 | * 307 | * @param key 308 | * @param scoure 309 | * @param scoure1 310 | * @return Set 311 | */ 312 | public Set rangeByScore(Object key, double scoure, double scoure1); 313 | 314 | /** 315 | * 将hashKey中储存的数字加上指定的增量值(操作hash) 316 | * 317 | * @param key 318 | * @param value 319 | * @return boolean 320 | */ 321 | public void hmSetIncrement(Object key, Object hashKey, Long value); 322 | 323 | } 324 | -------------------------------------------------------------------------------- /src/main/java/com/wuliang/ncov/core/redis/RedisDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov.core.redis; 2 | 3 | import org.springframework.data.redis.core.*; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Set; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | /** 12 | * 重写,实现接口并且继承抽象类 13 | */ 14 | @Repository("redisDao") 15 | public class RedisDaoImpl extends AbstractBaseRedisDao implements RedisDao { 16 | 17 | @Override 18 | public boolean existsKey(final Object key) { 19 | return redisTemplate.hasKey(key); 20 | } 21 | 22 | @Override 23 | public Set keys(final Object pattern) { 24 | return redisTemplate.keys(pattern); 25 | } 26 | 27 | @Override 28 | public boolean delete(final Object key) { 29 | return redisTemplate.delete(key); 30 | } 31 | 32 | @Override 33 | public int count(final Object key) { 34 | return redisTemplate.keys(key).size(); 35 | } 36 | 37 | @Override 38 | public long deletePattern(final Object pattern) { 39 | Set keys = redisTemplate.keys(pattern); 40 | if ((keys != null ? keys.size() : 0) > 0) { 41 | return redisTemplate.delete(keys); 42 | } else { 43 | return 0; 44 | } 45 | } 46 | 47 | @Override 48 | public void delete(final String[] keys) { 49 | for (String key : keys) { 50 | delete(key); 51 | } 52 | } 53 | 54 | @Override 55 | public long delete(final Set keys) { 56 | return redisTemplate.delete(keys); 57 | } 58 | 59 | @Override 60 | public boolean vSet(final Object key, Object value) { 61 | boolean result = false; 62 | try { 63 | ValueOperations operations = redisTemplate.opsForValue(); 64 | operations.set(key, value); 65 | result = true; 66 | } catch (Exception e) { 67 | e.printStackTrace(); 68 | } 69 | return result; 70 | } 71 | 72 | @Override 73 | public boolean vSet(final Object key, Object value, Long expireTime) { 74 | boolean result = false; 75 | try { 76 | ValueOperations operations = redisTemplate.opsForValue(); 77 | operations.set(key, value); 78 | redisTemplate.expire(key, expireTime, TimeUnit.SECONDS); 79 | result = true; 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | } 83 | return result; 84 | } 85 | 86 | @Override 87 | public boolean vSetUpdate(final Object key, Long expireTime) { 88 | boolean result = false; 89 | try { 90 | redisTemplate.expire(key, expireTime, TimeUnit.SECONDS); 91 | result = true; 92 | } catch (Exception e) { 93 | e.printStackTrace(); 94 | } 95 | return result; 96 | } 97 | 98 | @Override 99 | public Object vGet(final Object key) { 100 | Object result = null; 101 | ValueOperations operations = redisTemplate.opsForValue(); 102 | result = operations.get(key); 103 | return result; 104 | } 105 | 106 | @Override 107 | public void hmSet(Object key, Object hashKey, Object value) { 108 | HashOperations hash = redisTemplate.opsForHash(); 109 | hash.put(key, hashKey, value); 110 | } 111 | 112 | @Override 113 | public void hmSetAll(Object key, Map map) { 114 | HashOperations hash = redisTemplate.opsForHash(); 115 | hash.putAll(key, map); 116 | } 117 | 118 | @Override 119 | public Map hmGet(Object key) { 120 | HashOperations hash = redisTemplate.opsForHash(); 121 | return hash.entries(key); 122 | } 123 | 124 | @Override 125 | public Object hmGet(Object key, Object hashKey) { 126 | HashOperations hash = redisTemplate.opsForHash(); 127 | return hash.get(key, hashKey); 128 | } 129 | 130 | @Override 131 | public Object hmDel(Object key, Object hashKey) { 132 | HashOperations hash = redisTemplate.opsForHash(); 133 | return hash.delete(key, hashKey); 134 | } 135 | 136 | @Override 137 | public long lSize(Object k) { 138 | ListOperations list = redisTemplate.opsForList(); 139 | return list.size(k); 140 | } 141 | 142 | @Override 143 | public Object lRange(Object k) { 144 | ListOperations list = redisTemplate.opsForList(); 145 | return list.range(k, 0, list.size(k)); 146 | } 147 | 148 | @Override 149 | public List lRange(Object k, long start, long end) { 150 | ListOperations list = redisTemplate.opsForList(); 151 | return list.range(k, start, end); 152 | } 153 | 154 | @Override 155 | public Object lindexFirst(Object k) { 156 | ListOperations list = redisTemplate.opsForList(); 157 | return list.index(k, 0); 158 | } 159 | 160 | @Override 161 | public Object lindex(Object k, long index) { 162 | ListOperations list = redisTemplate.opsForList(); 163 | return list.index(k, index); 164 | } 165 | 166 | @Override 167 | public void lLeftPush(Object k, Object v) { 168 | ListOperations list = redisTemplate.opsForList(); 169 | list.leftPush(k, v); 170 | } 171 | 172 | @Override 173 | public void lLeftPush(Object k, Object v, boolean bool) { 174 | ListOperations list = redisTemplate.opsForList(); 175 | if (bool) { 176 | list.remove(k, list.size(k), v); 177 | } 178 | list.leftPush(k, v); 179 | } 180 | 181 | @Override 182 | public void lLeftPushAll(Object k, List lst) { 183 | ListOperations list = redisTemplate.opsForList(); 184 | list.leftPushAll(k, lst); 185 | } 186 | 187 | @Override 188 | public void lRightPush(Object k, Object v, boolean bool) { 189 | ListOperations list = redisTemplate.opsForList(); 190 | if (bool) { 191 | list.remove(k, list.size(k), v); 192 | } 193 | list.rightPush(k, v); 194 | } 195 | 196 | @Override 197 | public void lRightPush(Object k, Object v) { 198 | ListOperations list = redisTemplate.opsForList(); 199 | list.rightPush(k, v); 200 | } 201 | 202 | @Override 203 | public void lRightPushAll(Object k, List lst) { 204 | ListOperations list = redisTemplate.opsForList(); 205 | list.rightPushAll(k, lst); 206 | } 207 | 208 | 209 | 210 | @Override 211 | public Object lLeftPop(Object k) { 212 | ListOperations list = redisTemplate.opsForList(); 213 | return list.leftPop(k); 214 | } 215 | 216 | @Override 217 | public Object lRightPop(Object k) { 218 | ListOperations list = redisTemplate.opsForList(); 219 | return list.rightPop(k); 220 | } 221 | 222 | @Override 223 | public long lRemove(Object k, long count) { 224 | ListOperations list = redisTemplate.opsForList(); 225 | return list.remove(k, 0, null); 226 | } 227 | 228 | @Override 229 | public long lRemove(Object k, long count, Object v) { 230 | ListOperations list = redisTemplate.opsForList(); 231 | return list.remove(k, count, v); 232 | } 233 | 234 | @Override 235 | public long lRemove(Object k, Object v) { 236 | ListOperations list = redisTemplate.opsForList(); 237 | return list.remove(k, list.size(k), v); 238 | } 239 | 240 | @Override 241 | public void sAdd(Object key, Object value) { 242 | SetOperations set = redisTemplate.opsForSet(); 243 | set.add(key, value); 244 | } 245 | 246 | @Override 247 | public Set sMembers(Object key) { 248 | SetOperations set = redisTemplate.opsForSet(); 249 | return set.members(key); 250 | } 251 | 252 | @Override 253 | public void zAdd(Object key, Object value, double scoure) { 254 | ZSetOperations zset = redisTemplate.opsForZSet(); 255 | zset.add(key, value, scoure); 256 | } 257 | 258 | @Override 259 | public Set rangeByScore(Object key, double scoure, double scoure1) { 260 | ZSetOperations zset = redisTemplate.opsForZSet(); 261 | return zset.rangeByScore(key, scoure, scoure1); 262 | } 263 | 264 | @Override 265 | public void hmSetIncrement(Object key, Object hashKey, Long value) { 266 | HashOperations hash = redisTemplate.opsForHash(); 267 | hash.increment(key, hashKey, value); 268 | }} 269 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 80 3 | spring: 4 | application: 5 | name: ncov 6 | # redis: 7 | # port: 6379 8 | # database: 0 9 | # host: 127.0.0.1 10 | # password: 11 | # jedis: 12 | # pool: 13 | # max-active: 8 14 | # max-wait: -1ms 15 | # max-idle: 8 16 | # min-idle: 0 17 | # timeout: 5000ms 18 | 19 | -------------------------------------------------------------------------------- /src/test/java/com/wuliang/ncov/NcovApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wuliang.ncov; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class NcovApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------