Commit da1c359f by 111-PC\111

Merge remote-tracking branch 'origin/master'

2 parents c3d1e8ad 2736d7f8
package cn.com.glsx.vasp.modules.entity;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Accessors(chain = true)
@Data
@Entity
@Table(name = "smart_scene")
public class Scene implements Serializable {
@Id
@Column(
name = "id",
unique = true,
nullable = false
)
@GeneratedValue(
strategy = GenerationType.IDENTITY,
generator = "SELECT LAST_INSERT_ID()"
)
private Long id;
/**
* 用户ID 关联smart_user_relation中id
*/
@Column(name = "user_id")
private Long userId;
/**
* 场景名称
*/
@Column(name = "scene_name")
private String sceneName;
/**
* 场景类型key 关联smart_sys_code中dict_key
*/
@Column(name = "type_key")
private String typeKey;
/**
* 场景图标ID 关联smart_sys_file中id
*/
private Long icon;
/**
* 场景背景图ID 关联smart_sys_file中id
*/
@Column(name = "back_pic")
private Long backPic;
/**
* 查看次数
*/
@Column(name = "view_times")
private Long viewTimes;
/**
* 场景描述
*/
private String description;
/**
* 条件规则 1任一条件 2全部条件
*/
@Column(name = "condition_rule")
private Integer conditionRule;
/**
* 执行周期 1每天 2工作日 3法定节假日
*/
@Column(name = "execute_cycle")
private Integer executeCycle;
/**
* 开关说明:-1 无开关 0开关关 1开关开
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
@Column(name = "create_time")
private Date createTime;
/**
* 更新时间
*/
@Column(name = "update_time")
private Date updateTime;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.vasp.modules.mapper;
import cn.com.glsx.vasp.modules.entity.Scene;
import cn.com.glsx.vasp.modules.entity.ScenseData;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SceneMapper extends CommonBaseMapper<Scene> {
List<Long> getSceneAllConditionTime(int executeCycle);
}
\ No newline at end of file \ No newline at end of file
...@@ -8,7 +8,7 @@ import java.util.List; ...@@ -8,7 +8,7 @@ import java.util.List;
@Mapper @Mapper
public interface ScenseDataMapper extends CommonBaseMapper<ScenseData> { public interface ScenseDataMapper extends CommonBaseMapper<ScenseData> {
List<ScenseData> getScenseAnyCondition(int executeCycle); List<ScenseData> getScneByIds(List<Long> ids);
List<ScenseData> getScenseAllCondition(int executeCycle); List<ScenseData> getByAnyConditionTime(int executeCycle);
} }
\ No newline at end of file \ No newline at end of file
...@@ -37,9 +37,9 @@ ...@@ -37,9 +37,9 @@
</commentGenerator> </commentGenerator>
<!-- jdbc连接--> <!-- jdbc连接-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.3.222:3307/newgps?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true" connectionURL="jdbc:mysql://192.168.1.39:3306/cyb_os?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true"
userId="root" userId="os_user"
password="Msd^*$@online"> password="os#123">
<!--防止生成其他库同名表--> <!--防止生成其他库同名表-->
<property name="nullCatalogMeansCurrent" value="true"/> <property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection> </jdbcConnection>
...@@ -68,6 +68,6 @@ ...@@ -68,6 +68,6 @@
</javaClientGenerator> </javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 --> <!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table tableName="smart_devide_status" domainObjectName="DeviceStatus" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="smart_scene" domainObjectName="Scene" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context> </context>
</generatorConfiguration> </generatorConfiguration>
\ No newline at end of file \ No newline at end of file
<?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="cn.com.glsx.vasp.modules.mapper.SceneMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.vasp.modules.entity.Scene">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="scene_name" jdbcType="VARCHAR" property="sceneName" />
<result column="type_key" jdbcType="VARCHAR" property="typeKey" />
<result column="icon" jdbcType="BIGINT" property="icon" />
<result column="back_pic" jdbcType="BIGINT" property="backPic" />
<result column="view_times" jdbcType="BIGINT" property="viewTimes" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="condition_rule" jdbcType="TINYINT" property="conditionRule" />
<result column="execute_cycle" jdbcType="TINYINT" property="executeCycle" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, user_id, scene_name, type_key, icon, back_pic, view_times, description, condition_rule,
execute_cycle, `status`, remark, create_time, update_time
</sql>
<!-- 查询符合周期(每天+当天类型)且满足全部条件触发 -->
<select id="getSceneAllConditionTime" resultType="long">
select sms.id from smart_scene sms INNER JOIN smart_scene_data smsd on sms.id = smsd.scene_id where sms.status = 1 and smsd.type = 1 and smsd.param_key = 'scene_condition_time' and sms.execute_cycle in (1,#{executeCycle}) and sms.condition_rule = 2
</select>
</mapper>
\ No newline at end of file \ No newline at end of file
...@@ -19,13 +19,17 @@ ...@@ -19,13 +19,17 @@
id, template_id, `type`, sort, param_key, param_value id, template_id, `type`, sort, param_key, param_value
</sql> </sql>
<!-- 查询符合周期(每天+当天类型)且满足任意条件触发 --> <!--List:forech中的collection属性类型是List,collection的值必须是:list,item的值可以随意,Dao接口中参数名字随意 -->
<select id="getScenseAnyCondition" resultMap="BaseResultMap"> <select id="getScneByIds" resultMap="BaseResultMap">
select smsd.* from smart_scene sms INNER JOIN smart_scene_data smsd on sms.id = smsd.scene_id where sms.status = 1 and smsd.param_key = scene_condition_time and sms.execute_cycle in (1,#{executeCycle}) and sms.condition_rule = 1 and smsd.type = 1 select * from smart_scene_data where type = 1 and scene_id in
<foreach collection="list" item="sceneId" index="index"
open="(" close=")" separator=",">
#{sceneId}
</foreach>
</select> </select>
<!-- 查询符合周期(每天+当天类型)且满足全部条件触发 --> <!-- 查询符合周期(每天+当天类型)且满足任意条件触发 -->
<select id="getScenseAllCondition" resultMap="BaseResultMap"> <select id="getByAnyConditionTime" resultMap="BaseResultMap">
select smsd.* from smart_scene sms INNER JOIN smart_scene_data smsd on sms.id = smsd.scene_id where sms.status = 1 and smsd.param_key = scene_condition_time and sms.execute_cycle in (1,#{executeCycle}) and sms.condition_rule = 2 and smsd.type = 1 select smsd.* from smart_scene sms INNER JOIN smart_scene_data smsd on sms.id = smsd.scene_id where sms.status = 1 and smsd.type = 1 and smsd.param_key = 'scene_condition_time' and sms.execute_cycle in (1,#{executeCycle}) and sms.condition_rule = 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -35,7 +35,6 @@ public class KafkaProductorConfig { ...@@ -35,7 +35,6 @@ public class KafkaProductorConfig {
properties.setProperty("key.serializer.class", "kafka.serializer.DefaultEncoder"); properties.setProperty("key.serializer.class", "kafka.serializer.DefaultEncoder");
properties.setProperty("metadata.broker.list", mqConfig.getProductorServer()); properties.setProperty("metadata.broker.list", mqConfig.getProductorServer());
properties.setProperty("producer.type", "async"); properties.setProperty("producer.type", "async");
log.info("fz===kafka_server"+mqConfig.getProductorServer());
return properties; return properties;
} }
......
...@@ -15,4 +15,6 @@ public class Constants { ...@@ -15,4 +15,6 @@ public class Constants {
//时间触发条件key //时间触发条件key
public static final String CONDITION_TIME = "scene_condition_time"; public static final String CONDITION_TIME = "scene_condition_time";
//手动触发条件key
public static final String CONDITION_CLICK = "scene_condition_click";
} }
...@@ -3,6 +3,7 @@ package cn.com.glsx.smartdevice.factory.strategy; ...@@ -3,6 +3,7 @@ package cn.com.glsx.smartdevice.factory.strategy;
import cn.com.glsx.kafka.producer.ScenseProducer; import cn.com.glsx.kafka.producer.ScenseProducer;
import cn.com.glsx.smartdevice.factory.ConditionStrategy; import cn.com.glsx.smartdevice.factory.ConditionStrategy;
import cn.com.glsx.vasp.modules.entity.ScenseData; import cn.com.glsx.vasp.modules.entity.ScenseData;
import cn.com.glsx.vasp.modules.mapper.SceneMapper;
import cn.com.glsx.vasp.modules.mapper.ScenseDataMapper; import cn.com.glsx.vasp.modules.mapper.ScenseDataMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -19,12 +20,16 @@ public class AllMatchStrategy implements ConditionStrategy { ...@@ -19,12 +20,16 @@ public class AllMatchStrategy implements ConditionStrategy {
private ScenseDataMapper scenseDataMapper; private ScenseDataMapper scenseDataMapper;
@Autowired @Autowired
private SceneMapper sceneMapper;
@Autowired
private ScenseProducer scenseProducer; private ScenseProducer scenseProducer;
@Override @Override
public List<ScenseData> getScenseData(int executeCycle) { public List<ScenseData> getScenseData(int executeCycle) {
//获取符合周期且全部满足触发的场景对应的触发条件集合 //获取包含时间条件,符合周期且全部满足触发的场景对应的触发条件集合
return scenseDataMapper.getScenseAllCondition(executeCycle); List<Long> ids = sceneMapper.getSceneAllConditionTime(executeCycle);
return scenseDataMapper.getScneByIds(ids);
} }
@Override @Override
......
...@@ -2,6 +2,7 @@ package cn.com.glsx.smartdevice.factory.strategy; ...@@ -2,6 +2,7 @@ package cn.com.glsx.smartdevice.factory.strategy;
import cn.com.glsx.smartdevice.factory.ConditionStrategy; import cn.com.glsx.smartdevice.factory.ConditionStrategy;
import cn.com.glsx.vasp.modules.entity.ScenseData; import cn.com.glsx.vasp.modules.entity.ScenseData;
import cn.com.glsx.vasp.modules.mapper.SceneMapper;
import cn.com.glsx.vasp.modules.mapper.ScenseDataMapper; import cn.com.glsx.vasp.modules.mapper.ScenseDataMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -17,10 +18,13 @@ public class AnyMatchStrategy implements ConditionStrategy { ...@@ -17,10 +18,13 @@ public class AnyMatchStrategy implements ConditionStrategy {
@Autowired @Autowired
private ScenseDataMapper scenseDataMapper; private ScenseDataMapper scenseDataMapper;
@Autowired
private SceneMapper sceneMapper;
@Override @Override
public List<ScenseData> getScenseData(int executeCycle) { public List<ScenseData> getScenseData(int executeCycle) {
//获取符合周期且任意满足触发的场景对应的触发条件集合 //获取包含时间条件,符合周期且任意满足触发的场景对应的触发条件集合
return scenseDataMapper.getScenseAnyCondition(executeCycle); return scenseDataMapper.getByAnyConditionTime(executeCycle);
} }
@Override @Override
......
...@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component; ...@@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
*/ */
@Slf4j @Slf4j
@Component @Component
@ElasticSimpleJob(jobName = "TimerTriggerAllJob",cron="0/10 * * * * ?") @ElasticSimpleJob(jobName = "TimerTriggerAllJob",cron="1/59 * * * * ?")
public class TimerTriggerAllJob implements SimpleJob { public class TimerTriggerAllJob implements SimpleJob {
@Autowired @Autowired
private SceneService sceneComponent; private SceneService sceneComponent;
......
...@@ -15,7 +15,7 @@ import org.springframework.stereotype.Component; ...@@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
*/ */
@Slf4j @Slf4j
@Component @Component
@ElasticSimpleJob(jobName = "TimerTriggerAnyJob", cron = "0/10 * * * * ?") @ElasticSimpleJob(jobName = "TimerTriggerAnyJob", cron = "1/59 * * * * ?")
public class TimerTriggerAnyJob implements SimpleJob { public class TimerTriggerAnyJob implements SimpleJob {
@Autowired @Autowired
private SceneService sceneComponent; private SceneService sceneComponent;
......
...@@ -131,6 +131,7 @@ public class SceneService { ...@@ -131,6 +131,7 @@ public class SceneService {
scenseDataList = new ArrayList<>(); scenseDataList = new ArrayList<>();
} }
if(!Constants.CONDITION_CLICK.equals(data.getParamKey()))
scenseDataList.add(data); scenseDataList.add(data);
scenseDataMap.put(scenseId, scenseDataList); scenseDataMap.put(scenseId, scenseDataList);
}); });
...@@ -194,6 +195,7 @@ public class SceneService { ...@@ -194,6 +195,7 @@ public class SceneService {
//触发时间(时分)与当前时间(时分)是否相同 //触发时间(时分)与当前时间(时分)是否相同
return ELogic.getValueByCode(ELogic.EQUALS.getCode(),paramValue.getDate(),DateUtils.getDate(new Date(rangeBegintTime), "HH:mm")); return ELogic.getValueByCode(ELogic.EQUALS.getCode(),paramValue.getDate(),DateUtils.getDate(new Date(rangeBegintTime), "HH:mm"));
} }
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!