REM:
1. emos派单信息存储数据库
This commit is contained in:
chenlinghy 2021-09-15 15:52:49 +08:00
parent 99d8f668be
commit 7c89c400bf
10 changed files with 179 additions and 8 deletions

View File

@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSONObject;
import com.dispose.common.Constants; import com.dispose.common.Constants;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.config.KafkaConfiguration; 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.BaseRespStatus;
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
import com.dispose.pojo.dto.protocol.kafka.EmosAlarmInfo; import com.dispose.pojo.dto.protocol.kafka.EmosAlarmInfo;
import com.dispose.pojo.dto.protocol.kafka.AlarmInfoReq; import com.dispose.pojo.dto.protocol.kafka.AlarmInfoReq;
import com.dispose.pojo.entity.AlarmInformation;
import com.dispose.pojo.entity.MsgSerial; import com.dispose.pojo.entity.MsgSerial;
import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.po.MulReturnType;
import com.dispose.security.annotation.Decryption; import com.dispose.security.annotation.Decryption;
@ -59,6 +61,12 @@ public class kafkaController {
@Resource @Resource
private MsgSerialService msgSerialService; private MsgSerialService msgSerialService;
/**
* The alarm information manager.
*/
@Resource
private AlarmInfoManager alarmInfoManager;
/** /**
* Dispatch command sent to kafka. * Dispatch command sent to kafka.
* *
@ -86,6 +94,8 @@ public class kafkaController {
//保存数据格式到数据库 //保存数据格式到数据库
log.info("send alarm :{}", content); log.info("send alarm :{}", content);
AlarmInformation alarmInformation = AlarmInformation.builder().alarmInfo(content).build();
alarmInfoManager.addAlarmInfo(alarmInformation);
//推动数据格式到kafka //推动数据格式到kafka
ListenableFuture<SendResult<String, String>> sendResult = kafkaConfiguration ListenableFuture<SendResult<String, String>> sendResult = kafkaConfiguration

View File

@ -0,0 +1,17 @@
package com.dispose.manager;
import com.dispose.pojo.entity.AlarmInformation;
/**
* The interface alarm information manager.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
public interface AlarmInfoManager {
/**
* Add alarm information.
*
* @param alarmInformation the alarm information
*/
void addAlarmInfo(AlarmInformation alarmInformation);
}

View File

@ -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 <chenlinghy@cmhi.chinamoblie.com>
*/
@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);
}
}

View File

@ -9,6 +9,11 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
/**
* The interface message serial manager.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
@Component @Component
@Slf4j @Slf4j
public class MsgSerialManagerImpl implements MsgSerialManager { public class MsgSerialManagerImpl implements MsgSerialManager {

View File

@ -0,0 +1,18 @@
package com.dispose.mapper;
import com.dispose.pojo.entity.AlarmInformation;
/**
* The interface alarm information mapper.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
public interface AlarmInformationMapper {
/**
* Add alarm information.
*
* @param alarmInformation the alarm information
* @return the int
*/
int addAlarmInfo(AlarmInformation alarmInformation);
}

View File

@ -2,6 +2,11 @@ package com.dispose.mapper;
import com.dispose.pojo.entity.MsgSerial; import com.dispose.pojo.entity.MsgSerial;
/**
* The interface message serial mapper.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
public interface MsgSerialMapper { public interface MsgSerialMapper {
/** /**

View File

@ -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 <chenlinghy@cmhi.chinamoblie.com>
*/
@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;
}

View File

@ -14,9 +14,9 @@ import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
* The type Dispose capacity. * The message serial.
* *
* @author <huangxin@cmhi.chinamoblie.com> * @author <chenlinghy@cmhi.chinamoblie.com>
*/ */
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -33,16 +33,14 @@ public class MsgSerial implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* The Id. * The id.
*/ */
@Id @Id
@KeySql(useGeneratedKeys = true) @KeySql(useGeneratedKeys = true)
private Long id; private Long id;
/** /**
* The Device id. * The message serial.
*/ */
private Long msgSerial; private Long msgSerial;
} }

View File

@ -182,6 +182,20 @@ DROP TABLE IF EXISTS `msg_serial`;
CREATE TABLE `msg_serial` CREATE TABLE `msg_serial`
( (
`id` bigint(20) NOT NULL AUTO_INCREMENT, `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`) 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;

View File

@ -0,0 +1,19 @@
<?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.dispose.mapper.AlarmInformationMapper">
<resultMap id="msg_serial" type="com.dispose.pojo.entity.AlarmInformation">
<id column="id" property="id"/>
<result column="alarmInfo" property="alarmInfo"/>
<result column="createTime" property="createTime"/>
</resultMap>
<insert id="addAlarmInfo" useGeneratedKeys="true" keyProperty="id"
parameterType="com.dispose.pojo.entity.AlarmInformation">
INSERT
IGNORE INTO alarm_information(alarmInfo)
VALUES (
#{alarmInfo}
)
</insert>
</mapper>