增加五常生成逻辑
This commit is contained in:
parent
53138f981a
commit
eea1e7fcad
|
|
@ -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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<FSurvConfig> {
|
||||
public class SurvConfig extends Model<SurvConfig> {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
|
|
@ -92,6 +92,12 @@ public class SurvHisdataAir extends Model<SurvHisdataAir> {
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -121,6 +121,12 @@ public class SurvHisdataLivestockwater extends Model<SurvHisdataLivestockwater>
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -79,6 +79,12 @@ public class SurvHisdataLivestockwaterError extends Model<SurvHisdataLivestockwa
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
@ -218,6 +224,8 @@ public class SurvHisdataLivestockwaterError extends Model<SurvHisdataLivestockwa
|
|||
private String mainSideStatus;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -115,6 +115,12 @@ public class SurvHisdataOrientwater extends Model<SurvHisdataOrientwater> {
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
@ -206,6 +212,8 @@ public class SurvHisdataOrientwater extends Model<SurvHisdataOrientwater> {
|
|||
private Date updatedTime;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
|
|
|
|||
|
|
@ -145,6 +145,12 @@ public class SurvHisdataOrientwaterError extends Model<SurvHisdataOrientwaterErr
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
@ -236,6 +242,8 @@ public class SurvHisdataOrientwaterError extends Model<SurvHisdataOrientwaterErr
|
|||
private Date updatedTime;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -216,6 +216,12 @@ public class SurvHisdataSoil extends Model<SurvHisdataSoil> {
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自动任务配置
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since 2024-12-25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class SurvTaskConfig extends Model<SurvTaskConfig> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -91,6 +91,12 @@ public class SurvTransdataAir extends Model<SurvTransdataAir> {
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
@ -189,6 +195,8 @@ public class SurvTransdataAir extends Model<SurvTransdataAir> {
|
|||
private String deployType;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
|
|
|
|||
|
|
@ -123,6 +123,12 @@ public class SurvTransdataLivestockwater extends Model<SurvTransdataLivestockwat
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
@ -208,6 +214,8 @@ public class SurvTransdataLivestockwater extends Model<SurvTransdataLivestockwat
|
|||
private Date updatedTime;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
|
|
|
|||
|
|
@ -116,6 +116,12 @@ public class SurvTransdataOrientwater extends Model<SurvTransdataOrientwater> {
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
@ -201,6 +207,8 @@ public class SurvTransdataOrientwater extends Model<SurvTransdataOrientwater> {
|
|||
private Date updatedTime;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
|
|
|
|||
|
|
@ -218,6 +218,12 @@ public class SurvTransdataSoil extends Model<SurvTransdataSoil> {
|
|||
@TableField("DATA_GATHER_TYPE")
|
||||
private String dataGatherType;
|
||||
|
||||
/**
|
||||
* 规则类型
|
||||
*/
|
||||
@TableField("RULE_TYPE")
|
||||
private String ruleType;
|
||||
|
||||
/**
|
||||
* 站点ID
|
||||
*/
|
||||
|
|
@ -310,7 +316,7 @@ public class SurvTransdataSoil extends Model<SurvTransdataSoil> {
|
|||
private String deployId;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
* 部署类型
|
||||
*/
|
||||
@TableField("DEPLOY_TYPE")
|
||||
private String deployType;
|
||||
|
|
@ -320,6 +326,7 @@ public class SurvTransdataSoil extends Model<SurvTransdataSoil> {
|
|||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.id;
|
||||
|
|
|
|||
|
|
@ -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<JSONObject> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<FSurvConfig> {
|
||||
public interface SurvConfigMapper extends BaseMapper<SurvConfig> {
|
||||
|
||||
FSurvConfig getOneByTypeWithTenant(@Param("tenantId") String tenantId, @Param("type")String type);
|
||||
SurvConfig getOneByTypeWithTenant(@Param("tenantId") String tenantId, @Param("type")String type);
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自动任务配置 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since 2024-12-25
|
||||
*/
|
||||
public interface SurvTaskConfigMapper extends BaseMapper<SurvTaskConfig> {
|
||||
|
||||
SurvTaskConfig getConfigByTaskCode(@Param("taskCode")String taskCode);
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.lanhai.mapper.FSurvConfigMapper">
|
||||
<mapper namespace="com.lanhai.mapper.SurvConfigMapper">
|
||||
|
||||
<select id="getOneByTypeWithTenant" resultType="com.lanhai.entity.FSurvConfig">
|
||||
<select id="getOneByTypeWithTenant" resultType="com.lanhai.entity.SurvConfig">
|
||||
select * from surv_config where CONFIG_TYPE = #{type} AND TENANT_ID = #{tenantId} limit 1
|
||||
</select>
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.lanhai.mapper.SurvTaskConfigMapper">
|
||||
|
||||
<resultMap type="com.lanhai.entity.SurvTaskConfig" id="SurvTaskConfigMap">
|
||||
<result property="id" column="ID" jdbcType="VARCHAR"/>
|
||||
<result property="taskCode" column="TASK_CODE" jdbcType="VARCHAR"/>
|
||||
<result property="taskName" column="TASK_NAME" jdbcType="VARCHAR"/>
|
||||
<result property="taskType" column="TASK_TYPE" jdbcType="TINYINT"/>
|
||||
<result property="taskDes" column="TASK_DES" jdbcType="VARCHAR"/>
|
||||
<result property="protpcolCode" column="PROTPCOL_CODE" jdbcType="VARCHAR"/>
|
||||
<result property="belongCompanyId" column="BELONG_COMPANY_ID" jdbcType="VARCHAR"/>
|
||||
<result property="belongTenantId" column="BELONG_TENANT_ID" jdbcType="VARCHAR"/>
|
||||
<result property="initTime" column="INIT_TIME" jdbcType="VARCHAR"/>
|
||||
<result property="executeRate" column="EXECUTE_RATE" jdbcType="INTEGER"/>
|
||||
<result property="delayMin" column="DELAY_MIN" jdbcType="INTEGER"/>
|
||||
<result property="executeJson" column="EXECUTE_JSON" jdbcType="VARCHAR" typeHandler="com.lanhai.handler.JsonTypeHandler"/>
|
||||
<result property="tenantId" column="TENANT_ID" jdbcType="VARCHAR"/>
|
||||
<result property="reVision" column="RE_VISION" jdbcType="INTEGER"/>
|
||||
<result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
|
||||
<result property="isDel" column="IS_DEL" jdbcType="INTEGER"/>
|
||||
<result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/>
|
||||
<result property="revision" column="REVISION" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="baseSql">
|
||||
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
|
||||
</sql>
|
||||
|
||||
<select id="getConfigByTaskCode" resultMap="SurvTaskConfigMap">
|
||||
select <include refid="baseSql"/>
|
||||
from surv_task_config
|
||||
<where>
|
||||
<if test="taskCode != null and taskCode !=''">
|
||||
and TASK_CODE = #{taskCode}
|
||||
</if>
|
||||
</where>
|
||||
order by CREATE_TIME limit 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.lanhai.o.iot.task;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DataExamineConfig {
|
||||
List<DataExamineDetail> configs;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.lanhai.o.iot.task;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@Data
|
||||
public class DataExamineDetail {
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
private List<String> deployId;
|
||||
|
||||
/**
|
||||
* 时间校验标准,如10分钟无数据需要生成,单位秒
|
||||
*/
|
||||
private Integer examineGap;
|
||||
|
||||
/**
|
||||
* 历史数据基准范围,最小1天,超出此时间段认为没有合适的数据,单位天
|
||||
*/
|
||||
private Integer historyRange;
|
||||
|
||||
/**
|
||||
* 生成规则配置
|
||||
*/
|
||||
private List<DataExamineRule> rules;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
package com.lanhai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lanhai.entity.FSurvConfig;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统配置表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since 2024-12-18
|
||||
*/
|
||||
public interface IFSurvConfigService extends IService<FSurvConfig> {
|
||||
FSurvConfig getOneByTypeWithTenant(String tenantId, String type);
|
||||
|
||||
|
||||
FSurvConfig getSurvConfigByType(String tenantId, String type);
|
||||
|
||||
FSurvConfig getConfigById(String survConfigId);
|
||||
}
|
||||
|
|
@ -18,4 +18,6 @@ public interface ISurvDeviceDeployService extends IService<SurvDeviceDeploy> {
|
|||
|
||||
|
||||
List<SurvDeviceDeploy> getDeviceByType(List<String> protocolCode,List<String> deviceType);
|
||||
|
||||
List<SurvDeviceDeploy> getDeploys(List<String> deployId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -14,4 +18,6 @@ import com.lanhai.entity.SurvTransdataLivestockwater;
|
|||
public interface ISurvHisdataLivestockwaterService extends IService<SurvHisdataLivestockwater> {
|
||||
|
||||
SurvTransdataLivestockwater genData(SurvDeviceDeploy deploy);
|
||||
|
||||
SurvTransdataLivestockwater genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail dataExamineDetail);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -14,4 +15,6 @@ import com.lanhai.entity.SurvTransdataOrientwater;
|
|||
public interface ISurvHisdataOrientwaterService extends IService<SurvHisdataOrientwater> {
|
||||
|
||||
SurvTransdataOrientwater genData(SurvDeviceDeploy deploy);
|
||||
|
||||
SurvTransdataOrientwater genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -11,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
*/
|
||||
public interface ISurvHisdataSoilService extends IService<SurvHisdataSoil> {
|
||||
|
||||
SurvTransdataSoil genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.lanhai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lanhai.entity.SurvConfig;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统配置表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since 2024-12-18
|
||||
*/
|
||||
public interface ISurvSurvConfigService extends IService<SurvConfig> {
|
||||
SurvConfig getOneByTypeWithTenant(String tenantId, String type);
|
||||
|
||||
|
||||
SurvConfig getSurvConfigByType(String tenantId, String type);
|
||||
|
||||
SurvConfig getConfigById(String survConfigId);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.lanhai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lanhai.entity.SurvTaskConfig;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自动任务配置 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since 2024-12-25
|
||||
*/
|
||||
public interface ISurvTaskConfigService extends IService<SurvTaskConfig> {
|
||||
|
||||
SurvTaskConfig getConfigByTask(String taskCode);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<FSurvConfigMapper, FSurvConfig> implements IFSurvConfigService {
|
||||
public class SurvConfigServiceImpl extends ServiceImpl<SurvConfigMapper, SurvConfig> implements ISurvSurvConfigService {
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
|
|
@ -30,21 +30,21 @@ public class FSurvConfigServiceImpl extends ServiceImpl<FSurvConfigMapper, FSurv
|
|||
private CommonServiceImpl commonService;
|
||||
|
||||
@Override
|
||||
public FSurvConfig getOneByTypeWithTenant(String tenantId, String type) {
|
||||
FSurvConfig fSurvConfig = commonService.getCacheTenant(tenantId, type);
|
||||
public SurvConfig getOneByTypeWithTenant(String tenantId, String type) {
|
||||
SurvConfig survConfig = commonService.getCacheTenant(tenantId, type);
|
||||
String cacheHead = IotConstants.IOT_SURVCONFIG_CACHE+"::%s:%s";
|
||||
redisTemplate.expire(String.format(cacheHead,tenantId,type),60, TimeUnit.MINUTES);//设置过期时间
|
||||
return fSurvConfig;
|
||||
return survConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FSurvConfig getSurvConfigByType(String tenantId, String type) {
|
||||
public SurvConfig getSurvConfigByType(String tenantId, String type) {
|
||||
return baseMapper.getOneByTypeWithTenant(tenantId, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE, key = "#survConfigId", unless = "#result == null ")
|
||||
public FSurvConfig getConfigById(String survConfigId) {
|
||||
public SurvConfig getConfigById(String survConfigId) {
|
||||
return baseMapper.selectById(survConfigId);
|
||||
}
|
||||
|
||||
|
|
@ -7,6 +7,7 @@ import com.lanhai.mapper.SurvDeviceDeployMapper;
|
|||
import com.lanhai.service.ISurvDeviceDeployService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -38,4 +39,10 @@ public class SurvDeviceDeployServiceImpl extends ServiceImpl<SurvDeviceDeployMap
|
|||
public List<SurvDeviceDeploy> getDeviceByType(List<String> protocolCode, List<String> deviceType) {
|
||||
return baseMapper.getProtocolDeviceType(protocolCode,deviceType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SurvDeviceDeploy> getDeploys(List<String> deployId) {
|
||||
List<SurvDeviceDeploy> list = lambdaQuery().in(SurvDeviceDeploy::getId,deployId).list();
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<SurvHisdat
|
|||
if (newestData.getDataDateTime() != null) {
|
||||
long secs = DateUtils.getSecondsDiff(newestData.getDataDateTime(), new Date());
|
||||
if (secs < PollutionConstants.dataGenGap) {//间隔不足时不生成
|
||||
log.warn("畜禽间隔为:{},跳过", secs);
|
||||
log.warn("畜禽间隔为:{}秒,跳过", secs);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -132,7 +133,7 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl<SurvHisdat
|
|||
hisdataLivestockwater.setIsDel(0);
|
||||
|
||||
hisdataLivestockwater.setDataDateTime(nowTime);
|
||||
hisdataLivestockwater.setDataGatherType("realTime");
|
||||
hisdataLivestockwater.setDataGatherType(IotConstants.MARK_GENDATA);
|
||||
|
||||
// hisdataLivestockwater.setDataWaterTp(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTp()), fixedRange, scale));
|
||||
// hisdataLivestockwater.setDataWaterTn(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTn()), fixedRange, scale));
|
||||
|
|
@ -182,4 +183,167 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl<SurvHisdat
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SurvTransdataLivestockwater genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail dataExamineDetail) {
|
||||
|
||||
if(deploy!=null && dataExamineDetail!=null){
|
||||
if(dataExamineDetail.getRules()!=null && !dataExamineDetail.getRules().isEmpty()) {
|
||||
String deployCode = deploy.getDeployCode();
|
||||
try {
|
||||
|
||||
SurvTransdataLivestockwater newestData = survTransdataLivestockwaterServiceImpl.getOneByDeviceCode(deployCode);
|
||||
|
||||
String orgId = null;
|
||||
if (newestData != null) {
|
||||
orgId = newestData.getId();
|
||||
boolean isNegative = false;
|
||||
//检查有没有负数
|
||||
if (StringUtils.isNotBlank(newestData.getDataWaterTp())) {//跳过负数
|
||||
if (newestData.getDataWaterTp().contains("-") || newestData.getDataWaterTp().length() > 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<String, DataExamineRule> 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<SurvHisdataOr
|
|||
if (newestData.getDataDateTime() != null) {
|
||||
long secs = DateUtils.getSecondsDiff(newestData.getDataDateTime(), new Date());
|
||||
if (secs < PollutionConstants.dataGenGap) {//间隔不足时不生成
|
||||
log.warn("面源间隔为:{},跳过", secs);
|
||||
log.warn("面源间隔为:{}秒,跳过", secs);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +148,7 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl<SurvHisdataOr
|
|||
hisdataOrientwater.setIsDel(0);
|
||||
|
||||
hisdataOrientwater.setDataDateTime(nowTime);
|
||||
hisdataOrientwater.setDataGatherType("realTime");
|
||||
hisdataOrientwater.setDataGatherType(IotConstants.MARK_GENDATA);
|
||||
|
||||
// hisdataOrientwater.setDataWaterTp(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTp()), fixedRange, scale));
|
||||
// hisdataOrientwater.setDataWaterTn(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTn()), fixedRange, scale));
|
||||
|
|
@ -202,4 +203,167 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl<SurvHisdataOr
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SurvTransdataOrientwater genDataAuto(SurvDeviceDeploy deploy, DataExamineDetail config) {
|
||||
if(deploy!=null && config!=null) {
|
||||
if (config.getRules() != null && !config.getRules().isEmpty()) {
|
||||
try {
|
||||
String deployCode = deploy.getDeployCode();
|
||||
log.warn("=================new面源逻辑====================" + deployCode);
|
||||
SurvTransdataOrientwater newestData = orientwaterService.getOneByDeviceCode(deployCode);
|
||||
|
||||
String orgId = null;
|
||||
if (newestData != null) {
|
||||
orgId = newestData.getId();
|
||||
boolean isNegative = false;
|
||||
//检查有没有负数
|
||||
if (StringUtils.isNotBlank(newestData.getDataWaterTp())) {//跳过负数
|
||||
if (newestData.getDataWaterTp().contains("-") || newestData.getDataWaterTp().length() > 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<String, DataExamineRule> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 土壤污染监测历史数据 服务实现类
|
||||
|
|
@ -13,6 +36,143 @@ import org.springframework.stereotype.Service;
|
|||
*
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SurvHisdataSoilServiceImpl extends ServiceImpl<SurvHisdataSoilMapper, SurvHisdataSoil> 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<String, DataExamineRule> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 自动任务配置 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since 2024-12-25
|
||||
*/
|
||||
@Service
|
||||
public class SurvTaskConfigServiceImpl extends ServiceImpl<SurvTaskConfigMapper, SurvTaskConfig> implements ISurvTaskConfigService {
|
||||
|
||||
@Override
|
||||
public SurvTaskConfig getConfigByTask(String taskCode) {
|
||||
SurvTaskConfig survTaskConfig = baseMapper.getConfigByTaskCode(taskCode);
|
||||
return survTaskConfig;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<SurvDeviceDeploy> 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<String> deviceType = new ArrayList<String>();
|
||||
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数据校验任务完成=====================");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> deviceType = new ArrayList<String>();
|
||||
deviceType.add(PollutionConstants.WATER_LIVE);
|
||||
deviceType.add(PollutionConstants.WATER_ORIENT);
|
||||
//获取所有设备
|
||||
List<SurvDeviceDeploy> 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("===================数据校验任务完成=====================");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue