Commit 0443188f by 111-PC\111

[+]kafka消费数据修改

1 parent 72173ced
Showing 32 changed files with 1222 additions and 10 deletions
......@@ -35,6 +35,11 @@
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
......
package cn.com.glsx.smart;
import cn.com.glsx.smart.service.OrderIssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* @author zhouhaibao
* @date 2021/3/23 13:50
*/
@Controller
@RequestMapping("/test")
public class TestController {
@Autowired
private OrderIssueService orderIssueService;
@RequestMapping(value = "/test", method = RequestMethod.GET)
public void test(){
String data="{\"scenseId\":\"604\"}";
orderIssueService.processMessage(data);
}
}
......@@ -6,7 +6,16 @@ package cn.com.glsx.smart.commons;
*/
public class Constants {
public static final String MESSAGE_NOTI="scene_content_system";
public static final int SCENE_CONDITION_ALL = 2;
public static final String Order_Issue="scene_content_device";
}
// 机器点火指令
public static final String MACHINE_STATUS_ORDER = "machine_status";
// 机器离家指令
public static final String MACHINE_LEAVE_ORDER = "leavehome_flag";
// 机器点火指令
public static final String MACHINE_STATUS_IN_VALUE = "true";
// 机器火指令
public static final String MACHINE_STATUS_FAM_ORDER = "false";
}
\ No newline at end of file
package cn.com.glsx.smart.commons;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 工作日,节假日类型枚举
*/
public enum EDay {
WORKDAY {
@Override
public Integer getCode() {
return 0;
}
@Override
public Integer getValue() {
return 2;
}
@Override
public String getName(){
return "工作日";
}
},
HOLIDAY {
@Override
public Integer getCode() {
return 1;
}
@Override
public Integer getValue() {
return 3;
}
@Override
public String getName(){
return "节假日";
}
},
WEEKDAY {
@Override
public Integer getCode() {
return 2;
}
@Override
public Integer getValue() {
return 3;
}
@Override
public String getName(){
return "双休日";
}
},
LEAVE_OFF_DAY {
@Override
public Integer getCode() {
return 3;
}
@Override
public Integer getValue() {
return 2;
}
@Override
public String getName(){
return "调休日";
}
},;
public static Integer getValueByCode(Integer code) {
for (EDay day : EDay.values()) {
if (day.getCode().equals(code)) {
return day.getValue();
}
}
return null;
}
public static String getNameByCode(Integer code) {
for (EDay day : EDay.values()) {
if (day.getCode().equals(code)) {
return day.getName();
}
}
return null;
}
/* 0表示工作日、为1、节假日,为2双休日、3为调休日(上班)*/
public abstract Integer getCode();
// 依据接口整合为平台定义的值,1每天 2工作日 3法定节假日
public abstract Integer getValue();
public abstract String getName();
}
package cn.com.glsx.smart.commons;
/**
* @author fengzhi
* @date 2021/3/19 17:40
* @description 枚举,触发条件的逻辑判断
*/
public enum ELogic {
LESS_THAN {
@Override
public Integer getCode() {
return 3;
}
@Override
public boolean getValue(String deviceOrderValue,String deviceOrderValueReal) {
return Double.parseDouble(deviceOrderValueReal) < Double.parseDouble(deviceOrderValue);
}
@Override
public String getName(){
return "小于";
}
},
GREATER_THAN {
@Override
public Integer getCode() {
return 2;
}
@Override
public boolean getValue(String deviceOrderValue,String deviceOrderValueReal) {
return Double.parseDouble(deviceOrderValueReal) > Double.parseDouble(deviceOrderValue);
}
@Override
public String getName(){
return "大于";
}
},
EQUALS {
@Override
public Integer getCode() {
return 1;
}
@Override
public boolean getValue(String deviceOrderValue,String deviceOrderValueReal) {
return deviceOrderValueReal.equals(deviceOrderValue);
}
@Override
public String getName(){
return "等于";
}
},;
public static boolean getValueByCode(Integer code,String deviceOrderValue,String deviceOrderValueReal) {
for (ELogic day : ELogic.values()) {
if (day.getCode().equals(code)) {
return day.getValue(deviceOrderValue,deviceOrderValueReal);
}
}
return false;
}
public static String getNameByCode(Integer code) {
for (ELogic day : ELogic.values()) {
if (day.getCode().equals(code)) {
return day.getName();
}
}
return null;
}
/* 逻辑(1:<,2:>,3:=)*/
public abstract Integer getCode();
//deviceOrderValue:触发条件中的设备状态值,deviceOrderValueReal:数据库中的设备状态值
public abstract boolean getValue(String deviceOrderValue,String deviceOrderValueReal);
public abstract String getName();
}
package cn.com.glsx.smart.entity;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
@Accessors(chain = true)
@Data
@Entity
@Table(name = "smart_date")
public class DayInfo implements Serializable {
@Id
@Column(
name = "id",
unique = true,
nullable = false
)
@GeneratedValue(
strategy = GenerationType.IDENTITY,
generator = "SELECT LAST_INSERT_ID()"
)
private Long id;
/**
* 当前阳历日期,如:2019-10-01
*/
private String date;
/**
* 日期类型,为0表示工作日、为1节假日、为2双休日、3为调休日(上班)
*/
private Integer daycode;
/**
* 节假日名称,如:国庆节
*/
private String name;
/**
* 放假提示,如:10月1日至7日放假调休,共7天......
*/
private String tip;
}
\ No newline at end of file
package cn.com.glsx.smart.entity;
import lombok.Data;
@Data
public class ScenseParamValue {
//第一列下拉选项值
private String select;
//输入值
private String value;
//指令
private String order;
//指令条件
private String orderCondition;
//指令值
private String orderVal;
//指令值类型
private String valType;
//红外线远程id
private String remoteId;
//推送消息
private String msg;
//推送消息
private String date;
}
package cn.com.glsx.smart.entity;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
@Table(name = "smart_device_status")
public class SmartDevideStatus implements Serializable {
@Id
private Integer id;
/**
* 设备id
*/
@Column(name = "device_id")
private String deviceId;
/**
* 设备指令
*/
@Column(name = "device_order_code")
private String deviceOrderCode;
/**
* 设备指令值
*/
@Column(name = "device_order_value")
private String deviceOrderValue;
/**
* 创建时间
*/
private Date createtime;
/**
* 更新时间
*/
private Date updatetime;
/**
* 产品id
*/
@Column(name = "product_key")
private String productKey;
private static final long serialVersionUID = 1L;
/**
* @return id
*/
public Integer getId() {
return id;
}
/**
* @param id
*/
public void setId(Integer id) {
this.id = id;
}
/**
* 获取设备id
*
* @return device_id - 设备id
*/
public String getDeviceId() {
return deviceId;
}
/**
* 设置设备id
*
* @param deviceId 设备id
*/
public void setDeviceId(String deviceId) {
this.deviceId = deviceId == null ? null : deviceId.trim();
}
/**
* 获取设备指令
*
* @return device_order_code - 设备指令
*/
public String getDeviceOrderCode() {
return deviceOrderCode;
}
/**
* 设置设备指令
*
* @param deviceOrderCode 设备指令
*/
public void setDeviceOrderCode(String deviceOrderCode) {
this.deviceOrderCode = deviceOrderCode == null ? null : deviceOrderCode.trim();
}
/**
* 获取设备指令值
*
* @return device_order_value - 设备指令值
*/
public String getDeviceOrderValue() {
return deviceOrderValue;
}
/**
* 设置设备指令值
*
* @param deviceOrderValue 设备指令值
*/
public void setDeviceOrderValue(String deviceOrderValue) {
this.deviceOrderValue = deviceOrderValue == null ? null : deviceOrderValue.trim();
}
/**
* 获取创建时间
*
* @return createtime - 创建时间
*/
public Date getCreatetime() {
return createtime;
}
/**
* 设置创建时间
*
* @param createtime 创建时间
*/
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
/**
* 获取更新时间
*
* @return updatetime - 更新时间
*/
public Date getUpdatetime() {
return updatetime;
}
/**
* 设置更新时间
*
* @param updatetime 更新时间
*/
public void setUpdatetime(Date updatetime) {
this.updatetime = updatetime;
}
/**
* 获取产品id
*
* @return product_key - 产品id
*/
public String getProductKey() {
return productKey;
}
/**
* 设置产品id
*
* @param productKey 产品id
*/
public void setProductKey(String productKey) {
this.productKey = productKey == null ? null : productKey.trim();
}
}
\ No newline at end of file
package cn.com.glsx.smart.entity;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import javax.persistence.*;
@Table(name = "smart_scene_data")
public class SmartSceneData implements Serializable {
......@@ -34,11 +37,23 @@ public class SmartSceneData implements Serializable {
private String paramKey;
/**
* 设备id,取自param_value中select
*/
@Column(name = "device_id")
private String deviceId;
/**
* 参数值 数组对象
*/
@Column(name = "param_value")
private String paramValue;
@Transient
private Integer conditionRule;
@Transient
private Integer executeCycle;
private static final long serialVersionUID = 1L;
/**
......@@ -132,6 +147,24 @@ public class SmartSceneData implements Serializable {
}
/**
* 获取设备id,取自param_value中select
*
* @return device_id - 设备id,取自param_value中select
*/
public String getDeviceId() {
return deviceId;
}
/**
* 设置设备id,取自param_value中select
*
* @param deviceId 设备id,取自param_value中select
*/
public void setDeviceId(String deviceId) {
this.deviceId = deviceId == null ? null : deviceId.trim();
}
/**
* 获取参数值 数组对象
*
* @return param_value - 参数值 数组对象
......@@ -149,6 +182,22 @@ public class SmartSceneData implements Serializable {
this.paramValue = paramValue == null ? null : paramValue.trim();
}
public Integer getConditionRule() {
return conditionRule;
}
public void setConditionRule(Integer conditionRule) {
this.conditionRule = conditionRule;
}
public Integer getExecuteCycle() {
return executeCycle;
}
public void setExecuteCycle(Integer executeCycle) {
this.executeCycle = executeCycle;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
......@@ -160,6 +209,7 @@ public class SmartSceneData implements Serializable {
sb.append(", type=").append(type);
sb.append(", sort=").append(sort);
sb.append(", paramKey=").append(paramKey);
sb.append(", deviceId=").append(deviceId);
sb.append(", paramValue=").append(paramValue);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
......
package cn.com.glsx.smart.mapper;
import cn.com.glsx.smart.entity.DayInfo;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface DayInfoMapper extends CommonBaseMapper<DayInfo> {
int updateDayInsert(@Param("daysYear") List<DayInfo> daysYear);
DayInfo getDayCodeByDate(String date);
}
\ No newline at end of file
package cn.com.glsx.smart.mapper;
import cn.com.glsx.smart.entity.SmartDevideStatus;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface SmartDevideStatusMapper extends CommonBaseMapper<SmartDevideStatus> {
SmartDevideStatus findDevStatusByIdAndCode(@Param("devId") String devId, @Param("code") String code);
String findDeviceId(String sn);
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SmartSceneDataMapper extends CommonBaseMapper<SmartSceneData> {
List<SmartSceneData> findSceneDataByDeviceId(@Param("deviceId") String deviceId);
List<SmartSceneData> findByTemplateId(@Param("templateId") int templateId);
List<SmartSceneData> findBySceneId(Long sceneId);
}
\ No newline at end of file
package cn.com.glsx.smart.queue;
import cn.com.glsx.smart.queue.base.MessageReceiver;
import cn.com.glsx.smart.service.SmartDeviceStatusService;
import cn.com.glsx.smart.utils.ProtobufConvert;
import cn.com.glsx.smart.vo.Event;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 记录仪熄火数据消费
*
* @author zhouhaibao
* @date 2021/4/10 18:12
*/
public class EdrFlameOutConsumer extends MessageReceiver {
@Autowired
private SmartDeviceStatusService smartDeviceStatusService;
@Override
public void processMessage(String topic, byte[] message) {
Event event =ProtobufConvert.convertFlameOut(message);
if (event == null) {
return;
}
smartDeviceStatusService.saveEvent(event);
}
}
package cn.com.glsx.smart.queue;
import cn.com.glsx.smart.queue.base.MessageReceiver;
import cn.com.glsx.smart.service.SmartDeviceStatusService;
import cn.com.glsx.smart.utils.ProtobufConvert;
import cn.com.glsx.smart.vo.Event;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 记录仪点火数据消费
*
* @author zhouhaibao
* @date 2021/4/10 16:51
*/
public class EdrIgnitionConsumer extends MessageReceiver {
@Autowired
private SmartDeviceStatusService smartDeviceStatusService;
@Override
public void processMessage(String topic, byte[] message) {
Event event = ProtobufConvert.convertIgnition(message);
if (event == null) {
return;
}
smartDeviceStatusService.saveEvent(event);
}
}
package cn.com.glsx.smart.queue;
import cn.com.glsx.smart.queue.base.MessageReceiver;
import cn.com.glsx.smart.service.SmartDeviceStatusService;
import cn.com.glsx.smart.utils.ProtobufConvert;
import cn.com.glsx.smart.vo.Event;
import org.springframework.beans.factory.annotation.Autowired;
/**
* GPS熄火数据消费
*
* @author zhouhaibao
* @date 2021/4/10 18:12
*/
public class GPSFlameOutConsumer extends MessageReceiver {
@Autowired
private SmartDeviceStatusService smartDeviceStatusService;
@Override
public void processMessage(String topic, byte[] message) {
Event event =ProtobufConvert.convertFlameOut(message);
if (event == null) {
return;
}
smartDeviceStatusService.saveEvent(event);
}
}
package cn.com.glsx.smart.queue;
import cn.com.glsx.smart.queue.base.MessageReceiver;
import cn.com.glsx.smart.service.SmartDeviceStatusService;
import cn.com.glsx.smart.utils.ProtobufConvert;
import cn.com.glsx.smart.vo.Event;
import org.springframework.beans.factory.annotation.Autowired;
/**
* GPS点火数据消费
*
* @author zhouhaibao
* @date 2021/4/10 16:51
*/
public class GpsIgnitionConsumer extends MessageReceiver {
@Autowired
private SmartDeviceStatusService smartDeviceStatusService;
@Override
public void processMessage(String topic, byte[] message) {
Event event = ProtobufConvert.convertIgnition(message);
if (event == null) {
return;
}
smartDeviceStatusService.saveEvent(event);
}
}
package cn.com.glsx.smart.queue;
import cn.com.glsx.smart.queue.base.MessageReceiver;
import cn.com.glsx.smart.service.SmartDeviceStatusService;
import cn.com.glsx.smart.utils.ProtobufConvert;
import cn.com.glsx.smart.vo.Event;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author zhouhaibao
* @date 2021/4/9 18:14
*/
public class LeaveHomeFlagConsumer extends MessageReceiver {
@Autowired
private SmartDeviceStatusService smartDeviceStatusService;
@Override
public void processMessage(String topic, byte[] message) {
Event event = ProtobufConvert.convertLeaveHome(message);
if (event == null) {
return;
}
smartDeviceStatusService.saveEvent(event);
}
}
package cn.com.glsx.smart.service;
import cn.com.glsx.smart.entity.SmartSceneData;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.function.Predicate;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台统一对外接口
*/
public interface ConditionStrategy {
boolean isTrigger(List<SmartSceneData> dataList, Integer executeCycle, Predicate<SmartSceneData> predicate);
}
package cn.com.glsx.smart.service;
import cn.com.glsx.smart.commons.Constants;
import cn.com.glsx.smart.entity.SmartSceneData;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.function.Predicate;
/**
* @author zhouhaibao
* @date 2021/4/10 15:44
*/
@Service
public class ConditionStrategyImpl implements ConditionStrategy {
@Override
public boolean isTrigger(List<SmartSceneData> dataList, Integer executeCycle, Predicate<SmartSceneData> predicate) {
if(executeCycle.equals(Constants.SCENE_CONDITION_ALL)) {
return dataList.stream().allMatch(predicate);
}else{
return dataList.stream().anyMatch(predicate);
}
}
}
package cn.com.glsx.smart.service;
import cn.com.glsx.smart.commons.Constants;
import cn.com.glsx.smart.commons.EDay;
import cn.com.glsx.smart.commons.ELogic;
import cn.com.glsx.smart.entity.DayInfo;
import cn.com.glsx.smart.entity.ScenseParamValue;
import cn.com.glsx.smart.entity.SmartDevideStatus;
import cn.com.glsx.smart.entity.SmartSceneData;
import cn.com.glsx.smart.mapper.DayInfoMapper;
import cn.com.glsx.smart.mapper.SmartDevideStatusMapper;
import cn.com.glsx.smart.mapper.SmartSceneDataMapper;
import cn.com.glsx.smart.utils.DateUtils;
import cn.com.glsx.smart.utils.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author zhouhaibao
* @date 2021/4/10 16:20
*/
@Slf4j
@Service
public class SceneService {
@Autowired
private SmartDevideStatusMapper smartDevideStatusMapper;
@Autowired
private SmartSceneDataMapper smartSceneDataMapper;
@Autowired
private DayInfoMapper dayInfoMapper;
@Autowired
private ConditionStrategy conditionStrategy;
@Value("${issueOrderUrl}")
private String issueOrderUrl;
public void triggerScene(String deviceId){
// 判断该设备是否在用户场景里面
List<SmartSceneData> smartSceneDataList = smartSceneDataMapper.findSceneDataByDeviceId(deviceId);
if(CollectionUtils.isEmpty(smartSceneDataList)){
return;
}
smartSceneDataList.forEach(index -> {
Integer executeCycle = index.getExecuteCycle();
// 判断场景是否触发
List<SmartSceneData> list=smartSceneDataMapper.findBySceneId(index.getSceneId());
// 判断场景条件是否配置了时间并且是全部条件满足执行的
List<SmartSceneData> scene_condition_time = list.stream().filter(inx -> inx.getParamKey().equals("scene_condition_status")).collect(Collectors.toList());
if(list.size()!=scene_condition_time.size()&&executeCycle.equals(Constants.SCENE_CONDITION_ALL)){
return;
}
boolean isTrigger = conditionStrategy.isTrigger(scene_condition_time, executeCycle,
(SmartSceneData condition) -> getTriggerResult(condition));
if (isTrigger) {
// 下发场景
Map<String, String> requestMap = new HashMap<>();
requestMap.put("id", index.getSceneId() + "");
try {
String responseBody = HttpUtil.sendPost(issueOrderUrl, JSONObject.toJSONString(requestMap), new HashMap<>());
log.info("场景id{}下发结果{}", index.getSceneId(), responseBody);
} catch (Exception e) {
e.printStackTrace();
log.info("场景id{}下发指令异常,{}", index.getSceneId(), e);
}
}
});
}
//触发条件判断
private boolean getTriggerResult(SmartSceneData condition) {
if (!getExecuteCycle().equals(condition.getExecuteCycle())) {
log.info("当前时间不是触发周期:" + condition.getId());
return false;
}
String value = condition.getParamValue();
if (StringUtils.isEmpty(value)) {
log.info("触发条件的value不存在===id:" + condition.getId());
return false;
}
ScenseParamValue paramValue = null;
try {
paramValue = JSON.parseObject(JSON.parse(value).toString(), ScenseParamValue.class);
} catch (Exception e) {
log.info("JSON解析异常:ScenseParamValue====" + e.getMessage() + "===conditionId:" + condition.getId());
return false;
}
//参数一,设备id
String deviceId = paramValue.getSelect();
//参数二,设备指令
String deviceOrderCode = paramValue.getOrder();
//参数三,逻辑(1:<,2:>,3:=)
int logic = Integer.parseInt(paramValue.getOrderCondition());
//参数四,值
SmartDevideStatus smartDevideStatus = smartDevideStatusMapper.findDevStatusByIdAndCode(deviceId, deviceOrderCode);
if (smartDevideStatus == null) {
return false;
}
//触发状态值,如果value没有值,则取ordervalue
String Value = paramValue.getValue();
if (StringUtils.isEmpty(Value)) {
Value = paramValue.getOrderVal();
if (StringUtils.isEmpty(Value)) {
log.info("设备触发状态值不存在===deviceId:" + deviceId + "===deviceOrderCode:" + deviceOrderCode);
return false;
}
}
//根据logic逻辑码,判断触发条件与数据库中实际的值,判断是否满足
return ELogic.getValueByCode(logic, Value, smartDevideStatus.getDeviceOrderValue());
}
//根据当前时间对应的执行周期类型
private Integer getExecuteCycle() {
//判断当天的日类型
String date = DateUtils.getTodayDate();
//0表示工作日、为1节假日、为2双休日、3为调休日(上班)
DayInfo dayInfo = dayInfoMapper.getDayCodeByDate(date);
//转换为对应的执行周期
return EDay.getValueByCode(null == dayInfo ? -1 : dayInfo.getDaycode());
}
}
package cn.com.glsx.smart.service;
import cn.com.glsx.smart.commons.Constants;
import cn.com.glsx.smart.entity.SmartDevideStatus;
import cn.com.glsx.smart.mapper.SmartDevideStatusMapper;
import cn.com.glsx.smart.vo.Event;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author zhouhaibao
* @date 2021/4/10 17:59
*/
@Slf4j
@Service
public class SmartDeviceStatusService {
@Autowired
private SmartDevideStatusMapper smartDevideStatusMapper;
@Autowired
private SceneService sceneService;
public void saveEvent(Event event) {
String sn=event.getSn();
String deviceId=smartDevideStatusMapper.findDeviceId(sn);
SmartDevideStatus smartDevideStatus=smartDevideStatusMapper.findDevStatusByIdAndCode(deviceId, Constants.MACHINE_STATUS_ORDER);
if(smartDevideStatus==null){
smartDevideStatus=new SmartDevideStatus();
smartDevideStatus.setDeviceOrderCode(event.getDeviceType());
smartDevideStatus.setDeviceId(deviceId);
}
smartDevideStatus.setDeviceOrderValue(event.getValue());
if(smartDevideStatus.getId()==null){
smartDevideStatusMapper.insert(smartDevideStatus);
}else{
smartDevideStatusMapper.updateByPrimaryKeySelective(smartDevideStatus);
}
sceneService.triggerScene(deviceId);
}
}
package cn.com.glsx.smart.utils;
import cn.com.glsx.smart.commons.Constants;
import cn.com.glsx.smart.vo.Event;
import cn.com.glsx.smart.vo.Fence;
import cn.com.glsx.smart.vo.kafkasvr;
import org.apache.log4j.Logger;
public class ProtobufConvert {
protected final static Logger LOGGER = Logger.getLogger(ProtobufConvert.class);
// 点火
private static final String TOPIC_IGNITION = "ignition_ddbox";
// 熄火
private static final String TOPIC_FLAMEOUT = "flameout_ddbox";
public static Object convert(String topic, byte[] message) {
if (topic.contains(TOPIC_IGNITION)) {
return convertIgnition(message);
}
if (topic.contains(TOPIC_FLAMEOUT)) {
return convertFlameOut(message);
}
return null;
}
// 点火启动转换
public static Event convertIgnition(byte[] message) {
kafkasvr.EventStateReportReq protobufIgnition = null;
try {
protobufIgnition = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) {
e.printStackTrace();
protobufIgnition = null;
}
if (null == protobufIgnition) {
return null;
}
Event event = new Event();
event.setSn(String.valueOf(protobufIgnition.getDevicesn().trim()));
event.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("true");
return event;
}
// 熄火转换
public static Event convertFlameOut(byte[] message) {
kafkasvr.EventStateReportReq protobufFlameOut = null;
try {
protobufFlameOut = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) {
e.printStackTrace();
protobufFlameOut = null;
}
if (null == protobufFlameOut) {
return null;
}
Event event = new Event();
event.setSn(String.valueOf(protobufFlameOut.getDevicesn().trim()));
event.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("false");
return event;
}
// 回家离家转换
public static Event convertLeaveHome(byte[] message) {
Fence.TriggerDeviceFamilyInfo protobufFlameOut = null;
try {
protobufFlameOut = Fence.TriggerDeviceFamilyInfo.parseFrom(message);
} catch (Exception e) {
e.printStackTrace();
protobufFlameOut = null;
}
if (null == protobufFlameOut) {
return null;
}
Event event = new Event();
event.setSn(String.valueOf(protobufFlameOut.getSn()));
event.setDeviceType(Constants.MACHINE_LEAVE_ORDER);
if((protobufFlameOut.getStatus()+"").equals("1")) {
event.setValue("true");
}else{
event.setValue("false");
}
return event;
}
}
package cn.com.glsx.smart.vo;
import java.io.Serializable;
/**
* 发动机事件
* Created by Lenovo on 2016/5/12.
* @author wangxw
*/
public class Event implements Serializable{
private static final long serialVersionUID = -8941191960209465706L;
public static String TYPE_IGNITION = "1"; // 点火
public static String TYPE_FLAMEOUT = "2"; // 熄火
private String userId;
private String sn;
private String type; // 类型:10点火事件,11熄火事件
private String time; // 终端报警时上带的GPS时间 (服务器 + 8 小时),格式 yyyy-MM-dd HH:mm:ss
private String deviceType;//
private String accessTime;
private String receiveTime;
private String value;
public Event() {
}
public Event(String sn, String type, String time) {
this.sn = sn;
this.type = type;
this.time = time;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getAccessTime() {
return accessTime;
}
public void setAccessTime(String accessTime) {
this.accessTime = accessTime;
}
public String getReceiveTime() {
return receiveTime;
}
public void setReceiveTime(String receiveTime) {
this.receiveTime = receiveTime;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "Event{" +
"userId='" + userId + '\'' +
", sn='" + sn + '\'' +
", type='" + type + '\'' +
", time='" + time + '\'' +
", deviceType='" + deviceType + '\'' +
", accessTime='" + accessTime + '\'' +
", receiveTime='" + receiveTime + '\'' +
'}';
}
}
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
......@@ -68,7 +68,7 @@
</javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table tableName="smart_scene_data" domainObjectName="SmartSceneData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
<table tableName="smart_device_status" domainObjectName="Smart_device_status" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
\ No newline at end of file
......@@ -10,4 +10,38 @@
<property name="nThreads" value="${consumer.nThreads}" />
</bean>
<bean id="gpsIgnitionConsumer" class="cn.com.glsx.smart.queue.GpsIgnitionConsumer"
init-method="init" destroy-method="destroy">
<property name="consumerConfig" ref="consumerConfig" />
<property name="topic" value="${topic.gpsIgnitionConsumer}" />
<property name="nThreads" value="${consumer.nThreads}" />
</bean>
<bean id="gpsFlameOutConsumer" class="cn.com.glsx.smart.queue.GPSFlameOutConsumer"
init-method="init" destroy-method="destroy">
<property name="consumerConfig" ref="consumerConfig" />
<property name="topic" value="${topic.gpsFlameOutConsumer}" />
<property name="nThreads" value="${consumer.nThreads}" />
</bean>
<bean id="edrIgnitionConsumer" class="cn.com.glsx.smart.queue.EdrIgnitionConsumer"
init-method="init" destroy-method="destroy">
<property name="consumerConfig" ref="consumerConfig" />
<property name="topic" value="${topic.edrIgnitionConsumer}" />
<property name="nThreads" value="${consumer.nThreads}" />
</bean>
<bean id="leaveHomeFlagConsumer" class="cn.com.glsx.smart.queue.LeaveHomeFlagConsumer"
init-method="init" destroy-method="destroy">
<property name="consumerConfig" ref="consumerConfig" />
<property name="topic" value="${topic.leaveHomeFlagConsumer}" />
<property name="nThreads" value="${consumer.nThreads}" />
</bean>
<bean id="edrFlameOutConsumer" class="cn.com.glsx.smart.queue.EdrFlameOutConsumer"
init-method="init" destroy-method="destroy">
<property name="consumerConfig" ref="consumerConfig" />
<property name="topic" value="${topic.edrFlameOutConsumer}" />
<property name="nThreads" value="${consumer.nThreads}" />
</bean>
</beans>
\ 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.smart.mapper.DayInfoMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.smart.entity.DayInfo">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="date" jdbcType="VARCHAR" property="date" />
<result column="daycode" jdbcType="INTEGER" property="daycode" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="tip" jdbcType="VARCHAR" property="tip" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, `date`, daycode, `name`, tip
</sql>
<select id="getDayCodeByDate" resultMap="BaseResultMap">
select `daycode` from smart_date where date = #{date}
</select>
</mapper>
\ 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.smart.mapper.SmartDevideStatusMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.smart.entity.SmartDevideStatus">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="device_id" jdbcType="VARCHAR" property="deviceId"/>
<result column="device_order_code" jdbcType="VARCHAR" property="deviceOrderCode"/>
<result column="device_order_value" jdbcType="VARCHAR" property="deviceOrderValue"/>
<result column="createtime" jdbcType="TIMESTAMP" property="createtime"/>
<result column="updatetime" jdbcType="TIMESTAMP" property="updatetime"/>
<result column="product_key" jdbcType="VARCHAR" property="productKey"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, device_id, device_order_code, device_order_value, createtime, updatetime, product_key
</sql>
<select id="findDevStatusByIdAndCode" resultType="cn.com.glsx.smart.entity.SmartDevideStatus">
select * from smart_device_status
where device_order_code=#{code} and device_id=#{devId}
</select>
<select id="findDeviceId" resultType="java.lang.String">
select id from glsx_common_physical_device where sn=#{sn}
</select>
</mapper>
\ No newline at end of file
......@@ -10,16 +10,23 @@
<result column="type" jdbcType="TINYINT" property="type" />
<result column="sort" jdbcType="TINYINT" property="sort" />
<result column="param_key" jdbcType="VARCHAR" property="paramKey" />
<result column="device_id" jdbcType="VARCHAR" property="deviceId" />
<result column="param_value" jdbcType="VARCHAR" property="paramValue" />
<result column="condition_rule" jdbcType="TINYINT" property="conditionRule" />
<result column="execute_cycle" jdbcType="TINYINT" property="executeCycle" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, scene_id, `type`, sort, param_key, param_value
id, scene_id, `type`, sort, param_key, device_id, param_value
</sql>
<select id="findByTemplateId" resultMap="BaseResultMap">
select *
from smart_scene_data where scene_id=#{templateId} and type=2
<select id="findSceneDataByDeviceId" resultMap="BaseResultMap">
select t1.*,t2.condition_rule,t2.execute_cycle from smart_scene_data t1 left join smart_scene t2 on t1.scene_id=t2.id
where device_id=#{deviceId} and param_key='scene_condition_status'
</select>
<select id="findBySceneId" resultType="cn.com.glsx.smart.entity.SmartSceneData">
select * from smart_scene_data
where scene_id=#{sceneId} and (param_key='scene_condition_status' or param_key='scene_condition_time')
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!