diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java index 9bc93a2..5935dad 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java @@ -22,7 +22,7 @@ * @author: djt * @create: 2022-01-18 17:00 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class LoginAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java index 9bc93a2..5935dad 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java @@ -22,7 +22,7 @@ * @author: djt * @create: 2022-01-18 17:00 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class LoginAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java index 4623864..5e9f207 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java @@ -17,7 +17,7 @@ * @author: djt * @create: 2022-01-19 19:23 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class ZiGuangDataJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java index 9bc93a2..5935dad 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java @@ -22,7 +22,7 @@ * @author: djt * @create: 2022-01-18 17:00 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class LoginAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java index 4623864..5e9f207 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java @@ -17,7 +17,7 @@ * @author: djt * @create: 2022-01-19 19:23 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class ZiGuangDataJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java index 4cdc82d..3991a8a 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-01-20 13:56 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class GqAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java index 9bc93a2..5935dad 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java @@ -22,7 +22,7 @@ * @author: djt * @create: 2022-01-18 17:00 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class LoginAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java index 4623864..5e9f207 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java @@ -17,7 +17,7 @@ * @author: djt * @create: 2022-01-19 19:23 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class ZiGuangDataJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java index 4cdc82d..3991a8a 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-01-20 13:56 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class GqAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java index e191c81..9fdb68e 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java @@ -25,7 +25,7 @@ * @author: djt * @create: 2022-01-19 10:11 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class HdAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java index 9bc93a2..5935dad 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java @@ -22,7 +22,7 @@ * @author: djt * @create: 2022-01-18 17:00 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class LoginAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java index 4623864..5e9f207 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java @@ -17,7 +17,7 @@ * @author: djt * @create: 2022-01-19 19:23 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class ZiGuangDataJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java index 4cdc82d..3991a8a 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-01-20 13:56 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class GqAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java index e191c81..9fdb68e 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java @@ -25,7 +25,7 @@ * @author: djt * @create: 2022-01-19 10:11 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class HdAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java index 45cf4f8..1a8210b 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java @@ -27,7 +27,7 @@ * @author: djt * @create: 2022-01-19 19:26 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class HpAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java index 9bc93a2..5935dad 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java @@ -22,7 +22,7 @@ * @author: djt * @create: 2022-01-18 17:00 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class LoginAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java index 4623864..5e9f207 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java @@ -17,7 +17,7 @@ * @author: djt * @create: 2022-01-19 19:23 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class ZiGuangDataJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java index 4cdc82d..3991a8a 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-01-20 13:56 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class GqAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java index e191c81..9fdb68e 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java @@ -25,7 +25,7 @@ * @author: djt * @create: 2022-01-19 10:11 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class HdAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java index 45cf4f8..1a8210b 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java @@ -27,7 +27,7 @@ * @author: djt * @create: 2022-01-19 19:26 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class HpAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java index f034a84..14cfdf8 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java @@ -33,7 +33,7 @@ * @author: djt * @create: 2022-01-20 17:09 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class YlAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java new file mode 100644 index 0000000..7deb1d8 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/IResultCode.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import java.io.Serializable; + +/** + * 业务代码接口 + * + * @author Chill + */ +public interface IResultCode extends Serializable { + + /** + * 获取消息 + * + * @return + */ + String getMessage(); + + /** + * 获取状态码 + * + * @return + */ + int getCode(); + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/R.java b/src/main/java/org/springnewfiber/dataadapter/config/R.java new file mode 100644 index 0000000..fd3a213 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/R.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.lang.Nullable; + +import javax.servlet.http.HttpServletResponse; +import java.io.Serializable; +import java.util.Optional; + +/** + * 统一API响应结果封装 + * + * @author Chill + */ +@Getter +@Setter +@ToString +@ApiModel(description = "返回信息") +@NoArgsConstructor +public class R implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "状态码", required = true) + private int code; + @ApiModelProperty(value = "是否成功", required = true) + private boolean success; + @ApiModelProperty(value = "承载数据") + private T data; + @ApiModelProperty(value = "返回消息", required = true) + private String msg; + + private R(IResultCode resultCode) { + this(resultCode, null, resultCode.getMessage()); + } + + private R(IResultCode resultCode, String msg) { + this(resultCode, null, msg); + } + + private R(IResultCode resultCode, T data) { + this(resultCode, data, resultCode.getMessage()); + } + + private R(IResultCode resultCode, T data, String msg) { + this(resultCode.getCode(), data, msg); + } + + private R(int code, T data, String msg) { + this.code = code; + this.data = data; + this.msg = msg; + this.success = ResultCode.SUCCESS.code == code; + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isSuccess(@Nullable R result) { + return Optional.ofNullable(result) + .map(x -> ObjectUtil.notEqual(ResultCode.SUCCESS.code, x.code)) + .orElse(Boolean.FALSE); + } + + /** + * 判断返回是否为成功 + * + * @param result Result + * @return 是否成功 + */ + public static boolean isNotSuccess(@Nullable R result) { + return !R.isSuccess(result); + } + + /** + * 返回R + * + * @param data 数据 + * @param T 泛型标记 + * @return R + */ + public static R data(T data) { + return data(data, DEFAULT_SUCCESS_MESSAGE); + } + + /** + * 返回R + * + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(T data, String msg) { + return data(HttpServletResponse.SC_OK, data, msg); + } + + /** + * 返回R + * + * @param code 状态码 + * @param data 数据 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R data(int code, T data, String msg) { + return new R<>(code, data, data == null ? DEFAULT_NULL_MESSAGE : msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(T data, String msg) { + return new R(ResultCode.SUCCESS, data, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(String msg) { + return new R<>(ResultCode.SUCCESS, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R success(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(String msg) { + return new R<>(ResultCode.FAILURE, msg); + } + + + /** + * 返回R + * + * @param code 状态码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(int code, String msg) { + return new R<>(code, null, msg); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode) { + return new R<>(resultCode); + } + + /** + * 返回R + * + * @param resultCode 业务代码 + * @param msg 消息 + * @param T 泛型标记 + * @return R + */ + public static R fail(IResultCode resultCode, String msg) { + return new R<>(resultCode, msg); + } + + /** + * 返回R + * + * @param flag 成功状态 + * @return R + */ + public static R status(boolean flag) { + return flag ? success(DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 返回R + * + * @param id id + * @return R + */ + public static R status(T id) { + return Long.parseLong(id.toString()) > 0L ? success(id, DEFAULT_SUCCESS_MESSAGE) : fail(DEFAULT_FAILURE_MESSAGE); + } + + /** + * 默认为空消息 + */ + static String DEFAULT_NULL_MESSAGE = "暂无承载数据"; + /** + * 默认成功消息 + */ + static String DEFAULT_SUCCESS_MESSAGE = "操作成功"; + /** + * 默认失败消息 + */ + static String DEFAULT_FAILURE_MESSAGE = "操作失败"; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java new file mode 100644 index 0000000..f2fec4d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/config/ResultCode.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springnewfiber.dataadapter.config; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.servlet.http.HttpServletResponse; + +/** + * 业务代码枚举 + * + * @author Chill + */ +@Getter +@AllArgsConstructor +public enum ResultCode implements IResultCode { + + /** + * 操作成功 + */ + SUCCESS(HttpServletResponse.SC_OK, "操作成功"), + + /** + * 业务异常 + */ + FAILURE(HttpServletResponse.SC_BAD_REQUEST, "业务异常"), + + /** + * 请求未授权 + */ + UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "请求未授权"), + + /** + * 客户端请求未授权 + */ + CLIENT_UN_AUTHORIZED(HttpServletResponse.SC_UNAUTHORIZED, "客户端请求未授权"), + + /** + * 404 没找到请求 + */ + NOT_FOUND(HttpServletResponse.SC_NOT_FOUND, "404 没找到请求"), + + /** + * 消息不能读取 + */ + MSG_NOT_READABLE(HttpServletResponse.SC_BAD_REQUEST, "消息不能读取"), + + /** + * 不支持当前请求方法 + */ + METHOD_NOT_SUPPORTED(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "不支持当前请求方法"), + + /** + * 不支持当前媒体类型 + */ + MEDIA_TYPE_NOT_SUPPORTED(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "不支持当前媒体类型"), + + /** + * 请求被拒绝 + */ + REQ_REJECT(HttpServletResponse.SC_FORBIDDEN, "请求被拒绝"), + + /** + * 服务器异常 + */ + INTERNAL_SERVER_ERROR(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "服务器异常"), + + /** + * 缺少必要的请求参数 + */ + PARAM_MISS(HttpServletResponse.SC_BAD_REQUEST, "缺少必要的请求参数"), + + /** + * 请求参数类型错误 + */ + PARAM_TYPE_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数类型错误"), + + /** + * 请求参数绑定错误 + */ + PARAM_BIND_ERROR(HttpServletResponse.SC_BAD_REQUEST, "请求参数绑定错误"), + + /** + * 参数校验失败 + */ + PARAM_VALID_ERROR(HttpServletResponse.SC_BAD_REQUEST, "参数校验失败"), + ; + + /** + * code编码 + */ + final int code; + /** + * 中文信息描述 + */ + final String message; + +} diff --git a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java index 4d4c619..afaa888 100644 --- a/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java +++ b/src/main/java/org/springnewfiber/dataadapter/entity/PtReceiveBaseModel.java @@ -1,6 +1,5 @@ package org.springnewfiber.dataadapter.entity; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Data; @@ -14,7 +13,9 @@ */ @Data public class PtReceiveBaseModel implements Serializable { - public static final Set constantSet= Sets.newHashSet(RealTimeConsstant.st,RealTimeConsstant.tt,RealTimeConsstant.ut); + public static final Set constantSet = Sets.newHashSet(RealTimeConsstant.st, RealTimeConsstant.tt, RealTimeConsstant.ut); + public static final Set XFconstantSet = Sets.newHashSet(RealTimeConsstant.xfst, RealTimeConsstant.xftt, RealTimeConsstant.xfstnm); + /** * 站点标识符 */ @@ -71,5 +72,8 @@ String ut = "ut"; String st = "st"; String sn = "sn"; + String xfst = "stcd"; + String xftt = "tm"; + String xfstnm = "stnm"; } } diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java index d0a98f9..c2e71bd 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/core/SswjCoreJob.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-04-21 19:06 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class SswjCoreJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java index 0be4843..cbcbb40 100644 --- a/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java +++ b/src/main/java/org/springnewfiber/dataadapter/sswj/util/RealTimeSerializer.java @@ -5,18 +5,23 @@ import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Filter; +import cn.hutool.core.util.ReflectUtil; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.springnewfiber.dataadapter.entity.MqNodeData; import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; -import org.springnewfiber.dataadapter.sswj.entity.BzLive; +import org.springnewfiber.dataadapter.xf.entity.BaseXfInterfaceEntity; +import org.springnewfiber.dataadapter.xf.entity.MonitorChnlDataDto; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.util.Date; import java.util.Map; @@ -46,15 +51,23 @@ } public static void main(String[] args) { - BzLive bzLive = new BzLive(); - bzLive.setDataUpStatus("1"); - bzLive.setDataUpUuid("111111"); - System.out.println(); - System.out.println(JSONObject.toJSONString(bzLive)); +// BzLive bzLive = new BzLive(); +// bzLive.setDataUpStatus("1"); +// bzLive.setDataUpUuid("111111"); +// System.out.println(); +// System.out.println(JSONObject.toJSONString(bzLive)); + MonitorChnlDataDto dto = new MonitorChnlDataDto(); +// dto.setWptn(new BigDecimal(2)); + dto.setZ(new BigDecimal(2)); + dto.setTm(new Date()); + dto.setStnm("ceshi"); + dto.setStcd("123456789"); + PtReceiveBaseModel json = xfObjectToRealMap(dto); + System.out.println(JSONObject.toJSONString(json)); } public static PtReceiveBaseModel objectToRealMap(Object object) { - if(null==object){ + if (null == object) { return null; } Map map = BeanUtil.beanToMap(JSONObject.parse(JSONObject.toJSONString(object))); @@ -77,7 +90,46 @@ }); model.setSt(map.get(PtReceiveBaseModel.RealTimeConsstant.st).toString()); model.setTt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.tt).toString(), DatePattern.NORM_DATETIME_PATTERN)); - model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut)==null?DateUtil.format(new Date(),DatePattern.NORM_DATETIME_PATTERN):map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setUt(DateUtil.parse(map.get(PtReceiveBaseModel.RealTimeConsstant.ut) == null ? DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN) : map.get(PtReceiveBaseModel.RealTimeConsstant.ut).toString(), DatePattern.NORM_DATETIME_PATTERN)); + model.setDataMap(dataMap); + return model; + } + + public static PtReceiveBaseModel xfObjectToRealMap(BaseXfInterfaceEntity object) { + if (null == object) { + return null; + } + PtReceiveBaseModel model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + ReflectUtil.getFieldMap(object.getClass()).forEach((filedName, filed) -> { + try { + JsonProperty annotation = filed.getAnnotation(JsonProperty.class); + filed.setAccessible(true); + if (!PtReceiveBaseModel.XFconstantSet.contains(filedName)) { + if (filed.get(object) == null || StringUtils.isBlank(filed.get(object).toString())) { + return; + } + if (annotation != null) { + String name = annotation.value(); +// System.out.println(name); + MqNodeData data = new MqNodeData(); + data.setSn(filedName); + data.setKey(name); + data.setValue(filed.get(object)); + if(dataMap.containsKey(name)){ + dataMap.put(filedName, data); + }else { + dataMap.put(name, data); + } + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + }); + model.setSt(object.getStcd()); + model.setTt(object.getTm()); + model.setUt(new Date()); model.setDataMap(dataMap); return model; } diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java new file mode 100644 index 0000000..1a659ca --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/XfDataEnum.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum XfDataEnum { + ChnlData("ChnlData","港渠信息"), + ForcastData("ForcastData","汉口水情"), + LakeData("LakeData","湖泊监测数据"), + Meteorological("Meteorological","气象站实时监测数据"), + PptnData("PptnData","降雨量"), + PumpData("PumpData","泵站信息"), + RiverData("RiverData","河道信息"), + SoilData("SoilData","土壤墒情"), + WasData("WasData","涵闸监测数据"), + WetlogData("WetlogData","渍水实时数据"), + ; + private String code; + private String remark; + + XfDataEnum(String code, String remark) { + this.code = code; + this.remark = remark; + } + public static XfDataEnum match(String code){ + for (XfDataEnum value : XfDataEnum.values()) { + if(StringUtils.equalsIgnoreCase(value.getCode(),code)){ + return value; + } + } + return null; + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java new file mode 100644 index 0000000..7bd0e50 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/controller/MonitorDataController.java @@ -0,0 +1,101 @@ +package org.springnewfiber.dataadapter.xf.controller; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.collect.Maps; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springnewfiber.dataadapter.config.R; +import org.springnewfiber.dataadapter.entity.MqNodeData; +import org.springnewfiber.dataadapter.entity.PtReceiveBaseModel; +import org.springnewfiber.dataadapter.sswj.util.RealTimeSerializer; +import org.springnewfiber.dataadapter.xf.XfDataEnum; +import org.springnewfiber.dataadapter.xf.entity.*; + +import java.util.Date; +import java.util.Map; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 20:44 + **/ +@RestController +@AllArgsConstructor +//@PreAuth(AuthConstant.PERMISSION_ALL) +@RequestMapping("/monitorData") +@Api(value = "讯飞数据接受接口", tags = "讯飞数据接受接口") +@Slf4j +public class MonitorDataController { + @PostMapping("/xfInterface") + public R xfInterface(@ApiParam(value = "数据json") @RequestParam("data") String data, @ApiParam(value = "数据类型") @RequestParam("xfBaseData") XfDataEnum xfDataEnum) { + log.error("data:{},flag:{}", JSONObject.toJSONString(data), xfDataEnum.getRemark()); + PtReceiveBaseModel model = new PtReceiveBaseModel(); + try { + if (xfDataEnum == XfDataEnum.ChnlData) { + MonitorChnlDataDto DTO = JSONObject.parseObject(data, MonitorChnlDataDto.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.ForcastData) { + MonitorForcastData DTO = JSONObject.parseObject(data, MonitorForcastData.class); + model = new PtReceiveBaseModel(); + Map dataMap = Maps.newHashMap(); + MqNodeData dataQ = new MqNodeData(); + dataQ.setSn("q"); + dataQ.setKey("q"); + dataQ.setValue(DTO.getQ()); + MqNodeData dataZ = new MqNodeData(); + dataZ.setSn("z"); + dataZ.setKey("z"); + dataZ.setValue(DTO.getZ()); + MqNodeData dataYbt = new MqNodeData(); + dataYbt.setSn("ybt"); + dataYbt.setKey("ybt"); + dataYbt.setValue(DTO.getFocTime()); + dataMap.put("q", dataQ); + dataMap.put("z", dataZ); + dataMap.put("ybt", dataYbt); + model.setDataMap(dataMap); + model.setSt(DTO.getStcd()); + model.setTt(DTO.getPubTime()); + model.setUt(new Date()); + } else if (xfDataEnum == XfDataEnum.LakeData) { + MonitorLakeData DTO = JSONObject.parseObject(data, MonitorLakeData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.Meteorological) { + MonitorMeteorologicalData DTO = JSONObject.parseObject(data, MonitorMeteorologicalData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PptnData) { + MonitorPptnData DTO = JSONObject.parseObject(data, MonitorPptnData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.PumpData) { + MonitorPumpData DTO = JSONObject.parseObject(data, MonitorPumpData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.RiverData) { + MonitorRiverData DTO = JSONObject.parseObject(data, MonitorRiverData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.SoilData) { + MonitorSoilData DTO = JSONObject.parseObject(data, MonitorSoilData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WasData) { + MonitorWasData DTO = JSONObject.parseObject(data, MonitorWasData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else if (xfDataEnum == XfDataEnum.WetlogData) { + MonitorWetlogData DTO = JSONObject.parseObject(data, MonitorWetlogData.class); + model = RealTimeSerializer.xfObjectToRealMap(DTO); + } else { + throw new RuntimeException("暂未开发"); + } + log.info("cover:{}", JSONObject.toJSONString(model)); + return R.status(true); + } catch (Exception e) { + log.error("解析错误,:{}", e.getStackTrace()); + throw new RuntimeException("类型转换错误"); + } + } +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java new file mode 100644 index 0000000..b2ac242 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/BaseXfInterfaceEntity.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: + * @author: djt + * @create: 2022-06-14 14:38 + **/ +@Data +public class BaseXfInterfaceEntity implements Serializable { + @JsonProperty(value ="st") + @ApiModelProperty(value = "站码") + private String stcd; + @JSONField(serialize = false) + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value ="tt") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "监测时间") + private Date tm; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java new file mode 100644 index 0000000..2e31fbe --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorChnlDataDto.java @@ -0,0 +1,25 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 港渠监测信息 + * @author: djt + * @create: 2022-06-14 13:26 + **/ +@Data +public class MonitorChnlDataDto extends BaseXfInterfaceEntity { + @JsonProperty(value = "rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java new file mode 100644 index 0000000..3507b87 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorForcastData.java @@ -0,0 +1,40 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 汉口水情 + * @author: djt + * @create: 2022-06-14 14:24 + **/ +@Data +public class MonitorForcastData implements Serializable { + @JsonProperty(value = "ybt") + @ApiModelProperty(value = "预报时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date focTime; + @JsonProperty(value = "tt") + @ApiModelProperty(value = "发布时间") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date pubTime; + @JsonProperty(value = "st") + @ApiModelProperty(value = "站码") + private String stcd; + @ApiModelProperty(value = "测站名称") + private String stnm; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java new file mode 100644 index 0000000..38ac2a2 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorLakeData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 湖泊监测数据 + * @author: djt + * @create: 2022-06-14 14:28 + **/ +@Data +public class MonitorLakeData extends BaseXfInterfaceEntity { + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "水位") + private BigDecimal z; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java new file mode 100644 index 0000000..24f9831 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorMeteorologicalData.java @@ -0,0 +1,58 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 气象站实时监测数据 + * @author: djt + * @create: 2022-06-14 14:42 + **/ +@Data +public class MonitorMeteorologicalData extends BaseXfInterfaceEntity { + @JsonProperty(value ="ej") + @ApiModelProperty(value = "当前蒸发mm") + private BigDecimal evp; + @JsonProperty(value ="pj") + @ApiModelProperty(value = "当前降水量mm") + private BigDecimal pre; + @JsonProperty(value ="pn01") + @ApiModelProperty(value = "1分钟时段降水量mm") + private BigDecimal pre01; + @JsonProperty(value ="pn05") + @ApiModelProperty(value = "5分钟时段降雨量mm") + private BigDecimal pre05; + @JsonProperty(value ="pn10") + @ApiModelProperty(value = "10分钟时段降水量mm") + private BigDecimal pre10; + @JsonProperty(value ="pt") + @ApiModelProperty(value = "降水量累计值mm") + private BigDecimal presum; + @JsonProperty(value ="mst") + @ApiModelProperty(value = "湿度") + private BigDecimal rhu; + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10厘米处土壤含水量") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20厘米处土壤含水量") + private BigDecimal slm20; + @JsonProperty(value ="m30") + @ApiModelProperty(value = "30厘米处土壤含水量") + private BigDecimal slm30; + @JsonProperty(value ="ai") + @ApiModelProperty(value = "瞬时气温") + private BigDecimal tem; + @JsonProperty(value = "uc") + @ApiModelProperty(value = "风向") + private BigDecimal windAngle; + @JsonProperty(value ="us") + @ApiModelProperty(value = "风速m/s") + private BigDecimal windSpeed; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java new file mode 100644 index 0000000..5c89b26 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPptnData.java @@ -0,0 +1,24 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 降雨量 + * @author: djt + * @create: 2022-06-14 15:17 + **/ +@Data +public class MonitorPptnData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="drp") + @ApiModelProperty(value = "时段降雨量") + private BigDecimal drp; + @JsonProperty(value ="intv") + @ApiModelProperty(value = "时段长") + private BigDecimal intv; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java new file mode 100644 index 0000000..ae87e6d --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorPumpData.java @@ -0,0 +1,30 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 泵站信息 + * @author: djt + * @create: 2022-06-14 15:19 + **/ +@Data +public class MonitorPumpData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="ts") + @ApiModelProperty(value = "开机台数") + private BigDecimal omcn; + @JsonProperty(value = "z") + @ApiModelProperty(value = "前池水位") + private BigDecimal ppupz; + @JsonProperty(value ="qs") + @ApiModelProperty(value = "抽排量") + private BigDecimal qs; + @JsonProperty(value ="t") + @ApiModelProperty(value = "运行台时") + private BigDecimal t; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java new file mode 100644 index 0000000..539e8cf --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorRiverData.java @@ -0,0 +1,27 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 河道信息 + * @author: djt + * @create: 2022-06-14 15:29 + **/ +@Data +public class MonitorRiverData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="rate") + @ApiModelProperty(value = "水势") + private String wptn; + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal z; + @JsonProperty(value ="q") + @ApiModelProperty(value = "流量") + private BigDecimal q; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java new file mode 100644 index 0000000..511f155 --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorSoilData.java @@ -0,0 +1,28 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 土壤墒情 + * @author: djt + * @create: 2022-06-14 15:31 + **/ +@Data +public class MonitorSoilData extends BaseXfInterfaceEntity{ + @JsonProperty(value ="m10") + @ApiModelProperty(value = "10cm深度") + private BigDecimal slm10; + @JsonProperty(value ="m20") + @ApiModelProperty(value = "20cm深度") + private BigDecimal slm20; + @JsonProperty(value ="m40") + @ApiModelProperty(value = "40cm深度") + private BigDecimal slm40; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java new file mode 100644 index 0000000..7d1686a --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWasData.java @@ -0,0 +1,34 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @program: newfiber-data-adapter + * @description: 涵闸监测数据 + * @author: djt + * @create: 2022-06-14 15:32 + **/ +@Data +public class MonitorWasData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸内水位") + private BigDecimal dwz; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸内水势") + private String sdwwptn; + @JsonProperty(value ="rate") + @ApiModelProperty(value = "闸外水势") + private String supwptn; + @JsonProperty(value ="q") + @ApiModelProperty(value = "过闸流量") + private BigDecimal tgtq; + @JsonProperty(value ="z") + @ApiModelProperty(value = "闸外水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java new file mode 100644 index 0000000..87d74ec --- /dev/null +++ b/src/main/java/org/springnewfiber/dataadapter/xf/entity/MonitorWetlogData.java @@ -0,0 +1,21 @@ +package org.springnewfiber.dataadapter.xf.entity; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @program: newfiber-data-adapter + * @description: 渍水实时数据 + * @author: djt + * @create: 2022-06-14 16:11 + **/ +@Data +public class MonitorWetlogData extends BaseXfInterfaceEntity { + @JsonProperty(value ="z") + @ApiModelProperty(value = "水位") + private BigDecimal upz; +} diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java index 86db886..1cc7b20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/bz/action/BzAction.java @@ -24,7 +24,7 @@ * @author: djt * @create: 2022-01-20 14:24 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class BzAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java index 9bc93a2..5935dad 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/common/LoginAction.java @@ -22,7 +22,7 @@ * @author: djt * @create: 2022-01-18 17:00 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class LoginAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java index 4623864..5e9f207 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/core/ZiGuangDataJob.java @@ -17,7 +17,7 @@ * @author: djt * @create: 2022-01-19 19:23 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class ZiGuangDataJob { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java index 4cdc82d..3991a8a 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/gq/action/GqAction.java @@ -26,7 +26,7 @@ * @author: djt * @create: 2022-01-20 13:56 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class GqAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java index e191c81..9fdb68e 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/hd/action/HdAction.java @@ -25,7 +25,7 @@ * @author: djt * @create: 2022-01-19 10:11 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class HdAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java index 45cf4f8..1a8210b 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/hp/action/HpAction.java @@ -27,7 +27,7 @@ * @author: djt * @create: 2022-01-19 19:26 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class HpAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java index f034a84..14cfdf8 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/yl/action/YlAction.java @@ -33,7 +33,7 @@ * @author: djt * @create: 2022-01-20 17:09 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class YlAction { diff --git a/src/main/java/org/springnewfiber/dataadapter/ziguang/zs/action/ZsAction.java b/src/main/java/org/springnewfiber/dataadapter/ziguang/zs/action/ZsAction.java index 5824d6b..80dbf20 100644 --- a/src/main/java/org/springnewfiber/dataadapter/ziguang/zs/action/ZsAction.java +++ b/src/main/java/org/springnewfiber/dataadapter/ziguang/zs/action/ZsAction.java @@ -28,7 +28,7 @@ * @author: djt * @create: 2022-01-19 08:53 **/ -@Component +//@Component @Slf4j @AllArgsConstructor public class ZsAction {