diff --git a/src/main/java/com/dispose/controller/kafkaController.java b/src/main/java/com/dispose/controller/kafkaController.java index a955473f..113d7aed 100644 --- a/src/main/java/com/dispose/controller/kafkaController.java +++ b/src/main/java/com/dispose/controller/kafkaController.java @@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSONObject; import com.dispose.common.Constants; import com.dispose.common.ErrorCode; import com.dispose.config.KafkaConfiguration; +import com.dispose.manager.AlarmInfoManager; import com.dispose.pojo.dto.protocol.base.BaseRespStatus; import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.kafka.EmosAlarmInfo; import com.dispose.pojo.dto.protocol.kafka.AlarmInfoReq; +import com.dispose.pojo.entity.AlarmInformation; import com.dispose.pojo.entity.MsgSerial; import com.dispose.pojo.po.MulReturnType; import com.dispose.security.annotation.Decryption; @@ -59,6 +61,12 @@ public class kafkaController { @Resource private MsgSerialService msgSerialService; + /** + * The alarm information manager. + */ + @Resource + private AlarmInfoManager alarmInfoManager; + /** * Dispatch command sent to kafka. * @@ -86,6 +94,8 @@ public class kafkaController { //保存数据格式到数据库 log.info("send alarm :{}", content); + AlarmInformation alarmInformation = AlarmInformation.builder().alarmInfo(content).build(); + alarmInfoManager.addAlarmInfo(alarmInformation); //推动数据格式到kafka ListenableFuture> sendResult = kafkaConfiguration diff --git a/src/main/java/com/dispose/manager/AlarmInfoManager.java b/src/main/java/com/dispose/manager/AlarmInfoManager.java new file mode 100644 index 00000000..65bb579d --- /dev/null +++ b/src/main/java/com/dispose/manager/AlarmInfoManager.java @@ -0,0 +1,17 @@ +package com.dispose.manager; + +import com.dispose.pojo.entity.AlarmInformation; + +/** + * The interface alarm information manager. + * + * @author + */ +public interface AlarmInfoManager { + /** + * Add alarm information. + * + * @param alarmInformation the alarm information + */ + void addAlarmInfo(AlarmInformation alarmInformation); +} diff --git a/src/main/java/com/dispose/manager/impl/AlarmInfoManagerImpl.java b/src/main/java/com/dispose/manager/impl/AlarmInfoManagerImpl.java new file mode 100644 index 00000000..d953f3a7 --- /dev/null +++ b/src/main/java/com/dispose/manager/impl/AlarmInfoManagerImpl.java @@ -0,0 +1,34 @@ +package com.dispose.manager.impl; + +import com.dispose.manager.AlarmInfoManager; +import com.dispose.mapper.AlarmInformationMapper; +import com.dispose.pojo.entity.AlarmInformation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * The interface alarm information manager. + * + * @author + */ +@Component +@Slf4j +public class AlarmInfoManagerImpl implements AlarmInfoManager { + /** + * The alarm information mapper. + */ + @Resource + private AlarmInformationMapper alarmInformationMapper; + + /** + * Add alarm information. + * + * @param alarmInformation the alarm information + */ + @Override + public void addAlarmInfo(AlarmInformation alarmInformation) { + alarmInformationMapper.addAlarmInfo(alarmInformation); + } +} diff --git a/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java b/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java index ab26b187..2c70f843 100644 --- a/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java @@ -9,6 +9,11 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; +/** + * The interface message serial manager. + * + * @author + */ @Component @Slf4j public class MsgSerialManagerImpl implements MsgSerialManager { diff --git a/src/main/java/com/dispose/mapper/AlarmInformationMapper.java b/src/main/java/com/dispose/mapper/AlarmInformationMapper.java new file mode 100644 index 00000000..78335ee4 --- /dev/null +++ b/src/main/java/com/dispose/mapper/AlarmInformationMapper.java @@ -0,0 +1,18 @@ +package com.dispose.mapper; + +import com.dispose.pojo.entity.AlarmInformation; + +/** + * The interface alarm information mapper. + * + * @author + */ +public interface AlarmInformationMapper { + /** + * Add alarm information. + * + * @param alarmInformation the alarm information + * @return the int + */ + int addAlarmInfo(AlarmInformation alarmInformation); +} diff --git a/src/main/java/com/dispose/mapper/MsgSerialMapper.java b/src/main/java/com/dispose/mapper/MsgSerialMapper.java index 6dd62148..46402b16 100644 --- a/src/main/java/com/dispose/mapper/MsgSerialMapper.java +++ b/src/main/java/com/dispose/mapper/MsgSerialMapper.java @@ -2,6 +2,11 @@ package com.dispose.mapper; import com.dispose.pojo.entity.MsgSerial; +/** + * The interface message serial mapper. + * + * @author + */ public interface MsgSerialMapper { /** diff --git a/src/main/java/com/dispose/pojo/entity/AlarmInformation.java b/src/main/java/com/dispose/pojo/entity/AlarmInformation.java new file mode 100644 index 00000000..8606acbe --- /dev/null +++ b/src/main/java/com/dispose/pojo/entity/AlarmInformation.java @@ -0,0 +1,51 @@ +package com.dispose.pojo.entity; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import tk.mybatis.mapper.annotation.KeySql; +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * The emos alarm information. + * + * @author + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@Table(name = "alarm_information") +@NameStyle(Style.normal) +public class AlarmInformation implements Serializable { + + /** + * The constant serialVersionUID. + */ + private static final long serialVersionUID = 1L; + + /** + * The id. + */ + @Id + @KeySql(useGeneratedKeys = true) + private Long id; + + /** + * The alarm information. + */ + private String alarmInfo; + + /** + * The creating time. + */ + private String createTime; +} diff --git a/src/main/java/com/dispose/pojo/entity/MsgSerial.java b/src/main/java/com/dispose/pojo/entity/MsgSerial.java index 4f89bfa3..f779b04c 100644 --- a/src/main/java/com/dispose/pojo/entity/MsgSerial.java +++ b/src/main/java/com/dispose/pojo/entity/MsgSerial.java @@ -14,9 +14,9 @@ import javax.persistence.Table; import java.io.Serializable; /** - * The type Dispose capacity. + * The message serial. * - * @author + * @author */ @Data @NoArgsConstructor @@ -33,16 +33,14 @@ public class MsgSerial implements Serializable { private static final long serialVersionUID = 1L; /** - * The Id. + * The id. */ @Id @KeySql(useGeneratedKeys = true) private Long id; /** - * The Device id. + * The message serial. */ private Long msgSerial; - - } diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index 587e8229..e2eda18c 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -182,6 +182,20 @@ DROP TABLE IF EXISTS `msg_serial`; CREATE TABLE `msg_serial` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, - `msgSerial` bigint(20) NOT NULL DEFAULT '1', + `msgSerial` bigint(20) NOT NULL DEFAULT '1' COMMENT '连续消息序号', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8; + + +-- ---------------------------- +-- Table structure for alarm_information +-- ---------------------------- +DROP TABLE IF EXISTS `alarm_information`; +CREATE TABLE `alarm_information` +( + `id` bigint(11) NOT NULL AUTO_INCREMENT, + `alarmInfo` varchar(255) NOT NULL COMMENT 'emos告警内容', + `createTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8; + diff --git a/src/main/resources/mappers/AlarmInformation.xml b/src/main/resources/mappers/AlarmInformation.xml new file mode 100644 index 00000000..fadf3d36 --- /dev/null +++ b/src/main/resources/mappers/AlarmInformation.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + INSERT + IGNORE INTO alarm_information(alarmInfo) + VALUES ( + #{alarmInfo} + ) + + + \ No newline at end of file