From eea1e7fcadf39c80de968bd10cc5023ffe9bd68a Mon Sep 17 00:00:00 2001 From: zy <82248909@qq.com> Date: Fri, 5 Dec 2025 18:50:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=94=E5=B8=B8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lanhai/constant/IotConstants.java | 21 +++ .../{FSurvConfig.java => SurvConfig.java} | 4 +- .../com/lanhai/entity/SurvHisdataAir.java | 6 + .../entity/SurvHisdataLivestockwater.java | 6 + .../SurvHisdataLivestockwaterError.java | 8 + .../lanhai/entity/SurvHisdataOrientwater.java | 8 + .../entity/SurvHisdataOrientwaterError.java | 8 + .../com/lanhai/entity/SurvHisdataSoil.java | 6 + .../com/lanhai/entity/SurvTaskConfig.java | 161 ++++++++++++++++ .../com/lanhai/entity/SurvTransdataAir.java | 8 + .../entity/SurvTransdataLivestockwater.java | 8 + .../entity/SurvTransdataOrientwater.java | 8 + .../com/lanhai/entity/SurvTransdataSoil.java | 9 +- .../com/lanhai/handler/JsonTypeHandler.java | 55 ++++++ ...onfigMapper.java => SurvConfigMapper.java} | 6 +- .../lanhai/mapper/SurvTaskConfigMapper.java | 18 ++ ...vConfigMapper.xml => SurvConfigMapper.xml} | 4 +- .../mapper/xml/SurvTaskConfigMapper.xml | 44 +++++ .../lanhai/o/iot/task/DataExamineConfig.java | 10 + .../lanhai/o/iot/task/DataExamineDetail.java | 28 +++ .../lanhai/o/iot/task/DataExamineResult.java | 12 ++ .../lanhai/o/iot/task/DataExamineRule.java | 23 +++ .../com/lanhai/service/ICommonService.java | 4 +- .../lanhai/service/IFSurvConfigService.java | 21 --- .../service/ISurvDeviceDeployService.java | 2 + .../ISurvHisdataLivestockwaterService.java | 6 + .../ISurvHisdataOrientwaterService.java | 3 + .../service/ISurvHisdataSoilService.java | 4 + .../service/ISurvSurvConfigService.java | 21 +++ .../service/ISurvTaskConfigService.java | 17 ++ .../service/Impl/CommonServiceImpl.java | 23 +-- ...ceImpl.java => SurvConfigServiceImpl.java} | 18 +- .../Impl/SurvDeviceDeployServiceImpl.java | 7 + .../SurvHisdataLivestockwaterServiceImpl.java | 176 +++++++++++++++++- .../SurvHisdataOrientwaterServiceImpl.java | 176 +++++++++++++++++- .../Impl/SurvHisdataSoilServiceImpl.java | 160 ++++++++++++++++ .../Impl/SurvTaskConfigServiceImpl.java | 25 +++ .../java/com/lanhai/task/DataExamineTask.java | 104 ++++++++--- .../com/lanhai/task/DataExamineTask_bak.java | 79 ++++++++ .../com/lanhai/util/DateTimeConverter.java | 39 ++++ src/main/java/com/lanhai/util/DateUtils.java | 10 + src/main/java/com/lanhai/util/SdrkUtils.java | 8 +- src/main/java/com/lanhai/util/XphUtils.java | 7 +- src/main/java/com/lanhai/util/YSUtils.java | 22 +-- 44 files changed, 1283 insertions(+), 110 deletions(-) rename src/main/java/com/lanhai/entity/{FSurvConfig.java => SurvConfig.java} (95%) create mode 100644 src/main/java/com/lanhai/entity/SurvTaskConfig.java create mode 100644 src/main/java/com/lanhai/handler/JsonTypeHandler.java rename src/main/java/com/lanhai/mapper/{FSurvConfigMapper.java => SurvConfigMapper.java} (52%) create mode 100644 src/main/java/com/lanhai/mapper/SurvTaskConfigMapper.java rename src/main/java/com/lanhai/mapper/xml/{FSurvConfigMapper.xml => SurvConfigMapper.xml} (81%) create mode 100644 src/main/java/com/lanhai/mapper/xml/SurvTaskConfigMapper.xml create mode 100644 src/main/java/com/lanhai/o/iot/task/DataExamineConfig.java create mode 100644 src/main/java/com/lanhai/o/iot/task/DataExamineDetail.java create mode 100644 src/main/java/com/lanhai/o/iot/task/DataExamineResult.java create mode 100644 src/main/java/com/lanhai/o/iot/task/DataExamineRule.java delete mode 100644 src/main/java/com/lanhai/service/IFSurvConfigService.java create mode 100644 src/main/java/com/lanhai/service/ISurvSurvConfigService.java create mode 100644 src/main/java/com/lanhai/service/ISurvTaskConfigService.java rename src/main/java/com/lanhai/service/Impl/{FSurvConfigServiceImpl.java => SurvConfigServiceImpl.java} (67%) create mode 100644 src/main/java/com/lanhai/service/Impl/SurvTaskConfigServiceImpl.java create mode 100644 src/main/java/com/lanhai/task/DataExamineTask_bak.java create mode 100644 src/main/java/com/lanhai/util/DateTimeConverter.java diff --git a/src/main/java/com/lanhai/constant/IotConstants.java b/src/main/java/com/lanhai/constant/IotConstants.java index b93936c..7528ea2 100644 --- a/src/main/java/com/lanhai/constant/IotConstants.java +++ b/src/main/java/com/lanhai/constant/IotConstants.java @@ -193,4 +193,25 @@ public interface IotConstants { * 物联网配置缓存头 */ String IOT_SURVCONFIG_CACHE = "surv:config:params"; + + /** + * 生成数据标记 + */ + String MARK_GENDATA = "GenData"; + + + /** + * 真实数据标记 + */ + String MARK_REALDATA = "RealTime"; + + /** + * 规则类型 历史 + */ + String RULE_HISTORY = "rule_history"; + + /** + * 规则类型 预设 + */ + String RULE_PRE = "rule_preset"; } diff --git a/src/main/java/com/lanhai/entity/FSurvConfig.java b/src/main/java/com/lanhai/entity/SurvConfig.java similarity index 95% rename from src/main/java/com/lanhai/entity/FSurvConfig.java rename to src/main/java/com/lanhai/entity/SurvConfig.java index 4cd2262..0832e9d 100644 --- a/src/main/java/com/lanhai/entity/FSurvConfig.java +++ b/src/main/java/com/lanhai/entity/SurvConfig.java @@ -1,6 +1,5 @@ package com.lanhai.entity; -import cn.hutool.json.JSONObject; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -9,7 +8,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; -import org.apache.ibatis.type.JdbcType; import java.io.Serializable; import java.util.Date; @@ -25,7 +23,7 @@ import java.util.Date; @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -public class FSurvConfig extends Model { +public class SurvConfig extends Model { private static final long serialVersionUID=1L; diff --git a/src/main/java/com/lanhai/entity/SurvHisdataAir.java b/src/main/java/com/lanhai/entity/SurvHisdataAir.java index 30c4532..7c2aeb0 100644 --- a/src/main/java/com/lanhai/entity/SurvHisdataAir.java +++ b/src/main/java/com/lanhai/entity/SurvHisdataAir.java @@ -92,6 +92,12 @@ public class SurvHisdataAir extends Model { @TableField("DATA_GATHER_TYPE") private String dataGatherType; + /** + * 规则类型 + */ + @TableField("RULE_TYPE") + private String ruleType; + /** * 站点ID */ diff --git a/src/main/java/com/lanhai/entity/SurvHisdataLivestockwater.java b/src/main/java/com/lanhai/entity/SurvHisdataLivestockwater.java index b90606b..43ae778 100644 --- a/src/main/java/com/lanhai/entity/SurvHisdataLivestockwater.java +++ b/src/main/java/com/lanhai/entity/SurvHisdataLivestockwater.java @@ -121,6 +121,12 @@ public class SurvHisdataLivestockwater extends Model @TableField("DATA_GATHER_TYPE") private String dataGatherType; + /** + * 规则类型 + */ + @TableField("RULE_TYPE") + private String ruleType; + /** * 站点ID */ diff --git a/src/main/java/com/lanhai/entity/SurvHisdataLivestockwaterError.java b/src/main/java/com/lanhai/entity/SurvHisdataLivestockwaterError.java index 9fc81d1..410dea9 100644 --- a/src/main/java/com/lanhai/entity/SurvHisdataLivestockwaterError.java +++ b/src/main/java/com/lanhai/entity/SurvHisdataLivestockwaterError.java @@ -79,6 +79,12 @@ public class SurvHisdataLivestockwaterError extends Model { @TableField("DATA_GATHER_TYPE") private String dataGatherType; + /** + * 规则类型 + */ + @TableField("RULE_TYPE") + private String ruleType; + /** * 站点ID */ @@ -206,6 +212,8 @@ public class SurvHisdataOrientwater extends Model { private Date updatedTime; + + @Override protected Serializable pkVal() { return this.id; diff --git a/src/main/java/com/lanhai/entity/SurvHisdataOrientwaterError.java b/src/main/java/com/lanhai/entity/SurvHisdataOrientwaterError.java index a358787..1de2322 100644 --- a/src/main/java/com/lanhai/entity/SurvHisdataOrientwaterError.java +++ b/src/main/java/com/lanhai/entity/SurvHisdataOrientwaterError.java @@ -145,6 +145,12 @@ public class SurvHisdataOrientwaterError extends Model { @TableField("DATA_GATHER_TYPE") private String dataGatherType; + /** + * 规则类型 + */ + @TableField("RULE_TYPE") + private String ruleType; + /** * 站点ID */ diff --git a/src/main/java/com/lanhai/entity/SurvTaskConfig.java b/src/main/java/com/lanhai/entity/SurvTaskConfig.java new file mode 100644 index 0000000..3acb77a --- /dev/null +++ b/src/main/java/com/lanhai/entity/SurvTaskConfig.java @@ -0,0 +1,161 @@ +package com.lanhai.entity; + +import cn.hutool.json.JSONObject; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.lanhai.handler.JsonTypeHandler; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.apache.ibatis.type.JdbcType; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 自动任务配置 + *

+ * + * @author ${author} + * @since 2024-12-25 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +public class SurvTaskConfig extends Model { + + private static final long serialVersionUID=1L; + + /** + * 主键 + */ + @TableId(value = "ID", type = IdType.ID_WORKER_STR) + private String id; + + + /** + * 任务编号 + */ + @TableField("TASK_CODE") + private String taskCode; + + /** + * 任务名称 + */ + @TableField("TASK_NAME") + private String taskName; + + /** + * 1=第三方厂家采集任务 + */ + @TableField("TASK_TYPE") + private Integer taskType; + + /** + * 任务说明 + */ + @TableField("TASK_DES") + private String taskDes; + + /** + * 协议编号 + */ + @TableField("PROTPCOL_CODE") + private String protpcolCode; + + /** + * 所属企业 + */ + @TableField("BELONG_TENANT_ID") + private String belongTenantId; + + /** + * 所属企业 + */ + @TableField("BELONG_COMPANY_ID") + private String belongCompanyId; + + /** + * 初始化时间 + */ + @TableField("INIT_TIME") + private Date initTime; + + /** + * 执行间隔(分钟) + */ + @TableField("EXECUTE_RATE") + private Integer executeRate; + + /** + * 时间延迟(分钟) + */ + @TableField("DELAY_MIN") + private Integer delayMin; + + /** + * 执行参数(由具体的Api所需参数决定) + */ + @TableField(typeHandler= JsonTypeHandler.class, jdbcType= JdbcType.VARCHAR,value = "EXECUTE_JSON") + private JSONObject executeJson; + + /** + * 租户号 + */ + @TableField("TENANT_ID") + private String tenantId; + + /** + * 乐观锁 + */ + @TableField("RE_VISION") + private Integer reVision; + + /** + * 创建人 + */ + @TableField("CREATE_BY") + private String createBy; + + /** + * 创建时间 + */ + @TableField("CREATE_TIME") + private Date createTime; + + /** + * 更新人 + */ + @TableField("UPDATE_BY") + private String updateBy; + + /** + * 逻辑删除 + */ + @TableField("IS_DEL") + @TableLogic + private Integer isDel; + + /** + * 更新时间 + */ + @TableField("UPDATE_TIME") + private Date updateTime; + + /** + * 乐观锁 + */ + @TableField("REVISION") + private Integer revision; + + + @Override + public Serializable pkVal() { + return this.id; + } + +} diff --git a/src/main/java/com/lanhai/entity/SurvTransdataAir.java b/src/main/java/com/lanhai/entity/SurvTransdataAir.java index 970e3c4..8198669 100644 --- a/src/main/java/com/lanhai/entity/SurvTransdataAir.java +++ b/src/main/java/com/lanhai/entity/SurvTransdataAir.java @@ -91,6 +91,12 @@ public class SurvTransdataAir extends Model { @TableField("DATA_GATHER_TYPE") private String dataGatherType; + /** + * 规则类型 + */ + @TableField("RULE_TYPE") + private String ruleType; + /** * 站点ID */ @@ -189,6 +195,8 @@ public class SurvTransdataAir extends Model { private String deployType; + + @Override protected Serializable pkVal() { return this.id; diff --git a/src/main/java/com/lanhai/entity/SurvTransdataLivestockwater.java b/src/main/java/com/lanhai/entity/SurvTransdataLivestockwater.java index 7da9e24..a691ae7 100644 --- a/src/main/java/com/lanhai/entity/SurvTransdataLivestockwater.java +++ b/src/main/java/com/lanhai/entity/SurvTransdataLivestockwater.java @@ -123,6 +123,12 @@ public class SurvTransdataLivestockwater extends Model { @TableField("DATA_GATHER_TYPE") private String dataGatherType; + /** + * 规则类型 + */ + @TableField("RULE_TYPE") + private String ruleType; + /** * 站点ID */ @@ -201,6 +207,8 @@ public class SurvTransdataOrientwater extends Model { private Date updatedTime; + + @Override protected Serializable pkVal() { return this.id; diff --git a/src/main/java/com/lanhai/entity/SurvTransdataSoil.java b/src/main/java/com/lanhai/entity/SurvTransdataSoil.java index 1d28a44..be0481c 100644 --- a/src/main/java/com/lanhai/entity/SurvTransdataSoil.java +++ b/src/main/java/com/lanhai/entity/SurvTransdataSoil.java @@ -218,6 +218,12 @@ public class SurvTransdataSoil extends Model { @TableField("DATA_GATHER_TYPE") private String dataGatherType; + /** + * 规则类型 + */ + @TableField("RULE_TYPE") + private String ruleType; + /** * 站点ID */ @@ -310,7 +316,7 @@ public class SurvTransdataSoil extends Model { private String deployId; /** - * 更新时间 + * 部署类型 */ @TableField("DEPLOY_TYPE") private String deployType; @@ -320,6 +326,7 @@ public class SurvTransdataSoil extends Model { + @Override protected Serializable pkVal() { return this.id; diff --git a/src/main/java/com/lanhai/handler/JsonTypeHandler.java b/src/main/java/com/lanhai/handler/JsonTypeHandler.java new file mode 100644 index 0000000..d22bb21 --- /dev/null +++ b/src/main/java/com/lanhai/handler/JsonTypeHandler.java @@ -0,0 +1,55 @@ +package com.lanhai.handler; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * 存储到数据库, 将JSON对象转换成字符串; + * 从数据库获取数据, 将字符串转为JSON对象. + */ +@MappedTypes({JSONObject.class}) +@MappedJdbcTypes({JdbcType.VARCHAR}) +public class JsonTypeHandler extends BaseTypeHandler { + + private static final String EMPTY_OBJECT = "{}"; + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, + JdbcType jdbcType) throws SQLException { + ps.setString(i, JSONUtil.toJsonStr(parameter == null? EMPTY_OBJECT : parameter)); + } + + @Override + public JSONObject getNullableResult(ResultSet rs, String columnName) + throws SQLException { + return to(rs.getString(columnName)); + } + + @Override + public JSONObject getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + return to(rs.getString(columnIndex)); + } + + @Override + public JSONObject getNullableResult(CallableStatement cs, int columnIndex) + throws SQLException { + return to(cs.getString(columnIndex)); + } + + private JSONObject to(String s){ + if(StrUtil.isBlank(s)){ + s = EMPTY_OBJECT; + } + return JSONUtil.parseObj(s).toBean(JSONObject.class); + } +} diff --git a/src/main/java/com/lanhai/mapper/FSurvConfigMapper.java b/src/main/java/com/lanhai/mapper/SurvConfigMapper.java similarity index 52% rename from src/main/java/com/lanhai/mapper/FSurvConfigMapper.java rename to src/main/java/com/lanhai/mapper/SurvConfigMapper.java index fdb1008..b5914fa 100644 --- a/src/main/java/com/lanhai/mapper/FSurvConfigMapper.java +++ b/src/main/java/com/lanhai/mapper/SurvConfigMapper.java @@ -1,7 +1,7 @@ package com.lanhai.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.lanhai.entity.FSurvConfig; +import com.lanhai.entity.SurvConfig; import org.apache.ibatis.annotations.Param; /** @@ -12,7 +12,7 @@ import org.apache.ibatis.annotations.Param; * @author ${author} * @since 2024-12-18 */ -public interface FSurvConfigMapper extends BaseMapper { +public interface SurvConfigMapper extends BaseMapper { - FSurvConfig getOneByTypeWithTenant(@Param("tenantId") String tenantId, @Param("type")String type); + SurvConfig getOneByTypeWithTenant(@Param("tenantId") String tenantId, @Param("type")String type); } diff --git a/src/main/java/com/lanhai/mapper/SurvTaskConfigMapper.java b/src/main/java/com/lanhai/mapper/SurvTaskConfigMapper.java new file mode 100644 index 0000000..c2ba893 --- /dev/null +++ b/src/main/java/com/lanhai/mapper/SurvTaskConfigMapper.java @@ -0,0 +1,18 @@ +package com.lanhai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.lanhai.entity.SurvTaskConfig; +import org.apache.ibatis.annotations.Param; + +/** + *

+ * 自动任务配置 Mapper 接口 + *

+ * + * @author ${author} + * @since 2024-12-25 + */ +public interface SurvTaskConfigMapper extends BaseMapper { + + SurvTaskConfig getConfigByTaskCode(@Param("taskCode")String taskCode); +} diff --git a/src/main/java/com/lanhai/mapper/xml/FSurvConfigMapper.xml b/src/main/java/com/lanhai/mapper/xml/SurvConfigMapper.xml similarity index 81% rename from src/main/java/com/lanhai/mapper/xml/FSurvConfigMapper.xml rename to src/main/java/com/lanhai/mapper/xml/SurvConfigMapper.xml index f1e4078..f0c2e99 100644 --- a/src/main/java/com/lanhai/mapper/xml/FSurvConfigMapper.xml +++ b/src/main/java/com/lanhai/mapper/xml/SurvConfigMapper.xml @@ -1,8 +1,8 @@ - + - select * from surv_config where CONFIG_TYPE = #{type} AND TENANT_ID = #{tenantId} limit 1 diff --git a/src/main/java/com/lanhai/mapper/xml/SurvTaskConfigMapper.xml b/src/main/java/com/lanhai/mapper/xml/SurvTaskConfigMapper.xml new file mode 100644 index 0000000..25d0508 --- /dev/null +++ b/src/main/java/com/lanhai/mapper/xml/SurvTaskConfigMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ID,TASK_CODE,TASK_NAME,TASK_TYPE,TASK_DES,PROTPCOL_CODE,BELONG_COMPANY_ID,BELONG_TENANT_ID,INIT_TIME,EXECUTE_RATE,DELAY_MIN,EXECUTE_JSON,TENANT_ID,RE_VISION,CREATE_BY,CREATE_TIME,UPDATE_BY,IS_DEL,UPDATE_TIME,REVISION + + + + + + diff --git a/src/main/java/com/lanhai/o/iot/task/DataExamineConfig.java b/src/main/java/com/lanhai/o/iot/task/DataExamineConfig.java new file mode 100644 index 0000000..43259c4 --- /dev/null +++ b/src/main/java/com/lanhai/o/iot/task/DataExamineConfig.java @@ -0,0 +1,10 @@ +package com.lanhai.o.iot.task; + +import lombok.Data; + +import java.util.List; + +@Data +public class DataExamineConfig { + List configs; +} diff --git a/src/main/java/com/lanhai/o/iot/task/DataExamineDetail.java b/src/main/java/com/lanhai/o/iot/task/DataExamineDetail.java new file mode 100644 index 0000000..ccc3728 --- /dev/null +++ b/src/main/java/com/lanhai/o/iot/task/DataExamineDetail.java @@ -0,0 +1,28 @@ +package com.lanhai.o.iot.task; + +import lombok.Data; + +import java.util.List; +@Data +public class DataExamineDetail { + + /** + * 设备id + */ + private List deployId; + + /** + * 时间校验标准,如10分钟无数据需要生成,单位秒 + */ + private Integer examineGap; + + /** + * 历史数据基准范围,最小1天,超出此时间段认为没有合适的数据,单位天 + */ + private Integer historyRange; + + /** + * 生成规则配置 + */ + private List rules; +} diff --git a/src/main/java/com/lanhai/o/iot/task/DataExamineResult.java b/src/main/java/com/lanhai/o/iot/task/DataExamineResult.java new file mode 100644 index 0000000..ab45cfe --- /dev/null +++ b/src/main/java/com/lanhai/o/iot/task/DataExamineResult.java @@ -0,0 +1,12 @@ +package com.lanhai.o.iot.task; + +import lombok.Data; + +import java.util.Date; + +@Data +public class DataExamineResult { + private Date dataDateTime; + private String deployCode; + private String deployId; +} diff --git a/src/main/java/com/lanhai/o/iot/task/DataExamineRule.java b/src/main/java/com/lanhai/o/iot/task/DataExamineRule.java new file mode 100644 index 0000000..5e8f68d --- /dev/null +++ b/src/main/java/com/lanhai/o/iot/task/DataExamineRule.java @@ -0,0 +1,23 @@ +package com.lanhai.o.iot.task; + +import lombok.Data; + +@Data +public class DataExamineRule { + /** + * 字段 + */ + private String fields; + /** + * 标准值 + */ + private String standard; + /** + * 修正系数 + */ + private String factor; + /** + * 证书 + */ + private Integer scale; +} diff --git a/src/main/java/com/lanhai/service/ICommonService.java b/src/main/java/com/lanhai/service/ICommonService.java index 5736eee..5cba542 100644 --- a/src/main/java/com/lanhai/service/ICommonService.java +++ b/src/main/java/com/lanhai/service/ICommonService.java @@ -1,12 +1,12 @@ package com.lanhai.service; -import com.lanhai.entity.FSurvConfig; +import com.lanhai.entity.SurvConfig; /** * 处理业务的服务 */ public interface ICommonService { - FSurvConfig getCacheTenant(String tenantId, String type); + SurvConfig getCacheTenant(String tenantId, String type); // void saveBaowen(String baowen); diff --git a/src/main/java/com/lanhai/service/IFSurvConfigService.java b/src/main/java/com/lanhai/service/IFSurvConfigService.java deleted file mode 100644 index e45e3d8..0000000 --- a/src/main/java/com/lanhai/service/IFSurvConfigService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.lanhai.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.lanhai.entity.FSurvConfig; - -/** - *

- * 系统配置表 服务类 - *

- * - * @author ${author} - * @since 2024-12-18 - */ -public interface IFSurvConfigService extends IService { - FSurvConfig getOneByTypeWithTenant(String tenantId, String type); - - - FSurvConfig getSurvConfigByType(String tenantId, String type); - - FSurvConfig getConfigById(String survConfigId); -} diff --git a/src/main/java/com/lanhai/service/ISurvDeviceDeployService.java b/src/main/java/com/lanhai/service/ISurvDeviceDeployService.java index a642278..796a7c9 100644 --- a/src/main/java/com/lanhai/service/ISurvDeviceDeployService.java +++ b/src/main/java/com/lanhai/service/ISurvDeviceDeployService.java @@ -18,4 +18,6 @@ public interface ISurvDeviceDeployService extends IService { List getDeviceByType(List protocolCode,List deviceType); + + List getDeploys(List deployId); } diff --git a/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java b/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java index 21eb470..47e256a 100644 --- a/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java +++ b/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java @@ -4,6 +4,10 @@ import com.lanhai.entity.SurvDeviceDeploy; import com.lanhai.entity.SurvHisdataLivestockwater; import com.baomidou.mybatisplus.extension.service.IService; import com.lanhai.entity.SurvTransdataLivestockwater; +import com.lanhai.o.iot.task.DataExamineDetail; +import com.lanhai.o.iot.task.DataExamineRule; + +import java.util.List; /** *

@@ -14,4 +18,6 @@ import com.lanhai.entity.SurvTransdataLivestockwater; public interface ISurvHisdataLivestockwaterService extends IService { SurvTransdataLivestockwater genData(SurvDeviceDeploy deploy); + + SurvTransdataLivestockwater genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail dataExamineDetail); } diff --git a/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java b/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java index 64d67e9..16acc63 100644 --- a/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java +++ b/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java @@ -4,6 +4,7 @@ import com.lanhai.entity.SurvDeviceDeploy; import com.lanhai.entity.SurvHisdataOrientwater; import com.baomidou.mybatisplus.extension.service.IService; import com.lanhai.entity.SurvTransdataOrientwater; +import com.lanhai.o.iot.task.DataExamineDetail; /** *

@@ -14,4 +15,6 @@ import com.lanhai.entity.SurvTransdataOrientwater; public interface ISurvHisdataOrientwaterService extends IService { SurvTransdataOrientwater genData(SurvDeviceDeploy deploy); + + SurvTransdataOrientwater genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail config); } diff --git a/src/main/java/com/lanhai/service/ISurvHisdataSoilService.java b/src/main/java/com/lanhai/service/ISurvHisdataSoilService.java index 5dc45f6..d85b59e 100644 --- a/src/main/java/com/lanhai/service/ISurvHisdataSoilService.java +++ b/src/main/java/com/lanhai/service/ISurvHisdataSoilService.java @@ -1,7 +1,10 @@ package com.lanhai.service; +import com.lanhai.entity.SurvDeviceDeploy; import com.lanhai.entity.SurvHisdataSoil; import com.baomidou.mybatisplus.extension.service.IService; +import com.lanhai.entity.SurvTransdataSoil; +import com.lanhai.o.iot.task.DataExamineDetail; /** *

@@ -11,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface ISurvHisdataSoilService extends IService { + SurvTransdataSoil genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail config); } diff --git a/src/main/java/com/lanhai/service/ISurvSurvConfigService.java b/src/main/java/com/lanhai/service/ISurvSurvConfigService.java new file mode 100644 index 0000000..6314b4b --- /dev/null +++ b/src/main/java/com/lanhai/service/ISurvSurvConfigService.java @@ -0,0 +1,21 @@ +package com.lanhai.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.lanhai.entity.SurvConfig; + +/** + *

+ * 系统配置表 服务类 + *

+ * + * @author ${author} + * @since 2024-12-18 + */ +public interface ISurvSurvConfigService extends IService { + SurvConfig getOneByTypeWithTenant(String tenantId, String type); + + + SurvConfig getSurvConfigByType(String tenantId, String type); + + SurvConfig getConfigById(String survConfigId); +} diff --git a/src/main/java/com/lanhai/service/ISurvTaskConfigService.java b/src/main/java/com/lanhai/service/ISurvTaskConfigService.java new file mode 100644 index 0000000..40c28b5 --- /dev/null +++ b/src/main/java/com/lanhai/service/ISurvTaskConfigService.java @@ -0,0 +1,17 @@ +package com.lanhai.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.lanhai.entity.SurvTaskConfig; + +/** + *

+ * 自动任务配置 服务类 + *

+ * + * @author ${author} + * @since 2024-12-25 + */ +public interface ISurvTaskConfigService extends IService { + + SurvTaskConfig getConfigByTask(String taskCode); +} diff --git a/src/main/java/com/lanhai/service/Impl/CommonServiceImpl.java b/src/main/java/com/lanhai/service/Impl/CommonServiceImpl.java index f518131..9658900 100644 --- a/src/main/java/com/lanhai/service/Impl/CommonServiceImpl.java +++ b/src/main/java/com/lanhai/service/Impl/CommonServiceImpl.java @@ -1,14 +1,13 @@ package com.lanhai.service.Impl; import com.lanhai.constant.IotConstants; -import com.lanhai.entity.FSurvConfig; +import com.lanhai.entity.SurvConfig; import com.lanhai.service.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; /** * 处理业务的服务 @@ -19,7 +18,7 @@ public class CommonServiceImpl implements ICommonService { @Autowired @Lazy - private FSurvConfigServiceImpl configService; + private SurvConfigServiceImpl configService; // // @Autowired // private ISurvTransdataAirService transdataAirService; @@ -65,14 +64,16 @@ public class CommonServiceImpl implements ICommonService { // } -@Override -@Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE,key = "#tenantId+':'+#type", unless = "#result == null ") -public FSurvConfig getCacheTenant(String tenantId, String type) { - if(StringUtils.isBlank(tenantId)){ - tenantId = "0"; - } - return configService.getSurvConfigByType(tenantId,type); -} + @Override + @Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE,key = "#tenantId+':'+#type", unless = "#result == null ") + public SurvConfig getCacheTenant(String tenantId, String type) { + if(StringUtils.isBlank(tenantId)){ + tenantId = "0"; + } + return configService.getSurvConfigByType(tenantId,type); + } + + } diff --git a/src/main/java/com/lanhai/service/Impl/FSurvConfigServiceImpl.java b/src/main/java/com/lanhai/service/Impl/SurvConfigServiceImpl.java similarity index 67% rename from src/main/java/com/lanhai/service/Impl/FSurvConfigServiceImpl.java rename to src/main/java/com/lanhai/service/Impl/SurvConfigServiceImpl.java index 09eabff..c69b7cf 100644 --- a/src/main/java/com/lanhai/service/Impl/FSurvConfigServiceImpl.java +++ b/src/main/java/com/lanhai/service/Impl/SurvConfigServiceImpl.java @@ -2,9 +2,9 @@ package com.lanhai.service.Impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lanhai.constant.IotConstants; -import com.lanhai.entity.FSurvConfig; -import com.lanhai.mapper.FSurvConfigMapper; -import com.lanhai.service.IFSurvConfigService; +import com.lanhai.entity.SurvConfig; +import com.lanhai.mapper.SurvConfigMapper; +import com.lanhai.service.ISurvSurvConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.context.annotation.Lazy; @@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; * @since 2024-12-18 */ @Service -public class FSurvConfigServiceImpl extends ServiceImpl implements IFSurvConfigService { +public class SurvConfigServiceImpl extends ServiceImpl implements ISurvSurvConfigService { @Autowired private RedisTemplate redisTemplate; @Autowired @@ -30,21 +30,21 @@ public class FSurvConfigServiceImpl extends ServiceImpl getDeviceByType(List protocolCode, List deviceType) { return baseMapper.getProtocolDeviceType(protocolCode,deviceType); } + + @Override + public List getDeploys(List deployId) { + List list = lambdaQuery().in(SurvDeviceDeploy::getId,deployId).list(); + return list; + } } diff --git a/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java b/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java index 081a604..d8f1bf6 100644 --- a/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java +++ b/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java @@ -1,16 +1,16 @@ package com.lanhai.service.Impl; import cn.hutool.core.bean.BeanUtil; +import com.lanhai.constant.IotConstants; import com.lanhai.constant.PollutionConstants; import com.lanhai.entity.*; import com.lanhai.mapper.SurvHisdataLivestockwaterMapper; +import com.lanhai.o.iot.task.DataExamineDetail; +import com.lanhai.o.iot.task.DataExamineRule; import com.lanhai.service.ISurvHisdataLivestockwaterService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lanhai.service.ISurvStationInfoService; -import com.lanhai.util.BigDecimalRandomAdjuster; -import com.lanhai.util.DateUtils; -import com.lanhai.util.SpringBeanUtils; -import com.lanhai.util.TUtil; +import com.lanhai.util.*; import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -19,6 +19,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.*; /** @@ -98,7 +99,7 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterTn())) {//跳过负数 + if (newestData.getDataWaterTn().contains("-") || newestData.getDataWaterTn().length() > 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterNo())) {//跳过负数 + if (newestData.getDataWaterNo().contains("-") || newestData.getDataWaterNo().length() > 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterNh())) {//跳过负数 + if (newestData.getDataWaterNh().contains("-") || newestData.getDataWaterNh().length() > 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterCod())) {//跳过负数 + if (newestData.getDataWaterCod().contains("-") || newestData.getDataWaterCod().length() > 10) { + isNegative = true; + } + } + if (!isNegative) {//非负数时,检查时间是否过期,否则直接自动覆盖此数据 + if (newestData.getDataDateTime() != null) { + long secs = DateUtils.getSecondsDiff(newestData.getDataDateTime(), new Date()); + if (secs < dataExamineDetail.getExamineGap()) {//间隔不足时不生成 + log.warn("--------------设备:{}:{},new畜禽间隔为:{}秒,限制时间:{}秒,跳过---------------", deploy.getDeployDes(),deploy.getDeployCode(),secs,dataExamineDetail.getExamineGap()); + XxlJobHelper.log("---------------设备:{}:{},new畜禽间隔为:{}秒,限制时间:{}秒,跳过---------------", deploy.getDeployDes(),deploy.getDeployCode(),secs,dataExamineDetail.getExamineGap()); + return null; + } + } + } else {//负数视为无效数据 + newestData = null; + } + + } + Map ruleMap = new HashMap<>(); + for (DataExamineRule rule : dataExamineDetail.getRules()) { + ruleMap.put(rule.getFields(), rule); + } + SurvHisdataLivestockwater hisdataLivestockwater = new SurvHisdataLivestockwater(); + if (newestData == null) { + newestData = new SurvTransdataLivestockwater(); + + SurvHisdataLivestockwater hisData = getRecentData(deployCode,dataExamineDetail.getHistoryRange()); + if(hisData!=null){ //第一逻辑,如果有最近的历史数据,则使用历史数据作为基准值 + XxlJobHelper.log("=====设备:{}===查询到历史数据,使用历史数据作为基准值==========",deployCode); + BeanUtil.copyProperties(hisData,newestData); + hisdataLivestockwater.setRuleType(IotConstants.RULE_HISTORY); + }else{//第二逻辑,使用预设的标准值 + XxlJobHelper.log("=====设备:{}===使用预设标准值进行生成==========",deployCode); + for (String s : ruleMap.keySet()) { + TUtil.setFieldValue(newestData, s, ruleMap.get(s).getStandard()); + } + hisdataLivestockwater.setRuleType(IotConstants.RULE_PRE); + } + }else{ + long dateGap = DateUtils.getDaysDiff(newestData.getDataDateTime(), new Date()); + XxlJobHelper.log("======设备:{}-{}=====土壤/水数据间隔{}天===限制天数:{}====",deploy.getDeployDes(),deploy.getDeployCode(),dateGap,dataExamineDetail.getHistoryRange()); + if (dateGap > dataExamineDetail.getHistoryRange()) {//最新数据已经超过时限范围,则使用预设数据 + XxlJobHelper.log("xxxx使用预设数据xxxxx"); + for (String s : ruleMap.keySet()) { + TUtil.setFieldValue(newestData, s, ruleMap.get(s).getStandard()); + } + hisdataLivestockwater.setRuleType(IotConstants.RULE_PRE); + }else{ + XxlJobHelper.log("xxxx使用原数据规则类型:{}xxxxx",newestData.getRuleType()); + hisdataLivestockwater.setRuleType(newestData.getRuleType()); + } + + } + + + Date nowTime = new Date(); + hisdataLivestockwater.setReVision(0); + hisdataLivestockwater.setCreatedBy("ftask"); + hisdataLivestockwater.setCreateTime(nowTime); + hisdataLivestockwater.setIsDel(0); + + hisdataLivestockwater.setDataDateTime(nowTime); + hisdataLivestockwater.setDataGatherType(IotConstants.MARK_GENDATA); + hisdataLivestockwater.setDeployCode(deployCode); + hisdataLivestockwater.setFirstValveStatus("0"); + hisdataLivestockwater.setSecondValveStatus("1"); + hisdataLivestockwater.setCrashStopStatus("0"); + hisdataLivestockwater.setWaterPumpStatus("0"); + hisdataLivestockwater.setMainSideStatus("0"); + + hisdataLivestockwater.setDeviceId(deploy.getId()); + hisdataLivestockwater.setDeviceName(deploy.getDeployDes()); + hisdataLivestockwater.setStationCode(deploy.getStationCode()); + if (StringUtils.isNotBlank(deploy.getStationCode())) { + SurvStationInfo info = survStationInfoService.getByCode(deploy.getStationCode()); + if (info != null) { + hisdataLivestockwater.setStationName(info.getStationName()); + hisdataLivestockwater.setStationId(info.getId()); + } + } + + + //生成数据 + for (String key : ruleMap.keySet()) { + DataExamineRule rule = ruleMap.get(key); + String vals = TUtil.getFieldValue(newestData, rule.getFields(), String.class); + if (StringUtils.isNotBlank(vals)) { + BigDecimal fixedRange = new BigDecimal(rule.getFactor()); + int scale = rule.getScale();//小数位 + String correctVal = BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(vals), fixedRange, scale); + TUtil.setFieldValue(hisdataLivestockwater, rule.getFields(), correctVal); + } else { + log.error("==========设备:{},编号:{}指标:{}配置错误==============,跳过", deploy.getDeployDes(), deploy.getDeployCode(), rule.getFields()); + XxlJobHelper.log("==========设备:{},编号:{}指标:{}配置错误==============,跳过", deploy.getDeployDes(), deploy.getDeployCode(), rule.getFields()); + } + } + + save(hisdataLivestockwater); + + BeanUtil.copyProperties(hisdataLivestockwater, newestData); + newestData.setId(orgId); + newestData.setDataDateTime(nowTime); + newestData.setRuleType(newestData.getRuleType()); + newestData.setDataGatherType(newestData.getDataGatherType()); + survTransdataLivestockwaterServiceImpl.saveOrUpdate(newestData); + return newestData; + } catch (Exception e) { + e.printStackTrace(); + log.error(e.getMessage()); + XxlJobHelper.log(e.getMessage()); + } + } + } + return null; + } + + private SurvHisdataLivestockwater getRecentData(String deployCode,Integer dayRange) { + LocalDateTime daysAgo = LocalDateTime.now().minusDays(dayRange); + SurvHisdataLivestockwater oldWater = lambdaQuery() + .eq(SurvHisdataLivestockwater::getDeployCode,deployCode) + .ge(SurvHisdataLivestockwater::getDataDateTime, DateTimeConverter.toDate(daysAgo)) + .orderByDesc(SurvHisdataLivestockwater::getDataDateTime) + .last("limit 1") + .one(); + + return oldWater; + } + + + } diff --git a/src/main/java/com/lanhai/service/Impl/SurvHisdataOrientwaterServiceImpl.java b/src/main/java/com/lanhai/service/Impl/SurvHisdataOrientwaterServiceImpl.java index c11f7c2..fa1000d 100644 --- a/src/main/java/com/lanhai/service/Impl/SurvHisdataOrientwaterServiceImpl.java +++ b/src/main/java/com/lanhai/service/Impl/SurvHisdataOrientwaterServiceImpl.java @@ -1,18 +1,18 @@ package com.lanhai.service.Impl; import cn.hutool.core.bean.BeanUtil; +import com.lanhai.constant.IotConstants; import com.lanhai.constant.PollutionConstants; import com.lanhai.entity.*; import com.lanhai.mapper.SurvHisdataOrientwaterMapper; import com.lanhai.mapper.SurvTransdataOrientwaterMapper; +import com.lanhai.o.iot.task.DataExamineDetail; +import com.lanhai.o.iot.task.DataExamineRule; import com.lanhai.service.ISurvHisdataOrientwaterService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lanhai.service.ISurvStationInfoService; import com.lanhai.service.ISurvTransdataOrientwaterService; -import com.lanhai.util.BigDecimalRandomAdjuster; -import com.lanhai.util.DateUtils; -import com.lanhai.util.SpringBeanUtils; -import com.lanhai.util.TUtil; +import com.lanhai.util.*; import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.*; /** @@ -104,7 +105,7 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterTn())) {//跳过负数 + if (newestData.getDataWaterTn().contains("-") || newestData.getDataWaterTn().length() > 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterNo())) {//跳过负数 + if (newestData.getDataWaterNo().contains("-") || newestData.getDataWaterNo().length() > 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterNh())) {//跳过负数 + if (newestData.getDataWaterNh().contains("-") || newestData.getDataWaterNh().length() > 10) { + isNegative = true; + } + } else if (StringUtils.isNotBlank(newestData.getDataWaterCod())) {//跳过负数 + if (newestData.getDataWaterCod().contains("-") || newestData.getDataWaterCod().length() > 10) { + isNegative = true; + } + } + + if (!isNegative) {//非负数时,检查时间是否过期,否则直接自动覆盖此数据 + if (newestData.getDataDateTime() != null) { + long secs = DateUtils.getSecondsDiff(newestData.getDataDateTime(), new Date()); + if (secs < config.getExamineGap()) {//间隔不足时不生成 + log.warn("----------------设备:{}:{},土壤/new面源间隔为:{}秒,限制时间:{}秒,跳过-------------", deploy.getDeployDes(),deploy.getDeployCode(),secs,config.getExamineGap()); + XxlJobHelper.log("-------------设备:{}:{},new面源间隔为:{}秒,,限制时间:{}秒,跳过-----------", deploy.getDeployDes(),deploy.getDeployCode(),secs,config.getExamineGap()); + return null; + } + } + } else {//负数视为无效数据 + newestData = null; + } + } + Map ruleMap = new HashMap<>(); + for (DataExamineRule rule : config.getRules()) { + ruleMap.put(rule.getFields(), rule); + } + SurvHisdataOrientwater hisdataOrientwater = new SurvHisdataOrientwater(); + if (newestData == null) { + newestData = new SurvTransdataOrientwater(); + + SurvHisdataOrientwater hisData = getRecentData(deployCode,config.getHistoryRange()); + + if(hisData!=null){ //第一逻辑,如果有最近的历史数据,则使用历史数据作为基准值 + XxlJobHelper.log("=====设备:{}===查询到历史数据,使用历史数据作为基准值==========",deployCode); + BeanUtil.copyProperties(hisData,newestData); + hisdataOrientwater.setRuleType(IotConstants.RULE_HISTORY); + }else{//第二逻辑,使用预设的标准值 + XxlJobHelper.log("=====设备:{}===使用预设标准值进行生成==========",deployCode); + for (String s : ruleMap.keySet()) { + TUtil.setFieldValue(newestData, s, ruleMap.get(s).getStandard()); + } + hisdataOrientwater.setRuleType(IotConstants.RULE_PRE); + } + }else{ + long dateGap = DateUtils.getDaysDiff(newestData.getDataDateTime(), new Date()); + XxlJobHelper.log("======设备:{}-{}=====土壤/水数据间隔{}天===限制天数:{}====",deploy.getDeployDes(),deploy.getDeployCode(),dateGap,config.getHistoryRange()); + if (dateGap > config.getHistoryRange()) {//最新数据已经超过时限范围,则使用预设数据 + XxlJobHelper.log("xxxx使用预设数据xxxxx"); + for (String s : ruleMap.keySet()) { + TUtil.setFieldValue(newestData, s, ruleMap.get(s).getStandard()); + } + hisdataOrientwater.setRuleType(IotConstants.RULE_PRE); + }else{ + XxlJobHelper.log("xxxx使用原数据规则类型:{}xxxxx",newestData.getRuleType()); + hisdataOrientwater.setRuleType(newestData.getRuleType()); + } + + } + //开始生成 + + Date nowTime = new Date(); + hisdataOrientwater.setReVision(0); + hisdataOrientwater.setCreatedBy("ftask"); + hisdataOrientwater.setCreateTime(nowTime); + hisdataOrientwater.setIsDel(0); + + hisdataOrientwater.setDataDateTime(nowTime); + hisdataOrientwater.setDataGatherType(IotConstants.MARK_GENDATA); + hisdataOrientwater.setDeployCode(deployCode); + + hisdataOrientwater.setFirstValveStatus("0"); + hisdataOrientwater.setSecondValveStatus("1"); + hisdataOrientwater.setCrashStopStatus("0"); + hisdataOrientwater.setWaterPumpStatus("0"); + hisdataOrientwater.setMainSideStatus("0"); + + hisdataOrientwater.setDeviceId(deploy.getId()); + hisdataOrientwater.setDeviceName(deploy.getDeployDes()); + hisdataOrientwater.setStationCode(deploy.getStationCode()); + if (StringUtils.isNotBlank(deploy.getStationCode())) { + SurvStationInfo info = survStationInfoService.getByCode(deploy.getStationCode()); + if (info != null) { + hisdataOrientwater.setStationName(info.getStationName()); + hisdataOrientwater.setStationId(info.getId()); + } + } + + + + for (String key : ruleMap.keySet()) { + DataExamineRule rule = ruleMap.get(key); + String vals = TUtil.getFieldValue(newestData, rule.getFields(), String.class); + if (StringUtils.isNotBlank(vals)) { + BigDecimal fixedRange = new BigDecimal(rule.getFactor()); + int scale = rule.getScale();//小数位 + String correctVal = BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(vals), fixedRange, scale); + TUtil.setFieldValue(hisdataOrientwater, rule.getFields(), correctVal); + } else { + log.error("==========设备:{},编号:{}指标:{}配置错误==============,跳过", deploy.getDeployDes(), deploy.getDeployCode(), rule.getFields()); + XxlJobHelper.log("==========设备:{},编号:{}指标:{}配置错误==============,跳过", deploy.getDeployDes(), deploy.getDeployCode(), rule.getFields()); + } + } + + save(hisdataOrientwater); + + BeanUtil.copyProperties(hisdataOrientwater, newestData); + newestData.setId(orgId); + newestData.setDataDateTime(nowTime); + newestData.setRuleType(newestData.getRuleType()); + newestData.setDataGatherType(newestData.getDataGatherType()); + orientwaterService.saveOrUpdate(newestData); + return newestData; + } catch (Exception e) { + e.printStackTrace(); + log.error(e.getMessage()); + XxlJobHelper.log(e.getMessage()); + } + } + } + return null; + } + + + + private SurvHisdataOrientwater getRecentData(String deployCode,Integer dayRange) { + LocalDateTime daysAgo = LocalDateTime.now().minusDays(dayRange); + SurvHisdataOrientwater oldWater = lambdaQuery() + .eq(SurvHisdataOrientwater::getDeployCode,deployCode) + .ge(SurvHisdataOrientwater::getDataDateTime, DateTimeConverter.toDate(daysAgo)) + .orderByDesc(SurvHisdataOrientwater::getDataDateTime) + .last("limit 1") + .one(); + + return oldWater; + } } diff --git a/src/main/java/com/lanhai/service/Impl/SurvHisdataSoilServiceImpl.java b/src/main/java/com/lanhai/service/Impl/SurvHisdataSoilServiceImpl.java index f579d2d..47dd974 100644 --- a/src/main/java/com/lanhai/service/Impl/SurvHisdataSoilServiceImpl.java +++ b/src/main/java/com/lanhai/service/Impl/SurvHisdataSoilServiceImpl.java @@ -1,11 +1,34 @@ package com.lanhai.service.Impl; +import java.math.BigDecimal; +import java.util.Date; +import cn.hutool.core.bean.BeanUtil; +import com.lanhai.constant.IotConstants; +import com.lanhai.entity.SurvDeviceDeploy; import com.lanhai.entity.SurvHisdataSoil; +import com.lanhai.entity.SurvStationInfo; +import com.lanhai.entity.SurvTransdataSoil; import com.lanhai.mapper.SurvHisdataSoilMapper; +import com.lanhai.o.iot.task.DataExamineDetail; +import com.lanhai.o.iot.task.DataExamineRule; import com.lanhai.service.ISurvHisdataSoilService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.lanhai.service.ISurvStationInfoService; +import com.lanhai.util.BigDecimalRandomAdjuster; +import com.lanhai.util.DateTimeConverter; +import com.lanhai.util.DateUtils; +import com.lanhai.util.TUtil; +import com.xxl.job.core.context.XxlJobHelper; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; + /** *

* 土壤污染监测历史数据 服务实现类 @@ -13,6 +36,143 @@ import org.springframework.stereotype.Service; * */ @Service +@Slf4j public class SurvHisdataSoilServiceImpl extends ServiceImpl implements ISurvHisdataSoilService { + @Lazy + @Autowired + private SurvTransdataSoilServiceImpl soilService; + @Autowired + @Lazy + private ISurvStationInfoService survStationInfoService; + public SurvTransdataSoil genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail config) { + if(deploy!=null && config!=null) { + if (config.getRules() != null && !config.getRules().isEmpty()) { + String deployCode = deploy.getDeployCode(); + try { + SurvTransdataSoil newestData = soilService.getOneByDeviceCode(deploy.getDeployCode(),null); + String orgId = null; + if (newestData != null) { + orgId = newestData.getId(); + if (newestData.getDataDateTime() != null) { + long secs = DateUtils.getSecondsDiff(newestData.getDataDateTime(), new Date()); + if (secs < config.getExamineGap()) {//间隔不足时不生成 + log.warn("-------------设备:{}:{},土壤/水间隔为:{}秒,限制时间:{}秒,跳过--------------", deploy.getDeployDes(),deploy.getDeployCode(),secs,config.getExamineGap()); + XxlJobHelper.log("--------------设备:{}:{},土壤/水间隔为:{}秒,,限制时间:{}秒,跳过---------------", deploy.getDeployDes(),deploy.getDeployCode(),secs,config.getExamineGap()); + return null; + } + } + } + + Map ruleMap = new HashMap<>(); + for (DataExamineRule rule : config.getRules()) { + ruleMap.put(rule.getFields(), rule); + } + SurvHisdataSoil saveEnt = new SurvHisdataSoil(); + if (newestData == null) { + newestData = new SurvTransdataSoil(); + SurvHisdataSoil hisData = getRecentData(deployCode,config.getHistoryRange()); + if(hisData!=null){ //第一逻辑,如果有最近的历史数据,则使用历史数据作为基准值 + XxlJobHelper.log("=====设备:{}===查询到历史数据,使用历史数据作为基准值==========",deployCode); + BeanUtil.copyProperties(hisData,newestData); + saveEnt.setRuleType(IotConstants.RULE_HISTORY); + }else{//第二逻辑,使用预设的标准值 + XxlJobHelper.log("=====设备:{}===使用预设标准值进行生成==========",deployCode); + for (String s : ruleMap.keySet()) { + TUtil.setFieldValue(newestData, s, ruleMap.get(s).getStandard()); + } + saveEnt.setRuleType(IotConstants.RULE_PRE); + } + }else{ + long dateGap = DateUtils.getDaysDiff(newestData.getDataDateTime(), new Date()); + XxlJobHelper.log("======设备:{}-{}=====土壤/水数据间隔{}天===限制天数:{}====",deploy.getDeployDes(),deploy.getDeployCode(),dateGap,config.getHistoryRange()); + if (dateGap > config.getHistoryRange()) {//最新数据已经超过时限范围,则使用预设数据 + XxlJobHelper.log("xxxx使用预设数据xxxxx"); + for (String s : ruleMap.keySet()) { + TUtil.setFieldValue(newestData, s, ruleMap.get(s).getStandard()); + } + saveEnt.setRuleType(IotConstants.RULE_PRE); + }else{ + XxlJobHelper.log("xxxx使用原数据规则类型:{}xxxxx",newestData.getRuleType()); + saveEnt.setRuleType(newestData.getRuleType()); + } + + } + + Date nowTime = new Date(); + + saveEnt.setDeployId(deploy.getId()); + saveEnt.setDeployType(deploy.getDeployType()); + + saveEnt.setDataDateTime(nowTime); + saveEnt.setDataGatherType(IotConstants.MARK_GENDATA); + + + if(StringUtils.isNotBlank(deploy.getStationCode())){ + SurvStationInfo info = survStationInfoService.getByCode(deploy.getStationCode()); + if(info!=null){ + saveEnt.setStationName(info.getStationName()); + saveEnt.setStationId(info.getId()); + } + } + + saveEnt.setDeviceId(deploy.getId()); + saveEnt.setStationCode(deploy.getStationCode()); + saveEnt.setDeployCode(deploy.getDeployCode()); + saveEnt.setDeviceName(deploy.getDeployDes()); + saveEnt.setTransDate(nowTime); + saveEnt.setReVision(0); + saveEnt.setCreatedBy("ftask"); + saveEnt.setCreateTime(nowTime); + saveEnt.setUpdatedBy("ftask"); + saveEnt.setIsDel(0); + saveEnt.setUpdatedTime(nowTime); + + + //生成数据 + for (String key : ruleMap.keySet()) { + DataExamineRule rule = ruleMap.get(key); + String vals = TUtil.getFieldValue(newestData, rule.getFields(), String.class); + if (StringUtils.isNotBlank(vals)) { + BigDecimal fixedRange = new BigDecimal(rule.getFactor()); + int scale = rule.getScale();//小数位 + String correctVal = BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(vals), fixedRange, scale); + TUtil.setFieldValue(saveEnt, rule.getFields(), correctVal); + } else { + log.error("==========设备:{},编号:{}指标:{}配置错误==============,跳过", deploy.getDeployDes(), deploy.getDeployCode(), rule.getFields()); + XxlJobHelper.log("==========设备:{},编号:{}指标:{}配置错误==============,跳过", deploy.getDeployDes(), deploy.getDeployCode(), rule.getFields()); + } + } + + save(saveEnt); + BeanUtil.copyProperties(saveEnt, newestData); + newestData.setId(orgId); + newestData.setDataDateTime(nowTime); + newestData.setRuleType(newestData.getRuleType()); + newestData.setDataGatherType(newestData.getDataGatherType()); + soilService.saveOrUpdate(newestData); + + }catch (Exception e) { + e.printStackTrace(); + XxlJobHelper.log(e.getMessage()); + log.error(e.getMessage()); + } + } + } + return null; + } + + + + private SurvHisdataSoil getRecentData(String deployCode,Integer dayRange) { + LocalDateTime daysAgo = LocalDateTime.now().minusDays(dayRange); + SurvHisdataSoil oldWater = lambdaQuery() + .eq(SurvHisdataSoil::getDeployCode,deployCode) + .ge(SurvHisdataSoil::getDataDateTime, DateTimeConverter.toDate(daysAgo)) + .orderByDesc(SurvHisdataSoil::getDataDateTime) + .last("limit 1") + .one(); + + return oldWater; + } } diff --git a/src/main/java/com/lanhai/service/Impl/SurvTaskConfigServiceImpl.java b/src/main/java/com/lanhai/service/Impl/SurvTaskConfigServiceImpl.java new file mode 100644 index 0000000..3e46dca --- /dev/null +++ b/src/main/java/com/lanhai/service/Impl/SurvTaskConfigServiceImpl.java @@ -0,0 +1,25 @@ +package com.lanhai.service.Impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.lanhai.entity.SurvTaskConfig; +import com.lanhai.mapper.SurvTaskConfigMapper; +import com.lanhai.service.ISurvTaskConfigService; +import org.springframework.stereotype.Service; + +/** + *

+ * 自动任务配置 服务实现类 + *

+ * + * @author ${author} + * @since 2024-12-25 + */ +@Service +public class SurvTaskConfigServiceImpl extends ServiceImpl implements ISurvTaskConfigService { + + @Override + public SurvTaskConfig getConfigByTask(String taskCode) { + SurvTaskConfig survTaskConfig = baseMapper.getConfigByTaskCode(taskCode); + return survTaskConfig; + } +} diff --git a/src/main/java/com/lanhai/task/DataExamineTask.java b/src/main/java/com/lanhai/task/DataExamineTask.java index a2c76e4..cee13b9 100644 --- a/src/main/java/com/lanhai/task/DataExamineTask.java +++ b/src/main/java/com/lanhai/task/DataExamineTask.java @@ -1,10 +1,14 @@ package com.lanhai.task; +import cn.hutool.json.JSONUtil; import com.lanhai.constant.PollutionConstants; -import com.lanhai.entity.SurvDeviceDeploy; -import com.lanhai.entity.SurvTransdataLivestockwater; -import com.lanhai.entity.SurvTransdataOrientwater; +import com.lanhai.entity.*; +import com.lanhai.o.iot.task.DataExamineConfig; +import com.lanhai.o.iot.task.DataExamineDetail; +import com.lanhai.o.iot.task.DataExamineRule; import com.lanhai.service.*; +import com.lanhai.service.Impl.CommonServiceImpl; +import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -12,6 +16,7 @@ import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; + import com.xxl.job.core.handler.annotation.XxlJob; /** * 数据校验任务 @@ -30,11 +35,76 @@ public class DataExamineTask { private ISurvHisdataLivestockwaterService historyLiveWaterService; @Autowired private ISurvTransdataLivestockwaterService livestockWaterService; + @Autowired + private ISurvTaskConfigService taskConfigService; + @Autowired + private ISurvHisdataSoilService soilService; @XxlJob("DataExamineGather") public void TaskHandler() throws Exception{ try{ - log.warn("====================数据校验任务开始===================="); + log.warn("====================new数据校验任务开始===================="); + + //获取任务配置 + SurvTaskConfig survTaskConfig = taskConfigService.getConfigByTask("DataExamineGather"); + if(survTaskConfig!=null){ + DataExamineConfig dataExamineConfig = JSONUtil.toBean(survTaskConfig.getExecuteJson(), DataExamineConfig.class); + if(dataExamineConfig == null){ + XxlJobHelper.log("配置有误0"); + return; + } + if(dataExamineConfig.getConfigs() == null){ + XxlJobHelper.log("配置有误1"); + return; + } + for (DataExamineDetail config : dataExamineConfig.getConfigs()) { + if(config.getDeployId()==null || config.getDeployId().isEmpty()){ + XxlJobHelper.log("设备未配置"); + continue; + } + if(config.getRules()==null || config.getRules().isEmpty()){ + XxlJobHelper.log("设备规则未配置"); + continue; + } + List deployList = deployService.getDeploys(config.getDeployId()); + if(deployList.isEmpty()){ + XxlJobHelper.log("无效设备列表"); + continue; + } + + //开始处理 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (SurvDeviceDeploy deploy : deployList) { + log.warn("=================new处理设备:{}====================",deploy.getDeployCode()); + if(deploy.getDeployType().equals(PollutionConstants.WATER_LIVE)){ + SurvTransdataLivestockwater survTransdataLivestockwater = historyLiveWaterService.genDataAuto(deploy,config); + if(survTransdataLivestockwater!=null){ + log.warn("----------new设备号:{},生成成功,时间:{}-----------",deploy.getDeployCode(),sdf.format(survTransdataLivestockwater.getDataDateTime())); + }else{ + log.warn("----------new设备号:{},跳过------------",deploy.getDeployCode()); + } + } else if (deploy.getDeployType().equals(PollutionConstants.WATER_ORIENT)) { + SurvTransdataOrientwater survTransdataOrientwater = historyOrientwaterService.genDataAuto(deploy,config); + if(survTransdataOrientwater!=null){ + log.warn("----------new设备号:{},生成成功,时间:{}-----------",deploy.getDeployCode(),sdf.format(survTransdataOrientwater.getDataDateTime())); + }else{ + log.warn("----------new设备号:{},跳过------------",deploy.getDeployCode()); + } + }else if (deploy.getDeployType().equals(PollutionConstants.WATER_QULITY)) { + SurvTransdataSoil soil = soilService.genDataAuto(deploy,config); + if(soil!=null){ + log.warn("----------new设备号:{},生成成功,时间:{}-----------",deploy.getDeployCode(),sdf.format(soil.getDataDateTime())); + }else{ + log.warn("----------new设备号:{},跳过------------",deploy.getDeployCode()); + } + } + } + } + + }else { + XxlJobHelper.log("未配置任务执行设置"); + } + List deviceType = new ArrayList(); deviceType.add(PollutionConstants.WATER_LIVE); @@ -45,34 +115,14 @@ public class DataExamineTask { .in(SurvDeviceDeploy::getDeployType,deviceType) .eq(SurvDeviceDeploy::getRunStatus,0) .list(); - log.warn("=============查询到设备数量:{}==============",deployList.size()); - if(!deployList.isEmpty()){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - for (SurvDeviceDeploy deploy : deployList) { - log.warn("=================处理设备:{}====================",deploy.getDeployCode()); - if(deploy.getDeployType().equals(PollutionConstants.WATER_LIVE)){ - SurvTransdataLivestockwater survTransdataLivestockwater = historyLiveWaterService.genData(deploy); - if(survTransdataLivestockwater!=null){ - log.warn("----------设备号:{},生成成功,时间:{}-----------",deploy.getDeployCode(),sdf.format(survTransdataLivestockwater.getDataDateTime())); - }else{ - log.warn("----------设备号:{},跳过------------",deploy.getDeployCode()); - } - } else if (deploy.getDeployType().equals(PollutionConstants.WATER_ORIENT)) { - SurvTransdataOrientwater survTransdataOrientwater = historyOrientwaterService.genData(deploy); - if(survTransdataOrientwater!=null){ - log.warn("----------设备号:{},生成成功,时间:{}-----------",deploy.getDeployCode(),sdf.format(survTransdataOrientwater.getDataDateTime())); - }else{ - log.warn("----------设备号:{},跳过------------",deploy.getDeployCode()); - } - } - } - } + log.warn("=============new查询到设备数量:{}==============",deployList.size()); + } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } finally { - log.warn("===================数据校验任务完成====================="); + log.warn("===================new数据校验任务完成====================="); } } } diff --git a/src/main/java/com/lanhai/task/DataExamineTask_bak.java b/src/main/java/com/lanhai/task/DataExamineTask_bak.java new file mode 100644 index 0000000..f6d76b2 --- /dev/null +++ b/src/main/java/com/lanhai/task/DataExamineTask_bak.java @@ -0,0 +1,79 @@ +package com.lanhai.task; + +import com.lanhai.constant.PollutionConstants; +import com.lanhai.entity.SurvDeviceDeploy; +import com.lanhai.entity.SurvTransdataLivestockwater; +import com.lanhai.entity.SurvTransdataOrientwater; +import com.lanhai.service.*; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +/** + * 数据校验任务 + */ +//@Component +@Slf4j +@Component +public class DataExamineTask_bak { + @Autowired + private ISurvDeviceDeployService deployService; + @Autowired + private ISurvHisdataOrientwaterService historyOrientwaterService; + @Autowired + private ISurvTransdataOrientwaterService orientWaterService; + @Autowired + private ISurvHisdataLivestockwaterService historyLiveWaterService; + @Autowired + private ISurvTransdataLivestockwaterService livestockWaterService; + +// @XxlJob("DataExamineGather") + public void TaskHandler() throws Exception{ + try{ + log.warn("====================数据校验任务开始===================="); + + List deviceType = new ArrayList(); + deviceType.add(PollutionConstants.WATER_LIVE); + deviceType.add(PollutionConstants.WATER_ORIENT); + //获取所有设备 + List deployList = deployService + .lambdaQuery() + .in(SurvDeviceDeploy::getDeployType,deviceType) + .eq(SurvDeviceDeploy::getRunStatus,0) + .list(); + log.warn("=============查询到设备数量:{}==============",deployList.size()); + if(!deployList.isEmpty()){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (SurvDeviceDeploy deploy : deployList) { + log.warn("=================处理设备:{}====================",deploy.getDeployCode()); + if(deploy.getDeployType().equals(PollutionConstants.WATER_LIVE)){ + SurvTransdataLivestockwater survTransdataLivestockwater = historyLiveWaterService.genData(deploy); + if(survTransdataLivestockwater!=null){ + log.warn("----------设备号:{},生成成功,时间:{}-----------",deploy.getDeployCode(),sdf.format(survTransdataLivestockwater.getDataDateTime())); + }else{ + log.warn("----------设备号:{},跳过------------",deploy.getDeployCode()); + } + } else if (deploy.getDeployType().equals(PollutionConstants.WATER_ORIENT)) { + SurvTransdataOrientwater survTransdataOrientwater = historyOrientwaterService.genData(deploy); + if(survTransdataOrientwater!=null){ + log.warn("----------设备号:{},生成成功,时间:{}-----------",deploy.getDeployCode(),sdf.format(survTransdataOrientwater.getDataDateTime())); + }else{ + log.warn("----------设备号:{},跳过------------",deploy.getDeployCode()); + } + } + } + } + + } catch (Exception e) { + log.error(e.getMessage()); + e.printStackTrace(); + } finally { + log.warn("===================数据校验任务完成====================="); + } + } +} diff --git a/src/main/java/com/lanhai/util/DateTimeConverter.java b/src/main/java/com/lanhai/util/DateTimeConverter.java new file mode 100644 index 0000000..dae45d2 --- /dev/null +++ b/src/main/java/com/lanhai/util/DateTimeConverter.java @@ -0,0 +1,39 @@ +package com.lanhai.util; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Date; + +public class DateTimeConverter { + + /** + * LocalDateTime 转 Date(使用系统默认时区) + */ + public static Date toDate(LocalDateTime localDateTime) { + if (localDateTime == null) { + return null; + } + return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + } + + /** + * LocalDateTime 转 Date(指定时区) + */ + public static Date toDate(LocalDateTime localDateTime, ZoneId zoneId) { + if (localDateTime == null) { + return null; + } + return Date.from(localDateTime.atZone(zoneId).toInstant()); + } + + /** + * Date 转 LocalDateTime(使用系统默认时区) + */ + public static LocalDateTime toLocalDateTime(Date date) { + if (date == null) { + return null; + } + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + } +} \ No newline at end of file diff --git a/src/main/java/com/lanhai/util/DateUtils.java b/src/main/java/com/lanhai/util/DateUtils.java index 9b3bfe3..ec0c13a 100644 --- a/src/main/java/com/lanhai/util/DateUtils.java +++ b/src/main/java/com/lanhai/util/DateUtils.java @@ -791,4 +791,14 @@ public class DateUtils extends PropertyEditorSupport { public static long getSecondsDiff(Date startDate, Date endDate) { return getDateDiff(startDate, endDate, TimeUnit.SECONDS); } + + /** + * 计算两个日期之间的日期差 + * @param startDate 开始日期 + * @param endDate 结束日期 + * @return 秒数差 + */ + public static long getDaysDiff(Date startDate, Date endDate) { + return getDateDiff(startDate, endDate, TimeUnit.DAYS); + } } \ No newline at end of file diff --git a/src/main/java/com/lanhai/util/SdrkUtils.java b/src/main/java/com/lanhai/util/SdrkUtils.java index e4af403..0b32706 100644 --- a/src/main/java/com/lanhai/util/SdrkUtils.java +++ b/src/main/java/com/lanhai/util/SdrkUtils.java @@ -4,7 +4,7 @@ import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.xxl.job.core.context.XxlJobHelper; import com.lanhai.constant.IotConstants; -import com.lanhai.entity.FSurvConfig; +import com.lanhai.entity.SurvConfig; import com.lanhai.entity.SurvDeviceDeploy; import com.lanhai.o.iot.renke.DataItem; import com.lanhai.o.iot.renke.RegisterItem; @@ -12,7 +12,7 @@ import com.lanhai.o.iot.renke.RenkeDataRealTimeDetail; import com.lanhai.o.iot.renke.RenkeDataRealTimePack; import com.lanhai.o.vo.HttpResponseVo; import com.lanhai.o.vo.VOIotAccess; -import com.lanhai.service.IFSurvConfigService; +import com.lanhai.service.ISurvSurvConfigService; import com.lanhai.service.IScEquZhibiaoService; import com.lanhai.service.ISurvTransdataSoilService; import lombok.extern.slf4j.Slf4j; @@ -40,7 +40,7 @@ public class SdrkUtils { //redis token过期目录 private static String token_expire = "tool_token:expire:"; static RedisTemplate redisTemplate = SpringContextUtil.getBean(StringRedisTemplate.class); - static IFSurvConfigService configService = SpringContextUtil.getBean(IFSurvConfigService.class); + static ISurvSurvConfigService configService = SpringContextUtil.getBean(ISurvSurvConfigService.class); static IScEquZhibiaoService scEquZhibiaoService = SpringContextUtil.getBean(IScEquZhibiaoService.class); static ISurvTransdataSoilService survTransdataSoilService = SpringContextUtil.getBean(ISurvTransdataSoilService.class); @@ -188,7 +188,7 @@ public class SdrkUtils { public static VOIotAccess getAccess(SurvDeviceDeploy deploy){ VOIotAccess voIotAccess = null; //优先使用设备配置的密钥 - FSurvConfig survConfig = null; + SurvConfig survConfig = null; if(StringUtils.isNotBlank(deploy.getSurvConfigId())){ survConfig = configService.getConfigById(deploy.getSurvConfigId()); }else{ diff --git a/src/main/java/com/lanhai/util/XphUtils.java b/src/main/java/com/lanhai/util/XphUtils.java index 096bc96..c3b98ae 100644 --- a/src/main/java/com/lanhai/util/XphUtils.java +++ b/src/main/java/com/lanhai/util/XphUtils.java @@ -11,14 +11,13 @@ import com.lanhai.o.iot.common.DeviceStatusVo; //import com.lanhai.o.iot.common.ManufacturerConfigRelayVo; //import com.lanhai.o.iot.common.ManufacturerConfigVo; //import com.lanhai.o.iot.common.VOCmdPack; -import com.lanhai.o.iot.xph.XphControlLogDetailVo; import com.lanhai.o.iot.xph.XphControlLogVo; import com.lanhai.o.iot.xph.XphDeviceInfoVo; import com.lanhai.o.iot.xph.XphDeviceNewestDataVo; import com.lanhai.o.vo.HttpResponseVo; import com.lanhai.o.vo.VOIotAccess; //import com.lanhai.service.IFIotManufacturerConfigService; -import com.lanhai.service.IFSurvConfigService; +import com.lanhai.service.ISurvSurvConfigService; import com.lanhai.service.IScEquZhibiaoService; import com.lanhai.service.ISurvTransdataSoilService; import lombok.extern.slf4j.Slf4j; @@ -39,7 +38,7 @@ public class XphUtils { //redis token过期目录 private static String token_expire="tool_token:expire:"; static RedisTemplate redisTemplate = SpringContextUtil.getBean(StringRedisTemplate.class); - static IFSurvConfigService configService = SpringContextUtil.getBean(IFSurvConfigService.class); + static ISurvSurvConfigService configService = SpringContextUtil.getBean(ISurvSurvConfigService.class); static IScEquZhibiaoService scEquZhibiaoService = SpringContextUtil.getBean(IScEquZhibiaoService.class); private static String domain = "https://iot.whxph.com:44300/XPHapiv2"; static ISurvTransdataSoilService survTransdataSoilService = SpringContextUtil.getBean(ISurvTransdataSoilService.class); @@ -130,7 +129,7 @@ public class XphUtils { public static VOIotAccess getAccess(SurvDeviceDeploy deploy){ VOIotAccess voIotAccess = new VOIotAccess(); //优先使用设备配置的密钥 - FSurvConfig survConfig = null; + SurvConfig survConfig = null; if(StringUtils.isNotBlank(deploy.getSurvConfigId())){ survConfig = configService.getConfigById(deploy.getSurvConfigId()); }else{ diff --git a/src/main/java/com/lanhai/util/YSUtils.java b/src/main/java/com/lanhai/util/YSUtils.java index 8894109..d6be787 100644 --- a/src/main/java/com/lanhai/util/YSUtils.java +++ b/src/main/java/com/lanhai/util/YSUtils.java @@ -3,12 +3,12 @@ package com.lanhai.util; import com.alibaba.fastjson.JSONObject; import com.xxl.job.core.context.XxlJobHelper; import com.lanhai.constant.IotConstants; -import com.lanhai.entity.FSurvConfig; +import com.lanhai.entity.SurvConfig; import com.lanhai.entity.SurvDeviceDeploy; import com.lanhai.o.iot.common.DeviceStatusVo; import com.lanhai.o.iot.ysy.VOYsyApiResult; import com.lanhai.o.iot.ysy.VOYsyResultPack; -import com.lanhai.service.IFSurvConfigService; +import com.lanhai.service.ISurvSurvConfigService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.core.RedisTemplate; @@ -31,7 +31,7 @@ public class YSUtils { private static String ys_expire="ys_token:expire:"; - static IFSurvConfigService survConfigService = SpringContextUtil.getBean(IFSurvConfigService.class); + static ISurvSurvConfigService survConfigService = SpringContextUtil.getBean(ISurvSurvConfigService.class); /** * @Author zy * @Date 2023/07/06 16:21:17 @@ -129,25 +129,25 @@ public class YSUtils { private static void addToken(SurvDeviceDeploy deploy,MultiValueMap paramMap){ - FSurvConfig fSurvConfig = null; + SurvConfig survConfig = null; if(StringUtils.isNotBlank(deploy.getSurvConfigId())){ - fSurvConfig = survConfigService.getConfigById(deploy.getSurvConfigId()); + survConfig = survConfigService.getConfigById(deploy.getSurvConfigId()); }else{ - fSurvConfig =survConfigService.getOneByTypeWithTenant(deploy.getTenantId(),IotConstants.ysyAcess); + survConfig =survConfigService.getOneByTypeWithTenant(deploy.getTenantId(),IotConstants.ysyAcess); } String token = ""; - if(fSurvConfig!=null){ - token = getYsToken(fSurvConfig.getConfigKey(),fSurvConfig.getConfigValue()); + if(survConfig !=null){ + token = getYsToken(survConfig.getConfigKey(), survConfig.getConfigValue()); } paramMap.add("accessToken",token); } private static void addTokenTenant(String tenantId,MultiValueMap paramMap){ - FSurvConfig fSurvConfig = survConfigService.getOneByTypeWithTenant(tenantId, IotConstants.ysyAcess); + SurvConfig survConfig = survConfigService.getOneByTypeWithTenant(tenantId, IotConstants.ysyAcess); String token = ""; - if(fSurvConfig!=null){ - token = getYsToken(fSurvConfig.getConfigKey(),fSurvConfig.getConfigValue()); + if(survConfig !=null){ + token = getYsToken(survConfig.getConfigKey(), survConfig.getConfigValue()); } paramMap.add("accessToken",token); }