Commit 6845a6d1 by fengzhi

1.设备状态数值判断精度double

2.数据库实体对应字段修改
3.注释提示添加
1 parent 774018b4
...@@ -42,6 +42,4 @@ public class DayInfo implements Serializable { ...@@ -42,6 +42,4 @@ public class DayInfo implements Serializable {
* 放假提示,如:10月1日至7日放假调休,共7天...... * 放假提示,如:10月1日至7日放假调休,共7天......
*/ */
private String tip; private String tip;
private static final long serialVersionUID = -8402343759691572906L;
} }
\ No newline at end of file \ No newline at end of file
...@@ -26,18 +26,18 @@ public class ScenseData implements Serializable { ...@@ -26,18 +26,18 @@ public class ScenseData implements Serializable {
/** /**
* 场景ID 关联smart_scense中id * 场景ID 关联smart_scense中id
*/ */
@Column(name = "template_id") @Column(name = "scene_id")
private Long templateId; private Long sceneId;
/** /**
* 类型 1触发条件 2执行内容 * 类型 1触发条件 2执行内容
*/ */
private Byte type; private Integer type;
/** /**
* 排序 * 排序
*/ */
private Byte sort; private Integer sort;
/** /**
* 参数key * 参数key
...@@ -50,114 +50,4 @@ public class ScenseData implements Serializable { ...@@ -50,114 +50,4 @@ public class ScenseData implements Serializable {
*/ */
@Column(name = "param_value") @Column(name = "param_value")
private String paramValue; private String paramValue;
private static final long serialVersionUID = 1L;
/**
* 获取标识ID
*
* @return id - 标识ID
*/
public Long getId() {
return id;
}
/**
* 设置标识ID
*
* @param id 标识ID
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取场景ID 关联smart_scense中id
*
* @return template_id - 场景ID 关联smart_scense中id
*/
public Long getTemplateId() {
return templateId;
}
/**
* 设置场景ID 关联smart_scense中id
*
* @param templateId 场景ID 关联smart_scense中id
*/
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
/**
* 获取类型 1触发条件 2执行内容
*
* @return type - 类型 1触发条件 2执行内容
*/
public Byte getType() {
return type;
}
/**
* 设置类型 1触发条件 2执行内容
*
* @param type 类型 1触发条件 2执行内容
*/
public void setType(Byte type) {
this.type = type;
}
/**
* 获取排序
*
* @return sort - 排序
*/
public Byte getSort() {
return sort;
}
/**
* 设置排序
*
* @param sort 排序
*/
public void setSort(Byte sort) {
this.sort = sort;
}
/**
* 获取参数key
*
* @return param_key - 参数key
*/
public String getParamKey() {
return paramKey;
}
/**
* 设置参数key
*
* @param paramKey 参数key
*/
public void setParamKey(String paramKey) {
this.paramKey = paramKey == null ? null : paramKey.trim();
}
/**
* 获取参数值 数组对象
*
* @return param_value - 参数值 数组对象
*/
public String getParamValue() {
return paramValue;
}
/**
* 设置参数值 数组对象
*
* @param paramValue 参数值 数组对象
*/
public void setParamValue(String paramValue) {
this.paramValue = paramValue == null ? null : paramValue.trim();
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -11,5 +11,5 @@ import java.util.List; ...@@ -11,5 +11,5 @@ import java.util.List;
public interface DayInfoMapper extends CommonBaseMapper<DayInfo> { public interface DayInfoMapper extends CommonBaseMapper<DayInfo> {
int updateDayInsert(@Param("daysYear") List<DayInfo> daysYear); int updateDayInsert(@Param("daysYear") List<DayInfo> daysYear);
int getDayCodeByDate(String date); DayInfo getDayCodeByDate(String date);
} }
\ No newline at end of file \ No newline at end of file
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
`tip` = values(`tip`) `tip` = values(`tip`)
</update> </update>
<select id="getDayCodeByDate" resultType="integer"> <select id="getDayCodeByDate" resultMap="BaseResultMap">
select `daycode` from smart_date where date = #{date} select `daycode` from smart_date where date = #{date}
</select> </select>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
<result column="template_id" jdbcType="BIGINT" property="templateId" /> <result column="scene_id" jdbcType="BIGINT" property="sceneId" />
<result column="type" jdbcType="TINYINT" property="type" /> <result column="type" jdbcType="TINYINT" property="type" />
<result column="sort" jdbcType="TINYINT" property="sort" /> <result column="sort" jdbcType="TINYINT" property="sort" />
<result column="param_key" jdbcType="VARCHAR" property="paramKey" /> <result column="param_key" jdbcType="VARCHAR" property="paramKey" />
......
...@@ -41,7 +41,7 @@ public enum EDay { ...@@ -41,7 +41,7 @@ public enum EDay {
WEEKDAY { WEEKDAY {
@Override @Override
public Integer getCode() { public Integer getCode() {
return 3; return 2;
} }
@Override @Override
...@@ -57,7 +57,7 @@ public enum EDay { ...@@ -57,7 +57,7 @@ public enum EDay {
LEAVE_OFF_DAY { LEAVE_OFF_DAY {
@Override @Override
public Integer getCode() { public Integer getCode() {
return 4; return 3;
} }
@Override @Override
......
...@@ -5,6 +5,7 @@ package cn.com.glsx.smartdevice.Common; ...@@ -5,6 +5,7 @@ package cn.com.glsx.smartdevice.Common;
* @date 2021/3/19 17:40 * @date 2021/3/19 17:40
* @description 枚举,触发条件的逻辑判断 * @description 枚举,触发条件的逻辑判断
*/ */
public enum ELogic { public enum ELogic {
LESS_THAN { LESS_THAN {
@Override @Override
...@@ -14,7 +15,7 @@ public enum ELogic { ...@@ -14,7 +15,7 @@ public enum ELogic {
@Override @Override
public boolean getValue(String deviceOrderValue,String deviceOrderValueReal) { public boolean getValue(String deviceOrderValue,String deviceOrderValueReal) {
return Integer.parseInt(deviceOrderValueReal) < Integer.parseInt(deviceOrderValue); return Double.parseDouble(deviceOrderValueReal) < Double.parseDouble(deviceOrderValue);
} }
@Override @Override
...@@ -30,7 +31,7 @@ public enum ELogic { ...@@ -30,7 +31,7 @@ public enum ELogic {
@Override @Override
public boolean getValue(String deviceOrderValue,String deviceOrderValueReal) { public boolean getValue(String deviceOrderValue,String deviceOrderValueReal) {
return Integer.parseInt(deviceOrderValueReal) > Integer.parseInt(deviceOrderValue); return Double.parseDouble(deviceOrderValueReal) > Double.parseDouble(deviceOrderValue);
} }
......
...@@ -9,6 +9,7 @@ import cn.com.glsx.smartdevice.Common.ELogic; ...@@ -9,6 +9,7 @@ import cn.com.glsx.smartdevice.Common.ELogic;
import cn.com.glsx.smartdevice.factory.ConditionFactory; import cn.com.glsx.smartdevice.factory.ConditionFactory;
import cn.com.glsx.smartdevice.factory.ConditionStrategy; import cn.com.glsx.smartdevice.factory.ConditionStrategy;
import cn.com.glsx.smartdevice.utils.DateUtils; import cn.com.glsx.smartdevice.utils.DateUtils;
import cn.com.glsx.vasp.modules.entity.DayInfo;
import cn.com.glsx.vasp.modules.entity.DeviceStatus; import cn.com.glsx.vasp.modules.entity.DeviceStatus;
import cn.com.glsx.vasp.modules.entity.ScenseData; import cn.com.glsx.vasp.modules.entity.ScenseData;
import cn.com.glsx.vasp.modules.mapper.DayInfoMapper; import cn.com.glsx.vasp.modules.mapper.DayInfoMapper;
...@@ -63,7 +64,11 @@ public class SceneService { ...@@ -63,7 +64,11 @@ public class SceneService {
//获取当前时间 //获取当前时间
long rangeBegintTime = System.currentTimeMillis(); long rangeBegintTime = System.currentTimeMillis();
//判断当前日期,转为周期类型 //判断当前日期,转为周期类型
int executeCycle = getExecuteCycle(); Integer executeCycle = getExecuteCycle();
if(null == executeCycle){
log.info("查询周期失败,无法获取对应的周期");
return;
}
//获取符合周期类型且满足判断策略(任意满足,全部满足触发)的触发条件 //获取符合周期类型且满足判断策略(任意满足,全部满足触发)的触发条件
List<ScenseData> dataAnyCondition = conditionStrategy.getScenseData(executeCycle); List<ScenseData> dataAnyCondition = conditionStrategy.getScenseData(executeCycle);
//将集合按key:场景id,val:场景触发条件集合转为map, //将集合按key:场景id,val:场景触发条件集合转为map,
...@@ -75,12 +80,11 @@ public class SceneService { ...@@ -75,12 +80,11 @@ public class SceneService {
//遍历场景,按每个场景处理对应的触发条件判断 //遍历场景,按每个场景处理对应的触发条件判断
long scenseId = entry.getKey(); long scenseId = entry.getKey();
List<ScenseData> dataList = entry.getValue(); List<ScenseData> dataList = entry.getValue();
if (CollectionUtils.isNotEmpty(dataList)) { if (CollectionUtils.isNotEmpty(dataList)) {
//判断当前场景的触发情况(时间符合或者设备状态符合) //判断当前场景的触发情况(时间符合或者设备状态符合)
boolean isTrigger = finalConditionStrategy.isTrigger(dataList, rangeBegintTime, boolean isTrigger = finalConditionStrategy.isTrigger(dataList, rangeBegintTime,
(ScenseData condition) -> getTriggerResult(rangeBegintTime, condition)); (ScenseData condition) -> getTriggerResult(rangeBegintTime, condition,conditionType));
if (isTrigger) { if (isTrigger) {
//如果符合触发场景,推送kafka //如果符合触发场景,推送kafka
...@@ -100,13 +104,14 @@ public class SceneService { ...@@ -100,13 +104,14 @@ public class SceneService {
} }
//根据当前时间对应的执行周期类型 //根据当前时间对应的执行周期类型
private int getExecuteCycle() { private Integer getExecuteCycle() {
//判断当天的日类型 //判断当天的日类型
String date = DateUtils.getDate(); String date = DateUtils.getDate();
//0表示工作日、为1节假日、为2双休日、3为调休日(上班) //0表示工作日、为1节假日、为2双休日、3为调休日(上班)
int dayCode = dayInfoMapper.getDayCodeByDate(date); DayInfo dayInfo = dayInfoMapper.getDayCodeByDate(date);
//转换为对应的执行周期 //转换为对应的执行周期
return EDay.getValueByCode(dayCode); return EDay.getValueByCode(null == dayInfo ? -1 : dayInfo.getDaycode());
} }
//将场景触发条件转为map,key为场景id,val为触发条件集合 //将场景触发条件转为map,key为场景id,val为触发条件集合
...@@ -116,7 +121,7 @@ public class SceneService { ...@@ -116,7 +121,7 @@ public class SceneService {
if (CollectionUtils.isNotEmpty(dataAnyCondition)) { if (CollectionUtils.isNotEmpty(dataAnyCondition)) {
dataAnyCondition.stream().forEach(data -> { dataAnyCondition.stream().forEach(data -> {
List<ScenseData> scenseDataList = null; List<ScenseData> scenseDataList = null;
long scenseId = data.getTemplateId(); long scenseId = data.getSceneId();
if (scenseDataMap.containsKey(scenseId)) { if (scenseDataMap.containsKey(scenseId)) {
scenseDataList = scenseDataMap.get(scenseId); scenseDataList = scenseDataMap.get(scenseId);
...@@ -132,17 +137,17 @@ public class SceneService { ...@@ -132,17 +137,17 @@ public class SceneService {
} }
//触发条件判断 //触发条件判断
private boolean getTriggerResult(long rangeBegintTime, ScenseData condition) { private boolean getTriggerResult(long rangeBegintTime, ScenseData condition,int conditionType) {
String key = condition.getParamKey(); String key = condition.getParamKey();
String value = condition.getParamValue(); String value = condition.getParamValue();
//log.info("fz====scenseId:"+condition.getSceneId()+"===key:"+key+"==VAL:"+value);
//scene_condition_status设备状态 //scene_condition_status设备状态
if (Constants.CONDITION_STATUS.equals(key)) { if (Constants.CONDITION_STATUS.equals(key)) {
//value为设备状态的条件数组 //value为设备状态的条件数组
if (StringUtils.isEmpty(value)) { if (StringUtils.isEmpty(value)) {
log.info("设备状态触发条件的value不存在===id:"+condition.getId());
return false; return false;
} }
log.info("getParamValue=="+value);
String[] vals = value.split(","); String[] vals = value.split(",");
//参数一,设备id //参数一,设备id
String deviceId = vals[0]; String deviceId = vals[0];
...@@ -160,6 +165,7 @@ public class SceneService { ...@@ -160,6 +165,7 @@ public class SceneService {
} }
//根据logic逻辑码,判断触发条件与数据库中实际的值,判断是否满足 //根据logic逻辑码,判断触发条件与数据库中实际的值,判断是否满足
//log.info("fz===scenseId:"+condition.getSceneId()+"===condition_val:"+deviceOrderValue+"====realval:"+status.getDeviceOrderValue() );
return ELogic.getValueByCode(logic,deviceOrderValue,status.getDeviceOrderValue()); return ELogic.getValueByCode(logic,deviceOrderValue,status.getDeviceOrderValue());
} }
...@@ -167,6 +173,7 @@ public class SceneService { ...@@ -167,6 +173,7 @@ public class SceneService {
if (Constants.CONDITION_TIME.equals(key)) { if (Constants.CONDITION_TIME.equals(key)) {
//value为时分 //value为时分
if (StringUtils.isEmpty(value)) { if (StringUtils.isEmpty(value)) {
log.info("时间触发条件的value不存在===id:"+condition.getId());
return false; return false;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!