1. 心跳协议响应获取设备信息入库

2. 创建警报任务协议
3. 格式化代码
This commit is contained in:
HuangXin 2023-08-21 20:58:34 +08:00
parent 5503523a0c
commit d97abd5e16
40 changed files with 281 additions and 320 deletions

View File

@ -1,4 +1,4 @@
socket.server-host=localhost
socket.server-port=10000
socket.server-port=10001
socket.server-mode=tcp
socket.heart-timeout=60

View File

@ -30,10 +30,7 @@ public class MessageHandler<T> extends SimpleChannelInboundHandler<BaseBinaryPro
if (evt instanceof IdleStateEvent idleStateEvent) {
if (idleStateEvent.state() == IdleState.ALL_IDLE) {
log.info("{}:: Trigger Heart Signe", ctx.channel().id());
SocketNotifyEvent notify = new SocketNotifyEvent(this,
ctx.channel(),
SocketEventName.SOCKET_EVT_IDLE_TIMEOUT,
null);
SocketNotifyEvent notify = new SocketNotifyEvent(this, ctx.channel(), SocketEventName.SOCKET_EVT_IDLE_TIMEOUT, null);
applicationEventPublisher.publishEvent(notify);
}
} else {
@ -42,7 +39,7 @@ public class MessageHandler<T> extends SimpleChannelInboundHandler<BaseBinaryPro
}
@Override
public void channelRead0(ChannelHandlerContext ctx, BaseBinaryProtocol<T> message) throws Exception {
public void channelRead0(ChannelHandlerContext ctx, BaseBinaryProtocol<T> message) {
SocketNotifyEvent notify = new SocketNotifyEvent(this,
ctx.channel(),
message.getTimeStamp(),
@ -68,10 +65,7 @@ public class MessageHandler<T> extends SimpleChannelInboundHandler<BaseBinaryPro
super.channelInactive(ctx);
ctx.close();
SocketNotifyEvent notify = new SocketNotifyEvent(this,
ctx.channel(),
SocketEventName.SOCKET_EVT_DISCONNECT,
null);
SocketNotifyEvent notify = new SocketNotifyEvent(this, ctx.channel(), SocketEventName.SOCKET_EVT_DISCONNECT, null);
applicationEventPublisher.publishEvent(notify);
}

View File

@ -33,141 +33,141 @@ public class YuanRongProtocolDecode extends ByteToMessageDecoder {
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf buf, List<Object> list) {
log.info("\n{}", ByteBufUtil.prettyHexDump(buf));
try {
short msgLength = buf.readShort();
byte version = buf.readByte();
byte cryptCytp = buf.readByte();
int timeStamp = buf.readInt();
int statusCode = buf.readInt();
byte msgType = buf.readByte();
short msgSize = buf.readShort();
short msgLength = buf.readShort();
byte version = buf.readByte();
byte cryptCytp = buf.readByte();
int timeStamp = buf.readInt();
int statusCode = buf.readInt();
byte msgType = buf.readByte();
short msgSize = buf.readShort();
ControlCommandName cmd = CommonEnumHandler.codeOf(ControlCommandName.class, msgType);
if (cmd != null) {
switch (cmd) {
case COMMAND_REPORT_HEART -> {
SendStatusName sendStatus = CommonEnumHandler.codeOf(SendStatusName.class, buf.readByte());
ControlChannelStatus beidouStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class,
buf.readByte());
byte[] beidouCommFreq = new byte[3];
int heartSeq = buf.readInt();
SendStatusName sendStatus = CommonEnumHandler.codeOf(SendStatusName.class, buf.readByte());
ControlChannelStatus beidouStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
byte[] beidouCommFreq = new byte[3];
buf.readBytes(beidouCommFreq, 0, 3);
byte[] beidouSignal = new byte[10];
buf.readBytes(beidouSignal, 0, 10);
ControlChannelStatus wireStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class,
buf.readByte());
ControlChannelStatus phoneStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class,
buf.readByte());
ControlChannelStatus wireStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
ControlChannelStatus phoneStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
ControllerStatus status = ControllerStatus.builder()
.sendStatus(sendStatus)
.beidouStatus(beidouStatus)
.beidouFreq(beidouCommFreq)
.beidouSignalStrength(beidouSignal)
.wirelessStatus(wireStatus)
.telphoneStatus(phoneStatus)
.build();
.heartSeq(heartSeq)
.sendStatus(sendStatus)
.beidouStatus(beidouStatus)
.beidouFreq(beidouCommFreq)
.beidouSignalStrength(beidouSignal)
.wirelessStatus(wireStatus)
.telphoneStatus(phoneStatus)
.build();
MessageContent<ControllerStatus> msgCtx = MessageContent.<ControllerStatus>builder().msgType(
msgType).msgSize(msgSize).msgBody(status).build();
MessageContent<ControllerStatus> msgCtx = MessageContent.<ControllerStatus>builder().msgType(msgType).msgSize(
msgSize).msgBody(status).build();
list.add(BaseBinaryProtocol.<ControllerStatus>builder()
.msgLength(msgLength)
.version(version)
.cryptoType(cryptCytp)
.timeStamp(timeStamp)
.statusCode(statusCode)
.msgContent(msgCtx)
.build());
.msgLength(msgLength)
.version(version)
.cryptoType(cryptCytp)
.timeStamp(timeStamp)
.statusCode(statusCode)
.msgContent(msgCtx)
.build());
}
case COMMAND_REPORT_SENSOR -> {
int taskId = buf.readInt();
byte nItem = buf.readByte();
int taskId = buf.readInt();
byte nItem = buf.readByte();
SensorTaskAck taskAck = SensorTaskAck.builder()
.taskId(taskId)
.ackTimestamp(timeStamp)
.sensorStatus(new ArrayList<>(nItem))
.build();
SensorTaskAck taskAck = SensorTaskAck.builder().taskId(taskId).ackTimestamp(timeStamp).sensorStatus(new ArrayList<>(
nItem)).build();
for (int i = 0; i < nItem; i++) {
SensorTaskStatus taskStatus = SensorTaskStatus.builder()
.sensorId(buf.readInt())
.taskResult(CommonEnumHandler.codeOf(TaskResultName.class, buf.readByte()))
.tunnelName(CommonEnumHandler.codeOf(SensorControlTunnelName.class, buf.readByte()))
.build();
.sensorId(buf.readInt())
.taskResult(CommonEnumHandler.codeOf(TaskResultName.class,
buf.readByte()))
.tunnelName(CommonEnumHandler.codeOf(SensorControlTunnelName.class,
buf.readByte()))
.build();
taskAck.getSensorStatus().add(taskStatus);
}
MessageContent<SensorTaskAck> msgCtx = MessageContent.<SensorTaskAck>builder()
.msgType(msgType)
.msgSize(msgSize)
.msgBody(taskAck)
.build();
.msgType(msgType)
.msgSize(msgSize)
.msgBody(taskAck)
.build();
list.add(BaseBinaryProtocol.<SensorTaskAck>builder()
.msgLength(msgLength)
.version(version)
.cryptoType(cryptCytp)
.timeStamp(timeStamp)
.statusCode(statusCode)
.msgContent(msgCtx)
.build());
.msgLength(msgLength)
.version(version)
.cryptoType(cryptCytp)
.timeStamp(timeStamp)
.statusCode(statusCode)
.msgContent(msgCtx)
.build());
}
case COMMAND_REPORT_QUERY_SENSOR -> {
int nItems = buf.readByte();
int nItems = buf.readByte();
SensorStatusAck sensorAck = SensorStatusAck.builder().sensorStatus(new ArrayList<>()).build();
MessageContent<SensorStatusAck> msgCtx = MessageContent.<SensorStatusAck>builder().msgType(
msgType).msgSize(msgSize).msgBody(sensorAck).build();
MessageContent<SensorStatusAck> msgCtx = MessageContent.<SensorStatusAck>builder()
.msgType(msgType)
.msgSize(msgSize)
.msgBody(sensorAck)
.build();
for (int i = 0; i < nItems; i++) {
short tmInfo = buf.readShort();
SensorControlTunnelName tn = CommonEnumHandler.codeOf(SensorControlTunnelName.class,
buf.readByte());
int cmdType = buf.readByte();
short sa = buf.readShort();
short sid = buf.readShort();
int warrStatus = buf.readByte();
int emg0 = buf.readByte();
int emg1 = buf.readByte();
int emg2 = buf.readByte();
int spk0 = buf.readByte();
int spk1 = buf.readByte();
int spk2 = buf.readByte();
int runStatus = buf.readByte();
byte[] signale = new byte[5];
short tmInfo = buf.readShort();
SensorControlTunnelName tn = CommonEnumHandler.codeOf(SensorControlTunnelName.class, buf.readByte());
int cmdType = buf.readByte();
short sa = buf.readShort();
short sid = buf.readShort();
int warrStatus = buf.readByte();
int emg0 = buf.readByte();
int emg1 = buf.readByte();
int emg2 = buf.readByte();
int spk0 = buf.readByte();
int spk1 = buf.readByte();
int spk2 = buf.readByte();
int runStatus = buf.readByte();
byte[] signale = new byte[5];
buf.readBytes(signale, 0, 5);
byte[] id = new byte[3];
buf.readBytes(id, 0, 3);
SensorStatusInfo si = SensorStatusInfo.builder()
.dtInfo(tmInfo)
.tunnelName(tn)
.command(cmdType)
.startAddr(sa)
.sensorId(sid)
.warrningStatus(warrStatus)
.emergenStatus0(emg0)
.emergenStatus1(emg1)
.emergenStatus2(emg2)
.speakerStatus0(spk0)
.speakerStatus1(spk1)
.speakerStatus2(spk2)
.runStatus(runStatus)
.signalStrength(HelperUtils.bytesToHexString(signale))
.beidouId(HelperUtils.bytesToHexString(id))
.build();
.dtInfo(tmInfo)
.tunnelName(tn)
.command(cmdType)
.startAddr(sa)
.sensorId(sid)
.warrningStatus(warrStatus)
.emergenStatus0(emg0)
.emergenStatus1(emg1)
.emergenStatus2(emg2)
.speakerStatus0(spk0)
.speakerStatus1(spk1)
.speakerStatus2(spk2)
.runStatus(runStatus)
.signalStrength(HelperUtils.bytesToHexString(signale))
.beidouId(HelperUtils.bytesToHexString(id))
.build();
sensorAck.getSensorStatus().add(si);
}
list.add(BaseBinaryProtocol.<SensorStatusAck>builder()
.msgLength(msgLength)
.version(version)
.cryptoType(cryptCytp)
.timeStamp(timeStamp)
.statusCode(statusCode)
.msgContent(msgCtx)
.build());
.msgLength(msgLength)
.version(version)
.cryptoType(cryptCytp)
.timeStamp(timeStamp)
.statusCode(statusCode)
.msgContent(msgCtx)
.build());
}
default -> log.error("Unsupport Command: {}({})", cmd, msgType);
}

