From 5ad4e3799a861da02a280c579ec10f4b7c333695 Mon Sep 17 00:00:00 2001 From: wu Date: Wed, 8 May 2024 09:54:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 39 +++ pom.xml | 107 ++++++++ .../yingji/YingjiAlgorithmsApplication.java | 19 ++ .../com/yingji/base/constant/HttpStatus.java | 93 +++++++ .../base/controller/BaseController.java | 78 ++++++ .../com/yingji/base/domain/AjaxResult.java | 202 +++++++++++++++ .../com/yingji/config/MybatisPlusConfig.java | 26 ++ .../java/com/yingji/config/SwaggerConfig.java | 74 ++++++ .../yingji/controller/AlarmController.java | 131 ++++++++++ .../java/com/yingji/entity/AcceptEvents.java | 35 +++ src/main/java/com/yingji/entity/Alarm.java | 148 +++++++++++ src/main/java/com/yingji/entity/Amb.java | 22 ++ src/main/java/com/yingji/entity/Source.java | 36 +++ src/main/java/com/yingji/entity/Task.java | 37 +++ .../java/com/yingji/entity/TaskInfos.java | 19 ++ .../entity/dto/request/AccidentRequest.java | 32 +++ .../entity/dto/request/AlarmFindRequest.java | 90 +++++++ .../entity/dto/request/AlarmRequest.java | 44 ++++ .../entity/dto/request/TokenRequest.java | 38 +++ .../entity/dto/response/EventsResponse.java | 39 +++ .../entity/dto/response/GeneralResponse.java | 23 ++ .../java/com/yingji/mapper/AlarmMapper.java | 36 +++ .../java/com/yingji/mapper/SourceMapper.java | 31 +++ .../java/com/yingji/quartz/AlarmQuartz.java | 79 ++++++ .../com/yingji/quartz/SaveAlarmQuartz.java | 81 ++++++ .../java/com/yingji/service/AlarmService.java | 70 ++++++ .../com/yingji/service/SourceService.java | 36 +++ .../yingji/service/impl/AlarmServiceImpl.java | 234 ++++++++++++++++++ .../service/impl/SourceServiceImpl.java | 55 ++++ src/main/resources/application-dev.yml | 42 ++++ src/main/resources/application.yml | 7 + .../resources/mapper/yingji/AlarmMapper.xml | 85 +++++++ .../resources/mapper/yingji/SourceMapper.xml | 20 ++ 33 files changed, 2108 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/com/yingji/YingjiAlgorithmsApplication.java create mode 100644 src/main/java/com/yingji/base/constant/HttpStatus.java create mode 100644 src/main/java/com/yingji/base/controller/BaseController.java create mode 100644 src/main/java/com/yingji/base/domain/AjaxResult.java create mode 100644 src/main/java/com/yingji/config/MybatisPlusConfig.java create mode 100644 src/main/java/com/yingji/config/SwaggerConfig.java create mode 100644 src/main/java/com/yingji/controller/AlarmController.java create mode 100644 src/main/java/com/yingji/entity/AcceptEvents.java create mode 100644 src/main/java/com/yingji/entity/Alarm.java create mode 100644 src/main/java/com/yingji/entity/Amb.java create mode 100644 src/main/java/com/yingji/entity/Source.java create mode 100644 src/main/java/com/yingji/entity/Task.java create mode 100644 src/main/java/com/yingji/entity/TaskInfos.java create mode 100644 src/main/java/com/yingji/entity/dto/request/AccidentRequest.java create mode 100644 src/main/java/com/yingji/entity/dto/request/AlarmFindRequest.java create mode 100644 src/main/java/com/yingji/entity/dto/request/AlarmRequest.java create mode 100644 src/main/java/com/yingji/entity/dto/request/TokenRequest.java create mode 100644 src/main/java/com/yingji/entity/dto/response/EventsResponse.java create mode 100644 src/main/java/com/yingji/entity/dto/response/GeneralResponse.java create mode 100644 src/main/java/com/yingji/mapper/AlarmMapper.java create mode 100644 src/main/java/com/yingji/mapper/SourceMapper.java create mode 100644 src/main/java/com/yingji/quartz/AlarmQuartz.java create mode 100644 src/main/java/com/yingji/quartz/SaveAlarmQuartz.java create mode 100644 src/main/java/com/yingji/service/AlarmService.java create mode 100644 src/main/java/com/yingji/service/SourceService.java create mode 100644 src/main/java/com/yingji/service/impl/AlarmServiceImpl.java create mode 100644 src/main/java/com/yingji/service/impl/SourceServiceImpl.java create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/mapper/yingji/AlarmMapper.xml create mode 100644 src/main/resources/mapper/yingji/SourceMapper.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b14a138 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +/.idea + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f0d21e9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,107 @@ + + + 4.0.0 + com.yingji + yingjiAlgorithms + 0.0.1-SNAPSHOT + yingjiAlgorithms + 应急算法 + + 1.8 + UTF-8 + UTF-8 + 2.7.6 + + + + org.springframework.boot + spring-boot-starter-web + + + com.mysql + mysql-connector-j + 8.2.0 + runtime + + + org.projectlombok + lombok + true + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.5 + + + + com.github.xiaoymin + knife4j-openapi2-spring-boot-starter + 4.4.0 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + cn.hutool + hutool-all + 5.8.25 + + + com.alibaba.fastjson2 + fastjson2 + 2.0.41 + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + algorithms + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.yingji.YingjiAlgorithmsApplication + + + + repackage + + repackage + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/yingji/YingjiAlgorithmsApplication.java b/src/main/java/com/yingji/YingjiAlgorithmsApplication.java new file mode 100644 index 0000000..73edcbd --- /dev/null +++ b/src/main/java/com/yingji/YingjiAlgorithmsApplication.java @@ -0,0 +1,19 @@ +package com.yingji; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author wu + * @since 2024/2/26 10:24 + */ + +@SpringBootApplication +@MapperScan("com.yingji.mapper") +public class YingjiAlgorithmsApplication { + public static void main(String[] args) { + SpringApplication.run(YingjiAlgorithmsApplication.class, args); + + } +} \ No newline at end of file diff --git a/src/main/java/com/yingji/base/constant/HttpStatus.java b/src/main/java/com/yingji/base/constant/HttpStatus.java new file mode 100644 index 0000000..1d2ac09 --- /dev/null +++ b/src/main/java/com/yingji/base/constant/HttpStatus.java @@ -0,0 +1,93 @@ +package com.yingji.base.constant; + +/** + * 返回状态码 + * + * @author ruoyi + */ +public class HttpStatus { + /** + * 操作成功 + */ + public static final int SUCCESS = 200; + + /** + * 对象创建成功 + */ + public static final int CREATED = 201; + + /** + * 请求已经被接受 + */ + public static final int ACCEPTED = 202; + + /** + * 操作已经执行成功,但是没有返回数据 + */ + public static final int NO_CONTENT = 204; + + /** + * 资源已被移除 + */ + public static final int MOVED_PERM = 301; + + /** + * 重定向 + */ + public static final int SEE_OTHER = 303; + + /** + * 资源没有被修改 + */ + public static final int NOT_MODIFIED = 304; + + /** + * 参数列表错误(缺少,格式不匹配) + */ + public static final int BAD_REQUEST = 400; + + /** + * 未授权 + */ + public static final int UNAUTHORIZED = 401; + + /** + * 访问受限,授权过期 + */ + public static final int FORBIDDEN = 403; + + /** + * 资源,服务未找到 + */ + public static final int NOT_FOUND = 404; + + /** + * 不允许的http方法 + */ + public static final int BAD_METHOD = 405; + + /** + * 资源冲突,或者资源被锁 + */ + public static final int CONFLICT = 409; + + /** + * 不支持的数据,媒体类型 + */ + public static final int UNSUPPORTED_TYPE = 415; + + /** + * 系统内部错误 + */ + public static final int ERROR = 500; + + /** + * 接口未实现 + */ + public static final int NOT_IMPLEMENTED = 501; + + /** + * 系统警告消息 + */ + public static final int WARN = 601; +} diff --git a/src/main/java/com/yingji/base/controller/BaseController.java b/src/main/java/com/yingji/base/controller/BaseController.java new file mode 100644 index 0000000..6af991b --- /dev/null +++ b/src/main/java/com/yingji/base/controller/BaseController.java @@ -0,0 +1,78 @@ +package com.yingji.base.controller; + +import com.yingji.base.domain.AjaxResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * web层通用数据处理 + * + * @author ruoyi + */ +public class BaseController { + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + + /** + * 返回成功 + */ + public AjaxResult success() { + return AjaxResult.success(); + } + + /** + * 返回失败消息 + */ + public AjaxResult error() { + return AjaxResult.error(); + } + + /** + * 返回成功消息 + */ + public AjaxResult success(String message) { + return AjaxResult.success(message); + } + + /** + * 返回成功消息 + */ + public AjaxResult success(Object data) { + return AjaxResult.success(data); + } + + /** + * 返回失败消息 + */ + public AjaxResult error(String message) { + return AjaxResult.error(message); + } + + /** + * 返回警告消息 + */ + public AjaxResult warn(String message) { + return AjaxResult.warn(message); + } + + /** + * 响应返回结果 + * + * @param rows 影响行数 + * @return 操作结果 + */ + protected AjaxResult toAjax(int rows) { + return rows > 0 ? AjaxResult.success() : AjaxResult.error(); + } + + /** + * 响应返回结果 + * + * @param result 结果 + * @return 操作结果 + */ + protected AjaxResult toAjax(boolean result) { + return result ? success() : error(); + } + +} diff --git a/src/main/java/com/yingji/base/domain/AjaxResult.java b/src/main/java/com/yingji/base/domain/AjaxResult.java new file mode 100644 index 0000000..06fb8a0 --- /dev/null +++ b/src/main/java/com/yingji/base/domain/AjaxResult.java @@ -0,0 +1,202 @@ +package com.yingji.base.domain; + + +import cn.hutool.core.bean.BeanUtil; +import com.yingji.base.constant.HttpStatus; + +import java.util.HashMap; +import java.util.Objects; + +/** + * 操作消息提醒 + * + * @author ruoyi + */ +public class AjaxResult extends HashMap { + /** + * 状态码 + */ + public static final String CODE_TAG = "code"; + /** + * 返回内容 + */ + public static final String MSG_TAG = "msg"; + /** + * 数据对象 + */ + public static final String DATA_TAG = "data"; + private static final long serialVersionUID = 1L; + + /** + * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。 + */ + public AjaxResult() { + } + + /** + * 初始化一个新创建的 AjaxResult 对象 + * + * @param code 状态码 + * @param msg 返回内容 + */ + public AjaxResult(int code, String msg) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + } + + /** + * 初始化一个新创建的 AjaxResult 对象 + * + * @param code 状态码 + * @param msg 返回内容 + * @param data 数据对象 + */ + public AjaxResult(int code, String msg, Object data) { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + if (BeanUtil.isNotEmpty(data)) { + super.put(DATA_TAG, data); + } + } + + /** + * 返回成功消息 + * + * @return 成功消息 + */ + public static AjaxResult success() { + return AjaxResult.success("操作成功"); + } + + /** + * 返回成功数据 + * + * @return 成功消息 + */ + public static AjaxResult success(Object data) { + return AjaxResult.success("操作成功", data); + } + + /** + * 返回成功消息 + * + * @param msg 返回内容 + * @return 成功消息 + */ + public static AjaxResult success(String msg) { + return AjaxResult.success(msg, null); + } + + /** + * 返回成功消息 + * + * @param msg 返回内容 + * @param data 数据对象 + * @return 成功消息 + */ + public static AjaxResult success(String msg, Object data) { + return new AjaxResult(HttpStatus.SUCCESS, msg, data); + } + + /** + * 返回警告消息 + * + * @param msg 返回内容 + * @return 警告消息 + */ + public static AjaxResult warn(String msg) { + return AjaxResult.warn(msg, null); + } + + /** + * 返回警告消息 + * + * @param msg 返回内容 + * @param data 数据对象 + * @return 警告消息 + */ + public static AjaxResult warn(String msg, Object data) { + return new AjaxResult(HttpStatus.WARN, msg, data); + } + + /** + * 返回错误消息 + * + * @return 错误消息 + */ + public static AjaxResult error() { + return AjaxResult.error("操作失败"); + } + + /** + * 返回错误消息 + * + * @param msg 返回内容 + * @return 错误消息 + */ + public static AjaxResult error(String msg) { + return AjaxResult.error(msg, null); + } + + /** + * 返回错误消息 + * + * @param msg 返回内容 + * @param data 数据对象 + * @return 错误消息 + */ + public static AjaxResult error(String msg, Object data) { + return new AjaxResult(HttpStatus.ERROR, msg, data); + } + + /** + * 返回错误消息 + * + * @param code 状态码 + * @param msg 返回内容 + * @return 错误消息 + */ + public static AjaxResult error(int code, String msg) { + return new AjaxResult(code, msg, null); + } + + /** + * 是否为成功消息 + * + * @return 结果 + */ + public boolean isSuccess() { + return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG)); + } + + /** + * 是否为警告消息 + * + * @return 结果 + */ + public boolean isWarn() { + return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG)); + } + + /** + * 是否为错误消息 + * + * @return 结果 + */ + public boolean isError() { + return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG)); + } + + /** + * 方便链式调用 + * + * @param key 键 + * @param value 值 + * @return 数据对象 + */ + @Override + public AjaxResult put(String key, Object value) { + super.put(key, value); + return this; + } +} diff --git a/src/main/java/com/yingji/config/MybatisPlusConfig.java b/src/main/java/com/yingji/config/MybatisPlusConfig.java new file mode 100644 index 0000000..5943191 --- /dev/null +++ b/src/main/java/com/yingji/config/MybatisPlusConfig.java @@ -0,0 +1,26 @@ +package com.yingji.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author wu + * @since 2024/2/26 11:28 + */ +@Configuration +public class MybatisPlusConfig { + + /** + * 添加分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//如果配置多个插件,切记分页最后添加 + //interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); 如果有多数据源可以不配具体类型 否则都建议配上具体的DbType + return interceptor; + } +} diff --git a/src/main/java/com/yingji/config/SwaggerConfig.java b/src/main/java/com/yingji/config/SwaggerConfig.java new file mode 100644 index 0000000..e33e2f6 --- /dev/null +++ b/src/main/java/com/yingji/config/SwaggerConfig.java @@ -0,0 +1,74 @@ +package com.yingji.config; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +/** + * Swagger2的接口配置 + * + * @author ruoyi + */ +@Configuration +@EnableSwagger2WebMvc +public class SwaggerConfig { + + + /** + * 是否开启swagger + */ + @Value("${knife4j.enable}") + private boolean enabled; + + /** + * 创建API + */ + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + // 是否启用Swagger + .enable(enabled) + //分组名称 + .groupName("应急算法") + // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) + .apiInfo(apiInfo()) + // 设置哪些接口暴露给Swagger展示 + .select() + // 扫描所有有注解的api,用这种方式更灵活 + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) + // 扫描指定包中的swagger注解 + // .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger")) + // 扫描所有 .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() +// .pathMapping(pathMapping) + // 排除mybatis-plus的分页参数 + .ignoredParameterTypes(Page.class, IPage.class); + } + + + /** + * 添加摘要信息 + */ + private ApiInfo apiInfo() { + // 用ApiInfoBuilder进行定制 + return new ApiInfoBuilder() + // 设置标题 + .title("应急算法") + // 描述 + .description("描述:用于应急算法") + // 版本 + .version("版本号:" + 1) + .build(); + } +} diff --git a/src/main/java/com/yingji/controller/AlarmController.java b/src/main/java/com/yingji/controller/AlarmController.java new file mode 100644 index 0000000..9170e49 --- /dev/null +++ b/src/main/java/com/yingji/controller/AlarmController.java @@ -0,0 +1,131 @@ +package com.yingji.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.yingji.base.controller.BaseController; +import com.yingji.base.domain.AjaxResult; +import com.yingji.entity.Alarm; +import com.yingji.entity.dto.request.AlarmFindRequest; +import com.yingji.service.AlarmService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.List; + +/** + * 报警事件(Alarm)表控制层 + * + * @author wu + * @since 2024-05-06 09:15:01 + */ +@RestController +@RequestMapping("algorithms/alarm") +@Api(tags = "报警事件") +public class AlarmController extends BaseController { + /** + * 服务对象 + */ + @Resource + private AlarmService alarmService; + + /** + * 分页条件查询所有数据 + * + * @param page 分页条件 + * @param req 查询条件 + * @return 所有数据 + */ + @GetMapping + @ApiOperation(value = "分页条件查询报警事件", response = Alarm.class) + public AjaxResult page(Page page, AlarmFindRequest req) { + return success(alarmService.page(page, req)); + } + + /** + * 条件查询所有报警事件 + * + * @param req 查询条件 + * @return 所有数据 + */ + @GetMapping("/findAll") + @ApiOperation(value = "条件查询所有报警事件", response = Alarm.class) + public AjaxResult findAll(AlarmFindRequest req) { + return success(alarmService.findAll(req)); + } + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{id}") + @ApiOperation(value = "通过主键查询单条报警事件", response = Alarm.class) + public AjaxResult getById(@PathVariable Serializable id) { + return success(alarmService.getById(id)); + } + + /** + * 新增数据 + * + * @param alarm 实体对象 + * @return 新增结果 + */ + @PostMapping + @ApiOperation(value = "新增报警事件", response = Alarm.class) + public AjaxResult insert(@RequestBody Alarm alarm) { + return success(alarmService.save(alarm)); + } + + /** + * 修改数据 + * + * @param alarm 实体对象 + * @return 修改结果 + */ + @PutMapping + @ApiOperation(value = "修改报警事件") + public AjaxResult update(@RequestBody Alarm alarm) { + return success(alarmService.updateById(alarm)); + } + + /** + * 删除数据 + * + * @param idList 主键集合 + * @return 删除结果 + */ + @DeleteMapping + @ApiOperation(value = "删除报警事件") + public AjaxResult delete(@RequestParam("idList") List idList) { + return success(alarmService.removeByIds(idList)); + } + + /** + * 同步数据 + * + * @param startTime 查询条件 + * @param size 查询条数 + * @return 所有数据 + */ + @GetMapping("/synchronous") + @ApiOperation(value = "同步数据") + public AjaxResult synchronous(String startTime, Integer size) { + alarmService.synchronous(startTime,size); + return success(); + } +} + diff --git a/src/main/java/com/yingji/entity/AcceptEvents.java b/src/main/java/com/yingji/entity/AcceptEvents.java new file mode 100644 index 0000000..3207aa5 --- /dev/null +++ b/src/main/java/com/yingji/entity/AcceptEvents.java @@ -0,0 +1,35 @@ +package com.yingji.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author wu + * @since 2024/4/30 下午4:17 + */ +@Data +public class AcceptEvents implements Serializable { + + private static final long serialVersionUID = 2498572602663676559L; + + private String AlarmTelephone; + private String DiseaseJudge; + private String PatientName; + private String PatientSex; + private String PatientAge; + private String AcceptType; + private String ResponsibleRecipient; + private String WaitAddress; + private String SendAddress; + private String RingDateTime; + private Date StartAcceptDateTime; + private Date EndAcceptDateTime; + private Date SendOrderDateTime; + private String EventAddress; + private String AcceptId; + private String EventId; + private String AcceptOrder; + +} diff --git a/src/main/java/com/yingji/entity/Alarm.java b/src/main/java/com/yingji/entity/Alarm.java new file mode 100644 index 0000000..9906352 --- /dev/null +++ b/src/main/java/com/yingji/entity/Alarm.java @@ -0,0 +1,148 @@ +package com.yingji.entity; + +import cn.hutool.core.annotation.Alias; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDateTime; + + +/** + * (Alarm)表实体类 + * + * @author wu + * @since 2024-05-07 14:50:30 + */ +@Data +@ApiModel("实体类") +@TableName(value = "alarm") +public class Alarm implements Serializable { + + private static final long serialVersionUID = -61131421311961793L; + + /** + * 主键id + */ + @ApiModelProperty(value = "主键id") + @TableId(type = IdType.AUTO) + private Long emergencyEventId; + private Integer emergencyEventSource; + private Integer emergencyEventStatus; + private Integer warnResponseStatus; + private Integer emergencyResponseStatus; + private String emergencyEventTitle; + private Integer emergencyEventType; + private Integer emergencyEventLevel; + + /** + * 报警时间 + */ + @ApiModelProperty(value = "报警时间") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime emergencyEventTime; + + /** + * 报警内容 + */ + @ApiModelProperty(value = "报警内容") + @Alias("bjnr") + private String emergencyEventDesc; + + /** + * 报警地址 + */ + @Alias("sfdd") + @ApiModelProperty(value = "报警地址") + private String emergencyEventAddress; + private String emergencyEventArea; + private Double emergencyEventLon; + private Double emergencyEventLat; + private String submitUnit; + private String submitUnitContact; + private String submitUnitTelephone; + private String reportPerson; + private String reportPersonTelephone; + private String remark; + private String fileUrls; + + /** + * 是否删除 0未删除 1删除 + */ + @ApiModelProperty(value = "是否删除 0未删除 1删除") + private Integer delFlag; + + /** + * 创建人 + */ + @ApiModelProperty(value = "创建人") + private String createBy; + + /** + * 创建时间 + */ + @ApiModelProperty(value = "创建时间") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + /** + * 最后更新人 + */ + @ApiModelProperty(value = "最后更新人") + private String updateBy; + + /** + * 最后更新时间 + */ + @ApiModelProperty(value = "最后更新时间") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; + private String sendOutTimes; + private Long groupId; + private Integer isRehearsal; + + /** + * 手机号 + */ + @ApiModelProperty(value = "报警电话") + @Alias("bjdh") + private String alarmPhoneNumber; + + /** + * 源id + */ + @ApiModelProperty(value = "源id") + private String sourceId; + private Integer isJudged; + private String eventDetail; + /** + * 预警大类 + */ + @ApiModelProperty(value = "预警大类") + private String aiCategories; + /** + * 预警小类 + */ + @ApiModelProperty(value = "预警小类") + private String aiSubCategories; + /** + * 紧急程度 + */ + @ApiModelProperty(value = "紧急程度") + private String aiLevel; + /** + * 紧急系数 + */ + @ApiModelProperty(value = "紧急系数") + private Double aiNum; +} + diff --git a/src/main/java/com/yingji/entity/Amb.java b/src/main/java/com/yingji/entity/Amb.java new file mode 100644 index 0000000..c4a3ec1 --- /dev/null +++ b/src/main/java/com/yingji/entity/Amb.java @@ -0,0 +1,22 @@ +package com.yingji.entity; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author wu + * @since 2024/4/30 下午4:18 + */ +@Data +public class Amb implements Serializable { + + private static final long serialVersionUID = -9140135874884043915L; + + private String PlateNumber; + private String RealSign; + private String AmbCode; + private String StationName; + private String AmbType; + private String AmbPhone; +} diff --git a/src/main/java/com/yingji/entity/Source.java b/src/main/java/com/yingji/entity/Source.java new file mode 100644 index 0000000..a59046f --- /dev/null +++ b/src/main/java/com/yingji/entity/Source.java @@ -0,0 +1,36 @@ +package com.yingji.entity; + + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiModel; +import lombok.Data; + + +/** + * (Source)表实体类 + * + * @author wu + * @since 2024-05-07 18:03:09 + */ +@Data +@ApiModel("实体类") +@TableName(value = "source") +public class Source implements Serializable { + + private static final long serialVersionUID = -80185849209851185L; + /** + * 主键id + */ + @ApiModelProperty(value = "主键id") + private Long id; + /** + * 任务id + */ + @ApiModelProperty(value = "任务id") + private String sourceId; +} + diff --git a/src/main/java/com/yingji/entity/Task.java b/src/main/java/com/yingji/entity/Task.java new file mode 100644 index 0000000..095ea11 --- /dev/null +++ b/src/main/java/com/yingji/entity/Task.java @@ -0,0 +1,37 @@ +package com.yingji.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author wu + * @since 2024/4/30 下午4:23 + */ +@Data +public class Task implements Serializable { + private static final long serialVersionUID = 4118581272605160572L; + + private Boolean IsOver; + private String RealSendAddress; + private Date TaskCreatedDateTime; + private Date AcceptOrderDateTime; + private Date OutAmbDateTime; + private Date ArriveSceneDateTime; + private Date LeaveSceneDateTime; + private Date ArriveHospitalDateTime; + private Date ComplatedDateTime; + private Date ReturnStationDateTime; + private Boolean IsNormalOver; + private String AbnormalReason; + private String Driver; + private String Doctor; + private String Stretcher; + private String Nurse; + private String StationName; + private String TaskId; + private String AcceptOrder; + private String AcceptId; + private String EventId; +} diff --git a/src/main/java/com/yingji/entity/TaskInfos.java b/src/main/java/com/yingji/entity/TaskInfos.java new file mode 100644 index 0000000..183803d --- /dev/null +++ b/src/main/java/com/yingji/entity/TaskInfos.java @@ -0,0 +1,19 @@ +package com.yingji.entity; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author wu + * @since 2024/4/30 下午4:19 + */ +@Data +public class TaskInfos implements Serializable { + + private static final long serialVersionUID = 4118581272605160572L; + + private Amb Amb; + + private Task Task; +} diff --git a/src/main/java/com/yingji/entity/dto/request/AccidentRequest.java b/src/main/java/com/yingji/entity/dto/request/AccidentRequest.java new file mode 100644 index 0000000..556e9aa --- /dev/null +++ b/src/main/java/com/yingji/entity/dto/request/AccidentRequest.java @@ -0,0 +1,32 @@ +package com.yingji.entity.dto.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 120获取事件请求类 + * + * @author wu + * @since 2024/4/30 下午4:09 + */ +@Data +@ApiModel(value = "120获取事件请求类") +public class AccidentRequest implements Serializable { + + private static final long serialVersionUID = -3450693580974529886L; + + /** + * 开始时间字符串 + */ + @ApiModelProperty(value = "开始时间字符串") + private String StartDateTime; + + /** + * 结束时间字符串 + */ + @ApiModelProperty(value = "结束时间字符串") + private String EndDateTime; +} diff --git a/src/main/java/com/yingji/entity/dto/request/AlarmFindRequest.java b/src/main/java/com/yingji/entity/dto/request/AlarmFindRequest.java new file mode 100644 index 0000000..1421a28 --- /dev/null +++ b/src/main/java/com/yingji/entity/dto/request/AlarmFindRequest.java @@ -0,0 +1,90 @@ +package com.yingji.entity.dto.request; + +import cn.hutool.core.annotation.Alias; +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Date; + +/** + * Alarm查询请求类 + * + * @author wu + * @since 2024/4/30 下午3:59 + */ +@ApiModel(value = "Alarm查询请求类") +@Data +public class AlarmFindRequest implements Serializable { + + + private static final long serialVersionUID = 5773800327954649047L; + /** + * 开始时间 + */ + @ApiModelProperty("开始时间") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime startTime; + + /** + * 结束时间 + */ + @ApiModelProperty("结束时间") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime endTime; + + /** + * 报警内容 + */ + @ApiModelProperty(value = "报警内容") + private String emergencyEventDesc; + + /** + * 报警地址 + */ + @ApiModelProperty(value = "报警地址") + private String emergencyEventAddress; + + /** + * 手机号 + */ + @ApiModelProperty(value = "报警电话") + private String alarmPhoneNumber; + + /** + * 预警大类 + */ + @ApiModelProperty(value = "预警大类") + private String aiCategories; + + /** + * 预警小类 + */ + @ApiModelProperty(value = "预警小类") + private String aiSubCategories; + + /** + * 紧急程度 + */ + @ApiModelProperty(value = "紧急程度") + private String aiLevel; + + /** + * 紧急系数最小值 + */ + @ApiModelProperty(value = "紧急系数最小值") + private Double aiNumMin; + + /** + * 紧急系数最小值 + */ + @ApiModelProperty(value = "紧急系数最大值") + private Double aiNumMax; +} diff --git a/src/main/java/com/yingji/entity/dto/request/AlarmRequest.java b/src/main/java/com/yingji/entity/dto/request/AlarmRequest.java new file mode 100644 index 0000000..a48a234 --- /dev/null +++ b/src/main/java/com/yingji/entity/dto/request/AlarmRequest.java @@ -0,0 +1,44 @@ +package com.yingji.entity.dto.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 110报警请求类 + * + * @author wu + * @since 2024/4/30 下午3:59 + */ +@ApiModel(value = "110报警请求类") +@Data +public class AlarmRequest implements Serializable { + + private static final long serialVersionUID = 7661630897162054093L; + + /** + * 类型(getId / getValue) + */ + @ApiModelProperty(value = "类型(getId / getValue)", required = true) + private String type; + + /** + * 值(时间 / Id) + */ + @ApiModelProperty(value = "值(时间 / Id)", required = true) + private String value; + + /** + * 当前页 + */ + @ApiModelProperty(value = "当前页 默认1") + private Integer pageIndex; + + /** + * 每页显示条数 + */ + @ApiModelProperty(value = "每页显示条数 默认10") + private Integer pageSize; +} diff --git a/src/main/java/com/yingji/entity/dto/request/TokenRequest.java b/src/main/java/com/yingji/entity/dto/request/TokenRequest.java new file mode 100644 index 0000000..c9022fc --- /dev/null +++ b/src/main/java/com/yingji/entity/dto/request/TokenRequest.java @@ -0,0 +1,38 @@ +package com.yingji.entity.dto.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 120token请求类 + * + * @author wu + * @since 2024/4/30 下午4:05 + */ +@Data +@ApiModel(value = "120token请求类") +public class TokenRequest implements Serializable { + + private static final long serialVersionUID = -2538907503968466851L; + + /** + * key admin + */ + @ApiModelProperty(value = "key") + private String AKey; + + /** + * secret anchor120 + */ + @ApiModelProperty(value = "secret") + private String Asecret; + + /** + * 当前时间字符串 + */ + @ApiModelProperty(value = "当前时间字符串") + private String AccessDateTime; +} diff --git a/src/main/java/com/yingji/entity/dto/response/EventsResponse.java b/src/main/java/com/yingji/entity/dto/response/EventsResponse.java new file mode 100644 index 0000000..c690e58 --- /dev/null +++ b/src/main/java/com/yingji/entity/dto/response/EventsResponse.java @@ -0,0 +1,39 @@ +package com.yingji.entity.dto.response; + +import com.yingji.entity.AcceptEvents; +import com.yingji.entity.TaskInfos; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @author wu + * @since 2024/4/30 下午4:24 + */ +@Data +public class EventsResponse implements Serializable { + + private static final long serialVersionUID = -3894493286879970663L; + + private List AcceptEvents; + private List TaskInfos; + private String EventName; + private String EventType; + private String EventLevel; + private Date EventDateTime; + private String EventDescribe; + private String EventArea; + private String EventAddress; + private Double EventLongitude; + private Double EventLatitude; + private String AlarmUnit; + private String AlarmUnitContactor; + private String AlarmUnitTelephone; + private Integer SendAmbCount; + private String AttachmentInfo; + private String Remark; + private String EventId; + +} diff --git a/src/main/java/com/yingji/entity/dto/response/GeneralResponse.java b/src/main/java/com/yingji/entity/dto/response/GeneralResponse.java new file mode 100644 index 0000000..bb629d9 --- /dev/null +++ b/src/main/java/com/yingji/entity/dto/response/GeneralResponse.java @@ -0,0 +1,23 @@ +package com.yingji.entity.dto.response; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 通用响应类 + * + * @author wu + * @since 2024/4/30 下午4:16 + */ +@Data +public class GeneralResponse implements Serializable { + + private static final long serialVersionUID = 3346787118665022563L; + + private List data; + private String msg; + private int code; + +} diff --git a/src/main/java/com/yingji/mapper/AlarmMapper.java b/src/main/java/com/yingji/mapper/AlarmMapper.java new file mode 100644 index 0000000..f82c356 --- /dev/null +++ b/src/main/java/com/yingji/mapper/AlarmMapper.java @@ -0,0 +1,36 @@ +package com.yingji.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.yingji.entity.Alarm; +import com.yingji.entity.dto.request.AlarmFindRequest; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 报警事件(Alarm)表数据库访问层 + * + * @author wu + * @since 2024-05-06 09:15:01 + */ +public interface AlarmMapper extends BaseMapper { + + /** + * 分页条件查询数据 + * + * @param page 分页条件 + * @param req 查询条件 + * @return 数据 + */ + Page page(Page page, @Param("req") AlarmFindRequest req); + + /** + * 条件查询数据 + * + * @param req 查询条件 + * @return 数据 + */ + List findAll(@Param("req") AlarmFindRequest req); +} + diff --git a/src/main/java/com/yingji/mapper/SourceMapper.java b/src/main/java/com/yingji/mapper/SourceMapper.java new file mode 100644 index 0000000..f7091e8 --- /dev/null +++ b/src/main/java/com/yingji/mapper/SourceMapper.java @@ -0,0 +1,31 @@ +package com.yingji.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.yingji.entity.Source; + +import java.util.List; + +/** + * (Source)表数据库访问层 + * + * @author wu + * @since 2024-05-07 18:03:09 + */ +public interface SourceMapper extends BaseMapper { + + /** + * 保存任务源id + * + * @param list 任务源id + */ + void addList(List list); + + /** + * 查询所有sourceId + * + * @return SourceIdList + */ + List findSourceAll(); + +} + diff --git a/src/main/java/com/yingji/quartz/AlarmQuartz.java b/src/main/java/com/yingji/quartz/AlarmQuartz.java new file mode 100644 index 0000000..d9b740d --- /dev/null +++ b/src/main/java/com/yingji/quartz/AlarmQuartz.java @@ -0,0 +1,79 @@ +package com.yingji.quartz; + +import cn.hutool.core.util.StrUtil; +import com.yingji.entity.dto.request.AlarmRequest; +import com.yingji.service.AlarmService; +import com.yingji.service.SourceService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +/** + * 110数据保存定时任务 + * + * @author wu + * @since 2024/05/06 10:18 + */ +@Configuration +@EnableScheduling +public class AlarmQuartz { + + public static final Logger log = LoggerFactory.getLogger(AlarmQuartz.class); + + @Resource + private AlarmService alarmService; + + @Resource + private SourceService sourceService; + + /** + * 保存所有id + */ + @Scheduled(cron = "0 */5 * * * ? ") + private void savaData() { + // 获取token + String token = alarmService.getToken(); + if (StrUtil.isEmpty(token)) { + return; + } + // 获取五分钟前的时间 + LocalDateTime yesterday = LocalDateTime.now().minusMinutes(5); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm"); + String yesterdayStr = yesterday.format(formatter) + "00"; + // 定义起始页 + int pageIndex = 1; + // 定义每页显示条数 + int pageSize = 5000; + // 定义总数据条数 + int size = 0; + // 定义type + String type = "getId"; + // 查询id条件 + AlarmRequest req = new AlarmRequest(); + req.setType(type); + req.setValue(yesterdayStr); + req.setPageIndex(pageIndex); + req.setPageSize(pageSize); + while (true) { + List data = alarmService.findDataIdList(req, token); + if (data == null) { + return; + } + sourceService.addList(data); + size += data.size(); + if (data.size() == pageSize) { + req.setPageIndex(pageIndex++); + log.info("第" + pageIndex + "页==========================" + size + "条数据"); + } else { + break; + } + } + } +} diff --git a/src/main/java/com/yingji/quartz/SaveAlarmQuartz.java b/src/main/java/com/yingji/quartz/SaveAlarmQuartz.java new file mode 100644 index 0000000..cbf4106 --- /dev/null +++ b/src/main/java/com/yingji/quartz/SaveAlarmQuartz.java @@ -0,0 +1,81 @@ +package com.yingji.quartz; + +import cn.hutool.core.util.StrUtil; +import com.yingji.entity.Alarm; +import com.yingji.entity.dto.request.AlarmRequest; +import com.yingji.service.AlarmService; +import com.yingji.service.SourceService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * 110数据保存定时任务 + * + * @author wu + * @since 2024/05/06 10:18 + */ +@Configuration +@EnableScheduling +@Transactional(rollbackFor = Exception.class) +public class SaveAlarmQuartz { + + public static final Logger log = LoggerFactory.getLogger(SaveAlarmQuartz.class); + + @Resource + private AlarmService alarmService; + + @Resource + private SourceService sourceService; + + @Scheduled(cron = "0 */1 * * * ? ") + private void savaData() { + // 查询所有id + List data = sourceService.findSourceAll(); + // 查询数据条件 + AlarmRequest alarmRequest = new AlarmRequest(); + alarmRequest.setType("getValue"); + alarmRequest.setPageIndex(1); + alarmRequest.setPageSize(10); + // 定义成功条数 + int successNum = 0; + // 定义失败条数 + int failuresNum = 0; + List list = new ArrayList<>(); + if (data == null) { + return; + } + // 获取token + String token = alarmService.getToken(); + if (StrUtil.isEmpty(token)) { + return; + } + for (String x : data) { + try { + alarmRequest.setValue(x); + Alarm alarm = alarmService.findDataList(alarmRequest, token); + if (alarm != null) { + alarm.setSourceId(x); + list.add(alarm); + sourceService.delBySourceId(x); + successNum++; + Thread.sleep(2000); + } + } catch (Exception e) { + failuresNum++; + log.info("==========================" + "id:" + x, "更新数据失败"); + log.info("失败更新=========================" + failuresNum + "条数据"); + } + } + alarmService.saveBatch(list); + log.info("成功更新=========================" + successNum + "条数据"); + + } +} diff --git a/src/main/java/com/yingji/service/AlarmService.java b/src/main/java/com/yingji/service/AlarmService.java new file mode 100644 index 0000000..397182b --- /dev/null +++ b/src/main/java/com/yingji/service/AlarmService.java @@ -0,0 +1,70 @@ +package com.yingji.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.yingji.entity.Alarm; +import com.yingji.entity.dto.request.AlarmFindRequest; +import com.yingji.entity.dto.request.AlarmRequest; + +import java.util.List; + +/** + * 报警事件(Alarm)表服务接口 + * + * @author wu + * @since 2024-05-06 09:15:01 + */ +public interface AlarmService extends IService { + + /** + * 同步数据 + * + * @param startTime 查询条件 + * @param size 查询条数 + */ + void synchronous(String startTime, Integer size); + + + /** + * 查询数据Id + * + * @param req 查询条件 + * @param token token + * @return 数据IdList + */ + List findDataIdList(AlarmRequest req, String token); + + /** + * 查询数据 + * + * @param req 查询条件 + * @param token token + * @return 数据List + */ + Alarm findDataList(AlarmRequest req, String token); + + /** + * 获取110token + * + * @return token + */ + String getToken(); + + /** + * 分页条件查询数据 + * + * @param page 分页条件 + * @param req 查询条件 + * @return 数据 + */ + Page page(Page page, AlarmFindRequest req); + + /** + * 条件查询数据 + * + * @param req 查询条件 + * @return 数据 + */ + List findAll(AlarmFindRequest req); +} + diff --git a/src/main/java/com/yingji/service/SourceService.java b/src/main/java/com/yingji/service/SourceService.java new file mode 100644 index 0000000..ccb7fc2 --- /dev/null +++ b/src/main/java/com/yingji/service/SourceService.java @@ -0,0 +1,36 @@ +package com.yingji.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.yingji.entity.Source; + +import java.util.List; + +/** + * (Source)表服务接口 + * + * @author wu + * @since 2024-05-07 18:03:09 + */ +public interface SourceService extends IService { + + /** + * 保存任务源id + * + * @param list 任务源id + */ + void addList(List list); + + /** + * 查询所有sourceId + * + * @return SourceIdList + */ + List findSourceAll(); + + /** + * 根据sourceId删除 + * @param sourceId 源id + */ + void delBySourceId(String sourceId); +} + diff --git a/src/main/java/com/yingji/service/impl/AlarmServiceImpl.java b/src/main/java/com/yingji/service/impl/AlarmServiceImpl.java new file mode 100644 index 0000000..6fbb106 --- /dev/null +++ b/src/main/java/com/yingji/service/impl/AlarmServiceImpl.java @@ -0,0 +1,234 @@ +package com.yingji.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.codec.Base64; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.yingji.entity.Alarm; +import com.yingji.entity.dto.request.AlarmFindRequest; +import com.yingji.entity.dto.request.AlarmRequest; +import com.yingji.mapper.AlarmMapper; +import com.yingji.service.AlarmService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +/** + * 报警事件(Alarm)表服务实现类 + * + * @author wu + * @since 2024-05-06 09:15:01 + */ +@Service("alarmService") +public class AlarmServiceImpl extends ServiceImpl implements AlarmService { + + public static final Logger log = LoggerFactory.getLogger(AlarmServiceImpl.class); + @Value("${clientId}") + private String clientId; + + @Value("${clientSecret}") + private String clientSecret; + + @Value("${getToken}") + private String getToken; + + @Value("${specificWarn}") + private String specificWarn; + + /** + * base64加密密钥 + * + * @return base64加密后的密钥 + */ + public String findBase() { + String str = clientId + ":" + clientSecret; + return Base64.encode(str); + } + + /** + * 同步数据 + * + * @param startTime 查询条件 + * @param size 查询条数 + */ + @Override + public void synchronous(String startTime, Integer size) { + // 获取token + String token = getToken(); + if (StrUtil.isEmpty(token)) { + return; + } + // 定义起始页 + int pageIndex = 1; + // 定义每页显示条数 + int pageSize = 10; + // 保存获取的条数 + int total = 0; + // 定义type + String type = "getId"; + // 查询id条件 + AlarmRequest req = new AlarmRequest(); + req.setType(type); + req.setValue(startTime); + req.setPageIndex(pageIndex); + req.setPageSize(pageSize); + // 查询数据条件 + AlarmRequest alarmRequest = new AlarmRequest(); + alarmRequest.setType("getValue"); + alarmRequest.setPageIndex(1); + alarmRequest.setPageSize(10); + while (true) { + total += pageSize; + List data = findDataIdList(req, token); + if (data == null) { + return; + } + log.info("======================================="); + log.info("数据的条数为:" + data.size()); + List list = new ArrayList<>(); + data.forEach(x -> { + alarmRequest.setValue(x); + Alarm alarm = findDataList(alarmRequest, token); + alarm.setSourceId(x); + list.add(alarm); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + log.info("睡眠1秒失败"); + } + }); + saveBatch(list); + // 总条数 + if (total >= size) { + return; + } + if (data.size() == pageSize) { + req.setPageIndex(pageIndex++); + log.info("第" + pageIndex + "页==========================" + list.size() + "条数据"); + } else { + break; + } + } + } + + /** + * 查询数据Id + * + * @param req 查询条件 + * @param token token + * @return 数据IdList + */ + @Override + public List findDataIdList(AlarmRequest req, String token) { + String bodyJson = JSONObject.toJSONString(req); + List records = null; + // 获取id + String body = HttpRequest.post(specificWarn).header("Authorization", "Basic " + token).body(bodyJson).execute().body(); + JSONObject json = JSONObject.parse(body); + Object response = json.get("response"); + if (BeanUtil.isNotEmpty(response)) { + String responseStr = JSONUtil.toJsonStr(response); + JSONObject res = JSONObject.parse(responseStr); + String recordsStr = JSONUtil.toJsonStr(res.get("records")); + if (StrUtil.isNotEmpty(recordsStr)) { + records = JSONUtil.toList(recordsStr, String.class); + } + } + return records; + } + + /** + * 查询数据 + * + * @param req 查询条件 + * @param token token + * @return 数据List + */ + @Override + public Alarm findDataList(AlarmRequest req, String token) { + String bodyJson = JSONObject.toJSONString(req); + Alarm records = null; + // 获取id + String body = HttpRequest.post(specificWarn).header("Authorization", "Basic " + token).header("Content-Type", "application/json").body(bodyJson).execute().body(); + log.info("==============================="); + log.info("body数据为:" + body); + try { + JSONObject json = JSONObject.parse(body); + Object response = json.get("response"); + if (BeanUtil.isNotEmpty(response)) { + String recordsStr = JSONUtil.toJsonStr(response); + records = JSONUtil.toBean(recordsStr, Alarm.class); + JSONObject recordsJson = JSONObject.parse(recordsStr); + Object bjdhsj = recordsJson.get("bjdhsj"); + String bjdhsjStr = JSONUtil.toJsonStr(bjdhsj); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withZone(ZoneId.systemDefault()); + LocalDateTime emergencyEventTime = LocalDateTime.parse(bjdhsjStr, formatter); + records.setEmergencyEventTime(emergencyEventTime); + records.setCreateTime(LocalDateTime.now()); + records.setUpdateTime(LocalDateTime.now()); + records.setDelFlag(0); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return records; + } + + /** + * 获取110token + * + * @return token + */ + @Override + public String getToken() { + String accessToken = null; + String body = HttpRequest.get(getToken).header("Authorization", "Basic QkZTaFQzL1d3UGhaSlFkTDhlNEZkblExMWgwUU9lS3FCZG4reGVzQ1NKR2xESEtQazVmeG5tbkxrMW9ua20zWXpkZmpFMGdMR0VaN0g3dmZMczIxc0dNPTpHdGJnUmZOSW1Yam1CcVcwbnB4VWlHaS9zMG1iNVpkdlhBTnFVQ2dtSW00PQ==").header("Content-Type", "application/json").form("grant_type", "client_credentials").execute().body(); + JSONObject json = JSONObject.parse(body); + Object response = json.get("response"); + if (BeanUtil.isNotEmpty(response)) { + String recordsStr = JSONUtil.toJsonStr(response); + JSONObject res = JSONObject.parse(recordsStr); + accessToken = (String) res.get("access_token"); + } + log.info("======================================="); + log.info("token为:" + accessToken); + return accessToken; + } + + /** + * 分页条件查询数据 + * + * @param page 分页条件 + * @param req 查询条件 + * @return 数据 + */ + @Override + public Page page(Page page, AlarmFindRequest req) { + return baseMapper.page(page,req); + } + + /** + * 条件查询数据 + * + * @param req 查询条件 + * @return 数据 + */ + @Override + public List findAll(AlarmFindRequest req) { + return baseMapper.findAll(req); + } +} + diff --git a/src/main/java/com/yingji/service/impl/SourceServiceImpl.java b/src/main/java/com/yingji/service/impl/SourceServiceImpl.java new file mode 100644 index 0000000..cd272b8 --- /dev/null +++ b/src/main/java/com/yingji/service/impl/SourceServiceImpl.java @@ -0,0 +1,55 @@ +package com.yingji.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.yingji.entity.Source; +import com.yingji.mapper.SourceMapper; +import com.yingji.service.SourceService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * (Source)表服务实现类 + * + * @author wu + * @since 2024-05-07 18:03:09 + */ +@Service("sourceService") +public class SourceServiceImpl extends ServiceImpl implements SourceService { + + /** + * 保存任务源id + * + * @param list 任务源id + */ + @Override + public void addList(List list) { + baseMapper.addList(list); + } + + /** + * 查询所有sourceId + * + * @return SourceIdList + */ + @Override + public List findSourceAll() { + return baseMapper.findSourceAll(); + } + + /** + * 根据sourceId删除 + * + * @param sourceId 源id + */ + @Override + public void delBySourceId(String sourceId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("source_id", sourceId); + baseMapper.delete(wrapper); + } + + +} + diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..7c0aacb --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,42 @@ +# DataSource Config +spring: + datasource: + url: jdbc:mysql://localhost:3306/algorithms?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: root + password: 123456 + driverClassName: com.mysql.cj.jdbc.Driver + + + +# 日志配置 +logging: + level: + com.yingji: debug + org.springframework: warn + +# MyBatis配置 +mybatis-plus: + # 指定实体类所在包的路径,MyBatis-Plus 会自动扫描该路径下的实体类 + typeAliasesPackage: com.yingji.entity + # 指定 Mapper 接口所在包的路径,MyBatis-Plus 会自动扫描该路径下的 Mapper 接口 + mapperLocations: classpath*:mapper/yingji/*Mapper.xml + +knife4j: + enable: true +# openapi: +# group: +# test1: +# group-name: 应急算法 + +# 110获取token +getToken: http://2.46.4.198:8008/token + +# 110获取数据 +specificWarn: http://2.46.4.198:8008/rs/k4r3h/DataAnalysisService/sz/share/specificWarn + +#110 +clientId: BFShT3/WwPhZJQdL8e4FdnQ11h0QOeKqBdn+xesCSJGlDHKPk5fxnmnLk1onkm3YzdfjE0gLGEZ7H7vfLs21sGM= + +#110 +clientSecret: GtbgRfNImXjmBqW0npxUiGi/s0mb5ZdvXANqUCgmIm4= + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..b433159 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,7 @@ +server: + port: 9001 +spring: + profiles: + active: dev + + diff --git a/src/main/resources/mapper/yingji/AlarmMapper.xml b/src/main/resources/mapper/yingji/AlarmMapper.xml new file mode 100644 index 0000000..9d30dd2 --- /dev/null +++ b/src/main/resources/mapper/yingji/AlarmMapper.xml @@ -0,0 +1,85 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/yingji/SourceMapper.xml b/src/main/resources/mapper/yingji/SourceMapper.xml new file mode 100644 index 0000000..04f385e --- /dev/null +++ b/src/main/resources/mapper/yingji/SourceMapper.xml @@ -0,0 +1,20 @@ + + + + + + + insert into source + (source_id) values + + (#{id}) + + + + + \ No newline at end of file