diff --git a/src/main/java/com/dispose/controller/kafkaController.java b/src/main/java/com/dispose/controller/kafkaController.java index 113d7aed..39454035 100644 --- a/src/main/java/com/dispose/controller/kafkaController.java +++ b/src/main/java/com/dispose/controller/kafkaController.java @@ -11,7 +11,6 @@ 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; import com.dispose.security.annotation.Encryption; @@ -121,8 +120,7 @@ public class kafkaController { try { long dbIncrement = msgSerialService.getMaxMessageSerial(); long increment = dbIncrement + 1; - MsgSerial msgSerial = MsgSerial.builder().msgSerial(increment).build(); - MulReturnType returnType = msgSerialService.addMessageSerial(msgSerial); + MulReturnType returnType = msgSerialService.updateMessageSerial(increment); if (returnType.getFirstParam() == ErrorCode.ERR_OK) { increment = returnType.getSecondParam(); } else { diff --git a/src/main/java/com/dispose/manager/MsgSerialManager.java b/src/main/java/com/dispose/manager/MsgSerialManager.java index bebda584..308c9bca 100644 --- a/src/main/java/com/dispose/manager/MsgSerialManager.java +++ b/src/main/java/com/dispose/manager/MsgSerialManager.java @@ -1,7 +1,6 @@ package com.dispose.manager; import com.dispose.common.ErrorCode; -import com.dispose.pojo.entity.MsgSerial; public interface MsgSerialManager { /** @@ -10,7 +9,7 @@ public interface MsgSerialManager { * @param msgSerial the message serial * @return the error code */ - ErrorCode addMsgSerialNumber(MsgSerial msgSerial); + ErrorCode updateMsgSerialNumber(Long msgSerial); /** * get new max message serial. diff --git a/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java b/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java index 2c70f843..f00941a2 100644 --- a/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/MsgSerialManagerImpl.java @@ -3,7 +3,6 @@ package com.dispose.manager.impl; import com.dispose.common.ErrorCode; import com.dispose.manager.MsgSerialManager; import com.dispose.mapper.MsgSerialMapper; -import com.dispose.pojo.entity.MsgSerial; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -30,8 +29,8 @@ public class MsgSerialManagerImpl implements MsgSerialManager { * @return the error code */ @Override - public ErrorCode addMsgSerialNumber(MsgSerial msgSerial) { - if (msgSerialMapper.addMsgSerial(msgSerial) == 1) { + public ErrorCode updateMsgSerialNumber(Long msgSerial) { + if (msgSerialMapper.updateMsgSerial(msgSerial) == 1) { return ErrorCode.ERR_OK; } else { return ErrorCode.ERR_DATABASE; diff --git a/src/main/java/com/dispose/mapper/MsgSerialMapper.java b/src/main/java/com/dispose/mapper/MsgSerialMapper.java index 46402b16..33a63047 100644 --- a/src/main/java/com/dispose/mapper/MsgSerialMapper.java +++ b/src/main/java/com/dispose/mapper/MsgSerialMapper.java @@ -1,7 +1,5 @@ package com.dispose.mapper; -import com.dispose.pojo.entity.MsgSerial; - /** * The interface message serial mapper. * @@ -10,12 +8,12 @@ import com.dispose.pojo.entity.MsgSerial; public interface MsgSerialMapper { /** - * Add new task int. + * Update new task int. * * @param msgSerial the msgSerial number * @return the int */ - int addMsgSerial(MsgSerial msgSerial); + int updateMsgSerial(Long msgSerial); /** * get new max message serial. diff --git a/src/main/java/com/dispose/service/MsgSerialService.java b/src/main/java/com/dispose/service/MsgSerialService.java index 6d6af602..26a3599f 100644 --- a/src/main/java/com/dispose/service/MsgSerialService.java +++ b/src/main/java/com/dispose/service/MsgSerialService.java @@ -1,17 +1,16 @@ package com.dispose.service; import com.dispose.common.ErrorCode; -import com.dispose.pojo.entity.MsgSerial; import com.dispose.pojo.po.MulReturnType; public interface MsgSerialService { /** - * add message serial. + * update message serial. * * @param msgSerial the message serial * @return the mul return type */ - MulReturnType addMessageSerial(MsgSerial msgSerial); + MulReturnType updateMessageSerial(Long msgSerial); /** * get new max message serial. diff --git a/src/main/java/com/dispose/service/impl/MsgSerialServiceImpl.java b/src/main/java/com/dispose/service/impl/MsgSerialServiceImpl.java index 63be8481..8d1eb472 100644 --- a/src/main/java/com/dispose/service/impl/MsgSerialServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/MsgSerialServiceImpl.java @@ -2,7 +2,6 @@ package com.dispose.service.impl; import com.dispose.common.ErrorCode; import com.dispose.manager.MsgSerialManager; -import com.dispose.pojo.entity.MsgSerial; import com.dispose.pojo.po.MulReturnType; import com.dispose.service.MsgSerialService; import org.springframework.stereotype.Service; @@ -21,18 +20,17 @@ public class MsgSerialServiceImpl implements MsgSerialService { * @return the mul return type */ @Override - public MulReturnType addMessageSerial(MsgSerial msgSerial) { + public MulReturnType updateMessageSerial(Long msgSerial) { //告警序号的最大值2^32-1 long indexEnd = 4294967295L; long indexStart = 1L; - long currentSerial = msgSerial.getMsgSerial(); //编号从1开始,以实时消息发布通道为单位进行编号。如果编号超过最大正整数(2^32-1),重新从1开始编号。 - if (currentSerial > indexEnd) { - currentSerial = indexStart; + if (msgSerial > indexEnd) { + msgSerial = indexStart; } - if (msgSerialManager.addMsgSerialNumber(msgSerial) == ErrorCode.ERR_OK) { - return new MulReturnType<>(ErrorCode.ERR_OK, currentSerial); + if (msgSerialManager.updateMsgSerialNumber(msgSerial) == ErrorCode.ERR_OK) { + return new MulReturnType<>(ErrorCode.ERR_OK, msgSerial); } else { return new MulReturnType<>(ErrorCode.ERR_DATABASE, null); } diff --git a/src/main/resources/mappers/MsgSerial.xml b/src/main/resources/mappers/MsgSerial.xml index 4e9ceaa8..14aa6d8e 100644 --- a/src/main/resources/mappers/MsgSerial.xml +++ b/src/main/resources/mappers/MsgSerial.xml @@ -6,14 +6,12 @@ - - INSERT - IGNORE INTO msg_serial(msgSerial) - VALUES ( - #{msgSerial} - ) - + + UPDATE + msg_serial + SET msgSerial = #{msgSerial} + WHERE id = 1; +