View File

@ -2,7 +2,6 @@ package com.zjyr.beidouservice.adapter.impl.netty.encode;
import com.zjyr.beidouservice.pojo.vo.binary.BaseBinaryProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldPrepender;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,6 +1,5 @@
package com.zjyr.beidouservice.adapter.impl.netty.encode;
import com.zjyr.beidouservice.common.impl.AlarmModeName;
import com.zjyr.beidouservice.common.impl.ControlCommandName;
import com.zjyr.beidouservice.pojo.vo.binary.BaseBinaryProtocol;
import com.zjyr.beidouservice.pojo.vo.binary.HeartProtocol;
@ -19,12 +18,10 @@ import org.springframework.stereotype.Component;
@Slf4j
public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryProtocol<T>> {
@Override
protected void encode(ChannelHandlerContext channelHandlerContext,
BaseBinaryProtocol<T> baseBinaryProtocol,
ByteBuf byteBuf) {
protected void encode(ChannelHandlerContext channelHandlerContext, BaseBinaryProtocol<T> baseBinaryProtocol, ByteBuf byteBuf) {
if (baseBinaryProtocol == null || baseBinaryProtocol.getMsgContent() == null ||
baseBinaryProtocol.getMsgContent().getMsgBody() == null) {
baseBinaryProtocol.getMsgContent().getMsgBody() == null) {
return;
}
@ -47,7 +44,7 @@ public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryPr
byteBuf.writeByte(msg.getAlarmMode().getValue().byteValue());
byteBuf.writeByte(msg.getAlarmMode().getValue().byteValue());
byteBuf.writeByte(msg.getAlarmType().getValue().byteValue());
byteBuf.writeByte(msg.getControlTunnel().getValue().byteValue());
byteBuf.writeByte(msg.getControlTunnel().byteValue());
byteBuf.writeInt(msg.getTimeStamp());
if (msg.getCityCode().isEmpty()) {
@ -71,7 +68,7 @@ public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryPr
if (msg.getSensorId().isEmpty()) {
byteBuf.writeByte(0);
} else {
byteBuf.writeByte(msg.getSensorId().size() * 4);
byteBuf.writeByte(msg.getSensorId().size());
for (var c : msg.getSensorId()) {
byteBuf.writeInt(c);
}

View File

@ -27,6 +27,6 @@ public class SocketNotifyEvent extends ApplicationEvent {
this.socketEvent = evtType;
this.evtMessage = evtMessage;
this.ctxChannel = ctx;
this.timeStamp = (int)(System.currentTimeMillis() / 1000);
this.timeStamp = (int) (System.currentTimeMillis() / 1000);
}
}

View File

@ -36,10 +36,7 @@ public final class CommonEnumHandler<E extends EnumerationBase> extends BaseType
}
@Override
public void setNonNullParameter(PreparedStatement preparedStatement,
int i,
E e,
JdbcType jdbcType) throws SQLException {
public void setNonNullParameter(PreparedStatement preparedStatement, int i, E e, JdbcType jdbcType) throws SQLException {
preparedStatement.setInt(i, e.getValue());
}

View File

@ -7,7 +7,7 @@ public enum TaskResultName implements EnumerationBase {
TASK_RESULT_FAILED(1, "TASK_RESULT_FAILED"),
;
private final Integer code;
private final String desc;
private final String desc;
TaskResultName(int val, String desc) {
this.code = val;

View File

@ -16,7 +16,7 @@ public enum AlarmTypeEnum {
private final Integer code;
private final String msg;
private final String msg;
public static String getByCode(Integer code) {
AlarmTypeEnum[] values = AlarmTypeEnum.values();
@ -30,7 +30,7 @@ public enum AlarmTypeEnum {
public static List<Integer> getAllCodes() {
AlarmTypeEnum[] values = AlarmTypeEnum.values();
List<Integer> codes = new ArrayList<>();
List<Integer> codes = new ArrayList<>();
for (AlarmTypeEnum v : values) {
codes.add(v.getCode());
}

View File

@ -32,7 +32,7 @@ public enum ManufacturerTypeEnum {
public static List<Integer> getAllCodes() {
ManufacturerTypeEnum[] values = ManufacturerTypeEnum.values();
List<Integer> codes = new ArrayList<>();
List<Integer> codes = new ArrayList<>();
for (ManufacturerTypeEnum v : values) {
codes.add(v.getCode());
}

View File

@ -1,7 +1,12 @@
package com.zjyr.beidouservice.controller;
import com.zjyr.beidouservice.common.impl.AlarmControlTypeName;
import com.zjyr.beidouservice.common.impl.AlarmModeName;
import com.zjyr.beidouservice.common.impl.AlarmTypeName;
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
import com.zjyr.beidouservice.pojo.dto.BaseProtocolDTO;
import com.zjyr.beidouservice.pojo.dto.GetUserConfig;
import com.zjyr.beidouservice.pojo.vo.binary.SensorControlProtocol;
import com.zjyr.beidouservice.service.AdapterProtocolService;
import com.zjyr.beidouservice.service.BaidouAdapterService;
import jakarta.annotation.Resource;
@ -14,8 +19,11 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.Date;
@Controller
//@RequestMapping(value = "/auth")
@ -37,33 +45,22 @@ public class AuthUser {
@PostMapping("/sensor/control")
@ResponseBody
public String getUserConfig(@RequestBody BaseProtocolDTO<GetUserConfig> mr, @RequestHeader HttpHeaders headers) {
// List<BeidouAdapterControlContent> adapterInfo = new ArrayList<>();
//
// for (int i = 0; i < 2; i++) {
//// adapterInfo.add(BeidouAdapterControlContent.builder()
//// .districtsCode(0x10 + i)
//// .sensorId(0x3f00 + i)
//// .controlAction(SensorControlActionName.ACTION_DISTRICTS_BASED)
//// .build());
// }
//
// SensorControlProtocol sp =
// adapterProtocolService.createSensorControlProtocol(SensorControlTunnelName.TUNNEL_BEIDOU,
// new byte[]{0x01, 0x02, 0x03},
// 8,
// 14,
// 20,
// 35,
// 3,
// 5,
// SensorControlModeName.CONTROL_TYPE_QUIET,
// 0,
// adapterProtocolService.createSensorCtrlInfo(
// adapterInfo));
// Long id = baidouAdapterService.getAllAdapter().get(0).getId();
// if (id != null) {
// baidouAdapterService.sendCommond(id, sp);
// }
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse("2023-08-30 18:24:30", pos);
SensorControlProtocol sensorPro = adapterProtocolService.createSensorControlProtocol(1024,
AlarmModeName.ALARM_MODE_MANUALLY,
AlarmControlTypeName.ALARM_CONTROL_TYPE_TEST_QUITE,
AlarmTypeName.ALARM_TYPE_AIRATTACK,
SensorControlTunnelName.TUNNEL_BEIDOU.getValue() |
SensorControlTunnelName.TUNNEL_WIRELESS.getValue(),
strtodate,
new ArrayList<>(),
new ArrayList<>(),
new ArrayList<>(Arrays.asList(0, 1, 2, 3)));
Long id = baidouAdapterService.getAllAdapter().get(0).getId();
baidouAdapterService.sendCommond(id, sensorPro);
return "{\"result\": 0}";
}

View File

@ -4,8 +4,8 @@ import com.zjyr.beidouservice.pojo.MyResp;
import com.zjyr.beidouservice.pojo.dto.city.CityRespDTO;
import com.zjyr.beidouservice.pojo.dto.city.CitySearchDTO;
import com.zjyr.beidouservice.pojo.dto.province.OnlyProvinceResp;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceSearchDTO;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceRespDTO;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceSearchDTO;
import com.zjyr.beidouservice.service.LocationService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
@ -30,6 +30,7 @@ public class LocationController {
OnlyProvinceResp onlyProvinceResp = locationService.getOnlyProvinces();
return MyResp.success(onlyProvinceResp);
}
@PostMapping("provinces")
public MyResp<ProvinceRespDTO> getProvinces(@RequestBody ProvinceSearchDTO provinceSearchDTO) {
ProvinceRespDTO provinceResp = locationService.getProvinces(provinceSearchDTO);

View File

@ -10,8 +10,7 @@ import java.util.List;
@Mapper
public interface DevAttributesMapper {
List<DevMaunDTO> selectManuByManufacturer(@Param("deviceId") Long deviceId,
@Param("manufacturer") String manufacturer);
List<DevMaunDTO> selectManuByManufacturer(@Param("deviceId") Long deviceId, @Param("manufacturer") String manufacturer);
List<DevAttributesDO> selectManuAll();

View File

@ -9,6 +9,5 @@ import java.util.List;
@Mapper
public interface LocCountyMapper {
List<LocCountyDO> selectCountyByCity(@Param("provinceCode") String provinceCode,
@Param("cityCode") String cityCode);
List<LocCountyDO> selectCountyByCity(@Param("provinceCode") String provinceCode, @Param("cityCode") String cityCode);
}

View File

@ -10,5 +10,6 @@ import java.util.List;
public interface LocProvinceMapper {
List<LocProvinceDO> selectAllProvince();
List<LocProvinceDO> selectProvince(@Param("provinceCode") String provinceCode);
}

View File

@ -11,33 +11,23 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class MyResp<T> {
private int code = Resp.SUCCESS.getCede();
private int code = Resp.SUCCESS.getCede();
private String msg;
private T data;
private T data;
public static MyResp build() {
return new MyResp();
}
public static MyResp result(Resp resp) {
return MyResp.builder()
.code(resp.getCede())
.msg(resp.getMsg())
.build();
return MyResp.builder().code(resp.getCede()).msg(resp.getMsg()).build();
}
public static <T> MyResp success(T data) {
return MyResp.builder()
.code(Resp.SUCCESS.getCede())
.msg(Resp.SUCCESS.getMsg())
.data(data)
.build();
return MyResp.builder().code(Resp.SUCCESS.getCede()).msg(Resp.SUCCESS.getMsg()).data(data).build();
}
public static MyResp error(Resp respEnum) {
return MyResp.builder()
.code(respEnum.getCede())
.msg(respEnum.getMsg())
.build();
return MyResp.builder().code(respEnum.getCede()).msg(respEnum.getMsg()).build();
}
}

View File

@ -1,29 +1,27 @@
package com.zjyr.beidouservice.pojo;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
public enum Resp {
//成功返回码
SUCCESS(200, "SUCCESS");
private int code;
private final int code;
private String msg;
@Getter
private final String msg;
Resp(int code, String msg) {
this.code = code;
this.msg = msg;
this.msg = msg;
}
public int getCede() {
return code;
}
public String getMsg() {
return msg;
}
@Override
public String toString() {
JSONObject json = new JSONObject();

View File

@ -28,7 +28,7 @@ public class DevAttributesDO {
private Date alarmInstallTime;
private String controlModel;
private String controlModel;
private Integer controlStatus;
private Integer controlManufacturer;

View File

@ -27,6 +27,6 @@ public class DevTaskDO {
private String execCmd;
private Integer execState;
private Date createTime;
private Date updateTime;
private Date createTime;
private Date updateTime;
}

View File

@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
public class AlarmDevContentDTO {
private String alarmType;
private String alarmType;
private Integer alarmNum;
private Double alarmRatio;

View File

@ -18,7 +18,7 @@ public class DeviceTaskContentDTO {
private String deviceName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date respTime;
private Integer execState;

View File

@ -18,7 +18,7 @@ public class DeviceTaskRespDTO {
private String taskId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date recodeTime;
private Integer deviceNum;

View File

@ -25,9 +25,9 @@ import javax.persistence.Table;
public class ControlDevice {
@Id
@KeySql(useGeneratedKeys = true)
private Long id;
private Long id;
private BeidouAdapterTypeName deviceType;
private String deviceAddr;
private String deviceAddr;
private Integer sendEnabled;
@ -35,7 +35,7 @@ public class ControlDevice {
private String beidouChannelStatus;
private String beidouSignalStrength;
private String beidouSignalStrength;
private Integer wirelessStatus;
private Integer telphoneStatus;
}

View File

@ -7,13 +7,13 @@ import lombok.Data;
@Builder
@Data
public class BeidouAdapterDevice {
private long id;
private long id;
private BeidouAdapterTypeName adapterType;
private String adapterAddr;
private int sendEnabled;
private int beidouStatus;
private String beidouChannelStatus;
private String beidouSignalStrength;
private int wirelessStatus;
private int telphoneStatus;
private String adapterAddr;
private int sendEnabled;
private int beidouStatus;
private String beidouChannelStatus;
private String beidouSignalStrength;
private int wirelessStatus;
private int telphoneStatus;
}

View File

@ -1,15 +1,17 @@
package com.zjyr.beidouservice.pojo.vo.binary;
import com.zjyr.beidouservice.common.impl.*;
import com.zjyr.beidouservice.common.impl.ControlChannelStatus;
import com.zjyr.beidouservice.common.impl.SendStatusName;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class ControllerStatus {
private byte[] beidouFreq;
private byte[] beidouSignalStrength;
private SendStatusName sendStatus;
private byte[] beidouFreq;
private byte[] beidouSignalStrength;
private int heartSeq;
private SendStatusName sendStatus;
private ControlChannelStatus beidouStatus;
private ControlChannelStatus wirelessStatus;
private ControlChannelStatus telphoneStatus;

View File

@ -3,15 +3,13 @@ package com.zjyr.beidouservice.pojo.vo.binary;
import lombok.Builder;
import lombok.Data;
import java.util.List;
@Data
@Builder
public class QuerySensorProtocol {
private byte province;
private byte city;
private byte nControlInfo;
private byte nControlInfo;
/**
* The Controll contents.
*/

View File

@ -3,7 +3,6 @@ package com.zjyr.beidouservice.pojo.vo.binary;
import com.zjyr.beidouservice.common.impl.AlarmControlTypeName;
import com.zjyr.beidouservice.common.impl.AlarmModeName;
import com.zjyr.beidouservice.common.impl.AlarmTypeName;
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
import lombok.Builder;
import lombok.Data;
@ -12,13 +11,13 @@ import java.util.List;
@Data
@Builder
public class SensorControlProtocol {
private int taskId;
private AlarmModeName alarmMode;
private int taskId;
private AlarmModeName alarmMode;
private AlarmControlTypeName alarmControlType;
private AlarmTypeName alarmType;
private SensorControlTunnelName controlTunnel;
private int timeStamp;
private List<Integer> cityCode;
private List<Integer> districtsCode;
private List<Integer> sensorId;
private AlarmTypeName alarmType;
private Integer controlTunnel;
private Integer timeStamp;
private List<Integer> cityCode;
private List<Integer> districtsCode;
private List<Integer> sensorId;
}

View File

@ -8,7 +8,7 @@ import java.util.List;
@Builder
@Data
public class SensorTaskAck {
private int taskId;
private int ackTimestamp;
private int taskId;
private int ackTimestamp;
private List<SensorTaskStatus> sensorStatus;
}

View File

@ -8,7 +8,7 @@ import lombok.Data;
@Builder
@Data
public class SensorTaskStatus {
private int sensorId;
private int sensorId;
private TaskResultName taskResult;
private SensorControlTunnelName tunnelName;

View File

@ -3,7 +3,6 @@ package com.zjyr.beidouservice.service;
import com.zjyr.beidouservice.common.impl.AlarmControlTypeName;
import com.zjyr.beidouservice.common.impl.AlarmModeName;
import com.zjyr.beidouservice.common.impl.AlarmTypeName;
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
import com.zjyr.beidouservice.pojo.vo.binary.HeartProtocol;
import com.zjyr.beidouservice.pojo.vo.binary.SensorControlProtocol;
@ -13,11 +12,15 @@ import java.util.List;
public interface AdapterProtocolService {
HeartProtocol createHeartProtocol();
SensorControlProtocol createSensorControlProtocol(AlarmModeName alarmMode, AlarmControlTypeName controlType,
AlarmTypeName alarmType, SensorControlTunnelName tunnelName,
SensorControlProtocol createSensorControlProtocol(int taskId,
AlarmModeName alarmMode,
AlarmControlTypeName controlType,
AlarmTypeName alarmType,
int tunnelName,
Date alarmDt,
List<Integer> citys,
List<Integer> areas,
List<Integer> sensors);
<T> Object createTransmissionProtocol(T proContent);
}

View File

@ -1,4 +1,5 @@
package com.zjyr.beidouservice.service;
import com.zjyr.beidouservice.pojo.dto.AlarmDevRespDTO;
import com.zjyr.beidouservice.pojo.dto.DeviceReqDTO;
import com.zjyr.beidouservice.pojo.dto.DeviceRespDTO;

View File

@ -4,13 +4,11 @@ import com.zjyr.beidouservice.pojo.dto.DevTaskExecRespDTO;
import com.zjyr.beidouservice.pojo.dto.DeviceTaskExecReqDTO;
import com.zjyr.beidouservice.pojo.dto.DeviceTaskRespDTO;
import java.util.List;
public interface DeviceTaskService {
List<DeviceTaskRespDTO> getDeviceTaskInfo();
DevTaskExecRespDTO deviceTaskExec(DeviceTaskExecReqDTO deviceTaskExecReqDTO);
}

View File

@ -3,11 +3,8 @@ package com.zjyr.beidouservice.service;
import com.zjyr.beidouservice.pojo.dto.city.CityRespDTO;
import com.zjyr.beidouservice.pojo.dto.city.CitySearchDTO;
import com.zjyr.beidouservice.pojo.dto.province.OnlyProvinceResp;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceSearchDTO;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceRespDTO;
import java.util.List;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceSearchDTO;
public interface LocationService {
OnlyProvinceResp getOnlyProvinces();

View File

@ -32,8 +32,7 @@ import static com.zjyr.beidouservice.common.impl.SocketEventName.SOCKET_EVT_CONN
@Service
@Slf4j
public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implements BaidouAdapterService,
ApplicationListener<T> {
public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implements BaidouAdapterService, ApplicationListener<T> {
private final ConcurrentHashMap<Long, ControlAdapterSocketCtx> ctxMap = new ConcurrentHashMap<>();
@Resource
@ -74,14 +73,14 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
if (evtContent instanceof SocketNotifyEvent event) {
InetSocketAddress sa = (InetSocketAddress) event.getCtxChannel().remoteAddress();
switch (event.getSocketEvent()) {
case SOCKET_EVT_CONNECT -> {
case SOCKET_EVT_CONNECT, SOCKET_EVT_IDLE_TIMEOUT -> {
sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol());
if (event.getSocketEvent() == SOCKET_EVT_CONNECT) {
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
.adapterAddr(sa.getAddress().getHostAddress())
.build();
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
.adapterAddr(sa.getAddress().getHostAddress())
.build();
addNewBeidouAdapter(a);
ControlAdapterSocketCtx sockCtx = new ControlAdapterSocketCtx(a.getId(), event.getCtxChannel());
@ -89,10 +88,6 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
}
}
case SOCKET_EVT_IDLE_TIMEOUT -> {
sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol());
}
case SOCKET_EVT_DISCONNECT -> {
for (ConcurrentHashMap.Entry<Long, ControlAdapterSocketCtx> entry : ctxMap.entrySet()) {
if (entry.getValue().getChannel().id() == event.getCtxChannel().id()) {
@ -104,19 +99,19 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
case SOCKET_EVT_RECV -> {
if (event.getEvtMessage() instanceof ControllerStatus status) {
log.info("+++{}, {}, {}",
status.getWirelessStatus(),
status.getTelphoneStatus(),
HelperUtils.bytesToHexString(status.getBeidouSignalStrength()));
status.getWirelessStatus(),
status.getTelphoneStatus(),
HelperUtils.bytesToHexString(status.getBeidouSignalStrength()));
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
.adapterAddr(sa.getAddress().getHostAddress())
.sendEnabled(status.getSendStatus().getValue())
.beidouStatus(status.getBeidouStatus().getValue())
.beidouChannelStatus(HelperUtils.bytesToHexString(status.getBeidouFreq()))
.beidouSignalStrength(HelperUtils.bytesToHexString(status.getBeidouSignalStrength()))
.wirelessStatus(status.getWirelessStatus().getValue())
.telphoneStatus(status.getTelphoneStatus().getValue())
.build();
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
.adapterAddr(sa.getAddress().getHostAddress())
.sendEnabled(status.getSendStatus().getValue())
.beidouStatus(status.getBeidouStatus().getValue())
.beidouChannelStatus(HelperUtils.bytesToHexString(status.getBeidouFreq()))
.beidouSignalStrength(HelperUtils.bytesToHexString(status.getBeidouSignalStrength()))
.wirelessStatus(status.getWirelessStatus().getValue())
.telphoneStatus(status.getTelphoneStatus().getValue())
.build();
addNewBeidouAdapter(a);
} /*else if (event.getEvtMessage() instanceof SensorCotrolAck ack) {
log.info("+++{}, {}, {}, {}, {}",
@ -143,16 +138,16 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
for (ControlDevice c : controlDevices) {
adapterDevices.add(BeidouAdapterDevice.builder()
.id(c.getId())
.adapterType(c.getDeviceType())
.adapterAddr(c.getDeviceAddr())
.sendEnabled(Optional.ofNullable(c.getSendEnabled()).orElse(0))
.beidouStatus(Optional.ofNullable(c.getBeidouStatus()).orElse(0))
.beidouChannelStatus(Optional.ofNullable(c.getBeidouChannelStatus()).orElse(""))
.beidouSignalStrength(Optional.ofNullable(c.getBeidouSignalStrength()).orElse(""))
.wirelessStatus(Optional.ofNullable(c.getWirelessStatus()).orElse(0))
.telphoneStatus(Optional.ofNullable(c.getTelphoneStatus()).orElse(0))
.build());
.id(c.getId())
.adapterType(c.getDeviceType())
.adapterAddr(c.getDeviceAddr())
.sendEnabled(Optional.ofNullable(c.getSendEnabled()).orElse(0))
.beidouStatus(Optional.ofNullable(c.getBeidouStatus()).orElse(0))
.beidouChannelStatus(Optional.ofNullable(c.getBeidouChannelStatus()).orElse(""))
.beidouSignalStrength(Optional.ofNullable(c.getBeidouSignalStrength()).orElse(""))
.wirelessStatus(Optional.ofNullable(c.getWirelessStatus()).orElse(0))
.telphoneStatus(Optional.ofNullable(c.getTelphoneStatus()).orElse(0))
.build());
}
return adapterDevices;
@ -164,20 +159,21 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
@Override
public void addNewBeidouAdapter(BeidouAdapterDevice adapter) {
ControlDevice device = ControlDevice.builder()
.id(adapter.getId())
.deviceType(adapter.getAdapterType())
.deviceAddr(adapter.getAdapterAddr())
.beidouStatus(adapter.getBeidouStatus())
.sendEnabled(adapter.getSendEnabled())
.beidouChannelStatus(adapter.getBeidouChannelStatus())
.beidouSignalStrength(adapter.getBeidouSignalStrength())
.wirelessStatus(adapter.getWirelessStatus())
.telphoneStatus(adapter.getTelphoneStatus())
.build();
.id(adapter.getId())
.deviceType(adapter.getAdapterType())
.deviceAddr(adapter.getAdapterAddr())
.beidouStatus(adapter.getBeidouStatus())
.sendEnabled(adapter.getSendEnabled())
.beidouChannelStatus(adapter.getBeidouChannelStatus())
.beidouSignalStrength(adapter.getBeidouSignalStrength())
.wirelessStatus(adapter.getWirelessStatus())
.telphoneStatus(adapter.getTelphoneStatus())
.build();
BeidouAdapterDevice dev = getAdapterByAddr(adapter.getAdapterAddr());
if (dev == null) {
controlDeviceMapper.addControlDevice(device);
} else {
device.setId(dev.getId());
adapter.setId(dev.getId());
controlDeviceMapper.upgradeControlDevice(device);
}

View File

@ -3,7 +3,6 @@ package com.zjyr.beidouservice.service.impl;
import com.zjyr.beidouservice.common.impl.AlarmControlTypeName;
import com.zjyr.beidouservice.common.impl.AlarmModeName;
import com.zjyr.beidouservice.common.impl.AlarmTypeName;
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
import com.zjyr.beidouservice.pojo.vo.binary.BaseBinaryProtocol;
import com.zjyr.beidouservice.pojo.vo.binary.HeartProtocol;
import com.zjyr.beidouservice.pojo.vo.binary.MessageContent;
@ -27,23 +26,27 @@ public class BeidouSocketProtocolServiceImpl implements AdapterProtocolService {
}
@Override
public SensorControlProtocol createSensorControlProtocol(AlarmModeName alarmMode,
public SensorControlProtocol createSensorControlProtocol(int taskId,
AlarmModeName alarmMode,
AlarmControlTypeName controlType,
AlarmTypeName alarmType,
SensorControlTunnelName tunnelName, Date alarmDt,
List<Integer> citys, List<Integer> areas,
int tunnelName,
Date alarmDt,
List<Integer> citys,
List<Integer> areas,
List<Integer> sensors) {
long timestamp = new Timestamp(alarmDt.getTime()).getTime();
long timestamp = new Timestamp(alarmDt.getTime()).getTime() / 1000;
return SensorControlProtocol.builder()
.alarmMode(alarmMode)
.alarmControlType(controlType)
.alarmType(alarmType)
.controlTunnel(tunnelName)
.timeStamp((int) timestamp)
.cityCode(citys)
.districtsCode(areas)
.sensorId(sensors)
.build();
.taskId(taskId)
.alarmMode(alarmMode)
.alarmControlType(controlType)
.alarmType(alarmType)
.controlTunnel(tunnelName)
.timeStamp((int) timestamp)
.cityCode(citys)
.districtsCode(areas)
.sensorId(sensors)
.build();
}
//

View File

@ -53,9 +53,9 @@ public class DeviceServiceImpl implements DeviceService {
}
devBasicInfoList.forEach(dev -> {
Long deviceId = dev.getDeviceId();
String manufacturer = deviceReqDTO.getManufacturer();
List<DevMaunDTO> devMaunDTO = devAttributesMapper.selectManuByManufacturer(deviceId, manufacturer);
Long deviceId = dev.getDeviceId();
String manufacturer = deviceReqDTO.getManufacturer();
List<DevMaunDTO> devMaunDTO = devAttributesMapper.selectManuByManufacturer(deviceId, manufacturer);
//根据过滤过厂商的device查找device基本信息
devMaunDTO.forEach(v -> {
DeviceRespDTO deviceResp = new DeviceRespDTO();
@ -87,8 +87,8 @@ public class DeviceServiceImpl implements DeviceService {
ManufacturerRespDTO manufacturerResp = new ManufacturerRespDTO();
//获取厂家名称和类型
List<ManufacturerContentDTO> contents = new ArrayList<>();
List<Integer> codeList = ManufacturerTypeEnum.getAllCodes();
codeList.forEach(v->{
List<Integer> codeList = ManufacturerTypeEnum.getAllCodes();
codeList.forEach(v -> {
ManufacturerContentDTO content = new ManufacturerContentDTO();
content.setManufacturerType(v);
content.setManufacturerName(ManufacturerTypeEnum.getByCode(v));
@ -102,7 +102,7 @@ public class DeviceServiceImpl implements DeviceService {
@Override
public AlarmDevRespDTO getAlarmDeviceInfo() {
AlarmDevRespDTO respDTO = new AlarmDevRespDTO();
AlarmDevRespDTO respDTO = new AlarmDevRespDTO();
List<AlarmDevContentDTO> contents = new ArrayList<>();
//获取所有的设备属性信息
@ -118,7 +118,7 @@ public class DeviceServiceImpl implements DeviceService {
List<Integer> typeList = AlarmTypeEnum.getAllCodes();
typeList.forEach(type -> {
AlarmDevContentDTO content = new AlarmDevContentDTO();
String typeMsg = AlarmTypeEnum.getByCode(type);
String typeMsg = AlarmTypeEnum.getByCode(type);
log.info("alarm type :[{}]", typeMsg);
//过滤出不同类型的设备属性

View File

@ -48,9 +48,9 @@ public class DeviceTaskServiceImpl implements DeviceTaskService {
//告警任务回示率,收到响应信息的设备数量(执行成功执行失败)/总设备数量
int respNum = task.getExecNormalNum() + task.getExecAbnormalNum();
int deviceNum = task.getDeviceNum();
double respRate = (double) respNum / (double) deviceNum;
int respNum = task.getExecNormalNum() + task.getExecAbnormalNum();
int deviceNum = task.getDeviceNum();
double respRate = (double) respNum / (double) deviceNum;
//告警任务执行设备数量执行正常数量执行异常数量回示率
taskResp.setDeviceNum(deviceNum);
@ -60,7 +60,7 @@ public class DeviceTaskServiceImpl implements DeviceTaskService {
//获取任务id详细信息
List<DeviceTaskContentDTO> devTaskContents = new ArrayList<>();
List<DevTaskDO> devTaskDOList = devTaskMapper.selectDevTaskByTaskId(task.getTaskId());
List<DevTaskDO> devTaskDOList = devTaskMapper.selectDevTaskByTaskId(task.getTaskId());
if (devTaskDOList.isEmpty()) {
log.warn("根据任务Id: [{}] 获取不到告警任务详情信息", task.getTaskId());
taskResp.setData(new ArrayList<>());

View File

@ -14,8 +14,8 @@ import com.zjyr.beidouservice.pojo.dto.province.CityContentDTO;
import com.zjyr.beidouservice.pojo.dto.province.OnlyProvinceContentDTO;
import com.zjyr.beidouservice.pojo.dto.province.OnlyProvinceResp;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceContent;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceSearchDTO;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceRespDTO;
import com.zjyr.beidouservice.pojo.dto.province.ProvinceSearchDTO;
import com.zjyr.beidouservice.service.LocationService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
@ -38,7 +38,7 @@ public class LocationServiceImpl implements LocationService {
@Override
public OnlyProvinceResp getOnlyProvinces() {
OnlyProvinceResp onlyProvinceResp = new OnlyProvinceResp();
OnlyProvinceResp onlyProvinceResp = new OnlyProvinceResp();
List<OnlyProvinceContentDTO> onlyProvinceList = new ArrayList<>();
//获取省份信息
@ -48,7 +48,7 @@ public class LocationServiceImpl implements LocationService {
return new OnlyProvinceResp();
}
provinceDOS.forEach(province ->{
provinceDOS.forEach(province -> {
OnlyProvinceContentDTO onlyProvinceContent = new OnlyProvinceContentDTO();
onlyProvinceContent.setProvinceName(province.getProvinceName());
onlyProvinceContent.setProvinceCode(province.getProvinceCode());
@ -61,12 +61,12 @@ public class LocationServiceImpl implements LocationService {
@Override
public ProvinceRespDTO getProvinces(ProvinceSearchDTO provinceSearchDTO) {
ProvinceRespDTO provinceResp = new ProvinceRespDTO();
ProvinceRespDTO provinceResp = new ProvinceRespDTO();
List<ProvinceContent> provinceContents = new ArrayList<>();
//获取省份信息
String provinceCode = provinceSearchDTO.getProvinceCode();
List<LocProvinceDO> provinceDOS = locProvinceMapper.selectProvince(provinceCode);
String provinceCode = provinceSearchDTO.getProvinceCode();
List<LocProvinceDO> provinceDOS = locProvinceMapper.selectProvince(provinceCode);
if (provinceDOS.isEmpty()) {
log.warn("不存在省份信息");
return new ProvinceRespDTO();
@ -80,7 +80,7 @@ public class LocationServiceImpl implements LocationService {
//根据省份查询对应的地市信息
List<CityContentDTO> cityContentDTOList = new ArrayList<>();
List<LocCityDO> cityDOList = locCityMapper.selectCityByProvince(province.getProvinceCode());
List<LocCityDO> cityDOList = locCityMapper.selectCityByProvince(province.getProvinceCode());
cityDOList.forEach(city -> {
CityContentDTO cityContent = new CityContentDTO();
cityContent.setCityName(city.getCityName());
@ -100,13 +100,13 @@ public class LocationServiceImpl implements LocationService {
@Override
public CityRespDTO getCity(CitySearchDTO citySearchDTO) {
CityRespDTO cityResp = new CityRespDTO();
CityRespDTO cityResp = new CityRespDTO();
List<CityCountyDTO> cityContents = new ArrayList<>();
//获取地市信息
String provinceCode = citySearchDTO.getProvinceCode();
String cityCode = citySearchDTO.getCityCode();
List<LocCityDO> cityDOS = locCityMapper.selectCity(provinceCode, cityCode);
String provinceCode = citySearchDTO.getProvinceCode();
String cityCode = citySearchDTO.getCityCode();
List<LocCityDO> cityDOS = locCityMapper.selectCity(provinceCode, cityCode);
if (cityDOS.isEmpty()) {
log.warn("不存在地市信息");
return new CityRespDTO();
@ -120,7 +120,7 @@ public class LocationServiceImpl implements LocationService {
//根据地市查询对应的区信息
List<CountyContent> countyContentList = new ArrayList<>();
List<LocCountyDO> countyDOList = locCountyMapper.selectCountyByCity(city.getProvinceCode(), city.getCityCode());
List<LocCountyDO> countyDOList = locCountyMapper.selectCountyByCity(city.getProvinceCode(), city.getCityCode());
countyDOList.forEach(county -> {
CountyContent countyContent = new CountyContent();
countyContent.setCountyName(county.getCountyName());

View File

@ -74,12 +74,8 @@ public class SensorDataServiceImpl implements SensorDataService {
.startAddr(v.getStartAddr().intValue())
.dtInfo(v.getDtInfo().intValue())
.warrningStatus(v.getWarrningStatus())
.emergStatus(createStatusMapValue(v.getEmergenStatus0(),
v.getEmergenStatus1(),
v.getEmergenStatus2()))
.spearkStatus(createStatusMapValue(v.getSpeakerStatus0(),
v.getSpeakerStatus1(),
v.getSpeakerStatus2()))
.emergStatus(createStatusMapValue(v.getEmergenStatus0(), v.getEmergenStatus1(), v.getEmergenStatus2()))
.spearkStatus(createStatusMapValue(v.getSpeakerStatus0(), v.getSpeakerStatus1(), v.getSpeakerStatus2()))
.runStatus(v.getRunStatus())
.signalStrength(v.getSignalStrength())
.beidouId(v.getBeidouId())

View File

@ -27,20 +27,16 @@
</select>
<update id="upgradeControlDevice" parameterType="com.zjyr.beidouservice.pojo.entry.ControlDevice">
INSERT IGNORE INTO control_device(deviceAddr, deviceType, sendEnabled, beidouStatus, beidouChannelStatus,
beidouSignalStrength, wirelessStatus, telphoneStatus)
SELECT #{device.deviceAddr},
#{device.deviceType},
#{device.sendEnabled},
#{device.beidouStatus},
#{device.beidouChannelStatus},
#{device.beidouSignalStrength},
#{device.wirelessStatus},
#{device.telphoneStatus}
FROM DUAL
WHERE NOT EXISTS (SELECT deviceAddr
FROM control_device
WHERE deviceAddr = #{device.deviceAddr})
UPDATE control_device
SET deviceAddr = #{device.deviceAddr},
deviceType = #{device.deviceType},
sendEnabled = #{device.sendEnabled},
beidouStatus = #{device.beidouStatus},
beidouChannelStatus = #{device.beidouChannelStatus},
beidouSignalStrength = #{device.beidouSignalStrength},
wirelessStatus = #{device.wirelessStatus},
telphoneStatus = #{device.telphoneStatus}
WHERE deviceAddr = #{device.deviceAddr}
</update>
<insert id="addControlDevice" useGeneratedKeys="true" keyProperty="id"